JSON api serializers for suppliers
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
@@ -3,3 +3,6 @@ App.DashboardActiveListComponent = Ember.Component.extend
|
|||||||
layoutName: 'dashboard/active-list'
|
layoutName: 'dashboard/active-list'
|
||||||
classNameBindings: ['classIdentifier']
|
classNameBindings: ['classIdentifier']
|
||||||
classIdentifier: Ember.computed 'list.id', -> "list-row-#{@get('list.id')}"
|
classIdentifier: Ember.computed 'list.id', -> "list-row-#{@get('list.id')}"
|
||||||
|
actions:
|
||||||
|
showList: (list)->
|
||||||
|
@get('targetObject').transitionToRoute 'list', list
|
||||||
|
|||||||
@@ -31,6 +31,3 @@ App.IndexController = Ember.Controller.extend
|
|||||||
actions:
|
actions:
|
||||||
toggleDashboardLists: -> @set 'show_lists', !@get('show_lists')
|
toggleDashboardLists: -> @set 'show_lists', !@get('show_lists')
|
||||||
toggleDashboardOrders: ->@set 'show_orders', !@get('show_orders')
|
toggleDashboardOrders: ->@set 'show_orders', !@get('show_orders')
|
||||||
|
|
||||||
showList: (id)->
|
|
||||||
@transitionToRoute 'list', id
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
attr = DS.attr
|
attr = DS.attr
|
||||||
App.Order = DS.Model.extend
|
App.Order = DS.Model.extend
|
||||||
state: attr('string')
|
state: attr('string')
|
||||||
list: DS.belongsTo('list')
|
|
||||||
price: attr('number')
|
price: attr('number')
|
||||||
section: DS.belongsTo('section')
|
|
||||||
section_id: attr('string')
|
list: DS.belongsTo('list', async: false)
|
||||||
product_orders: DS.hasMany('product_order')
|
section: DS.belongsTo('section', async: false)
|
||||||
|
product_orders: DS.hasMany('product_order', async: false)
|
||||||
|
user: DS.belongsTo 'user', async: false
|
||||||
|
|
||||||
active: (-> @get('state') == 'active').property('state')
|
active: (-> @get('state') == 'active').property('state')
|
||||||
delivered: (-> @get('state') == 'delivered').property('state')
|
delivered: (-> @get('state') == 'delivered').property('state')
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ App.User= DS.Model.extend
|
|||||||
avatar: attr('string')
|
avatar: attr('string')
|
||||||
list: DS.belongsTo('list') # in ember scope not many to many (yet)
|
list: DS.belongsTo('list') # in ember scope not many to many (yet)
|
||||||
join_requests: DS.hasMany('join_request')
|
join_requests: DS.hasMany('join_request')
|
||||||
avatar_tag: (->
|
avatar_tag: Ember.computed 'avatar', 'name', ->
|
||||||
return unless avatar = @get('avatar')
|
avatar = @get('avatar') || "#{$asset_path}/supplier/unknown-avatar.png"
|
||||||
name = @get('name')
|
name = @get('name')
|
||||||
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider')}'>".htmlSafe()
|
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider', '')}'>".htmlSafe()
|
||||||
).property('avatar', 'name')
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ App.ApplicationRoute = Ember.Route.extend
|
|||||||
#@sections = @store.findAll 'section'
|
#@sections = @store.findAll 'section'
|
||||||
#Ember.RSVP.all([@product_categories, @sections]).then (results)=>
|
#Ember.RSVP.all([@product_categories, @sections]).then (results)=>
|
||||||
@supplier.reload().then =>
|
@supplier.reload().then =>
|
||||||
@store.findAll('list', state: 'active') #.then (lists) -> lists.invoke('get', 'table')
|
@store.query('list', state: 'active') #.then (lists) -> lists.invoke('get', 'table')
|
||||||
#@lists = @store.peekAll 'list'
|
#@lists = @store.peekAll 'list'
|
||||||
# product_categories = controller.set 'product_categories', @store.peekAll('product_category')
|
# product_categories = controller.set 'product_categories', @store.peekAll('product_category')
|
||||||
#@store.findAll 'order', state: 'active' included in list
|
#@store.findAll 'order', state: 'active' included in list
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
td.user-info.show-for-large-up
|
td.user-info.show-for-large-up
|
||||||
h3= list.users.length
|
|
||||||
each list.users as |user|
|
each list.users as |user|
|
||||||
= user.avatar_tag
|
= user.avatar_tag
|
||||||
td.status-icons
|
td.status-icons
|
||||||
if list.needs_help
|
if list.needs_help
|
||||||
span.icon.needs-help
|
span.icon.needs-help
|
||||||
@@ -12,16 +11,7 @@ td.numeric.table_number= table-number-with-info list=list
|
|||||||
td.section_title: link-to 'section' list.table.section.id: span=list.table.section.title
|
td.section_title: link-to 'section' list.table.section.id: span=list.table.section.title
|
||||||
td.currency.total_list_amount=currency list.total
|
td.currency.total_list_amount=currency list.total
|
||||||
td.actions
|
td.actions
|
||||||
/ if list.needs_help
|
|
||||||
button.mark-list-as-helped-button{ action "markListAsHelped" list.id}
|
|
||||||
span.fa-stack.fa-2x.fa-stack-sized
|
|
||||||
i.fa.fa-bell.fa-stack-small
|
|
||||||
i.fa.fa-ban.revoke
|
|
||||||
/= view "mark-list-helped-button" content=list
|
|
||||||
= button-mark-list-helped content=list
|
= button-mark-list-helped content=list
|
||||||
= button-remove-list-needs-payment content=list
|
= button-remove-list-needs-payment content=list
|
||||||
/= view "remove-list-needs-payment" content=list
|
|
||||||
/= view "close-list-button" content=list
|
|
||||||
= button-close-list content=list
|
= button-close-list content=list
|
||||||
|
button.show-list.button{action "showList" list}: span
|
||||||
button.show-list.button{action "showList" list.id}: span
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
td.user-info.show-for-large-up
|
td.user-info.show-for-large-up= order.user.avatar_tag
|
||||||
each order.list.users as |user|
|
|
||||||
= user.avatar_tag
|
|
||||||
td.status-icons
|
td.status-icons
|
||||||
if order.active
|
if order.active
|
||||||
span.active-order.fa.fa-check.fa-lg
|
span.active-order
|
||||||
td= order.display
|
td= order.display
|
||||||
td.numeric.table_number= table-number-with-info list=order.list
|
td.numeric.table_number= table-number-with-info list=order.list
|
||||||
td.section_title= link-to 'section' order.list.table.section.id: span=order.list.table.section.title
|
td.section_title= link-to 'section' order.list.table.section.id: span=order.list.table.section.title
|
||||||
|
|||||||
@@ -28,8 +28,6 @@
|
|||||||
th.actions
|
th.actions
|
||||||
tbody
|
tbody
|
||||||
each active_lists as |list|
|
each active_lists as |list|
|
||||||
tr
|
|
||||||
td= list.users.length
|
|
||||||
= dashboard-active-list list=list
|
= dashboard-active-list list=list
|
||||||
.page-header
|
.page-header
|
||||||
if active_orders.length
|
if active_orders.length
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
.button-text
|
|
||||||
// Only icons for now
|
|
||||||
display: none
|
|
||||||
.active-orders-table
|
|
||||||
.status-icons
|
|
||||||
span
|
|
||||||
display: none
|
|
||||||
.active
|
|
||||||
.status-icons
|
|
||||||
.active-order
|
|
||||||
display: inline-block
|
|
||||||
.table-number-with-info
|
|
||||||
position: relative
|
|
||||||
.extra-list-info
|
|
||||||
// Facebook profiles
|
|
||||||
display: none
|
|
||||||
$extra-info-width: 220px
|
|
||||||
position: absolute
|
|
||||||
width: $extra-info-width
|
|
||||||
// 7px is padding + border, 5px is extra spacing
|
|
||||||
right: -$extra-info-width - 7px*2 - 5px
|
|
||||||
top: -7px*2
|
|
||||||
padding: 4px
|
|
||||||
border: 3px solid #aaa
|
|
||||||
border-radius: 3px
|
|
||||||
background-color: white
|
|
||||||
text-align: left
|
|
||||||
@@ -5,3 +5,4 @@ $wood: image-url('textures/theme1.jpg')
|
|||||||
$background-brown: #57351f
|
$background-brown: #57351f
|
||||||
$current-color: #fc3
|
$current-color: #fc3
|
||||||
$active-color: #fc3
|
$active-color: #fc3
|
||||||
|
$button-spacing: 8px
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//= require qtip
|
//= require qtip
|
||||||
//= require_directory ../base1-shared
|
|
||||||
//= require pickdate
|
//= require pickdate
|
||||||
//= require fullcalendar
|
//= require fullcalendar
|
||||||
// bourbon for animation
|
// bourbon for animation
|
||||||
@@ -13,6 +12,7 @@
|
|||||||
@import ./qdisplays
|
@import ./qdisplays
|
||||||
@import ./form_actions
|
@import ./form_actions
|
||||||
@import ./components/*
|
@import ./components/*
|
||||||
|
@import ./resources/*
|
||||||
@import ./qsections
|
@import ./qsections
|
||||||
@import ./section_tab_headers
|
@import ./section_tab_headers
|
||||||
@import ./qlists
|
@import ./qlists
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.button-text
|
||||||
|
// Only icons for now
|
||||||
|
display: none
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
//DEPRICATED
|
|
||||||
#product-category-list
|
|
||||||
list-style: none
|
|
||||||
li
|
|
||||||
clear: both
|
|
||||||
margin-bottom: 8px
|
|
||||||
.name
|
|
||||||
padding: 5px 5px
|
|
||||||
#week_days-group
|
|
||||||
display: inline-block
|
|
||||||
.week-day-toggle
|
|
||||||
margin: 0
|
|
||||||
&.active
|
|
||||||
// nothing for now
|
|
||||||
&.inactive
|
|
||||||
opacity: 0.4
|
|
||||||
#full_day-controller
|
|
||||||
line-height: 34px
|
|
||||||
vertical-align: top
|
|
||||||
// height: 34px
|
|
||||||
display: inline-block
|
|
||||||
span
|
|
||||||
@extend .fa
|
|
||||||
@extend .fa-clock-o
|
|
||||||
margin: 0 10px
|
|
||||||
color: #444
|
|
||||||
&.active
|
|
||||||
span
|
|
||||||
color: #f70
|
|
||||||
#sub-day-container
|
|
||||||
display: inline-block
|
|
||||||
vertical-align: top
|
|
||||||
&.hide
|
|
||||||
display: none
|
|
||||||
select
|
|
||||||
width: 70px
|
|
||||||
margin-right: 14px
|
|
||||||
margin-bottom: 0
|
|
||||||
.product-category-visible-never
|
|
||||||
@extend .fa
|
|
||||||
@extend .fa-times
|
|
||||||
.product-category-visible-always
|
|
||||||
@extend .fa
|
|
||||||
@extend .fa-circle-o-notch
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
.products_preview-date
|
|
||||||
.products_preview-time-container
|
|
||||||
float: left
|
|
||||||
input
|
|
||||||
width: 120px
|
|
||||||
.products_preview-hour
|
|
||||||
float: left
|
|
||||||
margin-left: 10px
|
|
||||||
select
|
|
||||||
width: 70px
|
|
||||||
&:after
|
|
||||||
content: " :"
|
|
||||||
.products_preview-minute
|
|
||||||
float: left
|
|
||||||
margin-left: 10px
|
|
||||||
select
|
|
||||||
width: 70px
|
|
||||||
#products-table
|
|
||||||
width: 100%
|
|
||||||
+23
-1
@@ -1,4 +1,9 @@
|
|||||||
$button-spacing: 8px
|
.active-orders-table
|
||||||
|
.status-icons
|
||||||
|
.active-order
|
||||||
|
@extend .fa
|
||||||
|
@extend .fa-check
|
||||||
|
@extend .fa-lg
|
||||||
.dashboard-lists-header, .dashboard-orders-header
|
.dashboard-lists-header, .dashboard-orders-header
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
.icon
|
.icon
|
||||||
@@ -36,3 +41,20 @@ $button-spacing: 8px
|
|||||||
span
|
span
|
||||||
@extend .fa
|
@extend .fa
|
||||||
@extend .fa-list-alt
|
@extend .fa-list-alt
|
||||||
|
|
||||||
|
.table-number-with-info
|
||||||
|
position: relative
|
||||||
|
.extra-list-info
|
||||||
|
// Facebook profiles
|
||||||
|
display: none
|
||||||
|
$extra-info-width: 220px
|
||||||
|
position: absolute
|
||||||
|
width: $extra-info-width
|
||||||
|
// 7px is padding + border, 5px is extra spacing
|
||||||
|
right: -$extra-info-width - 7px*2 - 5px
|
||||||
|
top: -7px*2
|
||||||
|
padding: 4px
|
||||||
|
border: 3px solid #aaa
|
||||||
|
border-radius: 3px
|
||||||
|
background-color: white
|
||||||
|
text-align: left
|
||||||
@@ -19,13 +19,13 @@ module Suppliers
|
|||||||
else
|
else
|
||||||
@lists = List.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25)
|
@lists = List.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25)
|
||||||
end
|
end
|
||||||
@lists.include_relation(:table, :users, orders: {product_orders: :product})
|
@lists.include_relation(:table, :users, orders: {user: nil, product_orders: :product})
|
||||||
|
|
||||||
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.list
|
||||||
|
orders.user
|
||||||
orders.product_orders
|
orders.product_orders
|
||||||
orders.product_orders.order
|
|
||||||
orders.product_orders.product
|
orders.product_orders.product
|
||||||
users
|
users
|
||||||
join_requests
|
join_requests
|
||||||
|
|||||||
@@ -5,8 +5,16 @@ module Suppliers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
[current_supplier].include_relations(sections: :tables, product_categories: {products: :product_variants})
|
current_supplier.sections.include_relations(:tables, :section_areas, :section_elements, product_categories: {products: :product_variants})
|
||||||
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer) #.new(current_supplier).as_json
|
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer, include: %w[
|
||||||
|
sections
|
||||||
|
sections.tables
|
||||||
|
sections.section_areas
|
||||||
|
sections.section_elements
|
||||||
|
product_categories
|
||||||
|
product_categories.products
|
||||||
|
product_categories.products.product_variants
|
||||||
|
]) #.new(current_supplier).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|||||||
+1
-1
@@ -81,7 +81,7 @@ class User
|
|||||||
|
|
||||||
# This is the user name as it is shown to the supplier
|
# This is the user name as it is shown to the supplier
|
||||||
def supplier_name
|
def supplier_name
|
||||||
auth_data['info']['name'] rescue I18n.t('user.unknown_supplier_name')
|
auth_data['info']['name'] rescue I18n.t('supplier.unknown_user_name')
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is the user name as it is shown to other users
|
# This is the user name as it is shown to other users
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
class ProductVariantSerializer < Qwaiter::Serializer
|
|
||||||
root 'product_variant'
|
|
||||||
attributes :name
|
|
||||||
end
|
|
||||||
@@ -4,5 +4,6 @@ class Suppliers::OrderSerializer
|
|||||||
|
|
||||||
has_one :list, serializer: Suppliers::ListSerializer
|
has_one :list, serializer: Suppliers::ListSerializer
|
||||||
has_many :product_orders, serializer: Suppliers::ProductOrderSerializer
|
has_many :product_orders, serializer: Suppliers::ProductOrderSerializer
|
||||||
|
has_one :user, serializer: Suppliers::UserSerializer
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Suppliers::ProductSerializer
|
class Suppliers::ProductSerializer
|
||||||
include Qwaiter::SupplierBaseSerializer
|
include Qwaiter::SupplierBaseSerializer
|
||||||
attributes :name, :price, :description, :code, :position, :visible, :active, :product_category_id
|
attributes :name, :price, :description, :code, :position, :visible, :active
|
||||||
attribute :image do
|
attribute :image do
|
||||||
if object.image.present?
|
if object.image.present?
|
||||||
{small: object.image.url(:small)}
|
{small: object.image.url(:small)}
|
||||||
@@ -10,4 +10,5 @@ class Suppliers::ProductSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
has_many :product_variants, serializer: Suppliers::ProductVariantSerializer
|
has_many :product_variants, serializer: Suppliers::ProductVariantSerializer
|
||||||
|
has_one :product_category, serializer: Suppliers::ProductSerializer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class Suppliers::ProductVariantSerializer
|
||||||
|
include Qwaiter::SupplierBaseSerializer
|
||||||
|
attributes :name
|
||||||
|
end
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
class Suppliers::SectionElementSerializer < Qwaiter::Serializer
|
class Suppliers::SectionElementSerializer
|
||||||
|
include Qwaiter::SupplierBaseSerializer
|
||||||
attributes :name, :box_width, :box_height, :dpm, :svg, :position_x, :position_y, :rotation
|
attributes :name, :box_width, :box_height, :dpm, :svg, :position_x, :position_y, :rotation
|
||||||
has_one :section, serializer: Suppliers::SectionSerializer
|
has_one :section, serializer: Suppliers::SectionSerializer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
class Suppliers::SectionSerializer
|
class Suppliers::SectionSerializer
|
||||||
include Qwaiter::SupplierBaseSerializer
|
include Qwaiter::SupplierBaseSerializer
|
||||||
attributes :title, :path, :width, :height
|
attributes :title, :path, :width, :height
|
||||||
|
has_many :tables, serializer: Suppliers::TableSerializer
|
||||||
|
has_many :section_areas, serializer: Suppliers::SectionAreaSerializer
|
||||||
|
has_many :section_elements, serializer: Suppliers::SectionElementSerializer
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#.merge(ActiveModel::ArraySerializer.new(list.supplier.product_categories, each_serializer: ProductCategorySerializer, root: :product_categories).as_json)
|
#.merge(ActiveModel::ArraySerializer.new(list.supplier.product_categories, each_serializer: ProductCategorySerializer, root: :product_categories).as_json)
|
||||||
#.merge(ActiveModel::ArraySerializer.new(list.orders, each_serializer: OrderSerializer, root: :orders).as_json)
|
#.merge(ActiveModel::ArraySerializer.new(list.orders, each_serializer: OrderSerializer, root: :orders).as_json)
|
||||||
#end
|
#end
|
||||||
|
=begin
|
||||||
class UserExtendedListSerializer < Qwaiter::Serializer
|
class UserExtendedListSerializer < Qwaiter::Serializer
|
||||||
# user ids for facebook pictures
|
# user ids for facebook pictures
|
||||||
self.root = :list
|
self.root = :list
|
||||||
@@ -30,3 +31,4 @@ class UserExtendedListSerializer < Qwaiter::Serializer
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|||||||
@@ -248,3 +248,4 @@ en:
|
|||||||
link: My schedule
|
link: My schedule
|
||||||
schedule:
|
schedule:
|
||||||
title: Schedule for %{name}
|
title: Schedule for %{name}
|
||||||
|
unknown_user_name: "?"
|
||||||
|
|||||||
@@ -251,3 +251,4 @@ nl:
|
|||||||
link: Mijn schema
|
link: Mijn schema
|
||||||
schedule:
|
schedule:
|
||||||
title: Schema voor %{name}
|
title: Schema voor %{name}
|
||||||
|
unknown_user_name: "?"
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Suppliers::OrderSerializer, type: :serializer do
|
||||||
|
it "works" do
|
||||||
|
user = create :user
|
||||||
|
order = create :order, user: user
|
||||||
|
order.product_orders # preload empty
|
||||||
|
result = nil
|
||||||
|
expect{ result = JSONAPI::Serializer.serialize order, serializer: described_class, include: %w[user user.order] }.not_to perform_any_queries
|
||||||
|
result[:included].size.should eq 4
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user