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
@@ -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: ->
@@ -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')
@@ -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')
@@ -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)
@@ -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
@@ -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
+2 -2
View File
@@ -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?
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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)
@@ -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
+1 -1
View File
@@ -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
@@ -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
@@ -1,4 +1,4 @@
- model_class = ProductCategory
.page-header
= title :edit, model_class
= render 'form'
= render 'form'