Major supplier refactor making the whole system work better
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
Qsupplier.App.IndexController = Ember.ObjectController.extend
|
||||
needs: ['application']
|
||||
lists: (-> @store.all('list')).property()
|
||||
orders: (-> @store.all('order')).property()
|
||||
sections: (-> @store.all('section')).property()
|
||||
active_lists: (->
|
||||
if @get('active_section.id')
|
||||
@get('lists').filter (l)=>( l.get('section.id') == @get('active_section.id') && l.get('state') == 'active' )
|
||||
if @get('controllers.application.active_section.id')
|
||||
@get('lists').filter (l)=>( l.get('section.id') == @get('controllers.application.active_section.id') && l.get('state') == 'active' )
|
||||
else
|
||||
@get('lists').filterProperty('state', 'active')
|
||||
).property('lists.@each.state', 'active_section.id')
|
||||
).property('lists.@each.state', 'controllers.application.active_section.id')
|
||||
|
||||
active_section: (-> @get('controllers.application.active_section')).property('controllers.application.active_section')
|
||||
active_orders: (->
|
||||
|
||||
@@ -6,4 +6,15 @@ Qsupplier.App.ListsIndexController = Ember.ArrayController.extend
|
||||
lists.then => @set('loading', false)
|
||||
@set 'model', lists
|
||||
).observes('date')
|
||||
lists: (-> @get('model')).property('model')
|
||||
lists: (->
|
||||
return @store.all('list') unless date = @get('date')
|
||||
@store.filter('list', (l)->
|
||||
return false unless list_date = l.get('created_at')
|
||||
list_date = list_date.toISOString().substring(0,10) if typeof(list_date) is 'object'
|
||||
list_date == date
|
||||
)
|
||||
).property('date')
|
||||
|
||||
sorted_lists: (->
|
||||
@get('lists').sortBy('created_at').reverseObjects()
|
||||
).property('lists.@each')
|
||||
|
||||
+1
-1
@@ -3,5 +3,5 @@ Qsupplier.App.ModalCloseListController = Ember.ObjectController.extend
|
||||
close: ->
|
||||
@send 'closeModal'
|
||||
confirm: ->
|
||||
@get('model').close()
|
||||
@get('model').then (l)->l.close()
|
||||
@send 'closeModal'
|
||||
|
||||
@@ -10,8 +10,8 @@ Qsupplier.App.SectionsIndexController = Ember.ArrayController.extend
|
||||
Routes.qr_codes_suppliers_tables_path section_id: section_id
|
||||
actions:
|
||||
showDashboardOrders: (section)->
|
||||
@transitionToRoute('index').then =>
|
||||
@get('controllers.index').set 'active_section', section
|
||||
@set 'controllers.application.active_section', section
|
||||
@transitionToRoute('index')
|
||||
addSection: -> @send 'openModal', 'modal_add_section', @get('model')
|
||||
goToSection: (section)->
|
||||
@set 'controllers.application.active_section', section
|
||||
|
||||
@@ -11,7 +11,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', async: true)
|
||||
#users: DS.hasMany('user', inverse: 'active_list')
|
||||
orders: DS.hasMany('order')
|
||||
section: DS.belongsTo('section')
|
||||
|
||||
@@ -4,6 +4,7 @@ DS.Model.reopen
|
||||
eraseRecord: ->
|
||||
@clearRelationships()
|
||||
@transitionTo('deleted.saved')
|
||||
then: (callback) -> callback.call(@, @)
|
||||
DS.Model.reopenClass
|
||||
findCached: (id)->
|
||||
return null unless id
|
||||
@@ -61,6 +62,6 @@ DS.Model.reopenClass
|
||||
#for record, i in records
|
||||
##console.log "Setting relation #{relation.name} to #{record.get('id')}"
|
||||
#new_record.set association_names[i], record
|
||||
#attributes[relation.name] =
|
||||
#attributes[relation.name] =
|
||||
#delete attributes["#{relation.name}_id"]
|
||||
#@createRecord attributes
|
||||
|
||||
@@ -13,4 +13,5 @@ Qsupplier.App.Router.map ->
|
||||
@resource 'lists', ->
|
||||
@resource 'list', path: ':list_id'
|
||||
@route 'settings'
|
||||
@route 'empty'
|
||||
#@resource 'lists', queryParams: ['state']
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
Qsupplier.App.ApplicationRoute = Ember.Route.extend
|
||||
beforeModel: ->
|
||||
# Preload only active lists and orders
|
||||
@store.find 'product_category'
|
||||
@supplier = @store.push 'supplier', supplier_object
|
||||
@product_categories = @store.find 'product_category'
|
||||
@sections = @store.find 'section'
|
||||
Ember.RSVP.all([@product_categories, @sections]).then (results)=>
|
||||
@store.find('list', state: 'active').then (lists) -> lists.invoke('get', 'table')
|
||||
@lists = @store.all 'list'
|
||||
# product_categories = controller.set 'product_categories', @store.all('product_category')
|
||||
#@store.find 'order', state: 'active' included in list
|
||||
setupController: (controller)->
|
||||
controller.set 'supplier', @supplier
|
||||
# @set 'supplier', @store.find('supplier', supplier_id)
|
||||
supplier = @store.push 'supplier', supplier_object
|
||||
controller.set 'supplier', supplier
|
||||
controller.set 'sections', @sections
|
||||
controller.set 'product_categories', @product_categories
|
||||
|
||||
@store.find 'list', state: 'active'
|
||||
@store.find 'section'
|
||||
|
||||
controller.set 'product_categories', @store.all('product_category')
|
||||
actions:
|
||||
openModal: (modalName, model, options={})->
|
||||
controller_name = options.controller || modalName
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
Qsupplier.App.IndexRoute = Ember.Route.extend
|
||||
model: (params, queryParams)->
|
||||
Ember.Object.create
|
||||
# Find with condition does not work since the resulting array promise is not updated for newly created records
|
||||
#lists: Qsupplier.App.List.find({state: 'active'})
|
||||
#orders: Qsupplier.App.Order.find({state: 'active'})
|
||||
#lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet)
|
||||
# use filter to create a scope on all the records
|
||||
#lists: @store.filter 'list', -> true
|
||||
lists: @store.all 'list'
|
||||
# mayby @store.all 'list' will work better!!!! (2014-04-24 a more experienced benjamin :)
|
||||
#orders: @store.filter 'order', -> true
|
||||
orders: @store.all 'order'
|
||||
sections: @store.all 'section'
|
||||
setupController: (controller, model)->
|
||||
controller.set('model', model)
|
||||
#$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
|
||||
#controller.set 'lists', @store.all('list')
|
||||
#controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active')
|
||||
#controller.set 'orders', Qsupplier.App.Order.all()
|
||||
#controller.set 'lists', model.get('lists')
|
||||
#controller.set 'orders', model.get('orders')
|
||||
# Qsupplier.App.IndexRoute = Ember.Route.extend
|
||||
# model: (params, queryParams)->
|
||||
# Ember.Object.create
|
||||
# # Find with condition does not work since the resulting array promise is not updated for newly created records
|
||||
# #lists: Qsupplier.App.List.find({state: 'active'})
|
||||
# #orders: Qsupplier.App.Order.find({state: 'active'})
|
||||
# #lists: @store.filter 'list', (l)-> l.get('state') == 'active' # DOES NOT WORK!!!! (yet)
|
||||
# # use filter to create a scope on all the records
|
||||
# #lists: @store.filter 'list', -> true
|
||||
# lists: @store.all 'list'
|
||||
# # mayby @store.all 'list' will work better!!!! (2014-04-24 a more experienced benjamin :)
|
||||
# #orders: @store.filter 'order', -> true
|
||||
# orders: @store.all 'order'
|
||||
# sections: @store.all 'section'
|
||||
# setupController: (controller, model)->
|
||||
# controller.set('model', model)
|
||||
# #$('#section_selector').on 'change', (-> controller.set('sectionId', $(this).val()))
|
||||
# #controller.set 'lists', @store.all('list')
|
||||
# #controller.set 'lists', Qsupplier.App.List.all() #.filterProperty('state', 'active')
|
||||
# #controller.set 'orders', Qsupplier.App.Order.all()
|
||||
# #controller.set 'lists', model.get('lists')
|
||||
# #controller.set 'orders', model.get('orders')
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
Qsupplier.App.SectionRoute = Ember.Route.extend
|
||||
model: (params) -> @store.findById 'section', params.section_id
|
||||
renderTemplate: ->
|
||||
@render 'section'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
h1=t 'models.plural.list'
|
||||
Qsupplier.App.ListDisplayDateSelector valueBinding="date"
|
||||
if lists
|
||||
if sorted_lists
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
@@ -12,7 +12,7 @@ if lists
|
||||
th.currentcy=t 'attributes.list.price'
|
||||
th.timestamp=t 'attributes.list.created_at'
|
||||
tbody
|
||||
each list in lists
|
||||
each list in sorted_lists
|
||||
tr
|
||||
td.state
|
||||
link-to 'list' list.id
|
||||
@@ -20,7 +20,7 @@ if lists
|
||||
td.boolean.needs_help=boolean list.needs_help
|
||||
td.boolean.needs_payment=boolean list.needs_payment
|
||||
td.timestamp=time list.closed_at
|
||||
td.table_number 7
|
||||
td.table_number= list.table.number
|
||||
td.currency=currency list.price
|
||||
td.timestamp=time list.created_at
|
||||
else
|
||||
|
||||
@@ -20,27 +20,18 @@
|
||||
Qsupplier.App.DropdownLink title="Action"
|
||||
ul
|
||||
li
|
||||
a{action addTables}
|
||||
span.section-add-tables-icon
|
||||
=t 'section.add_tables.button_label'
|
||||
a{action "addTables"}: span.section-add-tables-icon=t 'section.add_tables.button_label'
|
||||
li
|
||||
a{action arrangeTables}
|
||||
span.section-arrange-tables-icon
|
||||
=t 'section.arrange_tables.modal.title'
|
||||
a{action "arrangeTables"}: span.section-arrange-tables-icon=t 'section.arrange_tables.modal.title'
|
||||
li
|
||||
a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}"
|
||||
span.table-qr-codes
|
||||
=t 'tables.qr_codes.link'
|
||||
a href="{{route 'qr_codes_suppliers_tables_path' section_id=id}}": span.table-qr-codes=t 'tables.qr_codes.link'
|
||||
li
|
||||
/a.section-destroy href="{{route 'suppliers_section_path' id}}" data-method="delete" data-confirm="{{t 'helpers.links.are_you_sure' bare=true}}"
|
||||
a.section-destroy{action destroySection}
|
||||
span.section-remove-icon
|
||||
=t 'helpers.links.destroy'
|
||||
a.section-destroy{action "destroySection"}: span.section-remove-icon=t 'helpers.links.destroy'
|
||||
Ember.TextField valueBinding="title" class="section-edit-title-field"
|
||||
Qsupplier.App.NumberField valueBinding="width" class="dimension section-edit-width-field"
|
||||
span.fa.fa-lg.fa-times
|
||||
Qsupplier.App.NumberField valueBinding="height" class="dimension section-edit-height-field"
|
||||
a.section-normal-mode-button{ action finishEditable }: span
|
||||
a.section-normal-mode-button{ action "finishEditable" }: span
|
||||
else
|
||||
a.section-edit-mode-button{ action makeEditable }: span
|
||||
a.section-edit-mode-button{ action "makeEditable" }: span
|
||||
Qsupplier.App.SectionTablesView contentBinding="tables"
|
||||
|
||||
@@ -7,8 +7,8 @@ if table.active_list
|
||||
div.table-actions
|
||||
.title= table.number
|
||||
.table-action-row
|
||||
Qsupplier.App.MarkListHelpedButtonView content=table.active_list
|
||||
Qsupplier.App.CloseListButtonView content=table.active_list
|
||||
Qsupplier.App.MarkListHelpedButtonView contentBinding="table.active_list"
|
||||
Qsupplier.App.CloseListButtonView contentBinding="table.active_list"
|
||||
.table-action-row=currency table.active_list.total
|
||||
/.table-action-row
|
||||
a{action "editTable" table}: span.fa.fa-lg.fa-wrench
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
each table in tables
|
||||
Qsupplier.App.SectionTableView contentBinding="table"
|
||||
Qsupplier.App.SectionTableView content=table
|
||||
|
||||
@@ -4,4 +4,4 @@ Qsupplier.App.MarkListHelpedButtonView = Ember.View.extend
|
||||
classNameBindings: ['content.needs_help:show:hide']
|
||||
tagName: 'button'
|
||||
click: (e)->
|
||||
@get('content').is_helped()
|
||||
@get('content').then (l)->l.is_helped()
|
||||
|
||||
@@ -15,8 +15,9 @@ root.Qsupplier=
|
||||
list = order.get('list')
|
||||
list.get('orders').addRecord order
|
||||
if table = list.get('table')
|
||||
if table.get('active_list') isnt list
|
||||
table.set 'active_list', list
|
||||
if table.get('active_list')
|
||||
table.get('active_list').then (table_list)->
|
||||
table.set 'active_list', list if table_list isnt list
|
||||
, 200
|
||||
else if(e.event == 'list_needs_help')
|
||||
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
|
||||
|
||||
Reference in New Issue
Block a user