Upgrades and fixes, maintenance

This commit is contained in:
2014-06-09 19:07:46 +02:00
parent 78a894759b
commit 0e4993e8a6
23 changed files with 87 additions and 57 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
GIT GIT
remote: git://github.com/bterkuile/couch_potato.git remote: git://github.com/bterkuile/couch_potato.git
revision: c84d3d8931505cfb3a6c25599e08a5d4b6975168 revision: 6fbcb3edcaf3edec63230308f123c1e03417967d
specs: specs:
couch_potato (0.7.1) couch_potato (0.7.1)
activemodel activemodel
@@ -345,7 +345,7 @@ GEM
eventmachine (>= 1.0.0) eventmachine (>= 1.0.0)
rack (>= 1.0.0) rack (>= 1.0.0)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.3) thread_safe (0.3.4)
tilt (1.4.1) tilt (1.4.1)
tinymce-rails (4.0.26) tinymce-rails (4.0.26)
railties (>= 3.1.1) railties (>= 3.1.1)
@@ -355,7 +355,7 @@ GEM
turnip (1.2.1) turnip (1.2.1)
gherkin (>= 2.5) gherkin (>= 2.5)
rspec (>= 2.0, < 4.0) rspec (>= 2.0, < 4.0)
tzinfo (1.2.0) tzinfo (1.2.1)
thread_safe (~> 0.1) thread_safe (~> 0.1)
uglifier (2.5.0) uglifier (2.5.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
@@ -6,11 +6,15 @@ Qsupplier.App.List = DS.Model.extend
user_requests_closing: attr('boolean') user_requests_closing: attr('boolean')
users: DS.hasMany('user') users: DS.hasMany('user')
is_paid: attr 'boolean' 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' price: attr 'number'
closed_at: DS.attr('date') closed_at: DS.attr('date')
#table_number: attr 'number' #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') #users: DS.hasMany('user', inverse: 'active_list')
orders: DS.hasMany('order') orders: DS.hasMany('order')
section: DS.belongsTo('section') section: DS.belongsTo('section')
@@ -18,7 +22,7 @@ Qsupplier.App.List = DS.Model.extend
active: ( -> @get('state') == 'active' ).property('state') active: ( -> @get('state') == 'active' ).property('state')
markClosed: -> markClosed: ->
@set('state', 'closed') @set('state', 'closed')
@set 'has_active_orders', false #@set 'has_active_orders', false
@markHelped() @markHelped()
@markIsPaid() @markIsPaid()
markHelped: -> markHelped: ->
@@ -7,7 +7,9 @@ Qsupplier.App.Table = DS.Model.extend
position_y: attr 'number' position_y: attr 'number'
occupied: attr 'boolean' occupied: attr 'boolean'
section: DS.belongsTo('section') section: DS.belongsTo('section')
#active_list: DS.belongsTo('list', key: 'active_list')
active_list: DS.belongsTo('list') active_list: DS.belongsTo('list')
#list: DS.belongsTo('list')
#active_list: (-> #active_list: (->
#@get('list') #@get('list')
#).property('list') #).property('list')
@@ -1,3 +1,8 @@
Qsupplier.App.ApplicationRoute = Ember.Route.extend 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)-> setupController: (controller)->
controller.set 'product_categories', @store.find('product_category') @store.find 'list', state: 'active'
controller.set 'product_categories', @store.all('product_category')
@@ -1,17 +1,16 @@
Qsupplier.App.IndexRoute = Ember.Route.extend Qsupplier.App.IndexRoute = Ember.Route.extend
model: (params, queryParams)-> model: (params, queryParams)->
# Preload only active lists and orders
@store.find 'list', state: 'active'
@store.find 'order', state: 'active'
Ember.Object.create Ember.Object.create
# Find with condition does not work since the resulting array promise is not updated for newly created records # 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'}) #lists: Qsupplier.App.List.find({state: 'active'})
#orders: Qsupplier.App.Order.find({state: 'active'}) #orders: Qsupplier.App.Order.find({state: 'active'})
#lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet) #lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet)
# use filter to create a scope on all the records # 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 :) # 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' sections: @store.find 'section'
setupController: (controller, model)-> setupController: (controller, model)->
controller.set('model', model) controller.set('model', model)
@@ -1,16 +1,25 @@
$ -> $ ->
$('.week-day-toggle').each -> $('.week-day-toggle').each ->
select = $('#week-day-select-'+$(@).data('day')) select = $('#week-day-select-'+$(@).data('day'))
$(@).addClass('active') if select.val() == '1' $(@).addClass(if select.val() == '1' then 'active' else 'inactive')
$(@).click( -> select.val(Math.abs(select.val() - 1))) $(@).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 -> $('#full_day-controller').each ->
control = $('#product_category_full_day') control = $('#product_category_full_day')
if control.is(':checked') if control.is(':checked')
$('#sub-day-container').removeClass('hide') $('#sub-day-container').addClass('hide')
$(@).removeClass 'active'
else
$(@).addClass('active') $(@).addClass('active')
else
$(@).removeClass 'active'
$('#sub-day-container').removeClass('hide')
$(@).click -> $(@).click ->
if control.is(':checked') if control.is(':checked')
control.prop 'checked', false control.prop 'checked', false
@@ -6,20 +6,24 @@
.name .name
padding: 5px 5px padding: 5px 5px
#week_days-group #week_days-group
.btn display: inline-block
opacity: 0.4 .week-day-toggle
margin: 0
&.active &.active
opacity: 1 // nothing for now
&.inactive
opacity: 0.4
#full_day-controller #full_day-controller
span
@extend .fa @extend .fa
@extend .fa-clock-o @extend .fa-clock-o
margin: 0 10px margin: 0 10px
color: #f70 color: #f70
&.active &.active
span
// Full day active is not special, highlight when not active, // Full day active is not special, highlight when not active,
// because it indicates the being active of a time range // because it indicates the being active of a time range
color: #444 color: #444
#sub-day-container #sub-day-container
display: inline-block display: inline-block
&.hide &.hide
@@ -27,3 +31,9 @@
select select
width: 70px width: 70px
margin-right: 14px margin-right: 14px
.product-category-visible-never
@extend .fa
@extend .fa-times
.product-category-visible-always
@extend .fa
@extend .fa-circle-o-notch
+2 -2
View File
@@ -7,8 +7,8 @@ module ProductCategoryDecorator
def visible_on def visible_on
sum = week_days.sum sum = week_days.sum
return content_tag(:span, '', class: 'icon-eye-close icon-white') if sum.zero? return content_tag(:span, '', class: 'product-category-visible-never') 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-always') if sum == 7 && full_day
day_names = I18n.t('date.day_names') day_names = I18n.t('date.day_names')
days = week_days.map.with_index{|v,i| v == 1 ? day_names[i] : nil}.compact 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? days << days.shift if week_days.first == 1 && supplier.week_starts_on_monday?
+3 -3
View File
@@ -200,7 +200,7 @@ class List
def move_to_table! to_table def move_to_table! to_table
UserTableMove.create list: self, from_table_id: table_id, 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.table = to_table
self.section_id = to_table.section_id self.section_id = to_table.section_id
if save if save
@@ -210,8 +210,8 @@ class List
order.save order.save
end end
# user performs a client side refresh # 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_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(list).as_json broadcast_supplier supplier_id, 'list_changed_table', ListSerializer.new(self).as_json
end end
end end
+1 -1
View File
@@ -119,7 +119,7 @@ class Supplier
end end
def self.reset_counters! 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} 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) spec = Order.by_supplier_id_and_state(reduce: true, group_level: 2)
@@ -1,7 +1,7 @@
class SupplierExtendedTableSerializer < Qwaiter::Serializer class SupplierExtendedTableSerializer < Qwaiter::Serializer
root 'table' root 'table'
embed :ids, include: true 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 #def list_id
#object.active_list_id || object.active_list.try(:id) #object.active_list_id || object.active_list.try(:id)
@@ -11,9 +11,5 @@ class SupplierExtendedTableSerializer < Qwaiter::Serializer
#object.active_list #object.active_list
#end #end
def list #has_one :list, key: :active_list_id, serializer: SupplierExtendedListSerializer
object.active_list
end
has_one :list, key: :active_list_id, serializer: SupplierExtendedListSerializer
end end
+1 -1
View File
@@ -6,7 +6,7 @@ class SupplierListSerializer < Qwaiter::Serializer
:table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at :table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at
has_many :orders has_many :orders
#has_many :product_categories #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 :join_requests
has_many :users, serializer: SupplierUserSerializer has_many :users, serializer: SupplierUserSerializer
@@ -18,20 +18,20 @@
.form-label .form-label
= label_tag nil, ProductCategory.human_attribute_name(:week_days), class: 'control-label' = label_tag nil, ProductCategory.human_attribute_name(:week_days), class: 'control-label'
.form-field.full .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 = week_days.dup; day_names << day_names.shift if current_supplier.week_starts_on_monday?
- day_names.each do |day_name| - 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 #sub-day-container.hide
/= f.input_field :start_from, as: :select, collection: (1..24).map{|h| ["#{h}:00", h*60]} = f.select :start_from, (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 :end_on, (1..24).map{|h| ["#{h}:00", h*60]}
.hidden .hidden
- @product_category.week_days.each.with_index do |day, i| - @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] } = 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 :full_day, as: :select, collection: [true, false], label: false, include_blank: false
/= f.input_field :full_day, as: :boolean, label: false, wrapper: 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 = f.supplier_form_actions
+1 -1
View File
@@ -26,4 +26,4 @@ end
# use the connection from couchbase-structures/documents # use the connection from couchbase-structures/documents
# will be overwritten in the specs since flushing the real # will be overwritten in the specs since flushing the real
# thing is difficult # thing is difficult
Qwaiter::Counter.connection = $cb Qwaiter::Counter.connection = $cb unless Rails.env.test?
@@ -29,7 +29,7 @@ end
step "the supplier clicks on the edit product category button" do step "the supplier clicks on the edit product category button" do
within "#product_category_#{@product_category.id}" do within "#product_category_#{@product_category.id}" do
find('.edit-resource-button').click find('.table-edit').click
end end
end end
@@ -19,7 +19,7 @@ step "the supplier fills in the new product form selecting the first product cat
end end
step "the supplier submits the product form" do step "the supplier submits the product form" do
find('.save-product-button').click find('.form-action-submit').click
end end
@@ -38,7 +38,7 @@ end
step "the supplier clicks on the edit product button" do step "the supplier clicks on the edit product button" do
within ".product-row-#{@product.id}" do within ".product-row-#{@product.id}" do
find('.edit-resource-button').click find('.table-edit').click
end end
end end
@@ -10,6 +10,7 @@ end
step "the section table should be marked as having an active order" do step "the section table should be marked as having an active order" do
table = page.find(".section-table-#{@table.id}") table = page.find(".section-table-#{@table.id}")
binding.pry
table['class'].should include 'active_order' table['class'].should include 'active_order'
end end
@@ -10,7 +10,8 @@ step "the supplier fills in the new table form selecting the first section" do
end end
step "the supplier submits the table form" do step "the supplier submits the table form" do
find('.save-table-button').click #find('.save-table-button').click
find('.form-action-submit').click
end end
step "the new supplier table with proper properties should have been created" do step "the new supplier table with proper properties should have been created" do
@@ -35,12 +35,12 @@ describe ProductCategoryDecorator do
it "shows a dash when it is never visible" 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]) 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 end
it "should display an icon when always visible" do it "should display an icon when always visible" do
product_category.stub(:week_days).and_return([1,1,1,1,1,1,1]) 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 end
it "should only display time when all days active and time range given" do it "should only display time when all days active and time range given" do
+2
View File
@@ -17,6 +17,7 @@ describe Supplier do
end end
it 'cleans counter values if orders are no longer available' do it 'cleans counter values if orders are no longer available' do
old_connection = Qwaiter::Counter.connection
# this spec should run on the couchbase database # this spec should run on the couchbase database
Qwaiter::Counter.connection = $cb Qwaiter::Counter.connection = $cb
supplier = create :supplier supplier = create :supplier
@@ -24,6 +25,7 @@ describe Supplier do
supplier.orders_placed_count.should == 9 supplier.orders_placed_count.should == 9
Supplier.reset_counters! Supplier.reset_counters!
supplier.orders_placed_count.should == 0 supplier.orders_placed_count.should == 0
Qwaiter::Counter.connection = old_connection
end end
end end
+2 -2
View File
@@ -44,8 +44,6 @@ module SpecSelectorHelpers
end end
end end
# NOT THREADSAFE!!!!!! but good enough for testing since the real couchbase flush is slowwwwww....
Qwaiter::Counter.connection = InMemoryQCounter.new
class Couchbase::View class Couchbase::View
alias :old_initialize :initialize alias :old_initialize :initialize
def initialize(bucket, endpoint, params = {}) def initialize(bucket, endpoint, params = {})
@@ -108,6 +106,8 @@ RSpec.configure do |config|
#config.use_transactional_fixtures = true #config.use_transactional_fixtures = true
config.before :suite do config.before :suite do
Qwaiter::Couchbase.load_design_docs! 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 end
config.before :each do config.before :each do
+1
View File
@@ -282,6 +282,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
*/ */
keyForRelationship: function(key, kind) { keyForRelationship: function(key, kind) {
key = decamelize(key); key = decamelize(key);
//if(key === 'active_list') debugger;
if (kind === "belongsTo") { if (kind === "belongsTo") {
return key + "_id"; return key + "_id";
} else if (kind === "hasMany") { } else if (kind === "hasMany") {