From b5a68e96274bf99470b6908dde5b7a873de36b11 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 27 Jun 2014 14:52:18 +0200 Subject: [PATCH] All specs green, ember transition successful --- .../javascripts/supplier/app/app.js.coffee | 1 + .../supplier/app/models/list.js.coffee | 3 ++- .../modifications/model_extensions.js.coffee | 23 ++++++++++++++----- .../app/templates/_list_content.emblem | 9 ++++++-- .../supplier/foundation1/qsupplier.js.coffee | 6 ++++- .../user/app/models/list.js.coffee | 1 + .../user/app/templates/_list_content.emblem | 10 ++++++++ .../user/foundation/_display_fields.css.sass | 17 ++++++++++++++ .../user/foundation/_qlists.css.sass | 1 + .../user/foundation/application.css.sass | 1 + .../suppliers/application/_top_menu.html.slim | 4 ++-- config/locales/user.en.yml | 4 ++++ config/locales/user.nl.yml | 4 ++++ .../acceptance/suppliers/section_view.feature | 3 +++ spec/acceptance_steps/order_steps.rb | 4 ++++ .../suppliers/main_board_steps.rb | 1 - .../suppliers/section_view_steps.rb | 4 +++- spec/spec_helper.rb | 1 + spec/support/ember_helpers.rb | 17 ++++++++++++++ 19 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 app/assets/stylesheets/user/foundation/_display_fields.css.sass create mode 100644 spec/support/ember_helpers.rb diff --git a/app/assets/javascripts/supplier/app/app.js.coffee b/app/assets/javascripts/supplier/app/app.js.coffee index 84143d35..820acea0 100644 --- a/app/assets/javascripts/supplier/app/app.js.coffee +++ b/app/assets/javascripts/supplier/app/app.js.coffee @@ -1,3 +1,4 @@ Qsupplier.App = Ember.Application.create LOG_TRANSITIONS: true rootElement: '#ember-app-container' + store: -> @__container__.lookup('controller:application').store diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index e4b02611..baa3b8e5 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -9,7 +9,8 @@ Qsupplier.App.List = DS.Model.extend #has_active_orders: attr 'boolean' has_active_orders: (-> return false unless @get('state') == 'active' - !!@get('orders').filterProperty('state', 'active').length + #!!@get('orders').filterProperty('state', 'active').length + !!@get('orders').filter( (order) -> order.get('state') is 'active' or order.get('state') is 'placed').length ).property('state', 'orders.@each.state') price: attr 'number' closed_at: DS.attr('date') 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 b820652a..4e536eed 100644 --- a/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee +++ b/app/assets/javascripts/supplier/app/modifications/model_extensions.js.coffee @@ -20,19 +20,30 @@ DS.Model.reopenClass else #@store.find(@, attributes.id) @pushByAttriburtes(attributes) - pushByAttriburtes: (attributes)-> + pushByAttriburtes: (attributes, options = {})-> #store = @all().get('store') #Ugly hack at the cost of an extra request since I do not yet know the proper #code for adding a record by its attributes and having its associations set #@find(attributes.id) + decamelized = Ember.String.decamelize(@typeKey) + self_name = Ember.String.pluralize(decamelized) + self_name = self_name.substr(1) if self_name[0] == '.' - Ember.get(@, 'relationships').forEach (model, relation)=> - relation = relation[0] - if relation.kind == 'belongsTo' and id = attributes["#{relation.name}_id"] - attributes[relation.name] = id unless attributes[relation.name] + #belongs_tos = {} + #Ember.get(@, 'relationships').forEach (model, relation)=> + #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 - @store.push @toString(), attributes + nested_attributes = {} + nested_attributes[self_name] = attributes + # pushPayload makes association back references, just push not yet 2014-06-27 + new_record = @store.pushPayload(@toString(), nested_attributes) + + #debugger if options.debug #promises = [] #association_names = [] diff --git a/app/assets/javascripts/supplier/app/templates/_list_content.emblem b/app/assets/javascripts/supplier/app/templates/_list_content.emblem index 4f9b1bdb..d26f0874 100644 --- a/app/assets/javascripts/supplier/app/templates/_list_content.emblem +++ b/app/assets/javascripts/supplier/app/templates/_list_content.emblem @@ -1,11 +1,16 @@ .display-row .display-label=t 'attributes.list.created_at' .display-field=time list.created_at +if list.closed_at + .display-row + .display-label=t 'attributes.list.closed_at' + .display-field=time list.closed_at .display-row .display-label=t 'attributes.list.state' .display-field=state 'list' list.state -each user in list.users - img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f" +.row + each user in list.users + img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f" if list.orders .list-orders-container each order in list.sorted_orders diff --git a/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee b/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee index b20ffd16..733e534b 100644 --- a/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee +++ b/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee @@ -5,7 +5,11 @@ root.Qsupplier= faye.subscribe "/supplier/"+supplier_id, (e)=> console.log(e) if(e.event == 'new_order') - Qsupplier.App.Order.pushByAttriburtes(e.data.order) if Qsupplier.App + if Qsupplier.App + Qsupplier.App.store().pushPayload e.data + #Qsupplier.App.Order.pushByAttriburtes(e.data.order) + #for product_order in e.data.product_orders + #Qsupplier.App.ProductOrder.pushByAttriburtes product_order, debug: true else if(e.event == 'list_needs_help') if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id) list.markNeedsHelp() diff --git a/app/assets/javascripts/user/app/models/list.js.coffee b/app/assets/javascripts/user/app/models/list.js.coffee index d46a8b46..6fe79c81 100644 --- a/app/assets/javascripts/user/app/models/list.js.coffee +++ b/app/assets/javascripts/user/app/models/list.js.coffee @@ -7,6 +7,7 @@ App.List = DS.Model.extend supplier_name: attr('string') state: attr('string') price: attr('number') + closed_at: DS.attr('date') extended_version: attr('boolean') supplier_orders_in_process_count: attr('number') supplier_orders_placed_count: attr('number') diff --git a/app/assets/javascripts/user/app/templates/_list_content.emblem b/app/assets/javascripts/user/app/templates/_list_content.emblem index b21891f7..2add2c8b 100644 --- a/app/assets/javascripts/user/app/templates/_list_content.emblem +++ b/app/assets/javascripts/user/app/templates/_list_content.emblem @@ -1,5 +1,15 @@ each user in list.users img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f" +.display-row + .display-label=t 'attributes.list.created_at' + .display-field=time list.created_at +if list.closed_at + .display-row + .display-label=t 'attributes.list.closed_at' + .display-field=time list.closed_at +.display-row + .display-label=t 'attributes.list.state' + .display-field=state 'list' list.state if list.orders .list-orders-container each order in list.sorted_orders diff --git a/app/assets/stylesheets/user/foundation/_display_fields.css.sass b/app/assets/stylesheets/user/foundation/_display_fields.css.sass new file mode 100644 index 00000000..989ab917 --- /dev/null +++ b/app/assets/stylesheets/user/foundation/_display_fields.css.sass @@ -0,0 +1,17 @@ +.display-row + @extend .row + .display-label + font-weight: bold + @media #{$small-only} + +grid-column($columns:10, $center:true) + @media #{$medium-only} + +grid-column($columns:4, $offset:1) + @media #{$large-up} + +grid-column(3) + .display-field + @media #{$small-only} + +grid-column($columns:10, $center:true, $last-column:true) + @media #{$medium-only} + +grid-column($columns:4, $last-column:true) + @media #{$large-up} + +grid-column($columns: 3, $last-column:true) diff --git a/app/assets/stylesheets/user/foundation/_qlists.css.sass b/app/assets/stylesheets/user/foundation/_qlists.css.sass index 44f40f12..b42adb43 100644 --- a/app/assets/stylesheets/user/foundation/_qlists.css.sass +++ b/app/assets/stylesheets/user/foundation/_qlists.css.sass @@ -12,6 +12,7 @@ clear: right +panel($padding: 4px) .list-orders-container + border-top: 2px solid #555 .currency float: right list-style: none diff --git a/app/assets/stylesheets/user/foundation/application.css.sass b/app/assets/stylesheets/user/foundation/application.css.sass index 9422893c..37354e7d 100644 --- a/app/assets/stylesheets/user/foundation/application.css.sass +++ b/app/assets/stylesheets/user/foundation/application.css.sass @@ -6,6 +6,7 @@ @import ./menu_main @import ./menu_side @import ./qmodal +@import ./display_fields @import ./qproduct_orders @import ./qproduct_categories @import ./form_additions diff --git a/app/views/suppliers/application/_top_menu.html.slim b/app/views/suppliers/application/_top_menu.html.slim index 10dcdd1f..289027f5 100644 --- a/app/views/suppliers/application/_top_menu.html.slim +++ b/app/views/suppliers/application/_top_menu.html.slim @@ -17,8 +17,8 @@ header.top-menu .table-number .supplier-info-row .counter.supplier-orders-placed-count - span.orders-placed-count-number= current_supplier.orders_placed_count - span.orders-placed-count-icon + span.supplier-orders-placed-count-number= current_supplier.orders_placed_count + span.supplier-orders-placed-count-icon .counter.supplier-orders-in-process-count span.supplier-orders-in-process-count-number= current_supplier.orders_in_process_count span.supplier-orders-in-process-count-icon diff --git a/config/locales/user.en.yml b/config/locales/user.en.yml index 12636b14..cb6c024f 100644 --- a/config/locales/user.en.yml +++ b/config/locales/user.en.yml @@ -84,3 +84,7 @@ en: order_button: Order total: Total no_orders: No products + state: + list: + active: 'Active' + closed: 'Closed' diff --git a/config/locales/user.nl.yml b/config/locales/user.nl.yml index 07a93bf3..2bae57b7 100644 --- a/config/locales/user.nl.yml +++ b/config/locales/user.nl.yml @@ -82,3 +82,7 @@ nl: order_button: Bestel total: Totaal no_orders: Geen bestellingen + state: + list: + active: 'Actief' + closed: 'Afgesloten' diff --git a/spec/acceptance/suppliers/section_view.feature b/spec/acceptance/suppliers/section_view.feature index 28208189..6f58866a 100644 --- a/spec/acceptance/suppliers/section_view.feature +++ b/spec/acceptance/suppliers/section_view.feature @@ -11,6 +11,9 @@ Feature: Supplier section view And the section table should be marked as occupied And the section table should not be marked as in need of help + When the order gets marked as being in process + Then the section table should still be marked as having an active order + When the list is marked as in need of help # waiting here only needed in old style implementation And I wait 1 second diff --git a/spec/acceptance_steps/order_steps.rb b/spec/acceptance_steps/order_steps.rb index 493a1666..57e3866e 100644 --- a/spec/acceptance_steps/order_steps.rb +++ b/spec/acceptance_steps/order_steps.rb @@ -23,6 +23,10 @@ step "the user order should be created as a new order" do end step "the user order gets marked as being in process" do + step "the order gets marked as being in process" +end + +step "the order gets marked as being in process" do @order.is_being_processed! end diff --git a/spec/acceptance_steps/suppliers/main_board_steps.rb b/spec/acceptance_steps/suppliers/main_board_steps.rb index 923a4eb2..72009ae9 100644 --- a/spec/acceptance_steps/suppliers/main_board_steps.rb +++ b/spec/acceptance_steps/suppliers/main_board_steps.rb @@ -134,7 +134,6 @@ step "the active list changes to another table in another section" do end step "the supplier main board table number should be updated to the new table number" do - binding.pry expect( find(".list-row-#{@list.id} .table_number").text ).to eq "65" expect( find(".order-row-#{@list.orders.first.id} .table_number").text ).to eq "65" end diff --git a/spec/acceptance_steps/suppliers/section_view_steps.rb b/spec/acceptance_steps/suppliers/section_view_steps.rb index bbba0b16..8195042b 100644 --- a/spec/acceptance_steps/suppliers/section_view_steps.rb +++ b/spec/acceptance_steps/suppliers/section_view_steps.rb @@ -10,9 +10,11 @@ end step "the section table should be marked as having an active order" do table = page.find(".section-table-#{@table.id}") - binding.pry table['class'].should include 'active_order' end +step "the section table should still be marked as having an active order" do + step "the section table should be marked as having an active order" +end step "the section table should be marked as occupied" do table = page.find(".section-table-#{@table.id}") diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index db36af48..5d3fcd3b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -67,6 +67,7 @@ RSpec.configure do |config| config.include Matchers config.include Features::BasicHelpers, type: :feature config.include SpecRouteHelpers, type: :feature + config.include SpecEmberHelpers, type: :feature #config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = true config.filter_run_excluding broken: true diff --git a/spec/support/ember_helpers.rb b/spec/support/ember_helpers.rb new file mode 100644 index 00000000..664352bc --- /dev/null +++ b/spec/support/ember_helpers.rb @@ -0,0 +1,17 @@ +module SpecEmberHelpers + def ember_store + h = page.evaluate_script <<-SCRIPT + $s = Qsupplier.App.__container__.lookup('controller:application').store; + JSON.stringify({ + lists: $s.all('list').invoke('serialize'), + orders: $s.all('order').invoke('serialize'), + product_orders: $s.all('product_order').invoke('serialize'), + product_categories: $s.all('product_category').invoke('serialize'), + products: $s.all('product').invoke('serialize'), + sections: $s.all('section').invoke('serialize'), + tables: $s.all('table').invoke('serialize') + }) + SCRIPT + JSON.parse(h) + end +end