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 => @transitionToRoute('list', data.id).then =>
@set 'globals.list.state', 'closed' @set 'globals.list.state', 'closed'
@set 'globals.list', null @set 'globals.list', null
join_request_approved: (data)->
@setCurrentList -> @transitionToRoute('active_list')
order_being_processed: (data)-> order_being_processed: (data)->
order = @store.all('order').findBy 'id', data.id order = @store.all('order').findBy 'id', data.id
order.set('state', 'active') if order order.set('state', 'active') if order
@@ -63,16 +61,20 @@ App.ApplicationController = Ember.Controller.extend
if requestor_id is Qstorage.getItem('user_id') if requestor_id is Qstorage.getItem('user_id')
@set 'globals.notice', t('join_request.requestor.join_request_rejected') @set 'globals.notice', t('join_request.requestor.join_request_rejected')
@set 'globals.join_request_sent', false @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 -> @setCurrentList ->
@transitionToRoute('active_list').then => @transitionToRoute('active_list').then =>
@set 'globals.notice', t('join_request.requestor.join_request_approved') @set 'globals.notice', t('join_request.requestor.join_request_approved')
@set 'globals.join_request_sent', false @set 'globals.join_request_sent', false
list_changed_table: -> list_changed_table: (data)->
@setCurrentList() @store.findRecord('table', data.to_table_id).then (table)=>@set('globals.list.table', table)
orders_in_process_count: (data)-> orders_in_process_count: (data)->
@set 'globals.list.supplier.orders_in_process_count', data.count @set 'globals.list.supplier.orders_in_process_count', data.count
orders_placed_count: (data)-> orders_placed_count: (data)->
@@ -4,6 +4,7 @@ DS.Model.reopen
eraseRecord: -> eraseRecord: ->
#@clearRelationships() #@clearRelationships()
@transitionTo('deleted.saved') @transitionTo('deleted.saved')
@unloadRecord()
DS.Model.reopenClass DS.Model.reopenClass
findCached: (id)-> findCached: (id)->
return null unless id return null unless id
@@ -19,7 +19,7 @@
=link-to 'active_list' class="side-menu-active-list" =link-to 'active_list' class="side-menu-active-list"
span.active-list-icon span.active-list-icon
span= t 'active_list.title' span= t 'active_list.title'
if globals.list.join_requests if globals.list.join_requests.length
li li
=link-to 'join_requests' =link-to 'join_requests'
span= t 'models.plural.join_request' span= t 'models.plural.join_request'
@@ -26,7 +26,7 @@ module Suppliers
def active def active
@lists = List.active_for_supplier(current_supplier.id) @lists = List.active_for_supplier(current_supplier)
@lists.include_relation(:table) # for number @lists.include_relation(:table) # for number
respond_to do |format| respond_to do |format|
@@ -4,7 +4,7 @@ module Suppliers
# GET /tables.json # GET /tables.json
def index def index
if params[:state] == 'active' if params[:state] == 'active'
@orders = Order.active_for_supplier(current_supplier.id) @orders = Order.active_for_supplier(current_supplier)
else else
@orders = Order.for_supplier(current_supplier, page: params[:page], per_page: params['per_page'] || 25) @orders = Order.for_supplier(current_supplier, page: params[:page], per_page: params['per_page'] || 25)
end end
@@ -8,7 +8,7 @@ module Suppliers
@sections = current_supplier.sections @sections = current_supplier.sections
@sections.include_relation(:tables) @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 # @active_table_ids = @active_lists.map(&:table_id).compact
# for section in @sections # for section in @sections
# for table in section.tables # 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 :by_supplier_id_and_id, key: [:supplier_id, :_id]
view :for_supplier_view, key: [:supplier_id, :created_at] 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'){ if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.table_id, 1); emit([doc.supplier_id, doc.table_id], 1);
} }
}|, reduce_function: '_sum' }|, 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){ #view :active_by_supplier_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){ #if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc.supplier_id, 1); #emit(doc.supplier_id, 1);
} #}
}|, reduce_function: '_sum' #}|, reduce_function: '_sum'
view :active_by_section_id_view, type: :custom, map_function: %|function(doc){ view :active_by_section_id_view, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){ if(doc.ruby_class == 'List' && doc.state == 'active' && doc.section_id){
@@ -70,7 +75,7 @@ class List
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
def self.active 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 end
# Create, a list given a table and a user # Create, a list given a table and a user
@@ -107,13 +112,12 @@ class List
end end
end end
def self.active_for_supplier(supplier_id, options = {}) def self.active_for_supplier(supplier, options = {})
supplier_id = supplier_id.id if supplier_id.is_a?(Supplier) database.view(active_view(startkey: [supplier.id], endkey: ["#{supplier.id}\u9999"], reduce: false, include_docs: true))
database.view(active_by_supplier_id_view(key: supplier_id, reduce: false, include_docs: true))
end end
def self.active_for_section(section_id, options = {}) def self.active_for_section(section, options = {})
database.view(active_by_section_id_view(key: section_id, reduce: false, include_docs: true)) database.view(active_by_section_id_view(key: section.id, reduce: false, include_docs: true))
end end
# Return all currently active orders for a given section # 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)) database.view(active_for_supplier_and_section_view(key: [supplier.id, section_id], reduce: false, include_docs: true))
end end
def self.active_for_table(table_id, options = {}) def self.active_for_table(table_or_tables, options = {})
if table_id.is_a?(Array) if table_or_tables.is_a?(Array)
database.view(active_by_table_id_view(options.reverse_merge(keys: table_id, reduce: false, include_docs: true))) database.view(active_view(options.reverse_merge(keys: table_or_tables.map{|t| [t.supplier_id, t.id]}, reduce: false, include_docs: true)))
else else
table_id = table_id.id if table_id.is_a?(SimplyStored::Couch) database.view(active_view(options.reverse_merge(key: [table_or_tables.supplier_id, table_or_tables.id], reduce: false, include_docs: true)))
database.view(active_by_table_id_view(options.reverse_merge(key: table_id, reduce: false, include_docs: true)))
end end
end end
+2 -2
View File
@@ -20,14 +20,14 @@ class Section
def occupied_tables def occupied_tables
return @occupied_tables if @occupied_tables.present? 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) @active_lists.include_relation(:table)
@occupied_tables = @active_lists.map(&:table) @occupied_tables = @active_lists.map(&:table)
end end
def active_lists def active_lists
return @active_lists if @active_lists.present? return @active_lists if @active_lists.present?
@active_lists = List.active_for_section(self.id) @active_lists = List.active_for_section(self)
end end
def active_orders def active_orders
+2 -1
View File
@@ -99,9 +99,10 @@ class Supplier
@active_orders @active_orders
end end
# Tody, simplify to List.active_for_supplier(self)
def active_lists(options = {}) def active_lists(options = {})
return @active_lists if @active_lists 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.include_relations(table: :section, orders: {product_orders: :product})
@active_lists @active_lists
end end
+3 -3
View File
@@ -51,14 +51,14 @@ class Table
def occupied? def occupied?
return @is_occupied if instance_variable_defined?(:'@is_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 end
alias occupied occupied? alias occupied occupied?
def occupied=(val) end def occupied=(val) end
def self.enrich_active_list_id(tables) def self.enrich_active_list_id(tables)
if tables.is_a?(Array) if tables.is_a?(Array)
lists = List.active_for_table(tables.map(&:id)) lists = List.active_for_table(tables)
for table in tables for table in tables
if list = lists.find{|l| l.table_id == table.id} if list = lists.find{|l| l.table_id == table.id}
table.active_list_id = list.id table.active_list_id = list.id
@@ -79,7 +79,7 @@ class Table
def active_list def active_list
# nil memoizing # nil memoizing
return @active_list if @active_list || @active_list_is_set 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 end
def active_list=(val) def active_list=(val)
@@ -3,12 +3,6 @@ step "the user scans a table QR code" do
page.execute_script "App.__container__.lookup('route:application').transitionTo('table','#{@table.id}')" page.execute_script "App.__container__.lookup('route:application').transitionTo('table','#{@table.id}')"
end end
step "another user scans the QR code on the table" do
step 'there is another signed in user user'
visit user_root_path
page.execute_script "App.__container__.lookup('route:application').transitionTo('table','#{@table.id}')"
end
step "I am on the user homepage" do step "I am on the user homepage" do
step "the user is on the homepage" step "the user is on the homepage"
end end
@@ -14,6 +14,14 @@ step "the original user should not see the join request anymore" do
page.should_not have_content request_text page.should_not have_content request_text
end end
step "another user scans the QR code on the table" do
step 'there is another signed in user user'
visit user_root_path
when_ember_is_ready do
page.execute_script "App.__container__.lookup('route:application').transitionTo('table','#{@table.id}')"
end
end
step "the original user approves the other user's join request" do step "the original user approves the other user's join request" do
find('.join-request-approve').click find('.join-request-approve').click
end end
+3
View File
@@ -2,5 +2,8 @@ FactoryGirl.define do
factory :list do factory :list do
association :table association :table
association :supplier #TODO warning! this may create a different supplier than the one created by the associated table association :supplier #TODO warning! this may create a different supplier than the one created by the associated table
trait :active do
#default
end
end end
end end
+10
View File
@@ -164,4 +164,14 @@ describe List do
expect( list.needs_help? ).not_to be true expect( list.needs_help? ).not_to be true
end end
end end
context 'class_methods' do
describe 'active_for_supplier' do
it 'only returns the lists for the supplier' do
other_supplier = create :supplier, open: true
other_list = create :list, :active, supplier: other_supplier
described_class.active_for_supplier( list.supplier ).should eq [list]
end
end
end
end end
+12
View File
@@ -101,4 +101,16 @@ module SpecEmberHelpers
def faye_log def faye_log
JSON.parse(page.evaluate_script(%|JSON.stringify(window.faye_log)|)) JSON.parse(page.evaluate_script(%|JSON.stringify(window.faye_log)|))
end end
def when_ember_is_ready(&blk)
times = 0
ember_ready = page.evaluate_script('window.ember_ready')
while not ember_ready or times < 30
sleep 0.1
ember_ready = page.evaluate_script('window.ember_ready')
times += 1
end
raise "Ember is not loaded and should be" unless ember_ready
blk.call
end
end end
+3 -1
View File
@@ -18,9 +18,11 @@ module SpecRouteHelpers
max_wait = 4 max_wait = 4
time = 0.0 time = 0.0
time_step = 0.25 time_step = 0.25
while time < max_wait && ember_route != route_def current_route = ember_route
while time < max_wait && current_route != route_def
time += time_step time += time_step
sleep time_step sleep time_step
current_route = ember_route
end end
ember_route(omit_should_raise: true).should == route_def ember_route(omit_should_raise: true).should == route_def
end end
+4
View File
@@ -4,6 +4,8 @@ Release
Supplier Supplier
-------- --------
- Add confirmation on order
deletion!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Allow table drag rollback same as area and element in section edit - Allow table drag rollback same as area and element in section edit
mode view mode view
- Move arrange tables logic to the client - Move arrange tables logic to the client
@@ -24,6 +26,8 @@ Supplier
User User
---- ----
- Fix clicking on product with
variants!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Implement https://github.com/EddyVerbruggen/Custom-URL-scheme with mozo:// scheme - Implement https://github.com/EddyVerbruggen/Custom-URL-scheme with mozo:// scheme
- test met veel producten - test met veel producten
- product variants - product variants