diff --git a/app/assets/javascripts/user/app/components/lists/index-entry.js.coffee b/app/assets/javascripts/user/app/components/lists/index-entry.js.coffee index 16ce0989..f4bcc357 100644 --- a/app/assets/javascripts/user/app/components/lists/index-entry.js.coffee +++ b/app/assets/javascripts/user/app/components/lists/index-entry.js.coffee @@ -3,5 +3,4 @@ App.ListIndexEntryComponent = Ember.Component.extend classNames: ['lists-overview-entry'] classNameBindings: ['content.active:active'] click: -> - debugger - @get('controller').transitionToRoute 'list', @get('list') + @get('targetObject').transitionToRoute 'list', @get('list') diff --git a/app/assets/javascripts/user/app/controllers/lists_index_controller.js.coffee b/app/assets/javascripts/user/app/controllers/lists_index_controller.js.coffee index 4f822bf2..bf257004 100644 --- a/app/assets/javascripts/user/app/controllers/lists_index_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/lists_index_controller.js.coffee @@ -1,2 +1,2 @@ -App.ListsIndexController = Ember.Controller.extend App.PaginationModule, +App.ListsIndexController = Ember.Controller.extend #App.PaginationModule, lists: (->@get('model').sortBy('created_at').reverse()).property('model.[]') diff --git a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee index 32437279..cc06bba0 100644 --- a/app/assets/javascripts/user/app/controllers/table_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/table_controller.js.coffee @@ -19,3 +19,4 @@ App.TableController = Ember.Controller.extend Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id')) @set 'globals.join_request_sent', true # keeps the button deactivated #setupProductOrders: (-> @set('unordered_product_orders', @store.peekAll('product_order'))).on('init') + #openDebugger: Ember.computed 'model.id', (-> debugger; true) diff --git a/app/assets/javascripts/user/app/manifest.js.coffee b/app/assets/javascripts/user/app/manifest.js.coffee index 853e6285..83e49494 100644 --- a/app/assets/javascripts/user/app/manifest.js.coffee +++ b/app/assets/javascripts/user/app/manifest.js.coffee @@ -3,7 +3,7 @@ #= require handlebars #= require ember #= require ember-data -#= require active-model-adapter +# require active-model-adapter #= require_directory ./modifications #= require ./app #= require shared-ember-helpers/all diff --git a/app/assets/javascripts/user/app/models/product.js.coffee b/app/assets/javascripts/user/app/models/product.js.coffee index 943663bb..a599124b 100644 --- a/app/assets/javascripts/user/app/models/product.js.coffee +++ b/app/assets/javascripts/user/app/models/product.js.coffee @@ -6,9 +6,11 @@ App.Product = DS.Model.extend position: attr('number', defaultValue: 0) active: attr 'boolean', defaultValue: true 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 + sorted_product_variants: Ember.computed 'product_variants.@each.name', 'product_variants.@each.position', -> @get('product_variants').sortBy('position') diff --git a/app/assets/javascripts/user/app/models/product_category.js.coffee b/app/assets/javascripts/user/app/models/product_category.js.coffee index 6e404f00..5209bca0 100644 --- a/app/assets/javascripts/user/app/models/product_category.js.coffee +++ b/app/assets/javascripts/user/app/models/product_category.js.coffee @@ -1,8 +1,6 @@ attr = DS.attr App.ProductCategory = DS.Model.extend 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) @@ -13,7 +11,10 @@ App.ProductCategory = DS.Model.extend full_day: attr 'boolean', defaultValue: true start_from: attr('number') end_on: attr('number') - position: attr('number') + position: attr('number', defaultValue: 0) collapsed: attr('boolean', defaultValue: false) + products: DS.hasMany('product', async: false) + supplier: DS.belongsTo('supplier', async: false) + sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position') diff --git a/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee b/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee index 1576b59e..31ca208c 100644 --- a/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee +++ b/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee @@ -1,6 +1,6 @@ DS.Model.reopen - #created_at: DS.attr('date') - #updated_at: DS.attr('date') + created_at: DS.attr('date') + updated_at: DS.attr('date') eraseRecord: -> #@clearRelationships() @transitionTo('deleted.saved') diff --git a/app/assets/javascripts/user/app/routes/active_list_route.js.coffee b/app/assets/javascripts/user/app/routes/active_list_route.js.coffee index ca062609..bd203fe1 100644 --- a/app/assets/javascripts/user/app/routes/active_list_route.js.coffee +++ b/app/assets/javascripts/user/app/routes/active_list_route.js.coffee @@ -9,5 +9,3 @@ App.ActiveListRoute = Ember.Route.extend App.ResetScroll #@transitionTo 'table', table_id #else #controller.redirect_to 'index', message: 'the_list_has_been_closed' - #setupController: (controller, model)-> - #debugger diff --git a/app/assets/javascripts/user/app/routes/list_route.js.coffee b/app/assets/javascripts/user/app/routes/list_route.js.coffee index 8c1c5486..b5f1c2c0 100644 --- a/app/assets/javascripts/user/app/routes/list_route.js.coffee +++ b/app/assets/javascripts/user/app/routes/list_route.js.coffee @@ -1,5 +1,5 @@ App.ListRoute = Ember.Route.extend App.ResetScroll, model: (options)-> @store.findRecord 'list', options.list_id - afterModel: (model)-> - model.reload() unless model.is_extended_version() + #afterModel: (model)-> + # model.reload() unless model.is_extended_version() diff --git a/app/assets/javascripts/user/app/routes/lists_route.js.coffee b/app/assets/javascripts/user/app/routes/lists_route.js.coffee index fbef2cb2..4d9564a7 100644 --- a/app/assets/javascripts/user/app/routes/lists_route.js.coffee +++ b/app/assets/javascripts/user/app/routes/lists_route.js.coffee @@ -1,5 +1,6 @@ -App.ListsRoute = Ember.Route.extend App.ResetScroll, +App.ListsIndexRoute = Ember.Route.extend App.ResetScroll, model: -> - @store.findAll 'list' + @store.query('list', page: 1, per_page: 2) setupController: (controller, model)-> + @_super(controller, model) controller.set('alreadyLoaded', true) diff --git a/app/assets/javascripts/user/app/templates/global/_top_menu.emblem b/app/assets/javascripts/user/app/templates/global/_top_menu.emblem index 0e0d4678..dd949cc2 100644 --- a/app/assets/javascripts/user/app/templates/global/_top_menu.emblem +++ b/app/assets/javascripts/user/app/templates/global/_top_menu.emblem @@ -6,7 +6,7 @@ link-to 'index' class="top-menu-logo with-list" = image-tag 'user/logo-small.png' = menu-item route="active_list" - = menu-item route="table" route_param=globals.active_list.table.id + = menu-item route="table" route_param=globals.active_list.table = menu-item-list-needs-help = menu-item-list-needs-payment else diff --git a/app/assets/javascripts/user/app/templates/lists/index-entry.emblem b/app/assets/javascripts/user/app/templates/lists/index-entry.emblem index 7da66084..607913ec 100644 --- a/app/assets/javascripts/user/app/templates/lists/index-entry.emblem +++ b/app/assets/javascripts/user/app/templates/lists/index-entry.emblem @@ -1,3 +1,4 @@ span.created_at=time list.created_at span.price.currency= currency list.price +span.state= list.state span.name= list.supplier.name diff --git a/app/assets/javascripts/user/app/templates/table.emblem b/app/assets/javascripts/user/app/templates/table.emblem index 4f4e9bed..877ce2a6 100644 --- a/app/assets/javascripts/user/app/templates/table.emblem +++ b/app/assets/javascripts/user/app/templates/table.emblem @@ -17,3 +17,5 @@ .large-6.columns= new-product-orders-list table=model else .large12= menu-product-categories product_categories=model.supplier.product_categories orderProducts=false +if openDebugger + span Debugger active diff --git a/app/controllers/users/lists_controller.rb b/app/controllers/users/lists_controller.rb index d76133c1..76189676 100644 --- a/app/controllers/users/lists_controller.rb +++ b/app/controllers/users/lists_controller.rb @@ -5,10 +5,10 @@ module Users #lists = current_user.lists.include_relation(:supplier, :table) lists = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25) #lists.include_relation(:supplier) - lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present? - lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders + #lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present? + #lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders lists.include_relation(:users, :supplier) - render json: JSONAPI::Serializer.serialize(lists, serializer: Users::ListSerializer, include: %w[supplier users], is_collection: true, meta: {total_pages: lists.total_pages, page: lists.current_page}) #, root: :lists + render json: JSONAPI::Serializer.serialize(lists, serializer: Users::ListSerializer, include: %w[supplier users], is_collection: true, meta: {total_pages: lists.total_count, page: lists.current_page}) #, root: :lists end #EMBER diff --git a/app/serializers/users/list_serializer.rb b/app/serializers/users/list_serializer.rb index c6623379..859e5b67 100644 --- a/app/serializers/users/list_serializer.rb +++ b/app/serializers/users/list_serializer.rb @@ -1,4 +1,5 @@ -class Users::ListSerializer < Qwaiter::UserBaseSerializer +class Users::ListSerializer + include Qwaiter::UserBaseSerializer # user ids for facebook pictures #self.root = :list attributes :state, :needs_help, :needs_payment, :user_requests_closing, diff --git a/app/serializers/users/order_serializer.rb b/app/serializers/users/order_serializer.rb index d12d8071..afc7a33e 100644 --- a/app/serializers/users/order_serializer.rb +++ b/app/serializers/users/order_serializer.rb @@ -1,4 +1,5 @@ -class Users::OrderSerializer < Qwaiter::UserBaseSerializer +class Users::OrderSerializer + include Qwaiter::UserBaseSerializer attributes :state #, :list_id, :section_id, :table_id #, :price has_many :product_orders, serializer: Users::ProductOrderSerializer diff --git a/app/serializers/users/product_category_serializer.rb b/app/serializers/users/product_category_serializer.rb index 51c3d270..1312ca39 100644 --- a/app/serializers/users/product_category_serializer.rb +++ b/app/serializers/users/product_category_serializer.rb @@ -1,4 +1,5 @@ -class Users::ProductCategorySerializer < Qwaiter::UserBaseSerializer +class Users::ProductCategorySerializer + include Qwaiter::UserBaseSerializer 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 diff --git a/app/serializers/users/product_order_serializer.rb b/app/serializers/users/product_order_serializer.rb index 7a1927e8..a4b5da80 100644 --- a/app/serializers/users/product_order_serializer.rb +++ b/app/serializers/users/product_order_serializer.rb @@ -1,5 +1,5 @@ -# Used for user ember1 -class Users::ProductOrderSerializer < Qwaiter::UserBaseSerializer +class Users::ProductOrderSerializer + include Qwaiter::UserBaseSerializer attributes :quantity, :price, :product_name, :product_variant # belongs_to :product #DO NOT USE THIS, THIS IS NOT NEEDED has_one :order, serializer: Users::OrderSerializer diff --git a/app/serializers/users/product_serializer.rb b/app/serializers/users/product_serializer.rb index 68bbb19d..dfd1bfc7 100644 --- a/app/serializers/users/product_serializer.rb +++ b/app/serializers/users/product_serializer.rb @@ -1,4 +1,5 @@ -class Users::ProductSerializer < Qwaiter::UserBaseSerializer +class Users::ProductSerializer + include Qwaiter::UserBaseSerializer attributes :name, :price, :description, :image, :code, :position, :visible, :active, :product_category_id has_many :product_variants, serializer: Users::ProductVariantSerializer diff --git a/app/serializers/users/product_variant_serializer.rb b/app/serializers/users/product_variant_serializer.rb index 3d03cf3d..9f12c762 100644 --- a/app/serializers/users/product_variant_serializer.rb +++ b/app/serializers/users/product_variant_serializer.rb @@ -1,3 +1,4 @@ -class Users::ProductVariantSerializer < Qwaiter::UserBaseSerializer +class Users::ProductVariantSerializer + include Qwaiter::UserBaseSerializer attributes :name end diff --git a/app/serializers/users/supplier_serializer.rb b/app/serializers/users/supplier_serializer.rb index a04c24e9..813e441e 100644 --- a/app/serializers/users/supplier_serializer.rb +++ b/app/serializers/users/supplier_serializer.rb @@ -1,5 +1,5 @@ -class Users::SupplierSerializer < Qwaiter::UserBaseSerializer - #self.root = :supplier +class Users::SupplierSerializer + include Qwaiter::UserBaseSerializer attributes :open, :name has_many :product_categories, serializer: Users::ProductCategorySerializer end diff --git a/app/serializers/users/table_serializer.rb b/app/serializers/users/table_serializer.rb index a12cef73..0724bbff 100644 --- a/app/serializers/users/table_serializer.rb +++ b/app/serializers/users/table_serializer.rb @@ -1,5 +1,5 @@ -class Users::TableSerializer < Qwaiter::UserBaseSerializer - #self.root = :table +class Users::TableSerializer + include Qwaiter::UserBaseSerializer attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :supplier_id #, :alist_id has_one :supplier, serializer: Users::SupplierSerializer diff --git a/app/serializers/users/user_serializer.rb b/app/serializers/users/user_serializer.rb index eba6c81f..c74345b7 100644 --- a/app/serializers/users/user_serializer.rb +++ b/app/serializers/users/user_serializer.rb @@ -1,5 +1,5 @@ -class Users::UserSerializer < Qwaiter::UserBaseSerializer - #self.root = :user +class Users::UserSerializer + include Qwaiter::UserBaseSerializer attributes :email, :provider, :uid, :name, :avatar def name diff --git a/lib/qwaiter/user_base_serializer.rb b/lib/qwaiter/user_base_serializer.rb index 1057e7ae..844f46f0 100644 --- a/lib/qwaiter/user_base_serializer.rb +++ b/lib/qwaiter/user_base_serializer.rb @@ -1,9 +1,10 @@ -class Qwaiter::UserBaseSerializer +module Qwaiter::UserBaseSerializer + extend ActiveSupport::Concern include JSONAPI::Serializer - class_attribute :related_link_for - - def self.related_link_for(*attributes) - self.related_link_for = attributes + included do + class_attribute :related_link_for_attributes + attribute :created_at + attribute :updated_at end def base_url @@ -22,15 +23,22 @@ class Qwaiter::UserBaseSerializer #alias_method :default_relationship_related_link, :relationship_related_link def relationship_related_link(attribute_name) - super if related_link_for.include?(attribute_name) + #super if related_link_for_attributes.include?(attribute_name) + super end def relationship_self_link(attribute_name) end - def self.attributes(*attrs) - attrs.each do |attr| - attribute attr + module ClassMethods + def attributes(*attrs) + attrs.each do |attr| + attribute attr + end + end + + def related_link_for(*attributes) + self.related_link_for_attributes = attributes end end end