before switch to ubuntu commit since apple has issues

This commit is contained in:
2015-08-13 12:54:02 +02:00
parent 6b764fcd39
commit 919474b54c
17 changed files with 81 additions and 41 deletions
@@ -30,8 +30,6 @@ App.ApplicationController = Ember.Controller.extend
@transitionToRoute('list', data.id).then =>
@set 'globals.list.state', 'closed'
@set 'globals.list', null
join_request_approved: (data)->
@setCurrentList -> @transitionToRoute('active_list')
order_being_processed: (data)->
order = @store.all('order').findBy 'id', data.id
order.set('state', 'active') if order
@@ -63,16 +61,20 @@ App.ApplicationController = Ember.Controller.extend
if requestor_id is Qstorage.getItem('user_id')
@set 'globals.notice', t('join_request.requestor.join_request_rejected')
@set 'globals.join_request_sent', false
else
@transitionToRoute 'active_list'
join_request_approved: ->
return if @get('globals.list.id') # Not interested when there is an active list
join_request_approved: (data)->
return @transitionToRoute 'active_list' if @get('globals.list.id') # Not interested when there is an active list
# The rest of the code is for the new user
@setCurrentList ->
@transitionToRoute('active_list').then =>
@set 'globals.notice', t('join_request.requestor.join_request_approved')
@set 'globals.join_request_sent', false
list_changed_table: ->
@setCurrentList()
list_changed_table: (data)->
@store.findRecord('table', data.to_table_id).then (table)=>@set('globals.list.table', table)
orders_in_process_count: (data)->
@set 'globals.list.supplier.orders_in_process_count', data.count
orders_placed_count: (data)->
@@ -4,6 +4,7 @@ DS.Model.reopen
eraseRecord: ->
#@clearRelationships()
@transitionTo('deleted.saved')
@unloadRecord()
DS.Model.reopenClass
findCached: (id)->
return null unless id
@@ -19,7 +19,7 @@
=link-to 'active_list' class="side-menu-active-list"
span.active-list-icon
span= t 'active_list.title'
if globals.list.join_requests
if globals.list.join_requests.length
li
=link-to 'join_requests'
span= t 'models.plural.join_request'
@@ -26,7 +26,7 @@ module Suppliers
def active
@lists = List.active_for_supplier(current_supplier.id)
@lists = List.active_for_supplier(current_supplier)
@lists.include_relation(:table) # for number
respond_to do |format|
@@ -4,7 +4,7 @@ module Suppliers
# GET /tables.json
def index
if params[:state] == 'active'
@orders = Order.active_for_supplier(current_supplier.id)
@orders = Order.active_for_supplier(current_supplier)
else
@orders = Order.for_supplier(current_supplier, page: params[:page], per_page: params['per_page'] || 25)
end
@@ -8,7 +8,7 @@ module Suppliers
@sections = current_supplier.sections
@sections.include_relation(:tables)
# @active_lists = List.active_for_supplier(current_supplier.id)
# @active_lists = List.active_for_supplier(current_supplier)
# @active_table_ids = @active_lists.map(&:table_id).compact
# for section in @sections
# for table in section.tables
+21 -18
View File
@@ -29,17 +29,22 @@ class List
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
view :for_supplier_view, key: [:supplier_id, :created_at]
view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
view :active_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.table_id, 1);
emit([doc.supplier_id, doc.table_id], 1);
}
}|, reduce_function: '_sum'
#view :active_by_table_id_view, type: :custom, map_function: %|function(doc){
#if(doc.ruby_class == 'List' && doc.state == 'active'){
#emit(doc.table_id, 1);
#}
#}|, reduce_function: '_sum'
view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.supplier_id, 1);
}
}|, reduce_function: '_sum'
#view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
#if(doc.ruby_class == 'List' && doc.state == 'active'){
#emit(doc.supplier_id, 1);
#}
#}|, reduce_function: '_sum'
view :active_by_section_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
@@ -70,7 +75,7 @@ class List
}|, reduce_function: '_sum'
def self.active
database.view(active_by_supplier_id_view(reduce: false, include_docs: true))
database.view(active_view(reduce: false, include_docs: true))
end
# Create, a list given a table and a user
@@ -107,13 +112,12 @@ class List
end
end
def self.active_for_supplier(supplier_id, options = {})
supplier_id = supplier_id.id if supplier_id.is_a?(Supplier)
database.view(active_by_supplier_id_view(key: supplier_id, reduce: false, include_docs: true))
def self.active_for_supplier(supplier, options = {})
database.view(active_view(startkey: [supplier.id], endkey: ["#{supplier.id}\u9999"], reduce: false, include_docs: true))
end
def self.active_for_section(section_id, options = {})
database.view(active_by_section_id_view(key: section_id, reduce: false, include_docs: true))
def self.active_for_section(section, options = {})
database.view(active_by_section_id_view(key: section.id, reduce: false, include_docs: true))
end
# Return all currently active orders for a given section
@@ -121,12 +125,11 @@ class List
database.view(active_for_supplier_and_section_view(key: [supplier.id, section_id], reduce: false, include_docs: true))
end
def self.active_for_table(table_id, options = {})
if table_id.is_a?(Array)
database.view(active_by_table_id_view(options.reverse_merge(keys: table_id, reduce: false, include_docs: true)))
def self.active_for_table(table_or_tables, options = {})
if table_or_tables.is_a?(Array)
database.view(active_view(options.reverse_merge(keys: table_or_tables.map{|t| [t.supplier_id, t.id]}, reduce: false, include_docs: true)))
else
table_id = table_id.id if table_id.is_a?(SimplyStored::Couch)
database.view(active_by_table_id_view(options.reverse_merge(key: table_id, reduce: false, include_docs: true)))
database.view(active_view(options.reverse_merge(key: [table_or_tables.supplier_id, table_or_tables.id], reduce: false, include_docs: true)))
end
end
+2 -2
View File
@@ -20,14 +20,14 @@ class Section
def occupied_tables
return @occupied_tables if @occupied_tables.present?
@active_lists = List.active_for_section(self.id)
@active_lists = List.active_for_section(self)
@active_lists.include_relation(:table)
@occupied_tables = @active_lists.map(&:table)
end
def active_lists
return @active_lists if @active_lists.present?
@active_lists = List.active_for_section(self.id)
@active_lists = List.active_for_section(self)
end
def active_orders
+2 -1
View File
@@ -99,9 +99,10 @@ class Supplier
@active_orders
end
# Tody, simplify to List.active_for_supplier(self)
def active_lists(options = {})
return @active_lists if @active_lists
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(id)
@active_lists = options[:section_id].present? ? List.active_for_supplier_and_section(self, options[:section_id]) : List.active_for_supplier(self)
@active_lists.include_relations(table: :section, orders: {product_orders: :product})
@active_lists
end
+3 -3
View File
@@ -51,14 +51,14 @@ class Table
def occupied?
return @is_occupied if instance_variable_defined?(:'@is_occupied')
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
@is_occupied = !self.class.database.view(List.active_view(key: [supplier_id, id], reduce: true)).zero?
end
alias occupied occupied?
def occupied=(val) end
def self.enrich_active_list_id(tables)
if tables.is_a?(Array)
lists = List.active_for_table(tables.map(&:id))
lists = List.active_for_table(tables)
for table in tables
if list = lists.find{|l| l.table_id == table.id}
table.active_list_id = list.id
@@ -79,7 +79,7 @@ class Table
def active_list
# nil memoizing
return @active_list if @active_list || @active_list_is_set
self.active_list = self.class.database.view(List.active_by_table_id_view(key: id, include_docs: true, reduce: false, limit: 1)).try(:first)
self.active_list = self.class.database.view(List.active_view(key: [supplier_id, id], include_docs: true, reduce: false, limit: 1)).try(:first)
end
def active_list=(val)