Time dependant product categories for users
This commit is contained in:
@@ -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'
|
||||
|
||||
+9
-2
@@ -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
|
||||
|
||||
@@ -94,9 +94,9 @@ module ApplicationHelper
|
||||
current_user.try(:active_list_id)
|
||||
end
|
||||
|
||||
def week_days
|
||||
@week_days ||= %w[sunday monday tuesday wednesday thursday friday saturday].freeze # Do not allow changing this value
|
||||
end
|
||||
#def week_days
|
||||
#@week_days ||= %w[sunday monday tuesday wednesday thursday friday saturday].freeze # Do not allow changing this value
|
||||
#end
|
||||
|
||||
def current_supplier
|
||||
#@current_supplier ||= ActiveDecorator::Decorator.instance.decorate(super)
|
||||
|
||||
@@ -4,7 +4,6 @@ class ProductCategory
|
||||
|
||||
property :name
|
||||
property :position, type: Fixnum, default: 0
|
||||
property :week_days, type: Array, default: Array.new(7, 1)
|
||||
property :full_day, type: :boolean, default: true
|
||||
property :start_from, type: Fixnum, default: 1320 # 22:00
|
||||
property :end_on, type: Fixnum, default: 1380 # 23:00
|
||||
@@ -28,30 +27,6 @@ class ProductCategory
|
||||
validates :end_on, numericality: {less_than: 2880}, presence: {unless: :full_day?}
|
||||
|
||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||
view :by_supplier_id_and_week_time, type: :custom, map_function: "function(doc){
|
||||
if(doc.ruby_class == 'ProductCategory'){
|
||||
for(var i=0;i<7;i++){
|
||||
if(doc.full_day || !doc.end_on){
|
||||
if(doc.week_days[i]) emit([doc.supplier_id, i], 1);
|
||||
}else{
|
||||
for(var j=(doc.start_from || 0);j < doc.end_on;j++){
|
||||
if(doc.week_days[i]) emit([doc.supplier_id, i, j], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}", reduce_function: :_sum
|
||||
|
||||
#start_key: [supplier_id, wday, minute], end_key: [supplier_id, wday, 2880, minute]
|
||||
|
||||
#alias orignal_week_days= week_days=
|
||||
def week_days=(ary)
|
||||
#write_attribute(:week_days, ary.map(&:to_i))
|
||||
typecasted_value = ary.map(&:to_i)
|
||||
#return typecasted_value if @week_days == typecasted_value
|
||||
week_days_will_change! unless @skip_dirty_tracking || typecasted_value == week_days
|
||||
@week_days = typecasted_value
|
||||
end
|
||||
|
||||
#TODO I am uuuuggggllyyyyy
|
||||
def self.for_user(user, options = {})
|
||||
|
||||
@@ -14,6 +14,7 @@ html lang="en"
|
||||
var $event_host = '#{Qwaiter.event_host}';
|
||||
var $assets_path = './assets/';
|
||||
var $app_version = '#{app_version}';
|
||||
var $day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
|
||||
var $user_feedback_path = 'http://feedback.mozo.bar/user_feedback';
|
||||
var Qstorage = window.localStorage;
|
||||
Qstorage.setItem('root_url', '##root_url##');
|
||||
@@ -27,6 +28,7 @@ html lang="en"
|
||||
var $event_host = '#{Qwaiter.event_host}';
|
||||
var $assets_path = '/assets/';
|
||||
var $app_version = '#{app_version}';
|
||||
var $day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
|
||||
var $user_feedback_path = 'http://feedback.mozo.bar/user_feedback';
|
||||
var Qstorage = window.localStorage;
|
||||
#{user_dynamic_data_host};
|
||||
@@ -41,6 +43,7 @@ html lang="en"
|
||||
var $event_host = '#{Qwaiter.event_host}';
|
||||
var $assets_path = '/assets/';
|
||||
var $app_version = '#{app_version}';
|
||||
var $day_names = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
|
||||
var $user_feedback_path = '/user_feedback';
|
||||
var Qstorage = window.localStorage;
|
||||
#{user_dynamic_data_host};
|
||||
|
||||
Reference in New Issue
Block a user