give some love to the waiter app

This commit is contained in:
2016-06-02 16:38:09 +02:00
parent e4461d3d29
commit ca8cc80b22
19 changed files with 124 additions and 26 deletions
@@ -0,0 +1,27 @@
#App.ApplicationAdapter = DS.ActiveModelAdapter.extend
# namespace: 'supplier'
# headers:
# "Accept": "application/json, text/javascript; q=0.01"
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
namespace: 'waiter'
pathForType: (type)->
type.underscore().pluralize()
# Code for createRecord and updateRecord taken from ember data v2.0.0 restadapter
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
updateRecord: (store, type, snapshot)->
data = {}
#var serializer = store.serializerFor(type.modelName);
serializer = Ember.get(snapshot.record, 'store').serializerFor('creation')
id = snapshot.id
url = @buildURL(type.modelName, id, snapshot, 'updateRecord')
serializer.serializeIntoHash data, type, snapshot, includeId: true
@ajax url, "PUT", data: data
@@ -3,6 +3,6 @@ App.SectionHeaderComponent = Ember.Component.extend
tagName: 'dd'
classNameBindings: ['active']
active: (->
if @get('context.id') == @get('controller.controllers.section.model.id') then 'active' else ''
).property('controller.controllers.section.model.id')
#active: Ember.computed.equal "section.id", "globals.active_section.id"
active: Ember.computed "section.id", "globals.active_section.id", ->
if @get('section.id') is @get('globals.active_section.id') then 'active' else ''
@@ -1,4 +1,4 @@
App.ProductCategoriesController = Ember.ArrayController.extend
App.ProductCategoriesController = Ember.Controller.extend
#needs: ['table']
actions:
addProduct: (product)->
@@ -1 +1 @@
App.SectionController = Ember.ObjectController.extend {}
App.SectionController = Ember.Controller.extend {}
@@ -1,2 +1,2 @@
App.SectionsController = Ember.ArrayController.extend
App.SectionsController = Ember.Controller.extend
needs: ['section']
@@ -1,4 +1,4 @@
App.TableController = Ember.ObjectController.extend
App.TableController = Ember.Controller.extend
orderTotal: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity')
@@ -0,0 +1,20 @@
Globals = Ember.Object.extend
current_employee: null
current_supplier: null
active_section: null
flash_message: ''
modal_active: false
#locale: Qstorage.getItem('locale')
App.initializer
name: 'injectCurrent'
initialize: (container, app)->
#container.optionsForType 'globals', instantiate: false, singleton: true
app.register 'global:variables', Globals, singleton: true
app.inject 'controller', 'globals', 'global:variables'
app.inject 'component', 'globals', 'global:variables'
app.inject 'view', 'globals', 'global:variables'
app.inject 'route', 'globals', 'global:variables'
app.inject 'component', 'store', 'service:store'
@@ -2,7 +2,8 @@
#= require handlebars
#= require ember
#= require ember-data
#= require shared-ember-helpers/all
#= require active-model-adapter
#= require ./app
#= require shared-ember-helpers/all
#= require_tree .
@EmberENV = {FEATURES: {'query-params-new': true}}
@@ -1,4 +1,4 @@
attr = DS.attr
App.ProductCategory = DS.Model.extend
name: attr 'string'
products: DS.hasMany('product')
products: DS.hasMany('product', async: false)
@@ -1,10 +1,18 @@
App.ApplicationRoute = Ember.Route.extend
beforeModel: ->
@supplier = @store.push 'supplier', supplier_object
@employee = @store.push 'employee', employee_object
@supplier = @store.push
data:
id: supplier_object.id
type: 'supplier'
attributes: supplier_object
@employee = @store.push
data:
id: employee_object.id
type: 'employee'
attributes: employee_object
@supplier.reload().then =>
#@store.find('list', state: 'active')
setupController: (controller, model)->
controller.set 'supplier', @supplier
controller.set 'employee', @employee
@controllerFor('product_categories').set 'model', @store.find('product_category')
@controllerFor('product_categories').set 'model', @store.findAll('product_category')
@@ -0,0 +1,3 @@
App.SectionRoute = Ember.Route.extend
model: (options) -> @store.peekRecord('section', options.section_id)
afterModel: (model) -> @set('globals.active_section', model)
@@ -1,2 +1,2 @@
App.SectionsRoute = Ember.Route.extend
model: -> @store.find('section')
model: -> @store.findAll('section')
@@ -2,15 +2,18 @@
#DS.RESTAdapter.reopen
#namespace: 'waiter'
App.ApplicationSerializer = DS.ActiveModelSerializer
App.CustomAdapter = DS.RESTAdapter.extend
#App.ApplicationSerializer = DS.ActiveModelSerializer
#App.CustomAdapter = DS.RESTAdapter.extend
# user underscored paths
pathForType: (type)->
decamelized = Ember.String.decamelize(type)
Ember.String.pluralize(decamelized)
#App.Store = DS.Store.extend
#adapter: App.CustomAdapter
App.ApplicationStore = DS.Store.extend
adapter: DS.ActiveModelAdapter.extend
namespace: 'waiter'
# # user underscored paths
# pathForType: (type)->
# decamelized = Ember.String.decamelize(type)
# Ember.String.pluralize(decamelized)
##App.Store = DS.Store.extend
# #adapter: App.CustomAdapter
#App.ApplicationStore = DS.Store.extend
# adapter: DS.ActiveModelAdapter.extend
# namespace: 'waiter'
App.ApplicationSerializer = DS.JSONAPISerializer.extend {}
App.CreationSerializer = DS.ActiveModelSerializer.extend {}
@@ -1,2 +1,2 @@
= link-to 'section' section
span= title
span= section.title