User specs in the green
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
App.ButtonChangeListTableComponent = Ember.Component.extend
|
||||||
|
layoutName: 'components/button/change-list-table'
|
||||||
|
tagName: 'button'
|
||||||
|
classNames: ['change-list-table-button']
|
||||||
|
click: ->
|
||||||
|
@modal 'change-list-table',
|
||||||
|
model: @list
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#underscored = @constructor.toString().replace(/[a-zA-Z_-]+\@controller:modals\//, '').replace(/:$/, '').underscore() # ember cli
|
#underscored = @constructor.toString().replace(/[a-zA-Z_-]+\@controller:modals\//, '').replace(/:$/, '').underscore() # ember cli
|
||||||
# find translated title or humanize the controller name
|
# find translated title or humanize the controller name
|
||||||
if convention_translation = ttry("modal.#{underscored}.title", translation_params)
|
if convention_translation = ttry("modal.#{underscored}.title", translation_params)
|
||||||
tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe()
|
tspan("modal.#{underscored}.title", translation_params).htmlSafe()
|
||||||
else
|
else
|
||||||
underscored.capitalize().replace(/_/, ' ')
|
underscored.capitalize().replace(/_/, ' ')
|
||||||
).property('model.id', 'modal_options.title_path')
|
).property('model.id', 'modal_options.title_path')
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
App.modals.ChangeListTableController = @App.modals.BaseController.extend
|
||||||
|
list_moving: false
|
||||||
|
sections: Ember.computed -> @store.peekAll('section')
|
||||||
|
actions:
|
||||||
|
moveToTable: (table)->
|
||||||
|
@set 'list_moving', true
|
||||||
|
Ember.$.post Routes.change_table_suppliers_list_path(@get('model.id')), {table_id: table.id}, (response)=>
|
||||||
|
#@set "model.table", table
|
||||||
|
@send 'close'
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
App.TableNumberHelper = Ember.Helper.helper (params, options)->
|
||||||
|
table_number = params[0]
|
||||||
|
"# #{table_number}".htmlSafe()
|
||||||
@@ -16,13 +16,29 @@ App.List = DS.Model.extend
|
|||||||
#users: DS.hasMany('user', inverse: 'active_list')
|
#users: DS.hasMany('user', inverse: 'active_list')
|
||||||
orders: DS.hasMany('order', async: false)
|
orders: DS.hasMany('order', async: false)
|
||||||
section: DS.belongsTo('section', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
|
section: DS.belongsTo('section', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
|
||||||
active: ( -> @get('state') is 'active' ).property('state')
|
|
||||||
|
# COMPUTED PROPERTIES
|
||||||
|
active: Ember.computed.equal 'state', 'active'
|
||||||
|
total: (->
|
||||||
|
@get('relevant_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||||
|
).property('relevant_orders.@each.total')
|
||||||
|
relevant_orders: (-> @get('orders').filter((o)->o.get('state') isnt 'cancelled')).property('orders.@each.state')
|
||||||
|
active_orders: (-> @get('orders').filter((o)->o.get('state') is 'placed' or o.get('state') is 'active')).property('orders.@each.state')
|
||||||
|
sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.[]')
|
||||||
|
|
||||||
|
has_active_orders: (->
|
||||||
|
return false unless @get('state') == 'active'
|
||||||
|
!!@get('orders').filter( (order) -> order.get('state') is 'active' or order.get('state') is 'placed').length
|
||||||
|
).property('state', 'orders.@each.state')
|
||||||
|
|
||||||
isClosed: ->
|
isClosed: ->
|
||||||
@set('state', 'closed')
|
@set('state', 'closed')
|
||||||
#@set 'has_active_orders', false
|
#@set 'has_active_orders', false
|
||||||
@set 'table', null
|
@set 'table', null
|
||||||
@isHelped()
|
@isHelped()
|
||||||
@isPaid()
|
@isPaid()
|
||||||
|
|
||||||
|
# EVENTS
|
||||||
isHelped: ->
|
isHelped: ->
|
||||||
@set 'needs_help', false
|
@set 'needs_help', false
|
||||||
isNeedingHelp: ->
|
isNeedingHelp: ->
|
||||||
@@ -31,24 +47,14 @@ App.List = DS.Model.extend
|
|||||||
@set 'needs_payment', true
|
@set 'needs_payment', true
|
||||||
isPaid: ->
|
isPaid: ->
|
||||||
@set 'needs_payment', false
|
@set 'needs_payment', false
|
||||||
relevant_orders: (-> @get('orders').filter((o)->o.get('state') isnt 'cancelled')).property('orders.@each.state')
|
|
||||||
active_orders: (-> @get('orders').filter((o)->o.get('state') is 'placed' or o.get('state') is 'active')).property('orders.@each.state')
|
|
||||||
|
|
||||||
total: (->
|
# TRIGGERS
|
||||||
@get('relevant_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
|
||||||
).property('relevant_orders.@each.total')
|
|
||||||
has_active_orders: (->
|
|
||||||
return false unless @get('state') == 'active'
|
|
||||||
!!@get('orders').filter( (order) -> order.get('state') is 'active' or order.get('state') is 'placed').length
|
|
||||||
).property('state', 'orders.@each.state')
|
|
||||||
close: ->
|
close: ->
|
||||||
@isClosed()
|
@isClosed()
|
||||||
$.post Routes.close_suppliers_list_path(@id)
|
$.post Routes.close_suppliers_list_path(@id)
|
||||||
|
|
||||||
markHelped: ->
|
markHelped: ->
|
||||||
@isHelped()
|
@isHelped()
|
||||||
$.post Routes.mark_helped_suppliers_list_path(@id)
|
$.post Routes.mark_helped_suppliers_list_path(@id)
|
||||||
remove_needs_payment: ->
|
remove_needs_payment: ->
|
||||||
@set 'needs_payment', false
|
@set 'needs_payment', false
|
||||||
$.post Routes.remove_needs_payment_suppliers_list_path(@id)
|
$.post Routes.remove_needs_payment_suppliers_list_path(@id)
|
||||||
sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.@each.isLoaded')
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ App.Section = DS.Model.extend
|
|||||||
tables: DS.hasMany('table', async: false)
|
tables: DS.hasMany('table', async: false)
|
||||||
section_elements: DS.hasMany('section-element', async: false)
|
section_elements: DS.hasMany('section-element', async: false)
|
||||||
section_areas: DS.hasMany('section-area', async: false)
|
section_areas: DS.hasMany('section-area', async: false)
|
||||||
|
sorted_tables: Ember.computed 'tables.[]', -> @get('tables').sortBy('number')
|
||||||
|
|
||||||
editmode: false
|
editmode: false
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ App.ApplicationRoute = Ember.Route.extend
|
|||||||
if data.payload
|
if data.payload
|
||||||
@store.pushPayload(data.payload)
|
@store.pushPayload(data.payload)
|
||||||
try ion.sound.play('water_droplet')
|
try ion.sound.play('water_droplet')
|
||||||
list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list])
|
list_changed_table: (data)->
|
||||||
|
@store.pushPayload(data.payload)
|
||||||
list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id)
|
list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id)
|
||||||
list_helped: (data) -> list.isHelped() if list = @store.peekRecord('list', data.id)
|
list_helped: (data) -> list.isHelped() if list = @store.peekRecord('list', data.id)
|
||||||
remove_list_needs_payment: (data) -> list.set('needs_payment', false) if list = @store.peekRecord('list', data.id)
|
remove_list_needs_payment: (data) -> list.set('needs_payment', false) if list = @store.peekRecord('list', data.id)
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
span.fa.fa-random
|
||||||
@@ -7,8 +7,16 @@ if list.closed_at
|
|||||||
.display-field=time list.closed_at
|
.display-field=time list.closed_at
|
||||||
.display-row
|
.display-row
|
||||||
.display-label=t 'attributes.list.state'
|
.display-label=t 'attributes.list.state'
|
||||||
|
.display-field=state 'list' list.state
|
||||||
|
if list.active
|
||||||
|
.display-row
|
||||||
|
.display-label=t 'models.section'
|
||||||
|
.display-field= list.table.section.title
|
||||||
|
.display-row
|
||||||
|
.display-label=t 'models.table'
|
||||||
.display-field
|
.display-field
|
||||||
=state 'list' list.state
|
= table-number list.table.number
|
||||||
|
= button-change-list-table list=list
|
||||||
.display-row
|
.display-row
|
||||||
.display-label
|
.display-label
|
||||||
.display-field
|
.display-field
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
h3= tables.length
|
||||||
|
each sections as |section|
|
||||||
|
h3= section.title
|
||||||
|
ul.change-list-table-section-tables
|
||||||
|
each section.sorted_tables as |table|
|
||||||
|
unless table.active_list
|
||||||
|
li: a{action "moveToTable" table}= table-number table.number
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
errors: <%= I18n.t('errors', locale: :nl).to_json %>
|
errors: <%= I18n.t('errors', locale: :nl).to_json %>
|
||||||
date: <%= {day_name: Hash[Date::DAYNAMES.map(&:downcase).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)->
|
@day_minutes_to_time = (minutes)->
|
||||||
return "" unless minutes
|
return "" unless minutes
|
||||||
[("0" + Math.floor(minutes/60)).substr(-2,2), ("0" + Math.floor(minutes%60)).substr(-2,2)].join(":")
|
[("0" + Math.floor(minutes/60)).substr(-2,2), ("0" + Math.floor(minutes%60)).substr(-2,2)].join(":")
|
||||||
|
|||||||
@@ -16,7 +16,19 @@ td.boolean
|
|||||||
.boolean-false
|
.boolean-false
|
||||||
@extend .fa, .fa-lg, .fa-minus
|
@extend .fa, .fa-lg, .fa-minus
|
||||||
|
|
||||||
|
.change-list-table-button
|
||||||
|
+button($bg: $warning-color, $padding: $button-tny)
|
||||||
|
margin: 0
|
||||||
|
.change-list-table-section-tables
|
||||||
|
list-style: none
|
||||||
|
+clearfix
|
||||||
|
li
|
||||||
|
float: left
|
||||||
|
margin-right: 10px
|
||||||
|
margin-bottom: 10px
|
||||||
|
a
|
||||||
|
+button($padding: $button-sml)
|
||||||
|
margin: 0
|
||||||
td.colorbox
|
td.colorbox
|
||||||
+table-fit
|
+table-fit
|
||||||
.list-orders-container
|
.list-orders-container
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ class DashboardController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty_page
|
||||||
|
render text: ''
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# GET /select_qr_image
|
# GET /select_qr_image
|
||||||
# GET /select_qr_image.png
|
# GET /select_qr_image.png
|
||||||
|
|||||||
@@ -137,6 +137,23 @@ module Suppliers
|
|||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# POST /list/:id/change_table?to_table=:table_id
|
||||||
|
def change_table
|
||||||
|
res = {}
|
||||||
|
status = 200
|
||||||
|
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||||
|
@table = Table.find(params[:table_id])
|
||||||
|
res[:table_is_from_other_supplier] = true unless @table.supplier_id == @list.supplier_id
|
||||||
|
res[:table_occupied] = true if @table.occupied?
|
||||||
|
unless res[:table_is_from_other_supplier] or res[:table_occupied]
|
||||||
|
res[:ok] = true
|
||||||
|
@list.move_to_table! @table
|
||||||
|
else
|
||||||
|
res[:ok] = false
|
||||||
|
end
|
||||||
|
render json: res
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def list_params
|
def list_params
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ module Users
|
|||||||
list = List.from_table( table, current_user )
|
list = List.from_table( table, current_user )
|
||||||
res[:active_list_id] = list.id # used to set the active list in the app
|
res[:active_list_id] = list.id # used to set the active list in the app
|
||||||
order = list.place_order product_orders: product_orders, user: current_user, first_order: true
|
order = list.place_order product_orders: product_orders, user: current_user, first_order: true
|
||||||
res[:payload] = JSONAPI::Serializer.serialize(order, serializer: Users::OrderSerializer, include: %w[list list.users product_orders])
|
res[:supplier_orders_placed_count] = list.supplier.orders_placed_count
|
||||||
|
res[:payload] = Users::OrderSerializer.serialize(order, include: %w[list list.users product_orders])
|
||||||
end
|
end
|
||||||
render json: res
|
render json: res
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -163,7 +163,7 @@ class List
|
|||||||
for user in users
|
for user in users
|
||||||
user.active_list_id = nil
|
user.active_list_id = nil
|
||||||
user.save
|
user.save
|
||||||
#broadcast_user user.id, 'list_closed', broadcast_info
|
broadcast_user user.id, 'list_closed', broadcast_info
|
||||||
end
|
end
|
||||||
broadcast_supplier supplier_id, 'list_closed', broadcast_info
|
broadcast_supplier supplier_id, 'list_closed', broadcast_info
|
||||||
end
|
end
|
||||||
@@ -242,7 +242,7 @@ class List
|
|||||||
list_id: id,
|
list_id: id,
|
||||||
from_table_id: from_table_id,
|
from_table_id: from_table_id,
|
||||||
to_table_id: to_table.id,
|
to_table_id: to_table.id,
|
||||||
payload: JSONAPI::Serializer.serialize(self, serializer: Suppliers::ListSerializer)
|
payload: Suppliers::ListSerializer.serialize(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ if defined?(Ember::Emblem::Template)
|
|||||||
namespaces = %w[supplier waiter user]
|
namespaces = %w[supplier waiter user]
|
||||||
template_roots = namespaces.map{|namespace| namespace + '/app/templates'}
|
template_roots = namespaces.map{|namespace| namespace + '/app/templates'}
|
||||||
Ember::Emblem::Template.configure do |config|
|
Ember::Emblem::Template.configure do |config|
|
||||||
config.templates_root = ['app/templates']
|
#config.templates_root = ['app/templates']
|
||||||
|
|
||||||
config.templates_root = template_roots
|
config.templates_root = template_roots
|
||||||
# You can overwrite other config
|
# You can overwrite other config
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ en:
|
|||||||
modal:
|
modal:
|
||||||
info:
|
info:
|
||||||
close: OK
|
close: OK
|
||||||
|
change_list_table:
|
||||||
|
title: Change the ${models.table} of the ${models.list}
|
||||||
supplier_status_info:
|
supplier_status_info:
|
||||||
title: "%{name} info"
|
title: "%{name} info"
|
||||||
header: The icons at the top right corner contain information about the current orders
|
header: The icons at the top right corner contain information about the current orders
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ nl:
|
|||||||
modal:
|
modal:
|
||||||
info:
|
info:
|
||||||
close: OK
|
close: OK
|
||||||
|
change_list_table:
|
||||||
|
title: Verander de ${models.table} van de ${models.list}
|
||||||
supplier_status_info:
|
supplier_status_info:
|
||||||
title: "%{name} info"
|
title: "%{name} info"
|
||||||
header: The icons at the top right corner contain information about the current orders
|
header: The icons at the top right corner contain information about the current orders
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Qwaiter::Application.routes.draw do
|
|||||||
resources :product_categories
|
resources :product_categories
|
||||||
root to: 'users#index'
|
root to: 'users#index'
|
||||||
end
|
end
|
||||||
|
get 'empty-page' => 'dashboard#empty_page', as: :empty_page
|
||||||
|
|
||||||
|
|
||||||
post '/user_app' => 'dashboard#user_app_log' #TODO: separate high speed app at log.mozo.bar
|
post '/user_app' => 'dashboard#user_app_log' #TODO: separate high speed app at log.mozo.bar
|
||||||
@@ -169,6 +170,7 @@ Qwaiter::Application.routes.draw do
|
|||||||
post :mark_helped
|
post :mark_helped
|
||||||
post :close
|
post :close
|
||||||
post :remove_needs_payment
|
post :remove_needs_payment
|
||||||
|
post :change_table
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :product_categories do
|
resources :product_categories do
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ Feature: Active list view
|
|||||||
And the user is on the active list page
|
And the user is on the active list page
|
||||||
And the supplier orders placed counter for the user should be 1
|
And the supplier orders placed counter for the user should be 1
|
||||||
When the order gets cancelled
|
When the order gets cancelled
|
||||||
And I wait 1 second
|
|
||||||
Then the user should not see the order in the active list view
|
Then the user should not see the order in the active list view
|
||||||
And the supplier orders placed counter for the user should be 0
|
And the supplier orders placed counter for the user should be 0
|
||||||
|
|
||||||
|
|||||||
@@ -49,5 +49,5 @@ step "the user orders list gets closed" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "the order gets cancelled" do
|
step "the order gets cancelled" do
|
||||||
@order.cancel!
|
when_ember_is_ready { @order.cancel! }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
step "there is no user information stored in the local storage" do
|
step "there is no user information stored in the local storage" do
|
||||||
user_visit '/'
|
visit empty_page_path
|
||||||
page.execute_script %|Qstorage = window.localStorage|
|
page.execute_script %|Qstorage = window.localStorage|
|
||||||
page.execute_script(%|Qstorage.removeItem('user_id')|)
|
page.execute_script(%|Qstorage.removeItem('user_id')|)
|
||||||
page.execute_script(%|Qstorage.removeItem('auth_token')|)
|
page.execute_script(%|Qstorage.removeItem('auth_token')|)
|
||||||
@@ -27,7 +27,7 @@ step "there is a instagram user" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "the user is redirected to the sign in page" do
|
step "the user is redirected to the sign in page" do
|
||||||
ember_route_should_be '/sign_in'
|
when_ember_is_ready { ember_route_should_be '/sign-in' }
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I am signed in as a user" do
|
step "I am signed in as a user" do
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ step "another user scans the QR code on the table" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
step "the original user should see the other user added below the active list" do
|
step "the original user should see the other user added below the active list" do
|
||||||
page.evaluate_script(%|$('.list-user-total-container').length()|).should eq 2
|
page.evaluate_script(%|$('.list-user-total-container').length|).should eq 2
|
||||||
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
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ step "the user order :product_name should be in the order list with price" do |p
|
|||||||
#ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id}
|
#ember_order = ember_store['product_orders'].find{|po| po['product_id'] == concerning_product.id}
|
||||||
#ember_order = ember_find('product_order', concerning_product.id)
|
#ember_order = ember_find('product_order', concerning_product.id)
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
ember_order = ember_all('product_order').find{|po| po['product_id'] == concerning_product.id }
|
ember_order = ember_all('product_order').find{|po| po['product'] == concerning_product.id }
|
||||||
quantity = ember_order['quantity']
|
quantity = ember_order['quantity']
|
||||||
order_price = quantity * concerning_product.price
|
order_price = quantity * concerning_product.price
|
||||||
within '.product-orders .product-order' do
|
within '.product-orders .product-order' do
|
||||||
|
|||||||
@@ -85,13 +85,13 @@ module SpecEmberHelpers
|
|||||||
|
|
||||||
def ember_find(typeKey, id)
|
def ember_find(typeKey, id)
|
||||||
h = page.evaluate_script <<-SCRIPT
|
h = page.evaluate_script <<-SCRIPT
|
||||||
(MozoUser || App).__container__.lookup('store:main').all('#{typeKey}').findBy('id', '#{id}').serialize()
|
(MozoUser || App).__container__.lookup('service:store').peekRecord('#{typeKey}', '#{id}').toJSON()
|
||||||
SCRIPT
|
SCRIPT
|
||||||
end
|
end
|
||||||
|
|
||||||
def ember_all(typeKey)
|
def ember_all(typeKey)
|
||||||
h = page.evaluate_script <<-SCRIPT
|
h = page.evaluate_script <<-SCRIPT
|
||||||
(MozoUser || App).__container__.lookup('store:main').all('#{typeKey}').invoke('serialize')
|
(MozoUser || App).__container__.lookup('service:store').peekAll('#{typeKey}').map(function(r){ result = r.toJSON(); result['id'] = r.id; return result })
|
||||||
SCRIPT
|
SCRIPT
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user