From 0e4993e8a6b91f675084708c2472eed516d9681b Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Mon, 9 Jun 2014 19:07:46 +0200 Subject: [PATCH] Upgrades and fixes, maintenance --- Gemfile.lock | 6 ++-- .../supplier/app/models/list.js.coffee | 10 ++++-- .../supplier/app/models/table.js.coffee | 2 ++ .../app/routes/application_route.js.coffee | 7 +++- .../supplier/app/routes/index_route.js.coffee | 9 +++--- .../foundation1/initializer.js.coffee | 19 ++++++++--- .../foundation1/_product_categories.css.sass | 32 ++++++++++++------- app/decorators/product_category_decorator.rb | 4 +-- app/models/list.rb | 6 ++-- app/models/supplier.rb | 2 +- .../supplier_extended_table_serializer.rb | 8 ++--- app/serializers/supplier_list_serializer.rb | 2 +- .../product_categories/_form.html.slim | 12 +++---- .../product_categories/edit.html.slim | 2 +- lib/qwaiter/counter.rb | 2 +- .../suppliers/product_category_steps.rb | 2 +- .../suppliers/product_steps.rb | 4 +-- .../suppliers/section_view_steps.rb | 1 + .../acceptance_steps/suppliers/table_steps.rb | 3 +- .../product_category_decorator_spec.rb | 4 +-- spec/models/supplier_spec.rb | 2 ++ spec/spec_helper.rb | 4 +-- vendor/assets/ember/development/ember-data.js | 1 + 23 files changed, 87 insertions(+), 57 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d386d556..5218a10a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/bterkuile/couch_potato.git - revision: c84d3d8931505cfb3a6c25599e08a5d4b6975168 + revision: 6fbcb3edcaf3edec63230308f123c1e03417967d specs: couch_potato (0.7.1) activemodel @@ -345,7 +345,7 @@ GEM eventmachine (>= 1.0.0) rack (>= 1.0.0) thor (0.19.1) - thread_safe (0.3.3) + thread_safe (0.3.4) tilt (1.4.1) tinymce-rails (4.0.26) railties (>= 3.1.1) @@ -355,7 +355,7 @@ GEM turnip (1.2.1) gherkin (>= 2.5) rspec (>= 2.0, < 4.0) - tzinfo (1.2.0) + tzinfo (1.2.1) thread_safe (~> 0.1) uglifier (2.5.0) execjs (>= 0.3.0) diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index 9b4dc95b..c48beecf 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -6,11 +6,15 @@ Qsupplier.App.List = DS.Model.extend user_requests_closing: attr('boolean') users: DS.hasMany('user') is_paid: attr 'boolean' - has_active_orders: attr 'boolean' + #has_active_orders: attr 'boolean' + has_active_orders: (-> + return false unless @get('state') == 'active' + !!@get('orders').filterProperty('state', 'active').length + ).property('state', 'orders.@each.state') price: attr 'number' closed_at: DS.attr('date') #table_number: attr 'number' - table: DS.belongsTo('table', inverse: 'active_list') + #table: DS.belongsTo('table', inverse: 'active_list') #users: DS.hasMany('user', inverse: 'active_list') orders: DS.hasMany('order') section: DS.belongsTo('section') @@ -18,7 +22,7 @@ Qsupplier.App.List = DS.Model.extend active: ( -> @get('state') == 'active' ).property('state') markClosed: -> @set('state', 'closed') - @set 'has_active_orders', false + #@set 'has_active_orders', false @markHelped() @markIsPaid() markHelped: -> diff --git a/app/assets/javascripts/supplier/app/models/table.js.coffee b/app/assets/javascripts/supplier/app/models/table.js.coffee index d629f520..46bcca30 100644 --- a/app/assets/javascripts/supplier/app/models/table.js.coffee +++ b/app/assets/javascripts/supplier/app/models/table.js.coffee @@ -7,7 +7,9 @@ Qsupplier.App.Table = DS.Model.extend position_y: attr 'number' occupied: attr 'boolean' section: DS.belongsTo('section') + #active_list: DS.belongsTo('list', key: 'active_list') active_list: DS.belongsTo('list') + #list: DS.belongsTo('list') #active_list: (-> #@get('list') #).property('list') diff --git a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee index 672c25b5..4d20c935 100644 --- a/app/assets/javascripts/supplier/app/routes/application_route.js.coffee +++ b/app/assets/javascripts/supplier/app/routes/application_route.js.coffee @@ -1,3 +1,8 @@ Qsupplier.App.ApplicationRoute = Ember.Route.extend + beforeModel: -> + # Preload only active lists and orders + @store.find 'product_category' + #@store.find 'order', state: 'active' included in list setupController: (controller)-> - controller.set 'product_categories', @store.find('product_category') + @store.find 'list', state: 'active' + controller.set 'product_categories', @store.all('product_category') diff --git a/app/assets/javascripts/supplier/app/routes/index_route.js.coffee b/app/assets/javascripts/supplier/app/routes/index_route.js.coffee index 8b17125d..55911bf2 100644 --- a/app/assets/javascripts/supplier/app/routes/index_route.js.coffee +++ b/app/assets/javascripts/supplier/app/routes/index_route.js.coffee @@ -1,17 +1,16 @@ Qsupplier.App.IndexRoute = Ember.Route.extend model: (params, queryParams)-> - # Preload only active lists and orders - @store.find 'list', state: 'active' - @store.find 'order', state: 'active' Ember.Object.create # Find with condition does not work since the resulting array promise is not updated for newly created records #lists: Qsupplier.App.List.find({state: 'active'}) #orders: Qsupplier.App.Order.find({state: 'active'}) #lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet) # use filter to create a scope on all the records - lists: @store.filter 'list', -> true + #lists: @store.filter 'list', -> true + lists: @store.all 'list' # mayby @store.all 'list' will work better!!!! (2014-04-24 a more experienced benjamin :) - orders: @store.filter 'order', -> true + #orders: @store.filter 'order', -> true + orders: @store.all 'order' sections: @store.find 'section' setupController: (controller, model)-> controller.set('model', model) diff --git a/app/assets/javascripts/supplier/foundation1/initializer.js.coffee b/app/assets/javascripts/supplier/foundation1/initializer.js.coffee index 3d399cd7..9e5c4bc7 100644 --- a/app/assets/javascripts/supplier/foundation1/initializer.js.coffee +++ b/app/assets/javascripts/supplier/foundation1/initializer.js.coffee @@ -1,16 +1,25 @@ $ -> $('.week-day-toggle').each -> select = $('#week-day-select-'+$(@).data('day')) - $(@).addClass('active') if select.val() == '1' - $(@).click( -> select.val(Math.abs(select.val() - 1))) + $(@).addClass(if select.val() == '1' then 'active' else 'inactive') + $(@).click -> + new_val = Math.abs(select.val() - 1) + select.val new_val + if new_val == 1 + $(@).addClass('active') + $(@).removeClass('inactive') + else + $(@).addClass('inactive') + $(@).removeClass('active') $('#full_day-controller').each -> control = $('#product_category_full_day') if control.is(':checked') - $('#sub-day-container').removeClass('hide') - $(@).removeClass 'active' - else + $('#sub-day-container').addClass('hide') $(@).addClass('active') + else + $(@).removeClass 'active' + $('#sub-day-container').removeClass('hide') $(@).click -> if control.is(':checked') control.prop 'checked', false diff --git a/app/assets/stylesheets/supplier/foundation1/_product_categories.css.sass b/app/assets/stylesheets/supplier/foundation1/_product_categories.css.sass index a4590397..3d54484c 100644 --- a/app/assets/stylesheets/supplier/foundation1/_product_categories.css.sass +++ b/app/assets/stylesheets/supplier/foundation1/_product_categories.css.sass @@ -6,20 +6,24 @@ .name padding: 5px 5px #week_days-group - .btn - opacity: 0.4 + display: inline-block + .week-day-toggle + margin: 0 &.active - opacity: 1 + // nothing for now + &.inactive + opacity: 0.4 #full_day-controller - @extend .fa - @extend .fa-clock-o - margin: 0 10px - color: #f70 + span + @extend .fa + @extend .fa-clock-o + margin: 0 10px + color: #f70 &.active - // Full day active is not special, highlight when not active, - // because it indicates the being active of a time range - color: #444 - + span + // Full day active is not special, highlight when not active, + // because it indicates the being active of a time range + color: #444 #sub-day-container display: inline-block &.hide @@ -27,3 +31,9 @@ select width: 70px margin-right: 14px +.product-category-visible-never + @extend .fa + @extend .fa-times +.product-category-visible-always + @extend .fa + @extend .fa-circle-o-notch diff --git a/app/decorators/product_category_decorator.rb b/app/decorators/product_category_decorator.rb index f7db6319..27760f30 100644 --- a/app/decorators/product_category_decorator.rb +++ b/app/decorators/product_category_decorator.rb @@ -7,8 +7,8 @@ module ProductCategoryDecorator def visible_on sum = week_days.sum - return content_tag(:span, '', class: 'icon-eye-close icon-white') if sum.zero? - return content_tag(:span, '', class: 'icon-refresh icon-white') if sum == 7 && full_day + return content_tag(:span, '', class: 'product-category-visible-never') if sum.zero? + return content_tag(:span, '', class: 'product-category-visible-always') if sum == 7 && full_day day_names = I18n.t('date.day_names') days = week_days.map.with_index{|v,i| v == 1 ? day_names[i] : nil}.compact days << days.shift if week_days.first == 1 && supplier.week_starts_on_monday? diff --git a/app/models/list.rb b/app/models/list.rb index 8aa1f527..ac7c6263 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -200,7 +200,7 @@ class List def move_to_table! to_table UserTableMove.create list: self, from_table_id: table_id, to_table: to_table - from_table = self.table_id.try(:dup) + from_table_id = self.table_id.try(:dup) self.table = to_table self.section_id = to_table.section_id if save @@ -210,8 +210,8 @@ class List order.save end # user performs a client side refresh - broadcast_users 'list_changed_table', list_id: id #, from_table_id: from_table, to_table_id: to_table.id - broadcast_supplier supplier_id, 'list_changed_table', ListSerializer.new(list).as_json + broadcast_users 'list_changed_table', list_id: id, from_table_id: from_table_id, to_table_id: to_table.id + broadcast_supplier supplier_id, 'list_changed_table', ListSerializer.new(self).as_json end end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 02af8584..52ee53c1 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -119,7 +119,7 @@ class Supplier end def self.reset_counters! - + # Set all known counters to zero Qwaiter::Couchbase.design_doc('supplier').counters(reduce: false).each{|counter| Qwaiter::Counter.set counter.key, 0} spec = Order.by_supplier_id_and_state(reduce: true, group_level: 2) diff --git a/app/serializers/supplier_extended_table_serializer.rb b/app/serializers/supplier_extended_table_serializer.rb index a05e8d37..2173a0b9 100644 --- a/app/serializers/supplier_extended_table_serializer.rb +++ b/app/serializers/supplier_extended_table_serializer.rb @@ -1,7 +1,7 @@ class SupplierExtendedTableSerializer < Qwaiter::Serializer root 'table' embed :ids, include: true - attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :alist_id + attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied, :active_list_id #def list_id #object.active_list_id || object.active_list.try(:id) @@ -11,9 +11,5 @@ class SupplierExtendedTableSerializer < Qwaiter::Serializer #object.active_list #end - def list - object.active_list - end - - has_one :list, key: :active_list_id, serializer: SupplierExtendedListSerializer + #has_one :list, key: :active_list_id, serializer: SupplierExtendedListSerializer end diff --git a/app/serializers/supplier_list_serializer.rb b/app/serializers/supplier_list_serializer.rb index 91197775..30853159 100644 --- a/app/serializers/supplier_list_serializer.rb +++ b/app/serializers/supplier_list_serializer.rb @@ -6,7 +6,7 @@ class SupplierListSerializer < Qwaiter::Serializer :table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at has_many :orders #has_many :product_categories - has_one :table, serializer: SupplierTableSerializer + #has_one :table, serializer: SupplierTableSerializer # tables are part of the sectoins load has_many :join_requests has_many :users, serializer: SupplierUserSerializer diff --git a/app/views/suppliers/product_categories/_form.html.slim b/app/views/suppliers/product_categories/_form.html.slim index d7daeba5..8c729752 100644 --- a/app/views/suppliers/product_categories/_form.html.slim +++ b/app/views/suppliers/product_categories/_form.html.slim @@ -18,20 +18,20 @@ .form-label = label_tag nil, ProductCategory.human_attribute_name(:week_days), class: 'control-label' .form-field.full - #week_days-group.btn-group data-toggle="buttons-checkbox" + ul#week_days-group.button-group - day_names = week_days.dup; day_names << day_names.shift if current_supplier.week_starts_on_monday? - day_names.each do |day_name| - button.week-day-toggle.tiny type="button" data-day=day_name data-t="product_category.week_days.abbreviation.#{day_name}" + li: button.week-day-toggle.tiny type="button" data-day=day_name data-t="product_category.week_days.abbreviation.#{day_name}" - span#full_day-controller + span#full_day-controller: span #sub-day-container.hide - /= f.input_field :start_from, as: :select, collection: (1..24).map{|h| ["#{h}:00", h*60]} - /= f.input_field :end_on, as: :select, collection: (1..24).map{|h| ["#{h}:00", h*60]} + = f.select :start_from, (1..24).map{|h| ["#{h}:00", h*60]} + = f.select :end_on, (1..24).map{|h| ["#{h}:00", h*60]} .hidden - @product_category.week_days.each.with_index do |day, i| = select_tag 'product_category[week_days][]', options_for_select([0,1], day), class: 'week-day-select', id: "week-day-select-#{week_days[i]}", data: {day: week_days[i] } /= f.input :full_day, as: :select, collection: [true, false], label: false, include_blank: false /= f.input_field :full_day, as: :boolean, label: false, wrapper: false - /= f.check_box :full_day + = f.check_box :full_day = f.supplier_form_actions diff --git a/app/views/suppliers/product_categories/edit.html.slim b/app/views/suppliers/product_categories/edit.html.slim index b68302b0..12cc25f3 100644 --- a/app/views/suppliers/product_categories/edit.html.slim +++ b/app/views/suppliers/product_categories/edit.html.slim @@ -1,4 +1,4 @@ - model_class = ProductCategory .page-header = title :edit, model_class -= render 'form' += render 'form' diff --git a/lib/qwaiter/counter.rb b/lib/qwaiter/counter.rb index bdd4b2fd..ab7432f4 100644 --- a/lib/qwaiter/counter.rb +++ b/lib/qwaiter/counter.rb @@ -26,4 +26,4 @@ end # use the connection from couchbase-structures/documents # will be overwritten in the specs since flushing the real # thing is difficult -Qwaiter::Counter.connection = $cb +Qwaiter::Counter.connection = $cb unless Rails.env.test? diff --git a/spec/acceptance_steps/suppliers/product_category_steps.rb b/spec/acceptance_steps/suppliers/product_category_steps.rb index aa0f5a55..7a2b0b3f 100644 --- a/spec/acceptance_steps/suppliers/product_category_steps.rb +++ b/spec/acceptance_steps/suppliers/product_category_steps.rb @@ -29,7 +29,7 @@ end step "the supplier clicks on the edit product category button" do within "#product_category_#{@product_category.id}" do - find('.edit-resource-button').click + find('.table-edit').click end end diff --git a/spec/acceptance_steps/suppliers/product_steps.rb b/spec/acceptance_steps/suppliers/product_steps.rb index de1dad6e..7699924a 100644 --- a/spec/acceptance_steps/suppliers/product_steps.rb +++ b/spec/acceptance_steps/suppliers/product_steps.rb @@ -19,7 +19,7 @@ step "the supplier fills in the new product form selecting the first product cat end step "the supplier submits the product form" do - find('.save-product-button').click + find('.form-action-submit').click end @@ -38,7 +38,7 @@ end step "the supplier clicks on the edit product button" do within ".product-row-#{@product.id}" do - find('.edit-resource-button').click + find('.table-edit').click end end diff --git a/spec/acceptance_steps/suppliers/section_view_steps.rb b/spec/acceptance_steps/suppliers/section_view_steps.rb index b89b6971..bbba0b16 100644 --- a/spec/acceptance_steps/suppliers/section_view_steps.rb +++ b/spec/acceptance_steps/suppliers/section_view_steps.rb @@ -10,6 +10,7 @@ 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 diff --git a/spec/acceptance_steps/suppliers/table_steps.rb b/spec/acceptance_steps/suppliers/table_steps.rb index 25eb79c1..975c93e2 100644 --- a/spec/acceptance_steps/suppliers/table_steps.rb +++ b/spec/acceptance_steps/suppliers/table_steps.rb @@ -10,7 +10,8 @@ step "the supplier fills in the new table form selecting the first section" do end step "the supplier submits the table form" do - find('.save-table-button').click + #find('.save-table-button').click + find('.form-action-submit').click end step "the new supplier table with proper properties should have been created" do diff --git a/spec/decorators/product_category_decorator_spec.rb b/spec/decorators/product_category_decorator_spec.rb index 93de1a75..c27649af 100644 --- a/spec/decorators/product_category_decorator_spec.rb +++ b/spec/decorators/product_category_decorator_spec.rb @@ -35,12 +35,12 @@ describe ProductCategoryDecorator do it "shows a dash when it is never visible" do product_category.stub(:week_days).and_return([0,0,0,0,0,0,0]) - subject.visible_on.should include 'icon-eye-close' + subject.visible_on.should include 'product-category-visible-never' end it "should display an icon when always visible" do product_category.stub(:week_days).and_return([1,1,1,1,1,1,1]) - subject.visible_on.should include 'icon-refresh' + subject.visible_on.should include 'product-category-visible-always' end it "should only display time when all days active and time range given" do diff --git a/spec/models/supplier_spec.rb b/spec/models/supplier_spec.rb index 6f366a55..1e4194bd 100644 --- a/spec/models/supplier_spec.rb +++ b/spec/models/supplier_spec.rb @@ -17,6 +17,7 @@ describe Supplier do end it 'cleans counter values if orders are no longer available' do + old_connection = Qwaiter::Counter.connection # this spec should run on the couchbase database Qwaiter::Counter.connection = $cb supplier = create :supplier @@ -24,6 +25,7 @@ describe Supplier do supplier.orders_placed_count.should == 9 Supplier.reset_counters! supplier.orders_placed_count.should == 0 + Qwaiter::Counter.connection = old_connection end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0df81fbb..57c3c740 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -44,8 +44,6 @@ module SpecSelectorHelpers end end -# NOT THREADSAFE!!!!!! but good enough for testing since the real couchbase flush is slowwwwww.... -Qwaiter::Counter.connection = InMemoryQCounter.new class Couchbase::View alias :old_initialize :initialize def initialize(bucket, endpoint, params = {}) @@ -108,6 +106,8 @@ RSpec.configure do |config| #config.use_transactional_fixtures = true config.before :suite do Qwaiter::Couchbase.load_design_docs! + # NOT THREADSAFE!!!!!! but good enough for testing since the real couchbase flush is slowwwwww.... + Qwaiter::Counter.connection = InMemoryQCounter.new end config.before :each do diff --git a/vendor/assets/ember/development/ember-data.js b/vendor/assets/ember/development/ember-data.js index cf7d6aa1..318e9826 100644 --- a/vendor/assets/ember/development/ember-data.js +++ b/vendor/assets/ember/development/ember-data.js @@ -282,6 +282,7 @@ define("activemodel-adapter/lib/system/active_model_serializer", */ keyForRelationship: function(key, kind) { key = decamelize(key); + //if(key === 'active_list') debugger; if (kind === "belongsTo") { return key + "_id"; } else if (kind === "hasMany") {