diff --git a/app/assets/javascripts/admin/svg_element/svg_element.js.coffee b/app/assets/javascripts/admin/svg_element/svg_element.js.coffee index ce4428ed..3d287e0d 100644 --- a/app/assets/javascripts/admin/svg_element/svg_element.js.coffee +++ b/app/assets/javascripts/admin/svg_element/svg_element.js.coffee @@ -52,7 +52,7 @@ class SvgElementClass $(target).css('border', '1px solid black') @compileSource() compileSource: -> - source = @text_field.val() + return unless source = @text_field.val() results = $(@text_field.data('preview')) window.compiledJS = '' try diff --git a/app/assets/javascripts/supplier/app/application.js.coffee b/app/assets/javascripts/supplier/app/application.js.coffee index 4a2c0d75..a4293631 100644 --- a/app/assets/javascripts/supplier/app/application.js.coffee +++ b/app/assets/javascripts/supplier/app/application.js.coffee @@ -7,9 +7,11 @@ #= require shared-ember-helpers/all #= require ./app #= require_directory ./mixins +#= require_directory ./services #= require ./controllers/modals/base_controller #= require ion.sound #= require_tree . + @$assets_path = '/assets/' @EmberENV = {FEATURES: {'query-params-new': true}} @$days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'] diff --git a/app/assets/javascripts/supplier/app/components/section-area.js.coffee b/app/assets/javascripts/supplier/app/components/section-area.js.coffee new file mode 100644 index 00000000..a8af01fa --- /dev/null +++ b/app/assets/javascripts/supplier/app/components/section-area.js.coffee @@ -0,0 +1,34 @@ +App.SectionAreaComponent = Ember.Component.extend DragNDrop.Draggable, + classNames: ['section-area-container'] + attributeBindings: ['style'] + classNameBindings: ['vertical', 'right_half:right-half', 'section_area.rounded:rounded'] + pixelWidth: Ember.computed 'section_area.width', 'dpm', -> @get('dpm') * @get('section_area.width') + pixelHeight: Ember.computed 'section_area.height', 'dpm', -> @get('dpm') * @get('section_area.height') + offsetX: Ember.computed.product 'dpm', 'content.position_x' + offsetY: Ember.computed.product 'dpm', 'content.position_y' + vertical: Ember.computed 'section_area.width', 'section_area.height', 'targetObject.editmode', -> + not @get('targetObject.editmode') and @get('section_area.height') > @get('section_area.width') + right_half: Ember.computed 'section_area.position_x', 'section_area.width', 'section_area.sectino.width', -> + @get('section_area.position_x') + (@get('section_area.width') / 2) > (@get('section_area.section.width') / 2) + style: Ember.computed 'offsetX', 'offsetY', 'pixelWidth', 'pixelHeight', -> + App.CssObject.create( + width: @get('pixelWidth') + height: @get('pixelHeight') + left: @get('offsetX') + top: @get('offsetY') + "line-height": @get('pixelHeight') + ).toString() + content: Ember.computed.alias 'section_area' + draggable: (-> if @get('targetObject.editmode') then 'true' else 'false' ).property('targetObject.editmode') + dpm: Ember.computed.alias 'parentView.dpm' + positionChange: (position)-> + dpm = @get('dpm') + return if !dpm or parseFloat(dpm) is 0 + @get('content').setProperties + position_x: position.left / dpm + position_y: position.top / dpm + click: -> + return unless @get('targetObject.editmode') + @get('targetObject').modal 'section_area', + title_path: 'section_area.modal.title' + model: @get('section_area') diff --git a/app/assets/javascripts/supplier/app/controllers/modals/section_add_tables_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/section_add_tables_controller.js.coffee index 8480f72b..b1251d32 100644 --- a/app/assets/javascripts/supplier/app/controllers/modals/section_add_tables_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/modals/section_add_tables_controller.js.coffee @@ -19,17 +19,3 @@ App.modals.SectionAddTablesController = App.modals.BaseController.extend #@store.pushPayload 'table', result @store.pushPayload result @send 'close' - - #TODO remove followin code if Ember pushPayload is working - #properly with associations - section_id = @get('model.id') - tables_that_should_be_in_section = @store.all('table').filter((t)->t.get('section.id') == section_id) - current_table_ids = @get('model.tables').mapProperty('id') - for table in tables_that_should_be_in_section.toArray() - @get('model.tables').pushObject(table) unless table.get('id') in current_table_ids - #TODO it still does not work for the second client side action, - #soo the good old reload for now for the failing case - window.location.reload() if result.tables.length != tables_that_should_be_in_section.toArray().length - return - - diff --git a/app/assets/javascripts/supplier/app/controllers/modals/table_edit_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/table_edit_controller.js.coffee index e7525411..85d8bb9c 100644 --- a/app/assets/javascripts/supplier/app/controllers/modals/table_edit_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/modals/table_edit_controller.js.coffee @@ -9,5 +9,4 @@ App.modals.TableEditController = App.modals.BaseController.extend saveTable: -> #@set 'model.section', @get('selectedSection') @set 'model.section', @get('model.section') - #debugger @send 'save' diff --git a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee index f97b704d..64ad6826 100644 --- a/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/section_controller.js.coffee @@ -7,6 +7,7 @@ App.SectionController = Ember.ObjectController.extend @set('editmode', false) @get('model').save() @get('model.section_elements').forEach (section_element) -> section_element.save() + @get('model.section_areas').forEach (section_area) -> section_area.save() rollbackEditable: -> @get('model').rollback() @get('model.section_elements').forEach (section_element) -> @@ -14,6 +15,11 @@ App.SectionController = Ember.ObjectController.extend section_element.rollback() else section_element.deleteRecord() + @get('model.section_areas').forEach (section_area) -> + if section_area.get('id') + section_area.rollback() + else + section_area.deleteRecord() @set('editmode', false) addSection: -> @modal 'add_section', model: @get('model') addTables: -> @modal 'section_add_tables', model: @get('model') @@ -28,7 +34,14 @@ App.SectionController = Ember.ObjectController.extend @modal 'add_section_element', model: @get('model') ok: => @send 'makeEditable' - removeSectionElement: (section_element)-> section_element.destroy() + addSectionArea: -> + section_area = @store.createRecord('section-area') + section_area.set 'section', @get('model') + @modal 'section_area', + title_path: 'section_area.add_button' + model: section_area + ok: => @send 'makeEditable' + removeSectionElement: (section_element)-> section_element.destroyRecord() textures: ['wood1', 'wood2'] sections: (-> @get('controllers.sections.model')).property('controllers.sections.model') diff --git a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee index 1374c93f..dff8ef54 100644 --- a/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee +++ b/app/assets/javascripts/supplier/app/controllers/sections_index_controller.js.coffee @@ -2,7 +2,6 @@ App.SectionsIndexController = Ember.ArrayController.extend needs: ['application', 'sections', 'index'] sections: (-> @get('controllers.sections.model')).property('controllers.sections.model') sectionQrCodesUrl: ((a,b,c)-> - debugger Routes.qr_codes_suppliers_tables_path() ).property() newPath: Routes.new_suppliers_section_path() diff --git a/app/assets/javascripts/supplier/app/helpers/select-hour.js.coffee b/app/assets/javascripts/supplier/app/helpers/select-hour.js.coffee index 7ef849df..fb7c398b 100644 --- a/app/assets/javascripts/supplier/app/helpers/select-hour.js.coffee +++ b/app/assets/javascripts/supplier/app/helpers/select-hour.js.coffee @@ -1,5 +1,4 @@ Ember.Handlebars.helper 'select-hour', (params..., options)-> - debugger result = "" diff --git a/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee b/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee index fc9635f2..515c9e71 100644 --- a/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee +++ b/app/assets/javascripts/supplier/app/mixins/drag_n_drop.js.coffee @@ -11,8 +11,8 @@ DragNDrop.Draggable = Ember.Mixin.create draggable: 'true' dragStart: (ev)-> @set 'content.isDragging', true - @set 'controller.isDragging', true - @set 'controller.controllers.application.isDragging', true + @set 'targetObject.isDragging', true + @set 'targetObject.controllers.application.isDragging', true localStorage.setItem('draggingView', @get('elementId')) dataTransfer = ev.originalEvent.dataTransfer #dataTransfer.setData 'Text', @get('elementId') @@ -25,8 +25,8 @@ DragNDrop.Draggable = Ember.Mixin.create pageY: ev.originalEvent.pageY dragEnd: (e)-> @set 'content.isDragging', false - @set 'controller.isDragging', false - @set 'controller.controllers.application.isDragging', false + @set 'targetObject.isDragging', false + @set 'targetObject.controllers.application.isDragging', false localStorage.removeItem 'draggingView' if localStorage.getItem 'draggingView' DragNDrop.Droppable = Ember.Mixin.create diff --git a/app/assets/javascripts/supplier/app/models/section-area.js.coffee b/app/assets/javascripts/supplier/app/models/section-area.js.coffee new file mode 100644 index 00000000..a27ed082 --- /dev/null +++ b/app/assets/javascripts/supplier/app/models/section-area.js.coffee @@ -0,0 +1,11 @@ +attr = DS.attr +App.SectionArea = DS.Model.extend Ember.Validations.Mixin, + title: attr 'string' + width: attr 'number', defaultValue: 2 + height: attr 'number', defaultValue: 2 + position_x: attr 'number', defaultValue: 0 + position_y: attr 'number', defaultValue: 0 + rounded: attr 'boolean', defaultValue: false + section: DS.belongsTo('section') + validations: + title: {presence: true} diff --git a/app/assets/javascripts/supplier/app/models/section.js.coffee b/app/assets/javascripts/supplier/app/models/section.js.coffee index de3de325..de047ea4 100644 --- a/app/assets/javascripts/supplier/app/models/section.js.coffee +++ b/app/assets/javascripts/supplier/app/models/section.js.coffee @@ -5,3 +5,4 @@ App.Section = DS.Model.extend height: attr 'number' tables: DS.hasMany('table') section_elements: DS.hasMany('section-element') + section_areas: DS.hasMany('section-area') diff --git a/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee b/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee index bf4e65fa..70fc6d78 100644 --- a/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee +++ b/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee @@ -45,7 +45,6 @@ DS.Model.reopenClass #relation = relation[0] #if relation.kind == 'belongsTo' and id = attributes["#{relation.name}_id"] #attributes[relation.name] = id unless attributes[relation.name] - #debugger if options.debug #belongs_tos[relation.name] = id nested_attributes = {} @@ -53,8 +52,6 @@ DS.Model.reopenClass # pushPayload makes association back references, just push not yet 2014-06-27 new_record = @store.pushPayload(nested_attributes) - #debugger if options.debug - #promises = [] #association_names = [] #Ember.get(@, 'relationships').forEach (model, relation)=> @@ -64,7 +61,6 @@ DS.Model.reopenClass #promises.push @store.find(relation.name, id) #association_names.push relation.name #Ember.RSVP.all(promises).then (records)-> - #debugger #for record, i in records ##console.log "Setting relation #{relation.name} to #{record.get('id')}" #new_record.set association_names[i], record diff --git a/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee b/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee index 938bcdac..61a041de 100644 --- a/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee +++ b/app/assets/javascripts/supplier/app/routes/sections_route.js.coffee @@ -1,6 +1,7 @@ App.SectionsRoute = Ember.Route.extend beforeModel: -> @store.find 'section-element' + @store.find 'section-area' model: -> @store.all 'section' # setupController: (controller, collection) -> diff --git a/app/assets/javascripts/supplier/app/services/computed-product.js.coffee b/app/assets/javascripts/supplier/app/services/computed-product.js.coffee new file mode 100644 index 00000000..ff4645b5 --- /dev/null +++ b/app/assets/javascripts/supplier/app/services/computed-product.js.coffee @@ -0,0 +1,12 @@ +Ember.computed.product = -> + args = [] + for arg in arguments + args.push arg + callback = -> + product = 1 + for key in args + continue unless typeof(key) is 'string' + product *= @get(key) || 0 + product + args.push callback + Ember.computed.apply(@, args) diff --git a/app/assets/javascripts/supplier/app/services/css-object.js.coffee b/app/assets/javascripts/supplier/app/services/css-object.js.coffee new file mode 100644 index 00000000..5461bf72 --- /dev/null +++ b/app/assets/javascripts/supplier/app/services/css-object.js.coffee @@ -0,0 +1,10 @@ +App.CssObject = Ember.Object.extend + pixel_fields: ['width', 'height', 'left', 'top', 'line-height'] + isNumeric: /^[-+]?(\d+|\d+\.\d+)$/ + toString: -> + ret = "" + for k, v of JSON.parse(JSON.stringify(@)) + if @pixel_fields.indexOf(k) > -1 + v = "#{v}px" if @isNumeric.test(v) + ret += "#{k}:#{v};" + ret diff --git a/app/assets/javascripts/supplier/app/templates/components/section-area.emblem b/app/assets/javascripts/supplier/app/templates/components/section-area.emblem new file mode 100644 index 00000000..fa189fca --- /dev/null +++ b/app/assets/javascripts/supplier/app/templates/components/section-area.emblem @@ -0,0 +1 @@ +.title= section_area.title diff --git a/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem b/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem new file mode 100644 index 00000000..3e468d81 --- /dev/null +++ b/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem @@ -0,0 +1,21 @@ +.form-row.title + .form-label=t 'attributes.section_area.title' + .form-field + = input valueBinding="model.title" + .form-info + span.dimension m + = errors model.errors.title +.form-row.width + .form-label=t 'attributes.section_area.width' + .form-field= input type="number" valueBinding="model.width" +.form-row.height + .form-label=t 'attributes.section_area.height' + .form-field= input type="number" valueBinding="model.height" +.form-row.rounded + .form-label= t 'attributes.section_area.rounded' + .form-field= view "boolean-switch" value=model.rounded +hr +button.modal-close{action "close"}=t 'section_area.modal.close_button' +button.modal-confirm.right{action "save"} disabled=model.isInvalid + =t 'section_area.modal.save_button' +button.modal-destroy.right{action "destroy"}= t 'section_area.modal.destroy_button' diff --git a/app/assets/javascripts/supplier/app/templates/section.emblem b/app/assets/javascripts/supplier/app/templates/section.emblem index ed9568f8..56ccf7ec 100644 --- a/app/assets/javascripts/supplier/app/templates/section.emblem +++ b/app/assets/javascripts/supplier/app/templates/section.emblem @@ -19,8 +19,9 @@ ul li: a{action "addTables"}: span.section-add-tables-icon=t 'section.add_tables.button_label' li: a{action "arrangeTables"}: span.section-arrange-tables-icon=t 'section.arrange_tables.modal.title' - li: a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}" target="_blank": span.qr-icon=t 'table.print_qr_codes' li: a{action "addSectionElement"}: span.section-add-section-element-icon= t 'section_element.add_button' + li: a{action "addSectionArea"}: span.section-add-section-area-icon= t 'section_area.add_button' + li: a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}" target="_blank": span.qr-icon=t 'table.print_qr_codes' li: a.section-destroy{action "destroySection"}: span.section-remove-icon=t 'helpers.links.destroy' a.section-edit-mode-button{ action "makeEditable" }: span = view "section-tables" contentBinding="tables" diff --git a/app/assets/javascripts/supplier/app/templates/section/table.emblem b/app/assets/javascripts/supplier/app/templates/section/table.emblem index 13f2ddb0..0566a5be 100644 --- a/app/assets/javascripts/supplier/app/templates/section/table.emblem +++ b/app/assets/javascripts/supplier/app/templates/section/table.emblem @@ -1,8 +1,9 @@ .table-number= table.number -.status-icons - span.needs_payment - span.needs_help - span.active_order +unless editmode + .status-icons + span.needs_payment + span.needs_help + span.active_order if table.active_list div.table-actions .title= table.number @@ -19,8 +20,3 @@ if table.active_list a{action "editTable" table}: span.fa.fa-lg.fa-wrench each user in table.active_list.users = user.avatar_tag -if editmodedisabled - .table-settings - select - option Round - option rectangular diff --git a/app/assets/javascripts/supplier/app/templates/section/tables.emblem b/app/assets/javascripts/supplier/app/templates/section/tables.emblem index 381269c5..3a88396a 100644 --- a/app/assets/javascripts/supplier/app/templates/section/tables.emblem +++ b/app/assets/javascripts/supplier/app/templates/section/tables.emblem @@ -1,4 +1,6 @@ -each element in section_elements - view "section-element" content=element +each section_element in section_elements + view "section-element" content=section_element +each section_area in section_areas + = section-area section_area=section_area each table in tables = view "section-table" content=table diff --git a/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee b/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee index 59a37a11..c1e3899a 100644 --- a/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section/section-element.js.coffee @@ -17,6 +17,7 @@ App.SectionElementView = Ember.View.extend DragNDrop.Draggable, return 0 unless dpm = @get('dpm') dpm * (@get('content.position_y') || 0) ).property('dpm', 'content.position_y', 'content.rotation') + targetObject: Ember.computed.alias 'controller' #myHeight: (-> (@get('dpm') || 0 ) * @get('content.height')).property('dpm', 'content.height') #myWidth: (-> (@get('dpm') || 0 ) * @get('content.width')).property('dpm', 'content.width') diff --git a/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee b/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee index 8d309507..53b27d6b 100644 --- a/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section/table_view.js.coffee @@ -29,6 +29,7 @@ App.SectionTableView = Ember.View.extend DragNDrop.Draggable, "position:absolute;width:#{@get('myWidth')}px;height:#{@get('myHeight')}px;left:#{@get('offsetX')}px;top:#{@get('offsetY')}px" draggable: (-> if @get('controller.editmode') then 'true' else 'false' ).property('controller.editmode') + targetObject: Ember.computed.alias 'controller' placeInSection: -> @$el.css 'left', @offsetX() @$el.css 'top', @offsetY() diff --git a/app/assets/javascripts/supplier/app/views/section_view.js.coffee b/app/assets/javascripts/supplier/app/views/section_view.js.coffee index 595ac16e..d3054d00 100644 --- a/app/assets/javascripts/supplier/app/views/section_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section_view.js.coffee @@ -1,21 +1,15 @@ #App.SectionView = Ember.View.extend {} #initFoundation: (-> - #debugger #@$().foundation() #).on('didInsertElement') #didInsertElement: -> #@$().foundation() - #debugger #true #$(document).on 'load', '[data-dropdown]', (a,b,c)-> - #debugger #true #$(document).on 'change', '[data-dropdown]', (a,b,c)-> - #debugger #true #$(document).on 'ready', '[data-dropdown]', (a,b,c)-> - #debugger #true #$(document).on 'click', '[data-dropdown]', (a,b,c)-> - #debugger #true diff --git a/app/assets/stylesheets/supplier/foundation1/_qsections.css.sass b/app/assets/stylesheets/supplier/foundation1/_qsections.css.sass index 1b146cb1..71595c23 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qsections.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qsections.css.sass @@ -67,6 +67,10 @@ @extend .fa, .fa-image span padding-left: 7px + span.section-add-section-area-icon + @extend .fa, .fa-square + span + padding-left: 7px input height: auto padding-top: 4px diff --git a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass index b91cb41a..d5deb5a2 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qstructure.css.sass @@ -53,8 +53,8 @@ body margin: 0 .main-section +panel($bg:rgba(200,200,200,0.9)) - padding-bottom: 72px padding: 0 + padding-bottom: 72px margin: 0 min-height: 100% diff --git a/app/assets/stylesheets/supplier/foundation1/components/_forms.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_forms.css.sass index c2aa0f25..09a006e0 100644 --- a/app/assets/stylesheets/supplier/foundation1/components/_forms.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/components/_forms.css.sass @@ -15,7 +15,7 @@ @media #{$medium-only} +grid-column($columns:4, $last-column:true) @media #{$large-up} - +grid-column($columns: 3, $last-column:true) + +grid-column($columns: 4, $last-column:true) &.full @media #{$small-only} +grid-column($columns:10, $center:true, $last-column:true) @@ -27,6 +27,13 @@ +grid-column(6) .error color: $alert-color + .form-info + @media #{$small-only} + +grid-column($columns:10, $center:true) + @media #{$medium-only} + +grid-column($columns:4, $offset:1) + @media #{$large-up} + +grid-column(3) .error-message color: $alert-color &.form-actions diff --git a/app/assets/stylesheets/supplier/foundation1/components/_section_areas.css.sass b/app/assets/stylesheets/supplier/foundation1/components/_section_areas.css.sass new file mode 100644 index 00000000..38569393 --- /dev/null +++ b/app/assets/stylesheets/supplier/foundation1/components/_section_areas.css.sass @@ -0,0 +1,15 @@ +.section-area-container + position: absolute + background-color: #aaa + text-align: center + &.rounded + border-radius: 999px + .title + display: inline-block + &.vertical + .title + transform: rotate(270deg) + &.right-half + .title + transform: rotate(90deg) + diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index e4bdddf7..9e33dd78 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -27,7 +27,7 @@ class DashboardController < ApplicationController if Rails.env.test? @tables = Table.all else - @tables = List.active.map(&:table) | Supplier.find_by_name('Bora').tables.sample(3) + @tables = List.active.map(&:table) | Supplier.find_by_name('Mozo').tables.select{|t| t.number.between? 20, 50}.sample(3) end respond_to do |format| format.html { render layout: 'phone' } diff --git a/app/controllers/suppliers/section_areas_controller.rb b/app/controllers/suppliers/section_areas_controller.rb new file mode 100644 index 00000000..3c625a68 --- /dev/null +++ b/app/controllers/suppliers/section_areas_controller.rb @@ -0,0 +1,36 @@ +module Suppliers + class SectionAreasController < Suppliers::ApplicationController + def index + @section_areas = SectionArea.for_supplier(current_supplier) + render json: @section_areas, each_serializer: Suppliers::SectionAreaSerializer + end + + def create + @section_area.supplier = current_supplier + if @section_area.save + render json: @section_area, serializer: Suppliers::SectionAreaSerializer + else + render json: {errors: @section.errors}, status: :unprocessable_entity + end + end + + def update + if @section_area.update_attributes section_area_params + render json: @section_area, serializer: Suppliers::SectionAreaSerializer + else + render json: {errors: @section.errors}, status: :unprocessable_entity + end + end + + def destroy + @section_area.destroy + head :ok + end + + private + + def section_area_params + params.require(:section_area).permit %i[title width height position_x position_y section_id rounded] + end + end +end diff --git a/app/controllers/suppliers/section_elements_controller.rb b/app/controllers/suppliers/section_elements_controller.rb index 3fb917fc..d0caf4e2 100644 --- a/app/controllers/suppliers/section_elements_controller.rb +++ b/app/controllers/suppliers/section_elements_controller.rb @@ -22,6 +22,11 @@ module Suppliers end end + def destroy + @section_element.destroy() + head :ok + end + private def section_element_params diff --git a/app/controllers/suppliers/sections_controller.rb b/app/controllers/suppliers/sections_controller.rb index 72eb5120..cedcf405 100644 --- a/app/controllers/suppliers/sections_controller.rb +++ b/app/controllers/suppliers/sections_controller.rb @@ -124,14 +124,16 @@ module Suppliers @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) number_start = params[:number_start].to_i number_end = params[:number_end].to_i + added_tables = [] for table_number in number_start..number_end next if table_number.zero? table = Table.new(number: table_number) table.supplier = current_supplier table.section = @section table.save + added_tables << table end - @section.arrange_tables_in_grid + @section.arrange_tables_in_grid added_tables table_json = ActiveModel::ArraySerializer.new(@section.tables, each_serializer: SupplierTableSerializer, root: false).as_json render json: {tables: table_json} end diff --git a/app/models/section.rb b/app/models/section.rb index a7ae6b36..b0477b10 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -11,6 +11,7 @@ class Section has_many :lists has_many :orders has_many :section_elements + has_many :section_areas attr_protected :supplier_id @@ -99,7 +100,7 @@ class Section @for_tables_as_json = h end - def arrange_tables_in_grid + def arrange_tables_in_grid(tables = self.tables) w = width h = height n = tables.size diff --git a/app/models/section_area.rb b/app/models/section_area.rb new file mode 100644 index 00000000..a9be96ee --- /dev/null +++ b/app/models/section_area.rb @@ -0,0 +1,18 @@ +class SectionArea + include SimplyStored::Couch + include ActiveModel::SerializerSupport + property :title + property :width, type: Float, default: 2 + property :height, type: Float, default: 2 + property :position_x, type: Float, default: 0 + property :position_y, type: Float, default: 0 + property :rounded, type: :boolean, default: false + belongs_to :section + belongs_to :supplier + + view :by_supplier_id, key: :supplier_id + + def self.for_supplier(supplier) + find_all_by_supplier_id(supplier.id) + end +end diff --git a/app/serializers/suppliers/section_area_serializer.rb b/app/serializers/suppliers/section_area_serializer.rb new file mode 100644 index 00000000..1ad64194 --- /dev/null +++ b/app/serializers/suppliers/section_area_serializer.rb @@ -0,0 +1,3 @@ +class Suppliers::SectionAreaSerializer < Qwaiter::Serializer + attributes :title, :width, :height, :position_x, :position_y, :section_id, :rounded +end diff --git a/config/locales/models.en.yml b/config/locales/models.en.yml index d5499218..c7a6443e 100644 --- a/config/locales/models.en.yml +++ b/config/locales/models.en.yml @@ -14,8 +14,9 @@ en: user_feedback: User feedback employee: Employee employee_shift: Shift - section_element: Section element svg_element: Svg element + section_element: Section element + section_area: Section area plural: user: Users supplier: Restaurants @@ -30,8 +31,9 @@ en: user_feedback: User feedbacks employee: Employees employee_shift: Shifts - section_element: Section elements svg_element: Svg elements + section_element: Section elements + section_area: Section areas attributes: product_category: name: Name @@ -117,3 +119,7 @@ en: position_x: X position_y: Y rotation: Angle + section_area: + title: Title + width: Width + height: Height diff --git a/config/locales/models.nl.yml b/config/locales/models.nl.yml index f6cd2d2e..d955fbd4 100644 --- a/config/locales/models.nl.yml +++ b/config/locales/models.nl.yml @@ -13,8 +13,9 @@ nl: join_request: Deelname verzoek employee: Werknemer employee_shift: Shift - section_element: Ruimte element svg_element: Svg element + section_element: Ruimte element + section_area: Ruimte blok plural: user: Gebruikers supplier: Restaurants @@ -28,8 +29,9 @@ nl: join_request: Deelname verzoeken employee: Werknemers employee_shift: Shifts - section_element: Ruimte elementen svg_element: Svg element + section_element: Ruimte elementen + section_area: Ruimte blokken attributes: product_category: name: Naam @@ -116,3 +118,7 @@ nl: position_x: X position_y: Y rotation: Angle + section_area: + title: Titel + width: Breedte + height: Hoogte diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index 2aa17ed0..adf4c538 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -215,3 +215,10 @@ en: add_button: Add ${models.section_element} modal: title: Add ${models.section_element} + section_area: + add_button: Add ${models.section_area} + modal: + title: Add ${models.section_area} + save_button: Save + close_button: Close + destroy_button: Delete diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index fe2f7363..e7487e7f 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -218,3 +218,7 @@ nl: add_button: ${models.section_element} toevoegen modal: title: ${models.section_element} toevoegen + section_area: + add_button: ${models.section_area} toevoegen + modal: + title: ${models.section_area} toevoegen diff --git a/config/routes.rb b/config/routes.rb index cba4a93b..9708b1d7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -121,8 +121,9 @@ Qwaiter::Application.routes.draw do end end - resources :section_elements resources :svg_elements, only: [:index, :show] + resources :section_elements + resources :section_areas resources :tables do collection do get :qr_codes diff --git a/tmp.xml b/tmp.xml new file mode 100644 index 00000000..78c75430 --- /dev/null +++ b/tmp.xml @@ -0,0 +1,429 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +image/svg+xml + + + + +Openclipart + + +Plant +2011-03-07T16:35:20 +Plant with cobs +https://openclipart.org/detail/126049/plant-by-gsagri04 + + +gsagri04 + + + + +Plant +cob +green +leaf + + + + + + + + + + + +