diff --git a/app/assets/javascripts/waiter/app/adapters/application.js.coffee b/app/assets/javascripts/waiter/app/adapters/application.js.coffee new file mode 100644 index 00000000..c2842029 --- /dev/null +++ b/app/assets/javascripts/waiter/app/adapters/application.js.coffee @@ -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 diff --git a/app/assets/javascripts/waiter/app/components/section-header.js.coffee b/app/assets/javascripts/waiter/app/components/section-header.js.coffee index a45ab2c8..cb69d50b 100644 --- a/app/assets/javascripts/waiter/app/components/section-header.js.coffee +++ b/app/assets/javascripts/waiter/app/components/section-header.js.coffee @@ -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 '' diff --git a/app/assets/javascripts/waiter/app/controllers/product_categories_controller.js.coffee b/app/assets/javascripts/waiter/app/controllers/product_categories_controller.js.coffee index f7433282..6e719710 100644 --- a/app/assets/javascripts/waiter/app/controllers/product_categories_controller.js.coffee +++ b/app/assets/javascripts/waiter/app/controllers/product_categories_controller.js.coffee @@ -1,4 +1,4 @@ -App.ProductCategoriesController = Ember.ArrayController.extend +App.ProductCategoriesController = Ember.Controller.extend #needs: ['table'] actions: addProduct: (product)-> diff --git a/app/assets/javascripts/waiter/app/controllers/section_controller.js.coffee b/app/assets/javascripts/waiter/app/controllers/section_controller.js.coffee index 8fa0090f..e2b60ff7 100644 --- a/app/assets/javascripts/waiter/app/controllers/section_controller.js.coffee +++ b/app/assets/javascripts/waiter/app/controllers/section_controller.js.coffee @@ -1 +1 @@ -App.SectionController = Ember.ObjectController.extend {} +App.SectionController = Ember.Controller.extend {} diff --git a/app/assets/javascripts/waiter/app/controllers/sections_controller.js.coffee b/app/assets/javascripts/waiter/app/controllers/sections_controller.js.coffee index c2ea38a5..eb8cb89e 100644 --- a/app/assets/javascripts/waiter/app/controllers/sections_controller.js.coffee +++ b/app/assets/javascripts/waiter/app/controllers/sections_controller.js.coffee @@ -1,2 +1,2 @@ -App.SectionsController = Ember.ArrayController.extend +App.SectionsController = Ember.Controller.extend needs: ['section'] diff --git a/app/assets/javascripts/waiter/app/controllers/table_controller.js.coffee b/app/assets/javascripts/waiter/app/controllers/table_controller.js.coffee index 178c3c9e..70c9e6a0 100644 --- a/app/assets/javascripts/waiter/app/controllers/table_controller.js.coffee +++ b/app/assets/javascripts/waiter/app/controllers/table_controller.js.coffee @@ -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') diff --git a/app/assets/javascripts/waiter/app/initializers/globals.js.coffee b/app/assets/javascripts/waiter/app/initializers/globals.js.coffee new file mode 100644 index 00000000..361ff9c1 --- /dev/null +++ b/app/assets/javascripts/waiter/app/initializers/globals.js.coffee @@ -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' diff --git a/app/assets/javascripts/waiter/app/manifest.js.coffee b/app/assets/javascripts/waiter/app/manifest.js.coffee index c84acfa5..f0e5285b 100644 --- a/app/assets/javascripts/waiter/app/manifest.js.coffee +++ b/app/assets/javascripts/waiter/app/manifest.js.coffee @@ -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}} diff --git a/app/assets/javascripts/waiter/app/models/product_category.js.coffee b/app/assets/javascripts/waiter/app/models/product_category.js.coffee index 3dd78672..148d8e96 100644 --- a/app/assets/javascripts/waiter/app/models/product_category.js.coffee +++ b/app/assets/javascripts/waiter/app/models/product_category.js.coffee @@ -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) diff --git a/app/assets/javascripts/waiter/app/routes/application_route.js.coffee b/app/assets/javascripts/waiter/app/routes/application_route.js.coffee index 2ccff375..8360b3c4 100644 --- a/app/assets/javascripts/waiter/app/routes/application_route.js.coffee +++ b/app/assets/javascripts/waiter/app/routes/application_route.js.coffee @@ -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') diff --git a/app/assets/javascripts/waiter/app/routes/section_route.js.coffee b/app/assets/javascripts/waiter/app/routes/section_route.js.coffee new file mode 100644 index 00000000..d17bd3a1 --- /dev/null +++ b/app/assets/javascripts/waiter/app/routes/section_route.js.coffee @@ -0,0 +1,3 @@ +App.SectionRoute = Ember.Route.extend + model: (options) -> @store.peekRecord('section', options.section_id) + afterModel: (model) -> @set('globals.active_section', model) diff --git a/app/assets/javascripts/waiter/app/routes/sections_route.js.coffee b/app/assets/javascripts/waiter/app/routes/sections_route.js.coffee index 6b52d0c9..6f674c74 100644 --- a/app/assets/javascripts/waiter/app/routes/sections_route.js.coffee +++ b/app/assets/javascripts/waiter/app/routes/sections_route.js.coffee @@ -1,2 +1,2 @@ App.SectionsRoute = Ember.Route.extend - model: -> @store.find('section') + model: -> @store.findAll('section') diff --git a/app/assets/javascripts/waiter/app/store.js.coffee b/app/assets/javascripts/waiter/app/store.js.coffee index 56351dee..0987c8bc 100644 --- a/app/assets/javascripts/waiter/app/store.js.coffee +++ b/app/assets/javascripts/waiter/app/store.js.coffee @@ -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 {} diff --git a/app/assets/javascripts/waiter/app/templates/components/section-header.emblem b/app/assets/javascripts/waiter/app/templates/components/section-header.emblem index 842d72ce..10fcf03f 100644 --- a/app/assets/javascripts/waiter/app/templates/components/section-header.emblem +++ b/app/assets/javascripts/waiter/app/templates/components/section-header.emblem @@ -1,2 +1,2 @@ = link-to 'section' section - span= title + span= section.title diff --git a/app/controllers/waiter/product_categories_controller.rb b/app/controllers/waiter/product_categories_controller.rb new file mode 100644 index 00000000..540bb76f --- /dev/null +++ b/app/controllers/waiter/product_categories_controller.rb @@ -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 diff --git a/app/serializers/waiter/product_category_serializer.rb b/app/serializers/waiter/product_category_serializer.rb new file mode 100644 index 00000000..e12b8e4a --- /dev/null +++ b/app/serializers/waiter/product_category_serializer.rb @@ -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 diff --git a/app/serializers/waiter/product_serializer.rb b/app/serializers/waiter/product_serializer.rb new file mode 100644 index 00000000..883bef82 --- /dev/null +++ b/app/serializers/waiter/product_serializer.rb @@ -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 diff --git a/app/serializers/waiter/product_variant_serializer.rb b/app/serializers/waiter/product_variant_serializer.rb new file mode 100644 index 00000000..c7f9ecd2 --- /dev/null +++ b/app/serializers/waiter/product_variant_serializer.rb @@ -0,0 +1,5 @@ +class Waiter::ProductVariantSerializer + include Qwaiter::WaiterBaseSerializer + attributes :name + has_one :product, serializer: Waiter::ProductSerializer +end diff --git a/config/routes.rb b/config/routes.rb index 3c0ad606..632b69ec 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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