Style upgrades and emberified supplier lists

This commit is contained in:
2014-04-24 16:41:08 +02:00
parent 546e4499ea
commit 27a1022eb4
56 changed files with 321 additions and 139 deletions
@@ -1,18 +1,18 @@
Qsupplier.App.IndexController = Ember.ObjectController.extend
needs: ['application']
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('active_section.id')
@get('lists').filter (l)=>( l.get('section.id') == @get('active_section.id') && l.get('state') == 'active' )
else
@get('lists').filterProperty('state', 'active')
).property('lists.@each.state', 'active_section_id')
).property('lists.@each.state', 'active_section.id')
active_orders: (->
if @get('active_section_id')
@get('orders').filter (o)=>( o.get('section.id') == @get('active_section_id') && o.get('needs_supplier_attention') )
if @get('active_section.id')
@get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') )
else
@get('orders').filter (o)->( o.get('needs_supplier_attention') )
).property('orders.@each.state', 'active_section_id')
).property('orders.@each.state', 'active_section.id')
markListAsHelped: (id)->
if list = Qsupplier.App.List.findCached(id)
@@ -0,0 +1,6 @@
Qsupplier.App.ListController = Ember.ObjectController.extend
needs: ['application', 'lists', 'list'] #wtf? list, otherwise an Ember error
list: (-> @get('model')).property('model')
showTotal: (->
if @get('list.orders.length') && @get('list.orders.length') > 1 then true else false
).property('list.orders.length')
@@ -1,4 +0,0 @@
Qsupplier.App.ListsController = Ember.ArrayController.extend
dateChanged: (->
@set('model', @store.find('list', date: @get('date')))
).observes('date')
@@ -0,0 +1,8 @@
Qsupplier.App.ListsIndexController = Ember.ArrayController.extend
dateChanged: (->
if @get('date')
@set('model', @store.find('list', date: @get('date')))
else
@set('model', @store.find('list'))
).observes('date')
lists: (-> @get('model')).property('model')
@@ -1,5 +1,5 @@
Qsupplier.App.SectionsIndexController = Ember.ArrayController.extend
needs: ['application', 'sections']
needs: ['application', 'sections', 'index']
sections: (-> @get('controllers.sections.model')).property('controllers.sections.model')
sectionQrCodesUrl: ((a,b,c)->
debugger
@@ -8,3 +8,7 @@ Qsupplier.App.SectionsIndexController = Ember.ArrayController.extend
newPath: Routes.new_suppliers_section_path()
qrPath: (section_id)->
Routes.qr_codes_suppliers_tables_path section_id: section_id
actions:
showDashboardOrders: (section)->
@transitionToRoute('index').then =>
@get('controllers.index').set 'active_section', section
@@ -0,0 +1,4 @@
attr = DS.attr
Qsupplier.App.JoinRequest= DS.Model.extend
list: DS.belongsTo('list')
user: DS.belongsTo('user')
@@ -4,6 +4,7 @@ Qsupplier.App.List = DS.Model.extend
needs_help: attr 'boolean'
needs_payment: attr 'boolean'
user_requests_closing: attr('boolean')
users: DS.hasMany('user')
is_paid: attr 'boolean'
has_active_orders: attr 'boolean'
price: attr 'number'
@@ -28,6 +29,9 @@ Qsupplier.App.List = DS.Model.extend
@set 'needs_payment', true
markIsPaid: ->
@set 'needs_payment', false
total: (->
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('orders.@each.total')
close: ->
@markClosed()
@@ -36,3 +40,4 @@ Qsupplier.App.List = DS.Model.extend
is_helped: ->
@markHelped()
$.post Routes.supplier_mark_list_as_helped_path(), list_id: @id
sorted_orders: (-> @get('orders').sortBy('created_at').reverseObjects()).property('orders.@each.isLoaded')
@@ -1,4 +1,6 @@
attr = DS.attr
Qsupplier.App.User= DS.Model.extend
uid: attr 'string'
#active_list: DS.belongsTo('list')
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')
@@ -10,6 +10,7 @@ Qsupplier.App.IndexRoute = Ember.Route.extend
#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
# mayby @store.all 'list' will work better!!!! (2014-04-24 a more experienced benjamin :)
orders: @store.filter 'order', -> true
sections: @store.find 'section'
setupController: (controller, model)->
@@ -1,4 +1,4 @@
Qsupplier.App.ListsRoute = Ember.Route.extend
Qsupplier.App.ListsIndexRoute = Ember.Route.extend
#model: -> @store.find 'list'
setupController: (controller, model)->
controller.set 'date', (new Date()).toISOString().substr(0,10)
controller.set 'date', (new Date()).toISOString().substr(0,10) unless controller.get('date')
@@ -0,0 +1,19 @@
.display-row
.display-label=t 'attributes.list.created_at'
.display-field=time list.created_at
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
.list-orders-container
each order in list.sorted_orders
.list-order-container class=order.state
= order.display
span.currency= currency order.total
span.created_at= time order.created_at
if showTotal
.list-orders-total.total
= t 'total'
span.currency= currency list.total
else
p
span=t 'active_list.no_orders_explanation'
@@ -1,6 +1,6 @@
.page-header
div.pull-right
'{{view 'Qsupplier.App.HomeSectionSelectorView' content=controller.sections prompt=controllers.application.supplier.name}}
div.dashboard-section-selection
'{{view 'Qsupplier.App.HomeSectionSelectorView' selectionBinding="controller.active_section" content=controller.sections prompt=controllers.application.supplier.name}}
'{{view 'Qsupplier.App.HomeSectionJumperView'}}
h3 {{t 'active_lists.title'}}
.well
@@ -0,0 +1,5 @@
.row
h2=t 'models.list'
partial "list_content"
link-to 'lists'
span Go to lists
@@ -1,26 +1 @@
h1=t 'models.plural.list'
Qsupplier.App.ListDisplayDateSelector valueBinding=date
if controller.model
table.table
thead
tr
th.state=t 'attributes.list.state'
th.boolean=t 'attributes.list.needs_help'
th.boolean=t 'attributes.list.needs_payment'
th.timestamp=t 'attributes.list.closed_at'
th.table_number=t 'models.table'
th.currentcy=t 'attributes.list.price'
th.timestamp=t 'attributes.list.created_at'
tbody
each list in controller
tr
td.state=state 'list' list.state
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.currency=currency list.price
td.timestamp=time list.created_at
else
.row
.panel=t 'list.none_found'
= outlet
@@ -0,0 +1,28 @@
h1=t 'models.plural.list'
Qsupplier.App.ListDisplayDateSelector valueBinding="date"
if lists
table.table
thead
tr
th.state=t 'attributes.list.state'
th.boolean=t 'attributes.list.needs_help'
th.boolean=t 'attributes.list.needs_payment'
th.timestamp=t 'attributes.list.closed_at'
th.table_number=t 'models.table'
th.currentcy=t 'attributes.list.price'
th.timestamp=t 'attributes.list.created_at'
tbody
each list in lists
tr
td.state
link-to 'list' list.id
= state 'list' list.state
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.currency=currency list.price
td.timestamp=time list.created_at
else
.row
.panel=t 'list.none_found'
@@ -1,5 +1,5 @@
.section-tabs-container
link-to 'sections' | b
link-to 'sections' class="goto-sections-index-tab-header": span
each section in sections
view Qsupplier.App.SectionTabHeaderView context=section
.section-manage-tables.pull-right
@@ -31,6 +31,7 @@ if sections
/td.currency=currency list.price
/td.timestamp=time list.created_at
td.actions
a.section-dashboard-orders{action showDashboardOrders section}: span
a.table-qr-codes{path qr_codes_suppliers_tables section_id=section.id}
span
else
@@ -1,11 +1,9 @@
Qsupplier.App.HomeSectionJumperView = Ember.View.extend
tagName: 'a'
classNames: ['main-board-section-jumper']
attributeBindings: ['href']
#href: (-> Routes.suppliers_section_path(@get('controller.active_section_id') || 'nothing')).property('controller.active_section_id')
href: '#'
isVisible: (-> !!@get('controller.active_section_id') ).property('controller.active_section_id')
template: Ember.Handlebars.compile('=>')
isVisible: (-> !!@get('controller.active_section.id') ).property('controller.active_section.id')
template: Ember.Handlebars.compile('<span class="fa fa-lg fa-chevron-circle-right"></span>')
click: (e)->
e.preventDefault()
@get('controller').transitionToRoute 'section', @get('controller.active_section_id')
@get('controller').transitionToRoute 'section', @get('controller.active_section.id')
@@ -3,6 +3,6 @@ HomeSectionOption = Ember.SelectOption.extend
Qsupplier.App.HomeSectionSelectorView = Ember.Select.extend
classNames: 'section_selector'
optionView: HomeSectionOption
valueBinding: 'controller.active_section_id'
#valueBinding: 'controller.active_section_id'
optionValuePath: 'content.id'
optionLabelPath: 'select_label'
@@ -1,2 +1,5 @@
App.ListController = Ember.ObjectController.extend
list: (-> @get('model')).property('model')
showTotal: (->
if @get('list.orders.length') && @get('list.orders.length') > 1 then true else false
).property('list.orders.length')
@@ -4,6 +4,8 @@ App.ProductOrdersController = Ember.ArrayController.extend
#Math.round(Math.random()*100)
@get('model').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('model.@each.quantity')
product_orders: (->@get('model')).property('model')
showTotal: (-> if @get('model.length') && @get('model.length') > 1 then true else false ).property('model.length')
actions:
clearProductOrders: ->
#TODO: make clearing of unpersisted product orders
@@ -7,7 +7,7 @@ if list.orders
= order.display
span.currency= currency order.total
span.created_at= time order.created_at
if displayTotal
if showTotal
.list-orders-total.total
= t 'total'
span.currency= currency model.total
@@ -4,7 +4,7 @@ if modelDisabled
.clearfix
.panel
ul.product-orders
each product_order in controller
each product_order in product_orders
li.product_order
= product_order.quantity
| x
@@ -14,8 +14,9 @@ if modelDisabled
span.currency=currency product_order.total
else
li= t 'product_orders.no_orders'
li.total
= t 'product_orders.total'
span.right.currency=currency orderTotal
if model
a.tiny.button.right{action orderProducts} href="#"= t 'product_orders.order_button'
if showTotal
li.total
= t 'product_orders.total'
span.right.currency=currency orderTotal
if product_orders
a.order-selected-products-button{action orderProducts} href="#"= t 'product_orders.order_button'