diff --git a/Models.dia b/Models.dia index c3269c3a..8b46d74c 100644 Binary files a/Models.dia and b/Models.dia differ diff --git a/app/assets/images/icons/section-table.png b/app/assets/images/icons/section-table.png new file mode 100644 index 00000000..a757154c Binary files /dev/null and b/app/assets/images/icons/section-table.png differ diff --git a/app/assets/images/icons/section-table.svg b/app/assets/images/icons/section-table.svg new file mode 100644 index 00000000..7fa11df9 --- /dev/null +++ b/app/assets/images/icons/section-table.svg @@ -0,0 +1,159 @@ + + + + + Dining table + + + + + + + + + + + + + image/svg+xml + + Dining table + 17.02.2012 + + + Ozer Kavak + + + + + http://www.nestingo.com + + + http://www.nestingo.com/masa-sandalye/masalar/14-mutfak-masasi-efes7070.html + + + wood + dining + table + + + Based on wooden dining table NestinGo - Efes7070 at: http://www.nestingo.com/masa-sandalye/masalar/14-mutfak-masasi-efes7070.html + + + Ozer Kavak + + + + + + + + + + + + + + + diff --git a/app/assets/images/textures/wood1.jpg b/app/assets/images/textures/wood1.jpg new file mode 100644 index 00000000..e0f2d683 Binary files /dev/null and b/app/assets/images/textures/wood1.jpg differ diff --git a/app/assets/images/textures/wood2.jpg b/app/assets/images/textures/wood2.jpg new file mode 100644 index 00000000..986e677d Binary files /dev/null and b/app/assets/images/textures/wood2.jpg differ diff --git a/app/assets/images/textures/wood3.jpg b/app/assets/images/textures/wood3.jpg new file mode 100644 index 00000000..a77b45aa Binary files /dev/null and b/app/assets/images/textures/wood3.jpg differ diff --git a/app/assets/images/textures/wood4.jpg b/app/assets/images/textures/wood4.jpg new file mode 100644 index 00000000..31b37f21 Binary files /dev/null and b/app/assets/images/textures/wood4.jpg differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8819730e..4dbf3ebb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require jquery //= require jquery_ujs +//= require jquery-ui //= require twitter/bootstrap //= require_directory . //= require_self diff --git a/app/assets/javascripts/qsupplier.js.coffee b/app/assets/javascripts/qsupplier.js.coffee new file mode 100644 index 00000000..a205f602 --- /dev/null +++ b/app/assets/javascripts/qsupplier.js.coffee @@ -0,0 +1,54 @@ +root = exports ? this +root.Qsupplier= + move_table_to_active_section: (table_id)-> + table_container = $('#section-table-'+table_id) + section_container = $('.section-tables-active') + section_container.append(table_container) + Qsupplier.position_table_in_active_section(section_container, table_container) + position_table_in_active_section: (section_container, table_container)-> + button_container = table_container.find('.action-button-container') + button_container.html('') + button_container.append($('').click( -> Qsupplier.move_table_to_inactive_section(table_container.data('table-id')) )) + position_x = parseFloat(table_container.data('position-x')) + position_y = parseFloat(table_container.data('position-y')) + table_container.css('left', section_container.width()*position_x/current_section_width) + table_container.css('top', section_container.height()*position_y/current_section_height) + #TODO place element at 0.0 if it happens to be outside the region + table_container.show() + table_container.draggable( + containment: section_container, + stop: -> + position_x = current_section_width * $(this).position().left / section_container.width() + position_y = current_section_height * $(this).position().top / section_container.height() + table_container.data('position-x', position_x) + table_container.data('position-y', position_y) + $.ajax( + type: 'PUT', + url: '/supplier/tables/'+table_container.data('table-id'), + data: {table: {position_x: position_x, position_y: position_y}}, + dataType: 'json' + ) + ) + #TODO make ajax call safe + $.ajax( + type: 'PUT', + url: '/supplier/tables/'+table_container.data('table-id'), + data: {table: {section_id: current_section_id}}, + dataType: 'json' + ) + move_table_to_inactive_section: (table_id)-> + table_container = $('#section-table-'+table_id) + table_container.css('left', 'auto') + table_container.css('top', 'auto') + section_container = $('.section-tables-inactive') + section_container.prepend(table_container) + button_container = table_container.find('.action-button-container') + button_container.html('') + button_container.append($('').click( -> Qsupplier.move_table_to_active_section(table_container.data('table-id')) )) + #TODO make ajax call safe + $.ajax( + type: 'PUT', + url: '/supplier/tables/'+table_container.data('table-id'), + data: {table: {section_id: ''}}, + dataType: 'json' + ) diff --git a/app/assets/stylesheets/structure.css.sass b/app/assets/stylesheets/structure.css.sass index 89ce440d..13699164 100644 --- a/app/assets/stylesheets/structure.css.sass +++ b/app/assets/stylesheets/structure.css.sass @@ -3,6 +3,8 @@ table th &.currency text-align: right + &.numeric + text-align: right tbody td &.status-icons diff --git a/app/assets/stylesheets/tablet/structure.css.sass b/app/assets/stylesheets/tablet/structure.css.sass index e2a448ee..75dfc0e6 100644 --- a/app/assets/stylesheets/tablet/structure.css.sass +++ b/app/assets/stylesheets/tablet/structure.css.sass @@ -11,3 +11,28 @@ body margin-top: 4px margin-bottom: 6px padding-bottom: 0 +.section-tables-container + .section-table + background-color: #ccc + height: 44px + background-repeat: no-repeat + width: 45px + background-image: image-url('icons/section-table.png') + .table-number + margin-top: -45px + .action-button-container + margin-right: -20px + &.section-tables-active + position: relative + padding: 0 + height: 400px + background-image: image-url('textures/wood4.jpg') + .section-table + position: absolute + cursor: move + &.section-tables-inactive + .section-table + margin-top: 10px + margin-bottom: 30px + float: left + margin-right: 30px diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 59ebb86a..f2e427f6 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -5,6 +5,10 @@ class DashboardController < ApplicationController end + + def demo_both + end + # Testing action def select_qrcode @tables = Table.all diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb new file mode 100644 index 00000000..400a7e0e --- /dev/null +++ b/app/controllers/sections_controller.rb @@ -0,0 +1,90 @@ +class SectionsController < ApplicationController + before_filter :set_relation_options, only: [:new, :edit, :create, :update] + # GET /sections + # GET /sections.json + def index + @sections = Section.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @sections } + end + end + + # GET /sections/1 + # GET /sections/1.json + def show + @section = Section.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @section } + end + end + + # GET /sections/new + # GET /sections/new.json + def new + @section = Section.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @section } + end + end + + # GET /sections/1/edit + def edit + @section = Section.find(params[:id]) + end + + # POST /sections + # POST /sections.json + def create + @section = Section.new(params[:section]) + + respond_to do |format| + if @section.save + format.html { redirect_to @section, notice: t('action.create.successfull', model: Section.model_name.human) } + format.json { render json: @section, status: :created, location: @section } + else + format.html { render action: "new" } + format.json { render json: @section.errors, status: :unprocessable_entity } + end + end + end + + # PUT /sections/1 + # PUT /sections/1.json + def update + @section = Section.find(params[:id]) + + respond_to do |format| + if @section.update_attributes(params[:section]) + format.html { redirect_to @section, notice: t('action.update.successfull', model: Section.model_name.human) } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @section.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sections/1 + # DELETE /sections/1.json + def destroy + @section = Section.find(params[:id]) + @section.destroy + + respond_to do |format| + format.html { redirect_to sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) } + format.json { head :no_content } + end + end + + private + + def set_relation_options + @suppliers = Supplier.all + end +end diff --git a/app/controllers/suppliers/application_controller.rb b/app/controllers/suppliers/application_controller.rb new file mode 100644 index 00000000..9440529a --- /dev/null +++ b/app/controllers/suppliers/application_controller.rb @@ -0,0 +1,6 @@ +module Suppliers + class ApplicationController < ::ApplicationController + layout 'tablet' + + end +end diff --git a/app/controllers/suppliers/sections_controller.rb b/app/controllers/suppliers/sections_controller.rb new file mode 100644 index 00000000..e13ef6af --- /dev/null +++ b/app/controllers/suppliers/sections_controller.rb @@ -0,0 +1,87 @@ +module Suppliers + class SectionsController < Suppliers::ApplicationController + + # GET /sections + # GET /sections.json + def index + @sections = current_supplier.sections + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @sections } + end + end + + # GET /sections/1 + # GET /sections/1.json + def show + @section = Section.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @section } + end + end + + # GET /sections/new + # GET /sections/new.json + def new + @section = Section.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @section } + end + end + + # GET /sections/1/edit + def edit + @section = Section.find(params[:id]) + end + + # POST /sections + # POST /sections.json + def create + @section = Section.new(params[:section]) + @section.supplier = current_supplier + + respond_to do |format| + if @section.save + format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) } + format.json { render json: @section, status: :created, location: @section } + else + format.html { render action: "new" } + format.json { render json: @section.errors, status: :unprocessable_entity } + end + end + end + + # PUT /sections/1 + # PUT /sections/1.json + def update + @section = Section.find(params[:id]) + + respond_to do |format| + if @section.update_attributes(params[:section]) + format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @section.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sections/1 + # DELETE /sections/1.json + def destroy + @section = Section.find(params[:id]) + @section.destroy + + respond_to do |format| + format.html { redirect_to suppliers_sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) } + format.json { head :no_content } + end + end + end +end diff --git a/app/controllers/suppliers/tables_controller.rb b/app/controllers/suppliers/tables_controller.rb new file mode 100644 index 00000000..73cfe474 --- /dev/null +++ b/app/controllers/suppliers/tables_controller.rb @@ -0,0 +1,89 @@ +module Suppliers + class TablesController < Suppliers::ApplicationController + # GET /tables + # GET /tables.json + def index + @tables = current_supplier.tables + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @tables } + end + end + + # GET /tables/1 + # GET /tables/1.json + def show + @table = Table.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @table } + end + end + + # GET /tables/new + # GET /tables/new.json + def new + @table = Table.new + @table.section_id = params[:section_id].presence + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @table } + end + end + + # GET /tables/1/edit + def edit + @table = Table.find(params[:id]) + end + + # POST /tables + # POST /tables.json + def create + @table = Table.new(params[:table]) + @table.supplier = current_supplier + + respond_to do |format| + if @table.save + format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.create.successfull', model: Table.model_name.human) } + format.json { render json: @table, status: :created, location: @table } + else + format.html { render action: "new" } + format.json { render json: @table.errors, status: :unprocessable_entity } + end + end + end + + # PUT /tables/1 + # PUT /tables/1.json + def update + @table = Table.find(params[:id]) + + respond_to do |format| + if @table.update_attributes(params[:table]) + format.html { redirect_to [:suppliers, @table], notice: t('action.update.successfull', model: Table.model_name.human) } + format.json { head :no_content } + format.js { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @table.errors, status: :unprocessable_entity } + format.js { head :no_content } + end + end + end + + # DELETE /tables/1 + # DELETE /tables/1.json + def destroy + @table = Table.find(params[:id]) + @table.destroy + + respond_to do |format| + format.html { redirect_to suppliers_tables_url, notice: t('action.destroy.successfull', model: Table.model_name.human) } + format.json { head :no_content } + end + end + end +end diff --git a/app/models/section.rb b/app/models/section.rb new file mode 100644 index 00000000..08f05ad5 --- /dev/null +++ b/app/models/section.rb @@ -0,0 +1,40 @@ +class Section + include SimplyStored::Couch + + property :title + + property :path, type: Array, default: [] + + belongs_to :supplier + has_many :tables + + attr_protected :supplier_id + + validates :supplier_id, presence: true + + def width + self.path.last.try(:first).to_f - self.path.first.try(:first).to_f + end + def height + self.path.last.try(:last).to_f - self.path.first.try(:last).to_f + end + + def width=(val) + val = val.to_f + self.path[0] ||= [0.0, 0.0] + self.path[1] ||= [0.0, 0.0] + unless path[1][0] == val + self.path[1][0] = val + path_will_change! + end + end + def height=(val) + val = val.to_f + self.path[0] ||= [0.0, 0.0] + self.path[1] ||= [0.0, 0.0] + unless path[1][1] == val + self.path[1][1] = val + path_will_change! + end + end +end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index d7f17b4f..89f834db 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -10,6 +10,9 @@ class Supplier has_many :tables, dependent: :destroy #has_many :lists, through: :tables has_many :orders + has_many :sections, dependent: :destroy + + after_create :add_section_on_create def active_orders return @active_orders if @active_orders @@ -31,4 +34,14 @@ class Supplier tables end + def non_placed_tables + tables.reject{|t| t.section_id.present? } + end + + private + + def add_section_on_create + @section = Section.create supplier: self, title: I18n.t('section.first_section_title') + end + end diff --git a/app/models/table.rb b/app/models/table.rb index ec0d0d64..5042c97a 100644 --- a/app/models/table.rb +++ b/app/models/table.rb @@ -2,13 +2,19 @@ class Table include SimplyStored::Couch property :number, type: Fixnum, default: 1 + property :position_x, type: Float + property :position_y, type: Float belongs_to :supplier + belongs_to :section has_many :lists + attr_protected :supplier_id + validates :supplier_id, presence: true #validates :list_id, presence: true validates :number, numericality: {greater_than: 0} + validates_uniqueness_of :number view :active_lists, type: :custom, map_function: %|function(doc){ if(doc.ruby_class == 'List' && doc.state == 'active'){ @@ -20,4 +26,8 @@ class Table not self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero? end + def name + number + end + end diff --git a/app/views/dashboard/demo_both.html.slim b/app/views/dashboard/demo_both.html.slim new file mode 100644 index 00000000..83590aa8 --- /dev/null +++ b/app/views/dashboard/demo_both.html.slim @@ -0,0 +1,5 @@ +.phone-wrapper +iframe.phone-content-frame src=user_root_path + +.tablet-wrapper +iframe.tablet-content-frame src=supplier_root_path diff --git a/app/views/dashboard/home.html.slim b/app/views/dashboard/home.html.slim index 83590aa8..efa0e27d 100644 --- a/app/views/dashboard/home.html.slim +++ b/app/views/dashboard/home.html.slim @@ -1,5 +1,2 @@ -.phone-wrapper -iframe.phone-content-frame src=user_root_path - -.tablet-wrapper -iframe.tablet-content-frame src=supplier_root_path +.page-header + h1 Home diff --git a/app/views/layouts/tablet.html.slim b/app/views/layouts/tablet.html.slim index de96211b..223ae452 100644 --- a/app/views/layouts/tablet.html.slim +++ b/app/views/layouts/tablet.html.slim @@ -32,6 +32,8 @@ html lang="en" ul.nav#top-navigation-list li= link_to t('supplier.menu.active_orders', orders: Order.model_name.human_plural), supplier_active_orders_path li= link_to t('supplier.menu.active_lists', lists: List.model_name.human_plural), supplier_active_lists_path + li= link_to Section.model_name.human_plural, suppliers_sections_path + li= link_to Table.model_name.human_plural, suppliers_tables_path .container.nav-collapse .container @@ -48,6 +50,8 @@ html lang="en" .row .span12 = content_for?(:content) ? yield(:content) : yield + - if content_for?(:row) + .row= yield :row /! Javascripts \================================================== diff --git a/app/views/sections/_form.html.slim b/app/views/sections/_form.html.slim new file mode 100644 index 00000000..f7566f60 --- /dev/null +++ b/app/views/sections/_form.html.slim @@ -0,0 +1,18 @@ += form_for @section, html: {class: 'form-horizontal' } do |f| + = render 'error_messages', target: @section + .control-group class=(@section.errors[:title].any? ? 'error' : nil) + = f.label :title, class: 'control-label' + .controls + = f.text_field :title, class: 'text_field' + .control-group class=(@section.errors[:path].any? ? 'error' : nil) + = f.label :path, class: 'control-label' + .controls + = f.text_field :path, class: 'text_field' + .control-group class=(@section.errors[:supplier_id].any? ? 'error' : nil) + = f.label :supplier_id, Supplier.model_name.human, class: 'control-label' + .controls + = f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil + .form-actions + = f.submit nil, class: 'btn btn-primary' + ' + = link_to t("helpers.links.cancel"), sections_path, class: 'btn' diff --git a/app/views/sections/edit.html.slim b/app/views/sections/edit.html.slim new file mode 100644 index 00000000..3499adda --- /dev/null +++ b/app/views/sections/edit.html.slim @@ -0,0 +1,4 @@ +- model_class = Section +.page-header + = title :edit, model_class += render 'form' diff --git a/app/views/sections/index.html.slim b/app/views/sections/index.html.slim new file mode 100644 index 00000000..55b82051 --- /dev/null +++ b/app/views/sections/index.html.slim @@ -0,0 +1,26 @@ +- model_class = Section +.page-header= title :index, model_class +- if @sections.any? + table.table.table-striped + thead + tr + th= model_class.human_attribute_name(:title) + th= model_class.human_attribute_name(:path) + th= Supplier.model_name.human + th= model_class.human_attribute_name(:created_at) + th=t 'helpers.actions' + tbody + - @sections.each do |section| + tr + td= link_to section.title, section + td= section.path + td= link_to_if section.supplier.present?, section.supplier.try(:name), section.supplier + td=l section.created_at, format: :short + td + = link_to t('helpers.links.edit'), [:edit, section], class: 'btn btn-mini' + ' + = link_to t("helpers.links.destroy"), section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' +- else + = no_content_given model_class += link_to t("helpers.links.new"), new_section_path, class: 'btn btn-primary' + diff --git a/app/views/sections/new.html.slim b/app/views/sections/new.html.slim new file mode 100644 index 00000000..0838474a --- /dev/null +++ b/app/views/sections/new.html.slim @@ -0,0 +1,4 @@ +- model_class = Section +.page-header + = title :new, model_class += render 'form' diff --git a/app/views/sections/show.html.slim b/app/views/sections/show.html.slim new file mode 100644 index 00000000..c4eca468 --- /dev/null +++ b/app/views/sections/show.html.slim @@ -0,0 +1,18 @@ +- model_class = Section +.page-header= title :show, @section + +dl.dl-horizontal.show-list + dt= model_class.human_attribute_name(:title) + dd= @section.title + dt= model_class.human_attribute_name(:path) + dd= @section.path + - if @section.supplier.present? + dt= Supplier.model_name.human + dd= link_to @section.supplier.name, @section.supplier + +.form-actions + = link_to t("helpers.links.back"), sections_path, class: 'btn' + ' + = link_to t('helpers.links.edit'), [:edit, @section], class: 'btn' + ' + = link_to t("helpers.links.destroy"), @section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger' diff --git a/app/views/suppliers/sections/_form.html.slim b/app/views/suppliers/sections/_form.html.slim new file mode 100644 index 00000000..f87b8bd5 --- /dev/null +++ b/app/views/suppliers/sections/_form.html.slim @@ -0,0 +1,18 @@ += form_for [:suppliers, @section], html: {class: 'form-horizontal' } do |f| + = render 'error_messages', target: @section + .control-group class=(@section.errors[:title].any? ? 'error' : nil) + = f.label :title, class: 'control-label' + .controls + = f.text_field :title, class: 'text_field' + .control-group class=(@section.errors[:width].any? ? 'error' : nil) + = f.label :width, class: 'control-label' + .controls + = f.text_field :width, class: ['text_field', :numeric] + .control-group class=(@section.errors[:height].any? ? 'error' : nil) + = f.label :height, class: 'control-label' + .controls + = f.text_field :height, class: ['text_field', :numeric] + .form-actions + = f.submit nil, class: 'btn btn-primary' + ' + = link_to t("helpers.links.cancel"), suppliers_sections_path, class: 'btn' diff --git a/app/views/suppliers/sections/edit.html.slim b/app/views/suppliers/sections/edit.html.slim new file mode 100644 index 00000000..3499adda --- /dev/null +++ b/app/views/suppliers/sections/edit.html.slim @@ -0,0 +1,4 @@ +- model_class = Section +.page-header + = title :edit, model_class += render 'form' diff --git a/app/views/suppliers/sections/index.html.slim b/app/views/suppliers/sections/index.html.slim new file mode 100644 index 00000000..ba31fbcd --- /dev/null +++ b/app/views/suppliers/sections/index.html.slim @@ -0,0 +1,25 @@ +- model_class = Section +.page-header= title :index, model_class +- if @sections.any? + table.table.table-striped + thead + tr + th.link= model_class.human_attribute_name(:title) + th.numeric= model_class.human_attribute_name(:width) + th.numeric= model_class.human_attribute_name(:height) + th.timestamp= model_class.human_attribute_name(:created_at) + th.actions=t 'helpers.actions' + tbody + - @sections.each do |section| + tr + td.link= link_to section.title, [:suppliers, section] + td.numeric= section.width + td.numeric= section.height + td.timestamp=l section.created_at, format: :short + td.actions + = link_to t('helpers.links.edit'), [:edit, :suppliers, section], class: 'btn btn-mini' + ' + = link_to t("helpers.links.destroy"), [:suppliers, section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' +- else + = no_content_given model_class += link_to t("helpers.links.new"), new_suppliers_section_path, class: 'btn btn-primary' diff --git a/app/views/suppliers/sections/new.html.slim b/app/views/suppliers/sections/new.html.slim new file mode 100644 index 00000000..0838474a --- /dev/null +++ b/app/views/suppliers/sections/new.html.slim @@ -0,0 +1,4 @@ +- model_class = Section +.page-header + = title :new, model_class += render 'form' diff --git a/app/views/suppliers/sections/show.html.slim b/app/views/suppliers/sections/show.html.slim new file mode 100644 index 00000000..300033ab --- /dev/null +++ b/app/views/suppliers/sections/show.html.slim @@ -0,0 +1,41 @@ +- model_class = Section +.page-header= title :show, @section + +.form-actions + = link_to t("helpers.links.back"), suppliers_sections_path, class: 'btn' + ' + = link_to t('helpers.links.edit'), [:edit, :suppliers, @section], class: 'btn' + ' + = link_to t("helpers.links.destroy"), [:suppliers, @section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger' +- content_for :row do + ul.nav.nav-pills + - for section in @section.supplier.sections + li class=(section == @section ? 'active' : nil) = link_to section.title, [:suppliers, section] + .span9 + .well.section-tables-container.section-tables-active + - for table in @section.tables + .section-table.hide{ id="section-table-#{table.id}" data-position-x=table.position_x data-position-y=table.position_y data-table-id=table.id} + .pull-right.action-button-container + = link_to table.number, [:suppliers, table], class: 'btn btn-mini table-number' + .span3 + h3= t('table.has_no_section') + .well.section-tables-container.section-tables-inactive + - for table in @section.supplier.non_placed_tables + .section-table{ id="section-table-#{table.id}" data-position-x=table.position_x data-position-y=table.position_y data-table-id=table.id} + .pull-right.action-button-container + button.btn.btn-primary.btn-mini onClick="Qsupplier.move_table_to_active_section('#{table.id}')" + + = link_to table.number, [:suppliers, table], class: 'btn btn-mini table-number' + .clearfix +- content_for :footer do + javascript: + var current_section_id = '#{@section.id}'; + var current_section_width = #{@section.width}; + var current_section_height = #{@section.height}; + $(function(){ + var active_section_container = $('.section-tables-active') + active_section_container.css('width', active_section_container.width()); // break fluid layout + active_section_container.css('height', #{@section.height/@section.width}*active_section_container.width()); + active_section_container.find('.section-table').each(function(){ + Qsupplier.position_table_in_active_section(active_section_container, $(this)); + }); + }); diff --git a/app/views/suppliers/tables/_form.html.slim b/app/views/suppliers/tables/_form.html.slim new file mode 100644 index 00000000..67a124f6 --- /dev/null +++ b/app/views/suppliers/tables/_form.html.slim @@ -0,0 +1,14 @@ += form_for [:suppliers, @table], html: {class: 'form-horizontal' } do |f| + = render 'error_messages', target: @table + .control-group class=(@table.errors[:number].any? ? 'error' : nil) + = f.label :number, class: 'control-label' + .controls + = f.text_field :number, class: 'text_field' + .control-group class=(@table.errors[:section_id].any? ? 'error' : nil) + = f.label :section_id, Supplier.model_name.human, class: 'control-label' + .controls + = f.collection_select :section_id, current_supplier.sections, :id, :title, include_blank: "[#{t('table.has_no_section')}]" + .form-actions + = f.submit nil, class: 'btn btn-primary' + ' + = link_to t("helpers.links.cancel"), tables_path, class: 'btn' diff --git a/app/views/suppliers/tables/edit.html.slim b/app/views/suppliers/tables/edit.html.slim new file mode 100644 index 00000000..0f403e2a --- /dev/null +++ b/app/views/suppliers/tables/edit.html.slim @@ -0,0 +1,4 @@ +- model_class = Table +.page-header + = title :edit, model_class += render 'form' diff --git a/app/views/suppliers/tables/index.html.slim b/app/views/suppliers/tables/index.html.slim new file mode 100644 index 00000000..769f4c47 --- /dev/null +++ b/app/views/suppliers/tables/index.html.slim @@ -0,0 +1,24 @@ +- model_class = Table +div.page-header= title :index, model_class +- if @tables.any? + table.table.table-striped + thead + tr + th.link= model_class.human_attribute_name(:number) + th.link= Section.model_name.human + th.timestamp= model_class.human_attribute_name(:created_at) + th.actions=t 'helpers.actions' + tbody + - @tables.each do |table| + tr + td.link= link_to table.number, [:suppliers, table] + td.link= link_to_if table.section.present?, table.section.try(:title), [:suppliers, table.section] + td.timestamp=l table.created_at, format: :short + td.actions + = link_to t('helpers.links.edit'), [:edit, :suppliers, table], class: 'btn btn-mini' + ' + = link_to t("helpers.links.destroy"), [:suppliers, table], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' +- else + = no_content_given model_class += link_to t("helpers.links.new"), new_suppliers_table_path, class: 'btn btn-primary' + diff --git a/app/views/suppliers/tables/new.html.slim b/app/views/suppliers/tables/new.html.slim new file mode 100644 index 00000000..e30c254c --- /dev/null +++ b/app/views/suppliers/tables/new.html.slim @@ -0,0 +1,4 @@ +- model_class = Table +.page-header + = title :new, model_class += render 'form' diff --git a/app/views/suppliers/tables/show.html.slim b/app/views/suppliers/tables/show.html.slim new file mode 100644 index 00000000..9969c9c0 --- /dev/null +++ b/app/views/suppliers/tables/show.html.slim @@ -0,0 +1,16 @@ +- model_class = Table +.page-header= title :show, @table + +dl.dl-horizontal.show-list + dt= model_class.human_attribute_name(:number) + dd= @table.number + - if @table.section.present? + dt= Section.model_name.human + dd= link_to @table.section.title, [:suppliers, @table.section] + +.form-actions + = link_to t("helpers.links.back"), suppliers_tables_path, class: 'btn' + ' + = link_to t('helpers.links.edit'), [:edit, :suppliers, @table], class: 'btn' + ' + = link_to t("helpers.links.destroy"), [:suppliers, @table], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger' diff --git a/app/views/users/index.html.slim b/app/views/users/index.html.slim index 669c9c8f..686c150f 100644 --- a/app/views/users/index.html.slim +++ b/app/views/users/index.html.slim @@ -1,5 +1,5 @@ - model_class = User -div.page-header= title :index, model_class +.page-header= title :index, model_class - if @users.any? table.table.table-striped thead diff --git a/config/locales/en.yml b/config/locales/en.yml index c570e8ab..93d85b16 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -33,6 +33,7 @@ en: successfull: '%{model} is successfully destroyed' table: is_occupied: This table is occupied + has_no_section: "Not placed" activemodel: models: user: User @@ -42,6 +43,7 @@ en: product: Product order: Order product_category: Product category + section: Section plural: user: Users supplier: Restaurants @@ -50,6 +52,7 @@ en: product: Products order: Orders product_category: Product categories + section: Sections attributes: product: price: Price @@ -65,3 +68,5 @@ en: show_products: # The title gets products: Product.model_name.human_plural that can be used: e.g.: Showing %{products} title: Menu + section: + first_section_title: Room diff --git a/config/routes.rb b/config/routes.rb index 8cef3713..1fff0649 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,22 +1,24 @@ Qrammer::Application.routes.draw do devise_for :users devise_for :suppliers - resources :users - resources :tables do - member do - get :qrcode + authenticate :supplier do + resources :users + resources :tables do + member do + get :qrcode + end end - end - resources :orders do - member do - post :is_being_processed - post :is_delivered + resources :orders do + member do + post :is_being_processed + post :is_delivered + end end + resources :suppliers + resources :lists + resources :products + resources :product_categories end - resources :suppliers - resources :lists - resources :products - resources :product_categories get '/supplier' => 'supplier#home', as: :supplier_root get '/supplier/active_orders' => 'supplier#active_orders', as: :supplier_active_orders @@ -43,6 +45,12 @@ Qrammer::Application.routes.draw do match '/show_products' => 'dashboard#show_products', as: :user_products + namespace :suppliers, path: '/supplier' do + resources :sections + resources :tables + root to: 'sections#index' + end + match "/:action", controller: 'dashboard' # The priority is based upon order of creation: diff --git a/lib/generators/bootstrap/themed/templates/index.html.slim b/lib/generators/bootstrap/themed/templates/index.html.slim index e32c195d..3371ae83 100644 --- a/lib/generators/bootstrap/themed/templates/index.html.slim +++ b/lib/generators/bootstrap/themed/templates/index.html.slim @@ -1,5 +1,5 @@ - model_class = <%= resource_name.classify %> -div.page-header= title :index, model_class +.page-header= title :index, model_class - if @<%= plural_resource_name %>.any? table.table.table-striped thead @@ -10,22 +10,22 @@ div.page-header= title :index, model_class <%- belongs_to_associations.each do |association| -%> th= <%= association.options[:class_name] %>.model_name.human <%- end -%> - th= model_class.human_attribute_name(:created_at) - th=t 'helpers.actions' + th.timestamp= model_class.human_attribute_name(:created_at) + th.actions=t 'helpers.actions' tbody - @<%= plural_resource_name %>.each do |<%= resource_name %>| tr <%- columns.each.with_index do |column, index| -%> <%- if index.zero? -%> - td= link_to <%= resource_name %>.<%= column.name %>, <%= resource_name %> + td.link= link_to <%= resource_name %>.<%= column.name %>, <%= resource_name %> <%- else -%> td= <%= resource_name %>.<%= column.name %> <%- end end -%> <%- belongs_to_associations.each do |association| -%> - td= link_to_if <%= resource_name %>.<%= association.name %>.present?, <%= resource_name %>.<%= association.name %>.try(:<%= association.name_property %>), <%= resource_name %>.<%= association.name %> + td.link= link_to_if <%= resource_name %>.<%= association.name %>.present?, <%= resource_name %>.<%= association.name %>.try(:<%= association.name_property %>), <%= resource_name %>.<%= association.name %> <%- end -%> - td=l <%= resource_name %>.created_at, format: :short - td + td.timestamp=l <%= resource_name %>.created_at, format: :short + td.actions = link_to t('helpers.links.edit'), [:edit, <%= resource_name %>], class: 'btn btn-mini' ' = link_to t("helpers.links.destroy"), <%= resource_name %>, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger' diff --git a/spec/factories/section_factory.rb b/spec/factories/section_factory.rb new file mode 100644 index 00000000..ff8ab951 --- /dev/null +++ b/spec/factories/section_factory.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :section do + association :supplier + end +end diff --git a/spec/models/section_spec.rb b/spec/models/section_spec.rb new file mode 100644 index 00000000..44327820 --- /dev/null +++ b/spec/models/section_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe :section do + before :each do + @section = build :section + end + + describe :path do + describe :width do + it "should have zero width when initialized" do + Section.new.width.should be_zero + end + it "should have new width when it is defined using a setter" do + @section.width = 3.2 + @section.width.should == 3.2 + end + it "should persist width property through database" do + @section.width = 3.2 + @section.save + @reloaded_section = Section.find(@section.id) + @reloaded_section.width.should == 3.2 + end + end + describe :height do + it "should have zero height when initialized" do + Section.new.height.should be_zero + end + it "should have new height when it is defined using a setter" do + @section.height = 3.2 + @section.height.should == 3.2 + end + it "should persist height property through database" do + @section.height = 3.2 + @section.save + @reloaded_section = Section.find(@section.id) + @reloaded_section.height.should == 3.2 + end + + end + end + +end