Time dependant product categories for users
This commit is contained in:
@@ -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 = {})
|
||||
|
||||
Reference in New Issue
Block a user