give some love to the waiter app
This commit is contained in:
@@ -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
-1
@@ -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
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Waiter::ProductCategoriesController < Waiter::ApplicationController
|
||||
|
||||
def index
|
||||
records = current_supplier.product_categories.include_relation(product: :product_variants)
|
||||
render json: records, each_serializer: Waiter::ProductCategorySerializer, include: %w[products]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class Waiter::ProductCategorySerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :name, :supplier_id, :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,
|
||||
:position
|
||||
has_many :products, serializer: Waiter::ProductSerializer
|
||||
has_one :supplier, serializer: Waiter::SupplierSerializer
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class Waiter::ProductSerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :name, :price, :description, :code, :position, :visible, :active
|
||||
attribute :image do
|
||||
if object.image.present?
|
||||
{small: object.image.url(:small)}
|
||||
else
|
||||
{small: object.image.url}
|
||||
end
|
||||
end
|
||||
|
||||
has_many :product_variants, serializer: Waiter::ProductVariantSerializer
|
||||
has_one :product_category, serializer: Waiter::ProductCategorySerializer
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Waiter::ProductVariantSerializer
|
||||
include Qwaiter::WaiterBaseSerializer
|
||||
attributes :name
|
||||
has_one :product, serializer: Waiter::ProductSerializer
|
||||
end
|
||||
+2
-1
@@ -41,11 +41,12 @@ Qwaiter::Application.routes.draw do
|
||||
#WAITER
|
||||
#get '/waiter' => 'waiter#index' #, controller: 'waiter', action: 'index'
|
||||
#get '/waiter/sections' => 'waiter#sections'
|
||||
get '/waiter/product_categories' => 'waiter#product_categories'
|
||||
#get '/waiter/product_categories' => 'waiter#product_categories'
|
||||
post '/waiter/order_products' => 'waiter#order_products', as: :order_products_waiter
|
||||
namespace :waiter do
|
||||
resources :sections
|
||||
resources :suppliers
|
||||
resources :product_categories, only: %i[index]
|
||||
|
||||
root to: 'dashboard#index'
|
||||
get '/*rest' => redirect('/waiter') # Ember app refresh
|
||||
|
||||
Reference in New Issue
Block a user