Time dependant product categories for users

This commit is contained in:
2015-01-22 17:49:32 +01:00
parent f434b53161
commit 36525849bd
24 changed files with 9981 additions and 46 deletions
@@ -5,14 +5,14 @@
helpers: <%= I18n.t('helpers', locale: :en).to_json %>
pagination: <%= I18n.t('views.pagination', locale: :en).to_json %>
errors: <%= I18n.t('errors', locale: :en).to_json %>
date: <%= {day_name: Hash[%w[sunday monday tuesday wednesday thursday friday saturday].zip(I18n.t('date.day_names', locale: :en))]}.to_json %>
date: <%= {day_name: Hash[Date::DAYNAMES.map(&:downcase).zip(I18n.t('date.day_names', locale: :en))]}.to_json %>
nl:
models: <%= I18n.t('activemodel.models', locale: :nl).to_json %>
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>
errors: <%= I18n.t('errors', locale: :nl).to_json %>
date: <%= {day_name: Hash[%w[sunday monday tuesday wednesday thursday friday saturday].zip(I18n.t('date.day_names', locale: :nl))]}.to_json %>
date: <%= {day_name: Hash[Date::DAYNAMES.map(&:downcase).zip(I18n.t('date.day_names', locale: :nl))]}.to_json %>
@day_minutes_to_time = (minutes)->
return "" unless minutes
@@ -1,3 +1,21 @@
now = new Date()
ClockService = Ember.Object.extend
minute_of_day: 60*now.getHours() + now.getMinutes()
run_times: 0
tick: (->
clock = this
Ember.run.later ->
now = new Date()
clock.set 'minute_of_day', 60*now.getHours() + now.getMinutes()
clock.set 'run_times', 1 + clock.get('run_times')
, 20000
).observes('run_times').on('init')
Ember.Application.initializer
name: 'clockServiceInitializer'
initialize: (container, application)->
container.register 'clock:service', ClockService
application.inject 'component:menu-product-categories', 'clock', 'clock:service'
@App = Ember.Application.create
LOG_TRANSITIONS: true
rootElement: '#ember-app-container'
@@ -1,9 +1,16 @@
App.MenuProductCategoriesComponent = Ember.Component.extend
orderProducts: false
timestamp: 0 # invalidation param
#minute_of_day: 0 # invalidation param
active_product_categories: (->
console.log "Reevaluate product categories"
list = @get('product_categories')
).property('product_categories.@each', 'timestamp')
now = new Date()
list = list.filter (product_category) =>
return false unless product_category.get("active_on_#{$day_names[now.getDay()]}")
return true if product_category.get('full_day')
product_category.get('start_from') <= @get('clock.minute_of_day') and @get('clock.minute_of_day') <= product_category.get('end_on')
list.sortBy('position')
).property('product_categories.@each', 'clock.minute_of_day')
actions:
toggleProductCategory: (product_category) -> product_category.toggleProperty('collapsed')
@@ -3,6 +3,7 @@ App.Product = DS.Model.extend
name: attr 'string'
price: attr 'number'
description: attr 'string'
position: attr('number', defaultValue: 0)
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
@@ -3,4 +3,17 @@ App.ProductCategory = DS.Model.extend
name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo('supplier')
active_on_sunday: attr('boolean', defaultValue: true)
active_on_monday: attr('boolean', defaultValue: true)
active_on_tuesday: attr('boolean', defaultValue: true)
active_on_wednesday: attr('boolean', defaultValue: true)
active_on_thursday: attr('boolean', defaultValue: true)
active_on_friday: attr('boolean', defaultValue: true)
active_on_saturday: attr('boolean', defaultValue: true)
full_day: attr 'boolean', defaultValue: true
start_from: attr('number')
end_on: attr('number')
position: attr('number')
collapsed: attr('boolean', defaultValue: false)
sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position')
@@ -1,7 +1,5 @@
each product_category in active_product_categories
.product-category-container
if orderProducts
h4 OderProducts
.product-category-container id="product-category-#{unbound product_category.id}"
if product_category.products
h4.product_category-title{action "toggleProductCategory" product_category}
if product_category.collapsed
@@ -11,5 +9,5 @@ each product_category in active_product_categories
= product_category.name
unless product_category.collapsed
ul.product_category-products
each product in product_category.products
each product in product_category.sorted_products
= menu-product product=product orderProducts=orderProducts