serializer stuff

This commit is contained in:
2015-09-14 18:53:58 +02:00
parent 36e5b21b13
commit ef894f9e02
37 changed files with 141 additions and 63 deletions
@@ -4,3 +4,17 @@
# "Accept": "application/json, text/javascript; q=0.01"
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
namespace: 'supplier'
pathForType: (type)->
type.underscore().pluralize()
createRecord: (store, type, snapshot)->
data = {}
#var serializer = store.serializerFor(type.modelName);
serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
url = @buildURL(type.modelName, null, snapshot, 'createRecord')
serializer.serializeIntoHash data, type, snapshot, includeId: true
@ajax url, "POST", data: data
#debugger
#Ember.get(snapshot.record, 'store').serializerFor('creation').serialize(snapshot)
#3
@@ -2,29 +2,23 @@ App.IndexController = Ember.Controller.extend
show_lists: true
show_orders: true
lists: (-> @store.peekAll('list')).property()
orders: (-> @store.peekAll('order')).property()
orders: Ember.computed -> @store.peekAll('order')
sections: (-> @store.peekAll('section')).property()
active_section: Ember.computed.alias 'globals.active_section'
active_lists: (->
active_lists: Ember.computed 'lists.@each.state', 'active_section.id', ->
@get('orders') # trigger orders, otherwise observers are not initialized/triggered (active_orders)
if section_id = @get('active_section.id')
lists = @get('lists').filter (l)=>( l.get('section.id') == section_id && l.get('state') == 'active' )
else
lists = @get('lists').filterBy('state', 'active')
lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
).property('lists.@each.state', 'active_section.id')
lists.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness
active_orders: Ember.computed 'active_lists.[]', 'active_orders.@each.state', ->
active_orders: Ember.computed 'active_lists.[]', 'orders.@each.state', ->
orders = Ember.A()
@get('active_lists').forEach (list)->
list.get('orders').filterBy('needs_supplier_attention').forEach (order)->
orders.push order
return orders
#if @get('active_section.id')
# orders = @get('orders').filter (o)=>( o.get('section.id') == @get('active_section.id') && o.get('needs_supplier_attention') )
#else
# orders = @get('orders').filter (o)->( o.get('needs_supplier_attention') )
#orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first :-) Customer happyness
#).property('orders.@each.state', 'active_section.id')
orders.sortBy('created_at') # Not reversed, oldest on top, start with oldest order first, work your way down :-) Customer happyness
show_lists_table: Ember.computed 'show_lists', 'active_lists.[]', ->
@get('show_lists') and @get('active_lists.length')
@@ -2,8 +2,9 @@ attr = DS.attr
App.EmployeeShift = DS.Model.extend
start_from: attr('moment')
end_on: attr('moment')
employee: DS.belongsTo 'employee'
description: attr('string')
employee: DS.belongsTo 'employee', async: false
supplier: DS.belongsTo 'supplier', async: false
calendar_event: (->
id: @id
title: @get('title')
@@ -11,7 +12,6 @@ App.EmployeeShift = DS.Model.extend
end: @get('end_on')
color: @get('employee.color')
).property('start_from', 'end_on', 'title')
supplier: DS.belongsTo('supplier')
title: Ember.computed 'employee.name', 'description', ->
if @get('description')
@@ -5,18 +5,17 @@ App.List = DS.Model.extend
needs_payment: attr 'boolean'
user_requests_closing: attr('boolean')
# users: DS.hasMany('user', async: true)
users: DS.hasMany('user')
is_paid: attr 'boolean'
price: attr 'number'
#has_active_orders: attr 'boolean'
price: attr 'number'
closed_at: DS.attr('date')
users: DS.hasMany('user', async: false)
#table_number: attr 'number'
table: DS.belongsTo('table', inverse: 'active_list', async: true)
table: DS.belongsTo('table', inverse: 'active_list', async: false) # should be async, but synchroneously loading now fails with JSONAPI, this seems to work
#users: DS.hasMany('user', inverse: 'active_list')
orders: DS.hasMany('order')
section: DS.belongsTo('section')
section_id: attr('string')
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
active: ( -> @get('state') is 'active' ).property('state')
isClosed: ->
@set('state', 'closed')
@@ -11,7 +11,7 @@ App.Order = DS.Model.extend
active: (-> @get('state') == 'active').property('state')
delivered: (-> @get('state') == 'delivered').property('state')
placed: (-> @get('state') == 'placed').property('state')
needs_supplier_attention: (-> (@get('state') == 'placed') || (@get('state') == 'active')).property('state')
needs_supplier_attention: (-> (@get('state') is 'placed') or (@get('state') is 'active')).property('state')
isClosed: ->
@set 'state', 'closed'
@@ -8,9 +8,9 @@ App.Product = DS.Model.extend Ember.Validations.Mixin,
active: attr('boolean', defaultValue: true)
position: attr('number', defaultValue: 0)
image: attr()
product_category: DS.belongsTo('product_category')
product_orders: DS.hasMany('product_order')
product_variants: DS.hasMany('product_variant')
product_category: DS.belongsTo('product_category', async: false)
product_orders: DS.hasMany('product_order', async: false)
product_variants: DS.hasMany('product_variant', async: false)
image_src: (->
image = @get('image')
@@ -1,8 +1,6 @@
attr = DS.attr
App.ProductCategory = DS.Model.extend Ember.Validations.Mixin,
name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo 'supplier'
active_on_sunday: attr('boolean', defaultValue: true)
active_on_monday: attr('boolean', defaultValue: true)
active_on_tuesday: attr('boolean', defaultValue: true)
@@ -15,6 +13,9 @@ App.ProductCategory = DS.Model.extend Ember.Validations.Mixin,
end_on: attr('number')
position: attr('number')
products: DS.hasMany('product', async: false)
supplier: DS.belongsTo 'supplier', async: false
sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position')
availability_text: Ember.computed 'active_on_sunday', 'active_on_monday', 'active_on_tuesday', 'active_on_wednesday', 'active_on_thursday', 'active_on_friday', 'active_on_saturday', 'full_day', 'start_from', 'end_on', ->
@@ -5,7 +5,7 @@ App.ProductOrder = DS.Model.extend
product_variant: attr('string')
product_name: attr('string')
product: DS.belongsTo('product', async: true)
order: DS.belongsTo('order')
order: DS.belongsTo('order', async: false)
increment: ->
@set('quantity', @get('quantity') + 1)
total: (-> @get('quantity') * @get('price')).property('quantity', 'price')
@@ -6,6 +6,6 @@ App.SectionArea = DS.Model.extend Ember.Validations.Mixin,
position_x: attr 'number', defaultValue: 0
position_y: attr 'number', defaultValue: 0
rounded: attr 'boolean', defaultValue: false
section: DS.belongsTo('section')
section: DS.belongsTo('section', async: false)
validations:
title: {presence: true}
@@ -3,4 +3,4 @@ App.SectionElement = DS.Model.extend App.SvgElementMixin, App.Rotation,
position_x: attr 'number', defaultValue: 0
position_y: attr 'number', defaultValue: 0
rotation: attr 'number', defaultValue: 0
section: DS.belongsTo('section')
section: DS.belongsTo('section', async: false)
@@ -15,9 +15,10 @@ App.Supplier = DS.Model.extend
lat: attr 'number'
lng: attr 'number'
week_starts_on_monday: attr 'boolean'
product_categories: DS.hasMany 'product_category'
orders_in_process_count: attr('number')
orders_placed_count: attr('number')
product_categories: DS.hasMany 'product_category', async: false
employee_shifts: DS.hasMany('employee-shift')
close: ->
@@ -131,11 +131,12 @@ App.ApplicationRoute = Ember.Route.extend
@store.pushPayload(data.payload)
if order_id = data.payload.data.id
order = @store.peekRecord('order', order_id)
return if @get('globals.active_section.id') and order.get('section.id') isnt @get('globals.active_section.id')
return if @get('globals.active_section.id') and order.get('list.section.id') isnt @get('globals.active_section.id')
@set 'globals.flash_message', order.get('display_with_table')
try ion.sound.play('water_droplet')
new_list: (data)->
debugger
if data.payload
@store.pushPayload(data.payload)
try ion.sound.play('water_droplet')
list_changed_table: (data) -> @store.pushPayload('list', lists: [data.list])
list_closed: (data) -> list.isClosed() if list = @store.peekRecord('list', data.id)
@@ -1,7 +1,4 @@
App.SectionsRoute = Ember.Route.extend
beforeModel: ->
@store.findAll 'section-element'
@store.findAll 'section-area'
model: -> @store.peekAll 'section'
# setupController: (controller, collection) ->
@@ -1,7 +1,8 @@
#App.ApplicationSerializer = DS.ActiveModelSerializer
App.ApplicationSerializer = DS.JSONAPISerializer.extend
keyForAttribute: (attr, method)-> attr
App.ApplicationSerializer = DS.JSONAPISerializer.extend {}
App.CreationSerializer = DS.ActiveModelSerializer.extend {}
# keyForAttribute: (attr, method)-> attr
#App.ApplicationStore = DS.Store
#adapter: DS.ActiveModelAdapter.extend
#namespace: 'supplier'