From 6588a97560f9648dbbae72b2d810445365ce1395 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 30 Sep 2015 17:55:47 +0200 Subject: [PATCH] Add section area color and demo menu export --- .../app/components/section/area.js.coffee | 6 +- .../controllers/modals/section_area.js.coffee | 18 ++ .../app/models/section-area.js.coffee | 1 + .../app/services/css-object.js.coffee | 15 + .../button/change-list-table.emblem | 2 +- .../app/templates/list/_content.emblem | 1 - .../templates/modals/change-list-table.emblem | 7 +- .../app/templates/modals/section_area.emblem | 6 + .../supplier/foundation1/application.js.erb | 2 +- .../supplier/foundation1/_qlists.sass | 1 + .../foundation1/resources/_section_areas.sass | 1 - .../suppliers/section_areas_controller.rb | 2 +- app/models/section_area.rb | 1 + .../suppliers/section_area_serializer.rb | 2 +- config/locales/supplier.en.yml | 2 + config/locales/supplier.nl.yml | 1 + config/routes.rb | 2 +- doc/demo_menu.yml | 287 ++++++++++++++++++ lib/tasks/suppliers.rake | 19 ++ spec/javascript/unit/css_object_test.coffee | 3 + wip.md | 8 +- 21 files changed, 372 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/supplier/app/controllers/modals/section_area.js.coffee create mode 100644 doc/demo_menu.yml create mode 100644 lib/tasks/suppliers.rake create mode 100644 spec/javascript/unit/css_object_test.coffee diff --git a/app/assets/javascripts/supplier/app/components/section/area.js.coffee b/app/assets/javascripts/supplier/app/components/section/area.js.coffee index 344c674a..76505c60 100644 --- a/app/assets/javascripts/supplier/app/components/section/area.js.coffee +++ b/app/assets/javascripts/supplier/app/components/section/area.js.coffee @@ -11,12 +11,16 @@ App.SectionAreaComponent = Ember.Component.extend DragNDrop.Draggable, not @get('section.editmode') and @get('section_area.height') > @get('section_area.width') right_half: Ember.computed 'section_area.position_x', 'section_area.width', 'section_area.section.width', -> @get('section_area.position_x') + (@get('section_area.width') / 2) > (@get('section_area.section.width') / 2) - style: Ember.computed 'offsetX', 'offsetY', 'pixelWidth', 'pixelHeight', -> + style: Ember.computed 'offsetX', 'offsetY', 'pixelWidth', 'pixelHeight', 'section_area.color', -> + background_color = @get('section_area.color') + color = if App.CssObject.isColorDark(background_color) then 'white' else 'black' App.CssObject.create( width: @get('pixelWidth') height: @get('pixelHeight') left: @get('offsetX') top: @get('offsetY') + "background-color": background_color + color: color "line-height": @get('pixelHeight') ).toString() draggable: (-> if @get('section.editmode') then true else false ).property('section.editmode') diff --git a/app/assets/javascripts/supplier/app/controllers/modals/section_area.js.coffee b/app/assets/javascripts/supplier/app/controllers/modals/section_area.js.coffee new file mode 100644 index 00000000..0bae523c --- /dev/null +++ b/app/assets/javascripts/supplier/app/controllers/modals/section_area.js.coffee @@ -0,0 +1,18 @@ +App.modals.SectionAreaController = App.modals.BaseController.extend + colors: (-> + # taken from http://www.somacon.com/p142.php + [ + '#AAAAAA' + '#458B74' + '#838B8B' + '#8B7D6B' + '#00008B' + '#8B2323' + '#8A2BE2' + '#458B00' + '#EEAD0E' + ] + ).property() + actions: + setColor: (color)-> + @set 'model.color', color diff --git a/app/assets/javascripts/supplier/app/models/section-area.js.coffee b/app/assets/javascripts/supplier/app/models/section-area.js.coffee index 368e405f..6438e29c 100644 --- a/app/assets/javascripts/supplier/app/models/section-area.js.coffee +++ b/app/assets/javascripts/supplier/app/models/section-area.js.coffee @@ -6,6 +6,7 @@ App.SectionArea = DS.Model.extend Ember.Validations.Mixin, position_x: attr 'number', defaultValue: 0 position_y: attr 'number', defaultValue: 0 rounded: attr 'boolean', defaultValue: false + color: attr 'string', defaultValue: '#AAAAAA' section: DS.belongsTo('section', async: false) validations: title: {presence: true} diff --git a/app/assets/javascripts/supplier/app/services/css-object.js.coffee b/app/assets/javascripts/supplier/app/services/css-object.js.coffee index 4db4592c..dfb271a9 100644 --- a/app/assets/javascripts/supplier/app/services/css-object.js.coffee +++ b/app/assets/javascripts/supplier/app/services/css-object.js.coffee @@ -8,3 +8,18 @@ App.CssObject = Ember.Object.extend v = "#{v}px" if @isNumeric.test(v) ret += "#{k}:#{v};" ret.htmlSafe() +App.CssObject.reopenClass + rgb_to_numeric: (rgb_hex)-> + #http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black + rgb_hex = rgb_hex.substring(1) + rgb = parseInt(rgb_hex, 16) + r = (rgb >> 16) & 0xff + g = (rgb >> 8) & 0xff + b = (rgb >> 0) & 0xff + [r, g, b] + + isColorDark: (rgb_hex)-> + return false unless rbg_hex.match /#[0-9a-zA-Z]{6}/ + [r, g, b] = @rgb_to_numeric(rgb_hex) + luma = 0.2126 * r + 0.7152 * g + 0.0722 * b # per ITU-R BT.709 + luma < 40 diff --git a/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem b/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem index 71a63369..ad8d9592 100644 --- a/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem +++ b/app/assets/javascripts/supplier/app/templates/components/button/change-list-table.emblem @@ -1 +1 @@ -span.fa.fa-random += table-number list.table.number diff --git a/app/assets/javascripts/supplier/app/templates/list/_content.emblem b/app/assets/javascripts/supplier/app/templates/list/_content.emblem index 5dd35f3d..39dacb4d 100644 --- a/app/assets/javascripts/supplier/app/templates/list/_content.emblem +++ b/app/assets/javascripts/supplier/app/templates/list/_content.emblem @@ -15,7 +15,6 @@ if list.active .display-row .display-label=t 'models.table' .display-field - = table-number list.table.number = button-change-list-table list=list .display-row .display-label   diff --git a/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem b/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem index 581bface..aee8af6b 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/change-list-table.emblem @@ -1,7 +1,12 @@ -h3= tables.length +h4=t 'modal.change_list_table.subtitle' current_table_number=model.table.number +.user-info-container + each model.users as |user| + = user.avatar_tag each sections as |section| h3= section.title ul.change-list-table-section-tables each section.sorted_tables as |table| unless table.active_list li: a{action "moveToTable" table}= table-number table.number +hr +button.modal-close{action "close"}=t 'modal.change_list_table.close_button' diff --git a/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem b/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem index 68e60456..54489f42 100644 --- a/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem +++ b/app/assets/javascripts/supplier/app/templates/modals/section_area.emblem @@ -19,6 +19,12 @@ p= t 'section_area.modal.explanation' .form-row.rounded .form-label= t 'attributes.section_area.rounded' .form-field= boolean-switch value=model.rounded +.form-row.color + .form-label= t 'attributes.employee.color' + .form-field.full + span.current-color= colorbox model.color + each colors as |color| + a{action "setColor" color}= colorbox color hr button.modal-close{action "close"}=t 'section_area.modal.close_button' button.modal-confirm.right{action "save"} disabled=model.isInvalid diff --git a/app/assets/javascripts/supplier/foundation1/application.js.erb b/app/assets/javascripts/supplier/foundation1/application.js.erb index 714541c0..cee92822 100644 --- a/app/assets/javascripts/supplier/foundation1/application.js.erb +++ b/app/assets/javascripts/supplier/foundation1/application.js.erb @@ -17,8 +17,8 @@ if(!Modernizr.cssanimations){ window.location = "/unsupported-browser"; } - var Qstorage = localStorage; + $.extend($translations.en, <%= I18n.t('supplier', locale: :en).to_json %>); $.extend($translations.nl, <%= I18n.t('supplier', locale: :nl).to_json %>); diff --git a/app/assets/stylesheets/supplier/foundation1/_qlists.sass b/app/assets/stylesheets/supplier/foundation1/_qlists.sass index 09b45526..62918d20 100644 --- a/app/assets/stylesheets/supplier/foundation1/_qlists.sass +++ b/app/assets/stylesheets/supplier/foundation1/_qlists.sass @@ -19,6 +19,7 @@ td.boolean .change-list-table-button +button($bg: $warning-color, $padding: $button-tny) margin: 0 + margin-bottom: 8px .change-list-table-section-tables list-style: none +clearfix diff --git a/app/assets/stylesheets/supplier/foundation1/resources/_section_areas.sass b/app/assets/stylesheets/supplier/foundation1/resources/_section_areas.sass index 38569393..17dd8732 100644 --- a/app/assets/stylesheets/supplier/foundation1/resources/_section_areas.sass +++ b/app/assets/stylesheets/supplier/foundation1/resources/_section_areas.sass @@ -1,6 +1,5 @@ .section-area-container position: absolute - background-color: #aaa text-align: center &.rounded border-radius: 999px diff --git a/app/controllers/suppliers/section_areas_controller.rb b/app/controllers/suppliers/section_areas_controller.rb index 2aa90093..520e8f31 100644 --- a/app/controllers/suppliers/section_areas_controller.rb +++ b/app/controllers/suppliers/section_areas_controller.rb @@ -30,7 +30,7 @@ module Suppliers private def section_area_params - params.require(:section_area).permit %i[title width height position_x position_y section_id rounded] + params.require(:section_area).permit %i[title width height position_x position_y section_id rounded color] end end end diff --git a/app/models/section_area.rb b/app/models/section_area.rb index a9be96ee..75fe87e8 100644 --- a/app/models/section_area.rb +++ b/app/models/section_area.rb @@ -7,6 +7,7 @@ class SectionArea property :position_x, type: Float, default: 0 property :position_y, type: Float, default: 0 property :rounded, type: :boolean, default: false + property :color belongs_to :section belongs_to :supplier diff --git a/app/serializers/suppliers/section_area_serializer.rb b/app/serializers/suppliers/section_area_serializer.rb index 3d0dd095..0df7c57d 100644 --- a/app/serializers/suppliers/section_area_serializer.rb +++ b/app/serializers/suppliers/section_area_serializer.rb @@ -1,5 +1,5 @@ class Suppliers::SectionAreaSerializer include Qwaiter::SupplierBaseSerializer - attributes :title, :width, :height, :position_x, :position_y, :rounded + attributes :title, :width, :height, :position_x, :position_y, :rounded, :color has_one :section, serializer: Suppliers::SectionSerializer end diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index b42d841f..3920d068 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -198,6 +198,8 @@ en: close: OK change_list_table: title: Change the ${models.table} of the ${models.list} + subtitle: 'The current ${model.table} number is # %{current_table_number}' + close_button: Close supplier_status_info: title: "%{name} info" header: The icons at the top right corner contain information about the current orders diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index 3e3c45e8..6d481d2a 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -199,6 +199,7 @@ nl: close: OK change_list_table: title: Verander de ${models.table} van de ${models.list} + close_button: Sluiten supplier_status_info: title: "%{name} info" header: The icons at the top right corner contain information about the current orders diff --git a/config/routes.rb b/config/routes.rb index c7f421df..04d8e771 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,7 @@ Qwaiter::Application.routes.draw do # DEVELOPMENT ONLY get '/qr' => 'dashboard#qr' - get '/demo_both' => 'dashboard#demo_both' + get '/demo-both' => 'dashboard#demo_both' get :tests, to: 'test_squad#tests' unless Rails.env.production? # SUPPLIER diff --git a/doc/demo_menu.yml b/doc/demo_menu.yml new file mode 100644 index 00000000..cc32bc02 --- /dev/null +++ b/doc/demo_menu.yml @@ -0,0 +1,287 @@ +--- +- FEATURED: + - :name: Send me a mozo! + :description: + :price: 0.0 + :product_variants: [] +- ONTBIJT & ZOET: + - :name: Croissant + :description: Met jam & kaas + :price: 4.95 + :product_variants: [] + - :name: Cereals + :description: Met boerenyoghurt + :price: 4.5 + :product_variants: [] + - :name: Uitsmijter Titus + :description: Drie eitjes met naar keuze ham, kaas of fricandeau op speltbrood, + extra item + :price: 6.0 + :product_variants: [] + - :name: Seizoenstaart + :description: + :price: 5.0 + :product_variants: [] + - :name: Dudok Appeltaart + :description: + :price: 5.0 + :product_variants: [] + - :name: Cheesecake + :description: + :price: 5.0 + :product_variants: [] +- LUNCH - TOT 17:00: + - :name: Algen Bolletje Schapenkaas + :description: Spaanse Schapenkaas met appelstroop dressing + :price: 8.5 + :product_variants: [] + - :name: Panini Ham Kaas + :description: '' + :price: 4.3 + :product_variants: [] + - :name: Panini met Kip + :description: Met pesto + :price: 6.5 + :product_variants: [] + - :name: Vitello Tonat + :description: Met tonijnmayonaise, kappertjes, rode ui, oregano en rucola op speltbrood + :price: 9.5 + :product_variants: [] + - :name: Serranoham + :description: 24 maanden gerijpte Serranoham en truffelmayonaise op speltbrood + :price: 8.0 + :product_variants: [] + - :name: Van Dobben Kroketten + :description: Twee kroketten op speltbrood + :price: 7.0 + :product_variants: [] + - :name: Uitsmijter Mozo + :description: Drie eitjes met naar keuze ham, kaas of fricandeau op speltbrood + :price: 6.0 + :product_variants: [] + - :name: Algen Bolletje Mozzarella + :description: Met tomaat en basilicum pesto dressing + :price: 8.5 + :product_variants: [] + - :name: Special + :description: Uitgelegd door uw ober + :price: 7.5 + :product_variants: [] +- Beer: + - :name: La Chouffe + :description: Vanavond niet beschikbaar + :price: 4.1 + :product_variants: + - Zonder schuim5 + - Met schuim +- VOORGERECHTEN: + - :name: Tonijn Tartaar + :description: Vers gemarineerd met Granny Smith appel en marshmellow van sojasaus + :price: 12.5 + :product_variants: [] + - :name: Noordzee Krab + :description: Met tomaat, avocado en miso mayo + :price: 15.5 + :product_variants: [] + - :name: Coquilles + :description: Met zomer artisjok, kokkels en zwarte olijf + :price: 16.5 + :product_variants: [] + - :name: Vitello Tonato + :description: Met tonijnmayonaise, kappertjes, rode ui, oregano en rucola + :price: 10.5 + :product_variants: [] + - :name: Kreeft + :description: Lauwwarme halve kreeft met citrus structureren en venkel + :price: 18.5 + :product_variants: [] + - :name: Tortellini + :description: Tortellini van paddestoelen + :price: 14.5 + :product_variants: [] + - :name: Plateau Antipasti + :description: Dagelijks wisselende vegetarische-, vis- en vleesspecialiteiten + :price: 11.5 + :product_variants: [] + - :name: Visplateau Mozo + :description: Wisselende visspecialiteiten met o.a. schaal en schelpdiertjes + :price: 11.5 + :product_variants: [] +- SALADE: + - :name: Salade met Sognefjord zalm + :description: Met waterkers, rucola en wasabi-gember dressing + :price: 14.5 + :product_variants: [] + - :name: Zee Salade + :description: Groene salade, lamsoor, wakame, zeekraal en groene asperge + :price: 13.5 + :product_variants: [] + - :name: Salade Mozzarella + :description: Met tomaat, rucola en basilicum pesto dressing + :price: 13.5 + :product_variants: [] +- BIJGERECHTEN: + - :name: Diversen + :description: + :price: 3.5 + :product_variants: [] +- HOOFDGERECHTEN: + - :name: Visplateau + :description: Wisselende visspecialiteiten met o.a. schaal en schelpdiertjes + :price: 22.5 + :product_variants: [] + - :name: Black Angus Rib-eye + :description: Van de Green Egg met gepofte aardappel, salsa van avocado, appel + en Hollandse garnalen + :price: 27.95 + :product_variants: [] + - :name: Paddestoelen Tortellini + :description: Met seizoensgroenten en zongedroogde tomaat + :price: 16.5 + :product_variants: [] + - :name: Bio Burger + :description: Van 100% rundvlees met tomaat, ijsbergsla en truffel mayo + :price: 14.5 + :product_variants: [] + - :name: Kreeft Thermidor + :description: Hele kreeft gegratineerd met Thermidorsaus en seizoensgroenten + :price: 29.5 + :product_variants: [] + - :name: Tonijnsteak + :description: Met venkel, zeegroenten en sesam dressing + :price: 17.5 + :product_variants: [] + - :name: Tofu + :description: Gemarineerde Tofu met seizoensgroenten en teriyaki saus + :price: 15.5 + :product_variants: [] + - :name: Kalfskotelet + :description: Van de Green Egg met gepofte aardappel, salsa van avocado, appel + en Hollandse garnalen + :price: 24.5 + :product_variants: [] + - :name: Vis van de grill + :description: Toegelicht door het personeel + :price: 17.5 + :product_variants: [] +- VOOR DE KLEINTJES: + - :name: Pasta Pesto + :description: + :price: 6.5 + :product_variants: [] + - :name: Pannenkoek + :description: + :price: 4.95 + :product_variants: [] + - :name: Kroket / Kipnuggets / Fish fingers + :description: Geserveerd met frietjes + :price: 6.5 + :product_variants: [] +- DESSERTS: + - :name: Aarbeien ijs + :description: + :price: 6.0 + :product_variants: [] + - :name: Chocolade ijs + :description: + :price: 6.0 + :product_variants: [] + - :name: Ben & Jerry's + :description: '' + :price: 5.0 + :product_variants: [] + - :name: Espresso 43 + :description: + :price: 4.3 + :product_variants: [] + - :name: Cheesecake + :description: + :price: 5.0 + :product_variants: [] + - :name: Crêpes Suzette + :description: Warm pannenkoekje met sinaasappelsaus en ijs + :price: 6.5 + :product_variants: [] + - :name: Kaasplankje + :description: Variatie van drie kazen + :price: 9.95 + :product_variants: [] + - :name: Dudok Appeltaart + :description: '' + :price: 5.0 + :product_variants: [] + - :name: Seizoenstaart + :description: "(vraag Titus Crew)" + :price: 0.0 + :product_variants: [] +- BIJ DE BORREL: + - :name: Brood met smeersels + :description: Kruidenboter, Tapenade en Aioli + :price: 5.75 + :product_variants: [] + - :name: Kaasplankje + :description: Variatie van drie kazen + :price: 9.95 + :product_variants: [] + - :name: Visplateau Titus + :description: Wisselende visspecialiteiten met o.a. schaal en schelpdiertjes + :price: 11.5 + :product_variants: [] + - :name: Mini Loempia's + :description: + :price: 5.5 + :product_variants: [] + - :name: Vlammetjes + :description: + :price: 6.5 + :product_variants: [] + - :name: Torpedo Garnalen + :description: + :price: 6.5 + :product_variants: [] + - :name: Bittergarnituur + :description: + :price: 17.5 + :product_variants: [] + - :name: Bitterballen Van Dobben + :description: + :price: 5.5 + :product_variants: [] + - :name: Plateau Antipasti + :description: Dagelijks wisselende vegetarische-, vis- en vleesspecialiteiten + :price: 11.5 + :product_variants: [] + - :name: Plateau Mediterranee + :description: Mix van drie diverse vleessoorten en Perla Verde olijven + :price: 9.5 + :product_variants: [] + - :name: Nacho's + :description: Uit de oven, met kaas, tomaten, chilibonen en sour cream + :price: 5.5 + :product_variants: [] + - :name: Olijven + :description: Spaanse Perla Verda en zwarte Aragon olijven + :price: 3.5 + :product_variants: [] +- NATTÛH OESTÂHS: + - :name: Seizoensoester + :description: + :price: 2.85 + :product_variants: [] + - :name: Zeeuwse Creuses + :description: + :price: 3.2 + :product_variants: [] + - :name: Zeeuwse Platte + :description: + :price: 4.1 + :product_variants: [] +- BIER: + - :name: La Chouffe + :description: + :price: 4.2 + :product_variants: [] + - :name: Heininken Vaasje + :description: + :price: 2.6 + :product_variants: [] diff --git a/lib/tasks/suppliers.rake b/lib/tasks/suppliers.rake new file mode 100644 index 00000000..2280fe63 --- /dev/null +++ b/lib/tasks/suppliers.rake @@ -0,0 +1,19 @@ +namespace :supplier do + task export_menu: :environment do + supplier_name = ARGV[1] + raise "Please supply a suppliers' name as argument" unless supplier_name.present? + supplier = Supplier.find_by_name(supplier_name) + raise "Cannot find supplier with name #{supplier_name}" unless supplier.present? + object = supplier.product_categories.sort_by(&:position).map do |pc| + { pc.name => pc.products.map{ |product| + { + name: product.name.to_s.strip.presence, + description: product.description.presence, + price: product.price, + product_variants: product.product_variants.map(&:name) + }} + } + end + puts object.to_yaml + end +end diff --git a/spec/javascript/unit/css_object_test.coffee b/spec/javascript/unit/css_object_test.coffee new file mode 100644 index 00000000..ddfce93e --- /dev/null +++ b/spec/javascript/unit/css_object_test.coffee @@ -0,0 +1,3 @@ +test "CssObject isColorDark", -> + #expect 10 + equal App.CssObject.isColorDark('#FFFFFF'), false diff --git a/wip.md b/wip.md index 5dc0a8f1..208746c7 100644 --- a/wip.md +++ b/wip.md @@ -19,11 +19,10 @@ Supplier - Testing - Change list table - Set product_category day from false to true - +- Product order check for product being active User ---- -- Fix data model with consistent synchronous and asynchronous relations - Implement https://github.com/EddyVerbruggen/Custom-URL-scheme with mozo:// scheme - test met veel producten - remove active orders on list close @@ -31,13 +30,10 @@ User - rename "I am signed in as a user" to "there is a signed in user" in the specs - Kom in aanmerking voor vaste klanten acties! - - +- Add supplier info page Bugs ---- - -- obtain token does not refetch the current list after credentials are set General