This commit is contained in:
2015-09-05 14:14:28 +02:00
parent 7336585416
commit e2e883df1d
24 changed files with 62 additions and 44 deletions
@@ -3,5 +3,4 @@ App.ListIndexEntryComponent = Ember.Component.extend
classNames: ['lists-overview-entry'] classNames: ['lists-overview-entry']
classNameBindings: ['content.active:active'] classNameBindings: ['content.active:active']
click: -> click: ->
debugger @get('targetObject').transitionToRoute 'list', @get('list')
@get('controller').transitionToRoute 'list', @get('list')
@@ -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.[]') lists: (->@get('model').sortBy('created_at').reverse()).property('model.[]')
@@ -19,3 +19,4 @@ App.TableController = Ember.Controller.extend
Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id')) Ember.$.post("#{$data_host}/user/join_occupied_table.json", table_id: @get('model.id'))
@set 'globals.join_request_sent', true # keeps the button deactivated @set 'globals.join_request_sent', true # keeps the button deactivated
#setupProductOrders: (-> @set('unordered_product_orders', @store.peekAll('product_order'))).on('init') #setupProductOrders: (-> @set('unordered_product_orders', @store.peekAll('product_order'))).on('init')
#openDebugger: Ember.computed 'model.id', (-> debugger; true)
@@ -3,7 +3,7 @@
#= require handlebars #= require handlebars
#= require ember #= require ember
#= require ember-data #= require ember-data
#= require active-model-adapter # require active-model-adapter
#= require_directory ./modifications #= require_directory ./modifications
#= require ./app #= require ./app
#= require shared-ember-helpers/all #= require shared-ember-helpers/all
@@ -6,9 +6,11 @@ App.Product = DS.Model.extend
position: attr('number', defaultValue: 0) position: attr('number', defaultValue: 0)
active: attr 'boolean', defaultValue: true active: attr 'boolean', defaultValue: true
image: attr() image: attr()
product_category: DS.belongsTo('product-category')
product_orders: DS.hasMany('product-order') product_category: DS.belongsTo('product-category', async: false)
product_variants: DS.hasMany 'product-variant' 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', -> sorted_product_variants: Ember.computed 'product_variants.@each.name', 'product_variants.@each.position', ->
@get('product_variants').sortBy('position') @get('product_variants').sortBy('position')
@@ -1,8 +1,6 @@
attr = DS.attr attr = DS.attr
App.ProductCategory = DS.Model.extend App.ProductCategory = DS.Model.extend
name: attr('string') name: attr('string')
products: DS.hasMany('product')
supplier: DS.belongsTo('supplier')
active_on_sunday: attr('boolean', defaultValue: true) active_on_sunday: attr('boolean', defaultValue: true)
active_on_monday: attr('boolean', defaultValue: true) active_on_monday: attr('boolean', defaultValue: true)
active_on_tuesday: 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 full_day: attr 'boolean', defaultValue: true
start_from: attr('number') start_from: attr('number')
end_on: attr('number') end_on: attr('number')
position: attr('number') position: attr('number', defaultValue: 0)
collapsed: attr('boolean', defaultValue: false) 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') sorted_products: (-> @get('products').sortBy('position') ).property('products.@each.position')
@@ -1,6 +1,6 @@
DS.Model.reopen DS.Model.reopen
#created_at: DS.attr('date') created_at: DS.attr('date')
#updated_at: DS.attr('date') updated_at: DS.attr('date')
eraseRecord: -> eraseRecord: ->
#@clearRelationships() #@clearRelationships()
@transitionTo('deleted.saved') @transitionTo('deleted.saved')
@@ -9,5 +9,3 @@ App.ActiveListRoute = Ember.Route.extend App.ResetScroll
#@transitionTo 'table', table_id #@transitionTo 'table', table_id
#else #else
#controller.redirect_to 'index', message: 'the_list_has_been_closed' #controller.redirect_to 'index', message: 'the_list_has_been_closed'
#setupController: (controller, model)->
#debugger
@@ -1,5 +1,5 @@
App.ListRoute = Ember.Route.extend App.ResetScroll, App.ListRoute = Ember.Route.extend App.ResetScroll,
model: (options)-> model: (options)->
@store.findRecord 'list', options.list_id @store.findRecord 'list', options.list_id
afterModel: (model)-> #afterModel: (model)->
model.reload() unless model.is_extended_version() # model.reload() unless model.is_extended_version()
@@ -1,5 +1,6 @@
App.ListsRoute = Ember.Route.extend App.ResetScroll, App.ListsIndexRoute = Ember.Route.extend App.ResetScroll,
model: -> model: ->
@store.findAll 'list' @store.query('list', page: 1, per_page: 2)
setupController: (controller, model)-> setupController: (controller, model)->
@_super(controller, model)
controller.set('alreadyLoaded', true) controller.set('alreadyLoaded', true)
@@ -6,7 +6,7 @@
link-to 'index' class="top-menu-logo with-list" link-to 'index' class="top-menu-logo with-list"
= image-tag 'user/logo-small.png' = image-tag 'user/logo-small.png'
= menu-item route="active_list" = 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-help
= menu-item-list-needs-payment = menu-item-list-needs-payment
else else
@@ -1,3 +1,4 @@
span.created_at=time list.created_at span.created_at=time list.created_at
span.price.currency= currency list.price span.price.currency= currency list.price
span.state= list.state
span.name= list.supplier.name span.name= list.supplier.name
@@ -17,3 +17,5 @@
.large-6.columns= new-product-orders-list table=model .large-6.columns= new-product-orders-list table=model
else else
.large12= menu-product-categories product_categories=model.supplier.product_categories orderProducts=false .large12= menu-product-categories product_categories=model.supplier.product_categories orderProducts=false
if openDebugger
span Debugger active
+3 -3
View File
@@ -5,10 +5,10 @@ module Users
#lists = current_user.lists.include_relation(:supplier, :table) #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 = List.for_user(current_user, page: params[:page], per_page: params[:per_page].presence || 25)
#lists.include_relation(:supplier) #lists.include_relation(:supplier)
lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present? #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 == 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) 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 end
#EMBER #EMBER
+2 -1
View File
@@ -1,4 +1,5 @@
class Users::ListSerializer < Qwaiter::UserBaseSerializer class Users::ListSerializer
include Qwaiter::UserBaseSerializer
# user ids for facebook pictures # user ids for facebook pictures
#self.root = :list #self.root = :list
attributes :state, :needs_help, :needs_payment, :user_requests_closing, attributes :state, :needs_help, :needs_payment, :user_requests_closing,
+2 -1
View File
@@ -1,4 +1,5 @@
class Users::OrderSerializer < Qwaiter::UserBaseSerializer class Users::OrderSerializer
include Qwaiter::UserBaseSerializer
attributes :state #, :list_id, :section_id, :table_id #, :price attributes :state #, :list_id, :section_id, :table_id #, :price
has_many :product_orders, serializer: Users::ProductOrderSerializer has_many :product_orders, serializer: Users::ProductOrderSerializer
@@ -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, 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, :active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on,
:position :position
@@ -1,5 +1,5 @@
# Used for user ember1 class Users::ProductOrderSerializer
class Users::ProductOrderSerializer < Qwaiter::UserBaseSerializer include Qwaiter::UserBaseSerializer
attributes :quantity, :price, :product_name, :product_variant attributes :quantity, :price, :product_name, :product_variant
# belongs_to :product #DO NOT USE THIS, THIS IS NOT NEEDED # belongs_to :product #DO NOT USE THIS, THIS IS NOT NEEDED
has_one :order, serializer: Users::OrderSerializer has_one :order, serializer: Users::OrderSerializer
+2 -1
View File
@@ -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 attributes :name, :price, :description, :image, :code, :position, :visible, :active, :product_category_id
has_many :product_variants, serializer: Users::ProductVariantSerializer has_many :product_variants, serializer: Users::ProductVariantSerializer
@@ -1,3 +1,4 @@
class Users::ProductVariantSerializer < Qwaiter::UserBaseSerializer class Users::ProductVariantSerializer
include Qwaiter::UserBaseSerializer
attributes :name attributes :name
end end
+2 -2
View File
@@ -1,5 +1,5 @@
class Users::SupplierSerializer < Qwaiter::UserBaseSerializer class Users::SupplierSerializer
#self.root = :supplier include Qwaiter::UserBaseSerializer
attributes :open, :name attributes :open, :name
has_many :product_categories, serializer: Users::ProductCategorySerializer has_many :product_categories, serializer: Users::ProductCategorySerializer
end end
+2 -2
View File
@@ -1,5 +1,5 @@
class Users::TableSerializer < Qwaiter::UserBaseSerializer class Users::TableSerializer
#self.root = :table include Qwaiter::UserBaseSerializer
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :supplier_id #, :alist_id attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :supplier_id #, :alist_id
has_one :supplier, serializer: Users::SupplierSerializer has_one :supplier, serializer: Users::SupplierSerializer
+2 -2
View File
@@ -1,5 +1,5 @@
class Users::UserSerializer < Qwaiter::UserBaseSerializer class Users::UserSerializer
#self.root = :user include Qwaiter::UserBaseSerializer
attributes :email, :provider, :uid, :name, :avatar attributes :email, :provider, :uid, :name, :avatar
def name def name
+15 -7
View File
@@ -1,9 +1,10 @@
class Qwaiter::UserBaseSerializer module Qwaiter::UserBaseSerializer
extend ActiveSupport::Concern
include JSONAPI::Serializer include JSONAPI::Serializer
class_attribute :related_link_for included do
class_attribute :related_link_for_attributes
def self.related_link_for(*attributes) attribute :created_at
self.related_link_for = attributes attribute :updated_at
end end
def base_url def base_url
@@ -22,15 +23,22 @@ class Qwaiter::UserBaseSerializer
#alias_method :default_relationship_related_link, :relationship_related_link #alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name) 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 end
def relationship_self_link(attribute_name) def relationship_self_link(attribute_name)
end end
def self.attributes(*attrs) module ClassMethods
def attributes(*attrs)
attrs.each do |attr| attrs.each do |attr|
attribute attr attribute attr
end end
end end
def related_link_for(*attributes)
self.related_link_for_attributes = attributes
end
end
end end