From 2a30ff5d3de623c87776f36a996b72c576d36374 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Thu, 26 Jun 2014 17:26:15 +0200 Subject: [PATCH] General functionality improvement --- .../supplier/app/models/list.js.coffee | 2 +- .../app/templates/_list_content.emblem | 3 ++ .../supplier/app/templates/list.emblem | 4 +-- .../application_controller.js.coffee | 16 +++++++-- .../controllers/table_controller.js.coffee | 6 ++-- .../user/foundation/_qlists.css.sass | 1 + app/controllers/suppliers/lists_controller.rb | 4 ++- app/models/list.rb | 1 + app/views/suppliers/lists/show.html.slim | 2 +- config/locales/supplier.en.yml | 1 + config/locales/supplier.nl.yml | 1 + config/locales/user.en.yml | 6 ++-- config/locales/user.nl.yml | 6 ++-- .../users/join_an_occupied_table.feature | 14 ++------ spec/acceptance_steps/global_list_steps.rb | 13 ------- spec/acceptance_steps/global_user_steps.rb | 4 --- .../suppliers/main_board_steps.rb | 1 + .../users/join_request_steps.rb | 35 +++++++++++++++---- wip.md | 3 +- 19 files changed, 71 insertions(+), 52 deletions(-) diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index c48beecf..e4b02611 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -14,7 +14,7 @@ Qsupplier.App.List = DS.Model.extend price: attr 'number' closed_at: DS.attr('date') #table_number: attr 'number' - #table: DS.belongsTo('table', inverse: 'active_list') + table: DS.belongsTo('table', inverse: 'active_list') #users: DS.hasMany('user', inverse: 'active_list') orders: DS.hasMany('order') section: DS.belongsTo('section') diff --git a/app/assets/javascripts/supplier/app/templates/_list_content.emblem b/app/assets/javascripts/supplier/app/templates/_list_content.emblem index 16e52e94..4f9b1bdb 100644 --- a/app/assets/javascripts/supplier/app/templates/_list_content.emblem +++ b/app/assets/javascripts/supplier/app/templates/_list_content.emblem @@ -1,6 +1,9 @@ .display-row .display-label=t 'attributes.list.created_at' .display-field=time list.created_at +.display-row + .display-label=t 'attributes.list.state' + .display-field=state 'list' list.state each user in list.users img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f" if list.orders diff --git a/app/assets/javascripts/supplier/app/templates/list.emblem b/app/assets/javascripts/supplier/app/templates/list.emblem index 0549adfe..3a4ac5df 100644 --- a/app/assets/javascripts/supplier/app/templates/list.emblem +++ b/app/assets/javascripts/supplier/app/templates/list.emblem @@ -1,5 +1,5 @@ .row h2=t 'models.list' partial "list_content" - link-to 'lists' - span Go to lists + link-to 'lists' class="button" + span=t 'list.go_to_lists' diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index 28dbaf79..8d3aefb1 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -1,4 +1,5 @@ App.ApplicationController = Ember.Controller.extend + join_request_sent: false notice: '' actions: confirmCancel: -> @@ -39,11 +40,22 @@ App.ApplicationController = Ember.Controller.extend join_request = @store.createRecord 'join_request', data.join_request @transitionToRoute 'join_requests' join_request_rejected: (data)-> + # Remove join request from connected users join_request = @store.all('join_request').findBy 'id', data.id join_request.eraseRecord() if join_request + + # Notify requestor in a proper manner + # NOTE data.id is in the form of: jr-:user_id + requestor_id = data.id.substr(3) + if requestor_id is Qstorage.getItem('user_id') + @set 'notice', t('join_request.requestor.join_request_rejected') + @set 'join_request_sent', false + join_request_approved: -> @setCurrentList -> - @transitionToRoute 'active_list' + @transitionToRoute('active_list').then => + @set 'notice', t('join_request.requestor.join_request_approved') + list_changed_table: -> @setCurrentList() @@ -69,4 +81,4 @@ App.ApplicationController = Ember.Controller.extend @set 'list', null @store.find('list', 'current').then(success, error) didInsertElement: (e)-> - debugger + #debugger diff --git a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee index ea1b3c21..e4ef3e39 100644 --- a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee @@ -1,5 +1,5 @@ App.TableController = Ember.ObjectController.extend - join_request_sent: false + join_request_sent: (-> @get('controllers.application.join_request_sent')).property('controllers.application.join_request_sent') tableCanTakeOrders: (-> return false unless @get('supplier.can_take_orders') list = @get('controllers.application.list') @@ -14,7 +14,7 @@ App.TableController = Ember.ObjectController.extend showJoinButton: (-> return false unless @get('supplier.can_take_orders') return false if @get('controllers.application.list') # if you already have an active list, do not join another - if @get('model.occupied') then true else false + if @get('model.occupied') then true else false # no point in joining tables that are not occupied ).property('controllers.application.list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'controllers.application.list.table.id') actions: addProduct: (product)-> @@ -25,7 +25,7 @@ App.TableController = Ember.ObjectController.extend joinOccupiedTable: -> #@secured => Ember.$.post('/user/join_occupied_table.json', table_id: @get('model.id')) - @set 'join_request_sent', true # keeps the button deactivated + @set 'controllers.application.join_request_sent', true # keeps the button deactivated toggleProductCategory: (product_category)-> product_category.set 'collapsed', not product_category.get('collapsed') showProductDescription: (product)-> diff --git a/app/assets/stylesheets/user/foundation/_qlists.css.sass b/app/assets/stylesheets/user/foundation/_qlists.css.sass index 7400d0c3..44f40f12 100644 --- a/app/assets/stylesheets/user/foundation/_qlists.css.sass +++ b/app/assets/stylesheets/user/foundation/_qlists.css.sass @@ -1,5 +1,6 @@ .lists-overview-entry +grid-column(12) + cursor: pointer @media #{$medium-only} +grid-column(6) @media #{$large-up} diff --git a/app/controllers/suppliers/lists_controller.rb b/app/controllers/suppliers/lists_controller.rb index 4c2261db..4da8f899 100644 --- a/app/controllers/suppliers/lists_controller.rb +++ b/app/controllers/suppliers/lists_controller.rb @@ -3,7 +3,9 @@ module Suppliers # GET /lists # GET /lists.json def index - if params[:date].present? + if params[:state] == 'active' + @lists = List.active_for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25) + elsif params[:date].present? @date = params[:date].present? ? (Date.parse(params[:date]) rescue Date.today) : Date.today @time = @date.to_time(:utc) @start_time = @time.beginning_of_day diff --git a/app/models/list.rb b/app/models/list.rb index e9968b98..3f608111 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -99,6 +99,7 @@ class List 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)) end diff --git a/app/views/suppliers/lists/show.html.slim b/app/views/suppliers/lists/show.html.slim index a8c6b0a6..647ea197 100644 --- a/app/views/suppliers/lists/show.html.slim +++ b/app/views/suppliers/lists/show.html.slim @@ -35,7 +35,7 @@ /jQuery(function(){ /Qsupplier.load_list('#{@list.id}'); /}) -.test-div +/.test-div span.fa.fa-square-o.fa-2x span.fa-stack i.fa.fa-square-o.fa-stack-2x diff --git a/config/locales/supplier.en.yml b/config/locales/supplier.en.yml index de21cbac..edaad1ff 100644 --- a/config/locales/supplier.en.yml +++ b/config/locales/supplier.en.yml @@ -33,6 +33,7 @@ en: is_helped_button: Question answered! close_list: Close! none_found: 'No ${models.plural.list|downcase}' + go_to_lists: Go to lists order: being_processed: 'In process!' being_served: 'Is delivered!' diff --git a/config/locales/supplier.nl.yml b/config/locales/supplier.nl.yml index 96779321..da49120e 100644 --- a/config/locales/supplier.nl.yml +++ b/config/locales/supplier.nl.yml @@ -33,6 +33,7 @@ nl: is_helped_button: Vraag beantwoord! close_list: Afsluiten! none_found: 'Geen ${models.plural.list|downcase}' + go_to_lists: Naar lijsten order: being_processed: 'Ben bezig!' being_served: 'Ik kom het brengen!' diff --git a/config/locales/user.en.yml b/config/locales/user.en.yml index 7b6a8827..12636b14 100644 --- a/config/locales/user.en.yml +++ b/config/locales/user.en.yml @@ -13,8 +13,6 @@ en: table_is_reserved: The table you want to sit on is reserved by someone else table_is_closed: The table you want to sit on is not available for service supplier_is_closed: The owner of this table is currently not handling orders - join_request_rejected: Your request to join the table has been rejected - join_request_approved: Your request to join the table has been approved table_is_from_other_supplier: You cannot move to another table when you have an open list moved_to_another_table: You successfully moved to another table cannot_identify_table: The application cannot determine the table number @@ -34,10 +32,12 @@ en: title: '${models.plural.join_request}' reject_request: Reject approve_request: Approve - no_join_requests_message: Nobody wants to join right now + no_join_requests_message: No current join requests for your list requestor: join_this_table: Join this table waiting_for_approval: Waiting for approval + join_request_rejected: Your request to join the table has been rejected + join_request_approved: Your request to join the table has been approved list_products: title: Order diff --git a/config/locales/user.nl.yml b/config/locales/user.nl.yml index ec0b31c9..07a93bf3 100644 --- a/config/locales/user.nl.yml +++ b/config/locales/user.nl.yml @@ -13,8 +13,6 @@ nl: table_is_reserved: De tafel waar je aan wil gaan zitten is gereserveerd table_is_closed: De tafel waar je aan wil gaan zitten is niet beschikbaar voor bediening supplier_is_closed: De eigenaar van deze tafel is momenteel gesloten - join_request_rejected: Je verzoek om te mogen bestellen op een bestaande lijst is afgewezen - join_request_approved: Je verzoek om te mogen bestellen op een bestaande lijst is goedgekeurd table_is_from_other_supplier: Je kan geen lijst openen bij een andere zaak zolang je huidige lijst nog niet is afgesloten moved_to_another_table: De tafel is gewijzigd cannot_identify_table: De applicatie kan niet bepalen om welke tafel het gaat @@ -35,10 +33,12 @@ nl: title: '${models.plural.join_request}' reject_request: Afwijzen approve_request: Toestaan - no_join_requests_message: Niemand wil deelnemen aan de ${models.list} + no_join_requests_message: Geen deelname verzoeken voor de huidige ${models.list} requestor: waiting_for_approval: Wachten op toestemming join_this_table: Ik wil ook bestellen bij deze tafel + join_request_rejected: Je verzoek om deel te nemen aan de ${models.list|downcase} is afgewezen + join_request_approved: Je verzoek om deel te nemen aan de ${models.list|downcase} is goedgekeurd history_list: title: Afgesloten lijst list_history: diff --git a/spec/acceptance/users/join_an_occupied_table.feature b/spec/acceptance/users/join_an_occupied_table.feature index 4448c938..adaa0baf 100644 --- a/spec/acceptance/users/join_an_occupied_table.feature +++ b/spec/acceptance/users/join_an_occupied_table.feature @@ -12,9 +12,9 @@ Feature: Joining an occupied table When the original user approves the other user's join request Then the original user should not see the join request anymore And the other user should be added to the active list - And the other user should be redirected to the user menu page + And the other user should be redirected to active list it just joined - @javascript @broken + @javascript Scenario: Original user rejects the join request Given There is an open supplier with a menu And there is a signed in user with an active order @@ -27,13 +27,3 @@ Feature: Joining an occupied table Then the original user should not see the join request anymore And the other user should not be added to the active list And the other user should see a join reject message - - @javascript @broken - Scenario: The other user just wants to see the table menu - Given There is an open supplier with a menu - And there is a signed in user with an active order - And I am on the user homepage - When another user scans the QR code on the table - And the other user clicks the show me the menu button - Then the other user sees the table menu - And the other user does not see order buttons diff --git a/spec/acceptance_steps/global_list_steps.rb b/spec/acceptance_steps/global_list_steps.rb index 2c0b3c2d..a124ca30 100644 --- a/spec/acceptance_steps/global_list_steps.rb +++ b/spec/acceptance_steps/global_list_steps.rb @@ -30,16 +30,3 @@ step "I am signed in as a user" do step "I visit the user obtain token path" end -step "the other user should be added to the active list" do - @other_user.reload - @list.reload - @other_user.active_list_id.should == @list.id - @list.user_ids.should =~ [@user.id, @other_user.id] -end - -step "the other user should not be added to the active list" do - @other_user.reload - @list.reload - @other_user.active_list_id.should be_nil - @list.user_ids.should == [@user.id] -end diff --git a/spec/acceptance_steps/global_user_steps.rb b/spec/acceptance_steps/global_user_steps.rb index 31478415..17060682 100644 --- a/spec/acceptance_steps/global_user_steps.rb +++ b/spec/acceptance_steps/global_user_steps.rb @@ -39,7 +39,3 @@ step "the other user clicks the join table button" do find('.join-table-button').click end -step "the other user should be redirected to the user menu page" do - Capybara.session_name = :other_user - route_should_be 'user#list_products' -end diff --git a/spec/acceptance_steps/suppliers/main_board_steps.rb b/spec/acceptance_steps/suppliers/main_board_steps.rb index 72009ae9..923a4eb2 100644 --- a/spec/acceptance_steps/suppliers/main_board_steps.rb +++ b/spec/acceptance_steps/suppliers/main_board_steps.rb @@ -134,6 +134,7 @@ step "the active list changes to another table in another section" do end step "the supplier main board table number should be updated to the new table number" do + binding.pry expect( find(".list-row-#{@list.id} .table_number").text ).to eq "65" expect( find(".order-row-#{@list.orders.first.id} .table_number").text ).to eq "65" end diff --git a/spec/acceptance_steps/users/join_request_steps.rb b/spec/acceptance_steps/users/join_request_steps.rb index f00ae061..0fc486c8 100644 --- a/spec/acceptance_steps/users/join_request_steps.rb +++ b/spec/acceptance_steps/users/join_request_steps.rb @@ -1,8 +1,10 @@ step "the original user should see a join request message" do Capybara.session_name = :default - request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|) - request_text.should be_present - page.should have_content request_text + #request_text = page.evaluate_script(%|t('join_request.body', {email: '#{@other_user.email}'})|) + request_title = page.evaluate_script(%|t('join_request.existing_user.title')|) + request_title.should be_present + page.should have_content request_title + page.should have_content @other_user.email end step "the original user should not see the join request anymore" do @@ -13,11 +15,11 @@ step "the original user should not see the join request anymore" do end step "the original user approves the other user's join request" do - find('.approve-join-request-button').click + find('.join-request-approve').click end step "the original user rejects the other user's join request" do - find('.reject-join-request-button').click + find('.join-request-reject').click end step "the other user clicks the show me the menu button" do @@ -33,8 +35,29 @@ end step "the other user should see a join reject message" do Capybara.session_name = :other_user - reject_text = I18n.t('messages.join_request_rejected') + reject_text = page.evaluate_script(%|t('join_request.requestor.join_request_rejected')|) reject_text.should be_present reject_text.should_not include 'translation' page.should have_content reject_text end + +step "the other user should be added to the active list" do + sleep 1 + @other_user.reload + @list.reload + @other_user.active_list_id.should == @list.id + @list.user_ids.should =~ [@user.id, @other_user.id] +end + +step "the other user should not be added to the active list" do + sleep 1 + @other_user.reload + @list.reload + @other_user.active_list_id.should be_nil + @list.user_ids.should == [@user.id] +end + +step "the other user should be redirected to active list it just joined" do + Capybara.session_name = :other_user + ember_route_should_be '/active_list' +end diff --git a/wip.md b/wip.md index 7535aefa..f67f3491 100644 --- a/wip.md +++ b/wip.md @@ -47,4 +47,5 @@ General: Post release ------------ -noting so far +Chromecast app +Waiter app