switch to JSONAPI for suppliers
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
App.THelper = Ember.Helper.helper (params, options)->
|
App.THelper = Ember.Helper.helper (params, options)->
|
||||||
path = params[0]
|
path = params[0]
|
||||||
toptions = options
|
toptions = options
|
||||||
if params.length > 1 and typeof(params[1].serialize) is 'function'
|
if params.length > 1 and typeof(params[1].toJSON) is 'function'
|
||||||
$.extend toptions, params[1].serialize()
|
$.extend toptions, params[1].toJSON()
|
||||||
text = t(path, toptions)
|
text = t(path, toptions)
|
||||||
tag = if options.bare then text else "<span data-t='#{path}' class='translation' data-t-attributes='#{JSON.stringify(toptions)}'>#{text}</span>"
|
tag = if options.bare then text else "<span data-t='#{path}' class='translation' data-t-attributes='#{JSON.stringify(toptions)}'>#{text}</span>"
|
||||||
tag.htmlSafe()
|
tag.htmlSafe()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
# return translated title_path if directly set by controller
|
# return translated title_path if directly set by controller
|
||||||
translation_params = {}
|
translation_params = {}
|
||||||
if model = @get('model')
|
if model = @get('model')
|
||||||
translation_params = model.serialize() if model.serialize
|
translation_params = model.toJSON() if model.toJSON
|
||||||
|
|
||||||
# return translated title_path if directly set by options
|
# return translated title_path if directly set by options
|
||||||
# return translated title_path if directly set by controller
|
# return translated title_path if directly set by controller
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
#return tspan(@title_path, translation_params).htmlSafe() if @title_path
|
#return tspan(@title_path, translation_params).htmlSafe() if @title_path
|
||||||
# infer title path based on controller name App.modals.AddSectionController => add_section
|
# infer title path based on controller name App.modals.AddSectionController => add_section
|
||||||
underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()`
|
underscored = `this.constructor.toString().substr(11).replace(/Controller$/, '').underscore()`
|
||||||
|
#underscored = @constructor.toString().replace(/[a-zA-Z_-]+\@controller:modals\//, '').replace(/:$/, '').underscore() # ember cli
|
||||||
# find translated title or humanize the controller name
|
# find translated title or humanize the controller name
|
||||||
if convention_translation = ttry("modal.#{underscored}.title", translation_params)
|
if convention_translation = ttry("modal.#{underscored}.title", translation_params)
|
||||||
tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe()
|
tspan(@get("modal.#{underscored}.title"), translation_params).htmlSafe()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ App.EmployeesRoute = Ember.Route.extend
|
|||||||
ac = @controllerFor('application')
|
ac = @controllerFor('application')
|
||||||
if ac.get('employee.id') isnt employee.id
|
if ac.get('employee.id') isnt employee.id
|
||||||
ac.modal 'confirm',
|
ac.modal 'confirm',
|
||||||
title: t('employee.destroy.modal.title', employee.serialize())
|
title: t('employee.destroy.modal.title', employee.toJSON())
|
||||||
ok: -> employee.destroyRecord()
|
ok: -> employee.destroyRecord()
|
||||||
else
|
else
|
||||||
ac.modal 'alert',
|
ac.modal 'alert',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module Employees
|
|||||||
class EmployeeShiftsController < Employees::ApplicationController
|
class EmployeeShiftsController < Employees::ApplicationController
|
||||||
def index
|
def index
|
||||||
@employee_shifts = EmployeeShift.for_employee(current_employee).include_relation(:supplier)
|
@employee_shifts = EmployeeShift.for_employee(current_employee).include_relation(:supplier)
|
||||||
render json: @employee_shifts, each_serializer: Employees::EmployeeShiftSerializer
|
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Employees::EmployeeShiftSerializer, is_collection: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ module Employees
|
|||||||
class SuppliersController < Employees::ApplicationController
|
class SuppliersController < Employees::ApplicationController
|
||||||
def index
|
def index
|
||||||
@suppliers = current_employee.suppliers
|
@suppliers = current_employee.suppliers
|
||||||
render json: @suppliers, each_serializer: Employees::SupplierSerializer
|
render json: JSONAPI::Serializer.serialize(@suppliers, serializer: Employees::SupplierSerializer, is_collection: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ module Suppliers
|
|||||||
|
|
||||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
|
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
|
||||||
orders
|
orders
|
||||||
|
orders.list
|
||||||
orders.product_orders
|
orders.product_orders
|
||||||
orders.product_orders.order
|
orders.product_orders.order
|
||||||
orders.product_orders.product
|
orders.product_orders.product
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Employees::EmployeeShiftSerializer < Qwaiter::Serializer
|
class Employees::EmployeeShiftSerializer
|
||||||
self.root = :employee_shift
|
include Qwaiter::EmployeeBaseSerializer
|
||||||
attributes :start_from, :end_on, :employee_id, :description
|
attributes :start_from, :end_on, :description
|
||||||
has_one :supplier
|
has_one :supplier
|
||||||
|
has_one :employee
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Employees::SupplierSerializer < Qwaiter::Serializer
|
class Employees::SupplierSerializer
|
||||||
self.root = :supplier
|
include Qwaiter::EmployeeBaseSerializer
|
||||||
attributes :open, :name, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
attributes :open, :name, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||||
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ module Qwaiter
|
|||||||
autoload :Serializer
|
autoload :Serializer
|
||||||
autoload :UserBaseSerializer
|
autoload :UserBaseSerializer
|
||||||
autoload :SupplierBaseSerializer
|
autoload :SupplierBaseSerializer
|
||||||
|
autoload :EmployeeBaseSerializer
|
||||||
autoload :Counter
|
autoload :Counter
|
||||||
autoload :Broadcaster
|
autoload :Broadcaster
|
||||||
autoload :Couchbase
|
autoload :Couchbase
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
module Qwaiter::EmployeeBaseSerializer
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
include JSONAPI::Serializer
|
||||||
|
included do
|
||||||
|
class_attribute :related_link_for_attributes
|
||||||
|
attribute :created_at
|
||||||
|
attribute :updated_at
|
||||||
|
end
|
||||||
|
|
||||||
|
def base_url
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def format_name(attribute_name)
|
||||||
|
#attribute_name.to_s.dasherize
|
||||||
|
attribute_name.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def unformat_name(attribute_name)
|
||||||
|
#attribute_name.to_s.underscore
|
||||||
|
attribute_name.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
#alias_method :default_relationship_related_link, :relationship_related_link
|
||||||
|
def relationship_related_link(attribute_name)
|
||||||
|
super if related_link_for_attributes.include?(attribute_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def relationship_self_link(attribute_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user