User ember progress
This commit is contained in:
@@ -127,11 +127,11 @@
|
|||||||
inkscape:pageopacity="0"
|
inkscape:pageopacity="0"
|
||||||
inkscape:pageshadow="2"
|
inkscape:pageshadow="2"
|
||||||
inkscape:window-width="1435"
|
inkscape:window-width="1435"
|
||||||
inkscape:window-height="860"
|
inkscape:window-height="856"
|
||||||
id="namedview43"
|
id="namedview43"
|
||||||
showgrid="false"
|
showgrid="false"
|
||||||
inkscape:zoom="6.34"
|
inkscape:zoom="6.34"
|
||||||
inkscape:cx="35.062165"
|
inkscape:cx="44.999074"
|
||||||
inkscape:cy="30.642055"
|
inkscape:cy="30.642055"
|
||||||
inkscape:window-x="0"
|
inkscape:window-x="0"
|
||||||
inkscape:window-y="0"
|
inkscape:window-y="0"
|
||||||
@@ -165,6 +165,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<text
|
<text
|
||||||
id="text7"
|
id="text7"
|
||||||
x="12.23935"
|
x="12.23935"
|
||||||
@@ -183,6 +184,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<text
|
<text
|
||||||
font-size="9.4245"
|
font-size="9.4245"
|
||||||
id="text19"
|
id="text19"
|
||||||
@@ -199,6 +201,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<g
|
<g
|
||||||
id="g3012"
|
id="g3012"
|
||||||
inkscape:export-filename="/Users/bterkuile/Qwaiter/Android app/Pictures/icon-high-res.png"
|
inkscape:export-filename="/Users/bterkuile/Qwaiter/Android app/Pictures/icon-high-res.png"
|
||||||
@@ -364,13 +367,10 @@
|
|||||||
font-size="9.4245"
|
font-size="9.4245"
|
||||||
y="69.109116"
|
y="69.109116"
|
||||||
x="23.631485"
|
x="23.631485"
|
||||||
dx="0 0"><tspan
|
dx="0 0">Q<tspan
|
||||||
style="fill:#f8ad15;fill-opacity:1"
|
style="fill:#ffffff;fill-opacity:1"
|
||||||
id="tspan3824">Q</tspan><tspan
|
id="tspan3800">WAITE</tspan>R</tspan></text>
|
||||||
style="fill:#ffffff;fill-opacity:1"
|
|
||||||
id="tspan3800">WAITE</tspan><tspan
|
|
||||||
style="fill:#f8ad15;fill-opacity:1"
|
|
||||||
id="tspan3826">R</tspan></tspan></text>
|
|
||||||
|
|
||||||
|
|
||||||
<text
|
<text
|
||||||
@@ -384,4 +384,5 @@
|
|||||||
id="tspan3030"
|
id="tspan3030"
|
||||||
x="35.962147"
|
x="35.962147"
|
||||||
y="74.290222" /></text>
|
y="74.290222" /></text>
|
||||||
|
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
@$translations =
|
@$translations =
|
||||||
en:
|
en:
|
||||||
models: <%= I18n.t('activemodel.models', locale: :en).to_json %>
|
models: <%= I18n.t('activemodel.models', locale: :en).to_json %>
|
||||||
@@ -10,6 +9,7 @@
|
|||||||
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>
|
attributes: <%= I18n.t('activemodel.attributes', locale: :nl).to_json %>
|
||||||
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>
|
helpers: <%= I18n.t('helpers', locale: :nl).to_json %>
|
||||||
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>
|
pagination: <%= I18n.t('views.pagination', locale: :nl).to_json %>
|
||||||
|
|
||||||
@t = (path, vars={}) ->
|
@t = (path, vars={}) ->
|
||||||
#result = undefined
|
#result = undefined
|
||||||
#m = undefined
|
#m = undefined
|
||||||
|
|||||||
@@ -11,8 +11,18 @@ Ember.$.ajaxPrefilter (options) ->
|
|||||||
options.data = "auth_token=#{auth_token}"
|
options.data = "auth_token=#{auth_token}"
|
||||||
if options.type.toUpperCase() == 'POST'
|
if options.type.toUpperCase() == 'POST'
|
||||||
if auth_token = Qstorage.getItem('auth_token')
|
if auth_token = Qstorage.getItem('auth_token')
|
||||||
options.data ||= {}
|
if options.data
|
||||||
options.data.auth_token = auth_token
|
if typeof(options.data) == 'string'
|
||||||
|
if options.data[0] == '{' || options.data[0] == '[' # json
|
||||||
|
object = JSON.parse(options.data)
|
||||||
|
object.auth_token = auth_token
|
||||||
|
options.data = JSON.stringify(object)
|
||||||
|
else
|
||||||
|
options.data += "&auth_token=#{auth_token}"
|
||||||
|
else
|
||||||
|
options.data.auth_token = auth_token
|
||||||
|
else
|
||||||
|
options.data = "auth_token=#{auth_token}"
|
||||||
true
|
true
|
||||||
|
|
||||||
Ember.$.ajaxSetup
|
Ember.$.ajaxSetup
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ App.ActiveListController = Ember.ObjectController.extend
|
|||||||
#).property('controllers.application.list')
|
#).property('controllers.application.list')
|
||||||
|
|
||||||
displayTotal: (-> @get('model.orders.length') and @get('model.orders.length') > 1 ).property('model.orders.length')
|
displayTotal: (-> @get('model.orders.length') and @get('model.orders.length') > 1 ).property('model.orders.length')
|
||||||
|
list: (-> @get('controllers.application.list') ).property('controllers.application.list')
|
||||||
|
|||||||
@@ -20,6 +20,27 @@ App.ApplicationController = Ember.Controller.extend
|
|||||||
list_closed: -> @set 'list', null
|
list_closed: -> @set 'list', null
|
||||||
join_request_approved: (data)->
|
join_request_approved: (data)->
|
||||||
@setCurrentList -> @transitionToRoute('active_list')
|
@setCurrentList -> @transitionToRoute('active_list')
|
||||||
|
order_being_processed: (data)->
|
||||||
|
order = @store.all('order').findBy 'id', data.id
|
||||||
|
order.set('state', 'active') if order
|
||||||
|
order_being_delivered: (data)->
|
||||||
|
order = @store.all('order').findBy 'id', data.id
|
||||||
|
order.set('state', 'delivered') if order
|
||||||
|
user_join_request: (data)->
|
||||||
|
list = @store.all('list').findBy 'id', data.join_request.list_id
|
||||||
|
user_data = data.users[0]
|
||||||
|
user = @store.all('user').findBy 'id', user_data.id
|
||||||
|
user = @store.createRecord 'user', user_data unless user
|
||||||
|
data.join_request.list = list
|
||||||
|
data.join_request.user = user
|
||||||
|
join_request = @store.createRecord 'join_request', data.join_request
|
||||||
|
@transitionToRoute 'join_requests'
|
||||||
|
join_request_rejected: (data)->
|
||||||
|
join_request = @store.all('join_request').findBy 'id', data.id
|
||||||
|
join_request.eraseRecord() if join_request
|
||||||
|
join_request_approved: ->
|
||||||
|
@setCurrentList ->
|
||||||
|
@transitionToRoute 'active_list'
|
||||||
|
|
||||||
#getProducts: (options = {})->
|
#getProducts: (options = {})->
|
||||||
#@store.find('product_category', options).then (product_categories)=>
|
#@store.find('product_category', options).then (product_categories)=>
|
||||||
@@ -34,9 +55,12 @@ App.ApplicationController = Ember.Controller.extend
|
|||||||
error_list.eraseRecord()
|
error_list.eraseRecord()
|
||||||
@set 'list', list
|
@set 'list', list
|
||||||
@controllerFor('active_list').set('model', list)
|
@controllerFor('active_list').set('model', list)
|
||||||
|
if list.get('join_requests').toArray().length
|
||||||
|
@transitionToRoute 'join_requests'
|
||||||
callback.call(@) if callback
|
callback.call(@) if callback
|
||||||
error = (jqXHR)=>
|
error = (emberError)=>
|
||||||
# if jqXHR.status == 404 officially, now assume close list on error
|
# if jqXHR.status == 404 officially, now assume close list on error
|
||||||
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
#@redirect_to 'index', message: 'the_list_has_been_closed'
|
||||||
|
console.log "Error: #{emberError.message}" if emberError.message
|
||||||
@set 'list', null
|
@set 'list', null
|
||||||
@store.find('list', 'current').then(success, error)
|
@store.find('list', 'current').then(success, error)
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
App.JoinRequestsController = Ember.ArrayController.extend
|
||||||
|
join_requests: (-> @get('controllers.application.list.join_requests') ).property('controllers.application.list.join_requests')
|
||||||
|
actions:
|
||||||
|
rejectRequest: (join_request)->
|
||||||
|
Ember.$.post('/user/reject_join_request', user_id: join_request.get('user.id')).then (response)->
|
||||||
|
join_request.eraseRecord()
|
||||||
|
approveRequest: (join_request)->
|
||||||
|
Ember.$.post('/user/approve_join_request', user_id: join_request.get('user.id')).then (response)->
|
||||||
|
join_request.eraseRecord()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
App.ProductOrdersController = Ember.ArrayController.extend
|
App.ProductOrdersController = Ember.ArrayController.extend
|
||||||
|
needs: ['application', 'table']
|
||||||
orderTotal: (->
|
orderTotal: (->
|
||||||
#Math.round(Math.random()*100)
|
#Math.round(Math.random()*100)
|
||||||
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||||
@@ -8,16 +9,17 @@ App.ProductOrdersController = Ember.ArrayController.extend
|
|||||||
#TODO: make clearing of unpersisted product orders
|
#TODO: make clearing of unpersisted product orders
|
||||||
@store.all('product_order').toArray().invoke 'eraseRecord'
|
@store.all('product_order').toArray().invoke 'eraseRecord'
|
||||||
orderProducts: ->
|
orderProducts: ->
|
||||||
order = @store.createRecord('order', list: @get('controllers.application.list'))
|
table = @get('controllers.table.model')
|
||||||
|
list = @get('controllers.application.list')
|
||||||
|
order = @store.createRecord('order', list: list, table: table)
|
||||||
new_product_orders = @store.all('product_order').filterProperty('order', null)
|
new_product_orders = @store.all('product_order').filterProperty('order', null)
|
||||||
order.get('product_orders').pushObjects(new_product_orders)
|
order.get('product_orders').pushObjects(new_product_orders)
|
||||||
order.save().then (response)=>
|
order.save().then (response)=>
|
||||||
debugger
|
|
||||||
new_product_orders.invoke 'eraseRecord'
|
new_product_orders.invoke 'eraseRecord'
|
||||||
.error (a,b,c)=>
|
@transitionToRoute 'active_list'
|
||||||
d=a
|
, (jqXHR)=>
|
||||||
debugger
|
new_product_orders.invoke 'eraseRecord'
|
||||||
@transitionToRoute 'active_list'
|
@redirect_to 'index', message: 'order_could_not_be_processed'
|
||||||
|
|
||||||
#orders = @store.all('product_order').toArray()
|
#orders = @store.all('product_order').toArray()
|
||||||
#data = orders.map( (order)->order.serialize() )
|
#data = orders.map( (order)->order.serialize() )
|
||||||
|
|||||||
@@ -34,10 +34,4 @@ App.SelectQrcodeController = Ember.Controller.extend
|
|||||||
cancel: =>
|
cancel: =>
|
||||||
@redirect_to 'list_products'
|
@redirect_to 'list_products'
|
||||||
else
|
else
|
||||||
if res.occupied
|
@redirect_to 'table', table._id
|
||||||
@redirect_to 'join_occupied_table', {table_id: table._id}
|
|
||||||
else if res.supplier_closed
|
|
||||||
@redirect_to 'user_root', {message: 'supplier_is_closed'}
|
|
||||||
else
|
|
||||||
#$.post(data_host + '/user/create_list.json', {table_id: table._id}, (res)-> Quser.handle_response(res))
|
|
||||||
@redirect_to 'table', table._id, a: 3
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
attr = DS.attr
|
||||||
|
App.JoinRequest= DS.Model.extend
|
||||||
|
list: DS.belongsTo('list')
|
||||||
|
user: DS.belongsTo('user')
|
||||||
@@ -11,6 +11,8 @@ App.List = DS.Model.extend
|
|||||||
|
|
||||||
supplier: DS.belongsTo('supplier')
|
supplier: DS.belongsTo('supplier')
|
||||||
table: DS.belongsTo('table')
|
table: DS.belongsTo('table')
|
||||||
|
join_requests: DS.hasMany('join_request')
|
||||||
|
users: DS.hasMany('user')
|
||||||
|
|
||||||
total: (->
|
total: (->
|
||||||
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ attr = DS.attr
|
|||||||
App.Order = DS.Model.extend
|
App.Order = DS.Model.extend
|
||||||
state: attr 'string'
|
state: attr 'string'
|
||||||
list: DS.belongsTo('list')
|
list: DS.belongsTo('list')
|
||||||
|
table: DS.belongsTo('table')
|
||||||
product_orders: DS.hasMany('product_order', embedded: 'always')
|
product_orders: DS.hasMany('product_order', embedded: 'always')
|
||||||
total: (->
|
total: (->
|
||||||
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
attr = DS.attr
|
||||||
|
App.User = DS.Model.extend
|
||||||
|
facebook_id: attr('string')
|
||||||
|
email: attr('string')
|
||||||
|
list: DS.belongsTo('list') # in ember scope not many to many (yet)
|
||||||
|
join_requests: DS.hasMany('join_request')
|
||||||
@@ -8,13 +8,16 @@ Ember.Controller.reopen
|
|||||||
callback.call(@) if callback
|
callback.call(@) if callback
|
||||||
redirect_to: (route, args...)->
|
redirect_to: (route, args...)->
|
||||||
route = 'index' if route == 'user_root'
|
route = 'index' if route == 'user_root'
|
||||||
route_segments = App.Router.router.recognizer.names[route].segments
|
route_object= App.Router.router.recognizer.names[route]
|
||||||
dynamic_segments = route_segments.reduce (sum, segment) ->
|
throw "Route #{route} cannot exist" unless route_object
|
||||||
|
dynamic_segments = route_object.segments.reduce (sum, segment) ->
|
||||||
if segment.name then sum + 1 else sum
|
if segment.name then sum + 1 else sum
|
||||||
, 0
|
, 0
|
||||||
route_args = [route]
|
route_args = [route]
|
||||||
for isegment in [1..dynamic_segments]
|
|
||||||
route_args.push args.shift()
|
if dynamic_segments # needed because javascript for loop always fires, even when end is less than start :'(
|
||||||
|
for isegment in [1..dynamic_segments]
|
||||||
|
route_args.push args.shift()
|
||||||
|
|
||||||
options = args.pop() || {}
|
options = args.pop() || {}
|
||||||
|
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ App.Router.map ->
|
|||||||
@route 'list_products'
|
@route 'list_products'
|
||||||
@route 'list_products_for_table', path: '/list_products/:table_id'
|
@route 'list_products_for_table', path: '/list_products/:table_id'
|
||||||
@route 'table', path: '/tables/:table_id'
|
@route 'table', path: '/tables/:table_id'
|
||||||
|
@resource 'join_requests'
|
||||||
@resource 'lists', ->
|
@resource 'lists', ->
|
||||||
@resource 'list', path: ':list_id'
|
@resource 'list', path: ':list_id'
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
App.ActiveListRoute = Ember.Route.extend
|
App.ActiveListRoute = Ember.Route.extend {}
|
||||||
afterModel: (a,b,c)->
|
#model: ->
|
||||||
controller = @controllerFor('application')
|
#@get('controllers.application.list')
|
||||||
if table_id = controller.get('list.table.id')
|
#afterModel: ->
|
||||||
transitionTo 'table', table_id
|
#controller = @controllerFor('application')
|
||||||
else
|
#table_id = controller.get('list.table.id')
|
||||||
controller.redirect_to 'index', message: 'the_list_has_been_closed'
|
#debugger
|
||||||
|
#if table_id
|
||||||
|
#@transitionTo 'table', table_id
|
||||||
|
#else
|
||||||
|
#controller.redirect_to 'index', message: 'the_list_has_been_closed'
|
||||||
|
#setupController: (controller, model)->
|
||||||
|
#debugger
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ App.ApplicationRoute = Ember.Route.extend
|
|||||||
user_id = Qstorage.getItem('user_id')
|
user_id = Qstorage.getItem('user_id')
|
||||||
faye.subscribe "/user/"+user_id, (e)=>
|
faye.subscribe "/user/"+user_id, (e)=>
|
||||||
console.log e
|
console.log e
|
||||||
@events[e.event].call(@) if @events[e.event]
|
@events[e.event].call(@, e.data) if @events[e.event]
|
||||||
@setCurrentList()
|
@setCurrentList()
|
||||||
|
|
||||||
unauthorized: ->
|
unauthorized: ->
|
||||||
|
|||||||
@@ -1,19 +1,28 @@
|
|||||||
.row
|
.row
|
||||||
h2=t 'active_list.title'
|
h2=t 'active_list.title'
|
||||||
if orders
|
if list
|
||||||
ul.active_list-orders
|
each user in list.users
|
||||||
each order in orders
|
img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square"
|
||||||
li class=order.state
|
if list.orders
|
||||||
= order.display
|
.list-orders-container
|
||||||
span.currency= currency order.total
|
each order in orders
|
||||||
if displayTotal
|
.list-order-container class=order.state
|
||||||
li.total
|
= order.display
|
||||||
= t 'total'
|
span.currency= currency order.total
|
||||||
span.currency= currency model.total
|
if displayTotal
|
||||||
|
.list-orders-total.total
|
||||||
|
= t 'total'
|
||||||
|
span.currency= currency model.total
|
||||||
|
else
|
||||||
|
p
|
||||||
|
span=t 'active_list.no_orders_explanation'
|
||||||
|
br
|
||||||
|
link-to 'list_products' class="button"
|
||||||
|
span=t 'list_products.title'
|
||||||
|
|
||||||
else
|
else
|
||||||
p
|
p
|
||||||
span=t 'active_list.no_orders_explanation'
|
span=t 'active_list.not_active.message'
|
||||||
br
|
br
|
||||||
link-to 'list_products' class="button"
|
link-to 'index' class="button"
|
||||||
span=t 'list_products.title'
|
span= t 'active_list.not_active.home_button_text'
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,9 @@
|
|||||||
li
|
li
|
||||||
=link-to 'lists'
|
=link-to 'lists'
|
||||||
span= t 'models.plural.list'
|
span= t 'models.plural.list'
|
||||||
|
li
|
||||||
|
=link-to 'join_requests'
|
||||||
|
span= t 'models.plural.join_request'
|
||||||
section.main-section
|
section.main-section
|
||||||
if notice
|
if notice
|
||||||
#notice.alert-box{action clearNotice} data-alert=true
|
#notice.alert-box{action clearNotice} data-alert=true
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
.row
|
||||||
|
h2= t 'join_request.existing_user.title'
|
||||||
|
each join_request in join_requests
|
||||||
|
.join-request-container
|
||||||
|
img.facebook-image src="http://graph.facebook.com/#{unbound join_request.user.facebook_id}/picture?type=square"
|
||||||
|
span.user-email= join_request.user.email
|
||||||
|
.right
|
||||||
|
button.join-request-reject{action rejectRequest join_request}=t 'join_request.existing_user.reject_request'
|
||||||
|
button.join-request-approve{action approveRequest join_request}=t 'join_request.existing_user.approve_request'
|
||||||
|
else
|
||||||
|
p=t 'join_request.existing_user.no_join_requests_message'
|
||||||
@@ -10,10 +10,12 @@
|
|||||||
#= require js-routes
|
#= require js-routes
|
||||||
#= require_directory .
|
#= require_directory .
|
||||||
#= require_self
|
#= require_self
|
||||||
(($) ->
|
#
|
||||||
origAppend = $.fn.append
|
# (($) ->
|
||||||
$.fn.append = -> origAppend.apply(@, arguments).trigger("append")
|
# origAppend = $.fn.append
|
||||||
)(jQuery)
|
# $.fn.append = -> origAppend.apply(@, arguments).trigger("append")
|
||||||
|
# )(jQuery)
|
||||||
|
|
||||||
@Qstorage = localStorage
|
@Qstorage = localStorage
|
||||||
|
|
||||||
$.extend($translations.en, <%= I18n.t('user', locale: :en).to_json %>);
|
$.extend($translations.en, <%= I18n.t('user', locale: :en).to_json %>);
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
@import ./foundation_and_overrides
|
||||||
|
.join-request-container
|
||||||
|
.user-email
|
||||||
|
padding-left: 12px
|
||||||
|
.join-request-reject
|
||||||
|
+button
|
||||||
|
@extend .secondary
|
||||||
|
margin-right: 12px
|
||||||
|
.join-request-approve
|
||||||
|
+button
|
||||||
|
margin-right: 12px
|
||||||
|
|
||||||
@@ -11,3 +11,25 @@
|
|||||||
float: right
|
float: right
|
||||||
clear: right
|
clear: right
|
||||||
+panel($padding: 4px)
|
+panel($padding: 4px)
|
||||||
|
.list-orders-container
|
||||||
|
.currency
|
||||||
|
float: right
|
||||||
|
list-style: none
|
||||||
|
$padding: 6px 0 6px 35px
|
||||||
|
.list-order-container
|
||||||
|
background-position: left center
|
||||||
|
background-repeat: no-repeat
|
||||||
|
+grid-column(12)
|
||||||
|
padding: $padding
|
||||||
|
border-bottom: 1px solid #eee
|
||||||
|
&.active
|
||||||
|
background-image: image-url('icons/order-check.png')
|
||||||
|
&.delivered
|
||||||
|
background-image: image-url('icons/order-doublecheck.png')
|
||||||
|
.list-orders-total
|
||||||
|
+grid-column(12)
|
||||||
|
padding: $padding
|
||||||
|
border-top: 2px solid #444
|
||||||
|
font-weight: bold
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,18 @@ module Users
|
|||||||
class OrdersController < Users::ApplicationController
|
class OrdersController < Users::ApplicationController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
def create
|
def create
|
||||||
|
render json: {}, status: :unprocessable_entity and return unless params[:order].present? && params[:order][:product_orders].present?
|
||||||
converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
|
converted_order = params[:order][:product_orders].each_with_object({}){|po, o| o[po[:product_id]] = po[:quantity] }
|
||||||
unless list = current_user.active_list
|
if list = current_user.active_list
|
||||||
|
render json: {}, status: :not_acceptable and return unless list.supplier.open?
|
||||||
|
else
|
||||||
|
render json: {}, status: :unprocessable_entity and return unless params[:order][:table_id].present?
|
||||||
table = Table.find(params[:order][:table_id])
|
table = Table.find(params[:order][:table_id])
|
||||||
|
render json: {}, status: :not_acceptable and return unless table.supplier.open?
|
||||||
|
|
||||||
if table.occupied?
|
if table.occupied?
|
||||||
#render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id})
|
#render json: json_alert('messages.table_is_occupied', location: :join_occupied_table, location_params: {table_id: @table.id})
|
||||||
render status: :not_acceptable and return
|
render json: {}, status: :not_acceptable and return
|
||||||
end
|
end
|
||||||
|
|
||||||
list = List.from_table( table, current_user )
|
list = List.from_table( table, current_user )
|
||||||
|
|||||||
+12
-9
@@ -210,7 +210,7 @@ class List
|
|||||||
user.save
|
user.save
|
||||||
self.is_dirty
|
self.is_dirty
|
||||||
if save
|
if save
|
||||||
broadcast_user user.id, 'join_request_approved'
|
broadcast_user user.id, 'join_request_approved', UserUserSerializer.new(user).as_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -230,19 +230,26 @@ class List
|
|||||||
self.join_request_user_ids << requester.id
|
self.join_request_user_ids << requester.id
|
||||||
self.is_dirty
|
self.is_dirty
|
||||||
if save
|
if save
|
||||||
for user in users
|
broadcast_users 'user_join_request', JoinRequestSerializer.new(join_request_for_user(requester)).as_json
|
||||||
broadcast_user user.id, 'user_join_request', list_id: id, user_email: requester.email, user_id: requester.id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def join_request_for_user(user)
|
||||||
|
JoinRequest.new(user: user, list: self)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def join_requests
|
||||||
|
@join_requests ||= join_request_user_ids.any? ? self.class.database.load_document(join_request_user_ids).map{|user| join_request_for_user(user) } : []
|
||||||
|
end
|
||||||
|
|
||||||
def reject_join_request_for_user!(user_id)
|
def reject_join_request_for_user!(user_id)
|
||||||
if join_request_user_ids.include?(user_id)
|
if join_request_user_ids.include?(user_id)
|
||||||
join_request_user_ids.delete(user_id)
|
join_request_user_ids.delete(user_id)
|
||||||
self.is_dirty
|
self.is_dirty
|
||||||
if save
|
if save
|
||||||
broadcast_user user_id, 'join_request_rejected'
|
broadcast_user user_id, 'join_request_rejected', id: "jr-#{user_id}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -380,10 +387,6 @@ class List
|
|||||||
@join_requests_as_json = h
|
@join_requests_as_json = h
|
||||||
end
|
end
|
||||||
|
|
||||||
def join_requests
|
|
||||||
@join_requests ||= join_request_user_ids.any? ? self.class.database.load_document(join_request_user_ids).map{|user| JoinRequest.new(user: user, list: self) } : []
|
|
||||||
end
|
|
||||||
|
|
||||||
def product_categories
|
def product_categories
|
||||||
supplier.product_categories
|
supplier.product_categories
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ class Table
|
|||||||
end
|
end
|
||||||
|
|
||||||
def occupied?
|
def occupied?
|
||||||
return true #testing...
|
|
||||||
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_by_table_id_view(key: id, reduce: true)).zero?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class User
|
class User
|
||||||
include SimplyStored::Couch
|
include SimplyStored::Couch
|
||||||
|
include ActiveModel::SerializerSupport
|
||||||
|
|
||||||
property :name
|
property :name
|
||||||
property :active_list_id
|
property :active_list_id
|
||||||
@@ -41,6 +42,10 @@ class User
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def facebook_id
|
||||||
|
uid
|
||||||
|
end
|
||||||
|
|
||||||
def self.from_omniauth(auth)
|
def self.from_omniauth(auth)
|
||||||
binding.pry
|
binding.pry
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
class JoinRequestSerializer < Qwaiter::Serializer
|
class JoinRequestSerializer < Qwaiter::Serializer
|
||||||
attributes :user_id, :user_facebook_id, :list_id
|
embed :ids, include: true
|
||||||
|
attributes :list_id
|
||||||
|
has_one :user, serializer: UserUserSerializer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class UserExtendedListSerializer < Qwaiter::Serializer
|
|||||||
#has_many :product_categories
|
#has_many :product_categories
|
||||||
has_one :table, serializer: UserExtendedTableSerializer
|
has_one :table, serializer: UserExtendedTableSerializer
|
||||||
has_many :join_requests
|
has_many :join_requests
|
||||||
|
has_many :users, serializer: UserUserSerializer
|
||||||
|
|
||||||
def extended_version
|
def extended_version
|
||||||
true
|
true
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class UserUserSerializer < Qwaiter::Serializer
|
||||||
|
self.root = :user
|
||||||
|
attributes :email, :facebook_id
|
||||||
|
end
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
class JoinRequest
|
class JoinRequest
|
||||||
attr_reader :user, :list
|
attr_reader :user, :list
|
||||||
|
def id
|
||||||
|
"jr-#{user_id}"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(user: nil, list: nil)
|
def initialize(user: nil, list: nil)
|
||||||
@user, @list = user, list
|
@user, @list = user, list
|
||||||
@@ -9,6 +12,10 @@ class JoinRequest
|
|||||||
user.id
|
user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user_email
|
||||||
|
user.email
|
||||||
|
end
|
||||||
|
|
||||||
def user_facebook_id
|
def user_facebook_id
|
||||||
user.uid
|
user.uid
|
||||||
end
|
end
|
||||||
@@ -16,4 +23,22 @@ class JoinRequest
|
|||||||
def list_id
|
def list_id
|
||||||
list.id
|
list.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def read_attribute_for_serialization(a)
|
||||||
|
serializable_hash[a]
|
||||||
|
end
|
||||||
|
|
||||||
|
def object
|
||||||
|
self
|
||||||
|
end
|
||||||
|
|
||||||
|
def serializable_hash
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
user_id: user.id,
|
||||||
|
user_facebook_id: user.uid,
|
||||||
|
user_email: user.email,
|
||||||
|
list_id: list.id
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ en:
|
|||||||
order: Order
|
order: Order
|
||||||
product_category: Product category
|
product_category: Product category
|
||||||
section: Section
|
section: Section
|
||||||
|
join_request: Join request
|
||||||
plural:
|
plural:
|
||||||
user: Users
|
user: Users
|
||||||
supplier: Restaurants
|
supplier: Restaurants
|
||||||
@@ -18,6 +19,7 @@ en:
|
|||||||
order: Orders
|
order: Orders
|
||||||
product_category: Product categories
|
product_category: Product categories
|
||||||
section: Sections
|
section: Sections
|
||||||
|
join_request: Join requests
|
||||||
attributes:
|
attributes:
|
||||||
product_category:
|
product_category:
|
||||||
name: Name
|
name: Name
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ nl:
|
|||||||
order: Bestelling
|
order: Bestelling
|
||||||
product_category: Product categorie
|
product_category: Product categorie
|
||||||
section: Afdeling
|
section: Afdeling
|
||||||
|
join_request: Deelname verzoek
|
||||||
plural:
|
plural:
|
||||||
user: Gebruikers
|
user: Gebruikers
|
||||||
supplier: Restaurants
|
supplier: Restaurants
|
||||||
@@ -18,6 +19,7 @@ nl:
|
|||||||
order: Bestellingen
|
order: Bestellingen
|
||||||
product_category: Product categorieen
|
product_category: Product categorieen
|
||||||
section: Afdelingen
|
section: Afdelingen
|
||||||
|
join_request: Deelname verzoeken
|
||||||
attributes:
|
attributes:
|
||||||
product_category:
|
product_category:
|
||||||
name: Naam
|
name: Naam
|
||||||
|
|||||||
@@ -19,11 +19,21 @@ en:
|
|||||||
cannot_identify_table: The application cannot determine the table number
|
cannot_identify_table: The application cannot determine the table number
|
||||||
unknown_supplier_name: unknown
|
unknown_supplier_name: unknown
|
||||||
unauthorized: Unauthorized action detected
|
unauthorized: Unauthorized action detected
|
||||||
|
order_could_not_be_processed: 'The order could not be processed'
|
||||||
|
|
||||||
active_list:
|
active_list:
|
||||||
title: Active list
|
title: Active list
|
||||||
needs_payment: Check please!
|
needs_payment: Check please!
|
||||||
no_orders_explanation: You did not order anything
|
no_orders_explanation: You did not order anything yet
|
||||||
|
not_active:
|
||||||
|
message: At the moment there is no active list
|
||||||
|
home_button_text: Back
|
||||||
|
join_request:
|
||||||
|
existing_user:
|
||||||
|
title: '${models.plural.join_request}'
|
||||||
|
reject_request: Reject
|
||||||
|
approve_request: Approve
|
||||||
|
no_join_requests_message: Nobody wants to join right now
|
||||||
list_products:
|
list_products:
|
||||||
title: Order
|
title: Order
|
||||||
history_list:
|
history_list:
|
||||||
|
|||||||
@@ -19,12 +19,22 @@ nl:
|
|||||||
cannot_identify_table: De applicatie kan niet bepalen om welke tafel het gaat
|
cannot_identify_table: De applicatie kan niet bepalen om welke tafel het gaat
|
||||||
unknown_supplier_name: onbekend
|
unknown_supplier_name: onbekend
|
||||||
unauthorized: Niet toegestane actie
|
unauthorized: Niet toegestane actie
|
||||||
|
order_could_not_be_processed: 'De bestelling kan niet worden uitgevoerd'
|
||||||
active_list:
|
active_list:
|
||||||
title: Actieve lijst
|
title: Actieve lijst
|
||||||
needs_payment: Rekening vragen!
|
needs_payment: Rekening vragen!
|
||||||
no_orders_explanation: Je hebt nog niks besteld
|
no_orders_explanation: Je hebt nog niks besteld
|
||||||
|
not_active:
|
||||||
|
message: Momenteel is er geen lijst actief
|
||||||
|
home_button_text: Terug
|
||||||
list_products:
|
list_products:
|
||||||
title: Bestel
|
title: Bestel
|
||||||
|
join_request:
|
||||||
|
existing_user:
|
||||||
|
title: '${models.plural.join_request}'
|
||||||
|
reject_request: Afwijzen
|
||||||
|
approve_request: Toestaan
|
||||||
|
no_join_requests_message: Niemand wil deelnemen aan de ${models.list}
|
||||||
history_list:
|
history_list:
|
||||||
title: Afgesloten lijst
|
title: Afgesloten lijst
|
||||||
list_history:
|
list_history:
|
||||||
|
|||||||
Reference in New Issue
Block a user