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'
|
||||
classNameBindings: ['classIdentifier']
|
||||
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:
|
||||
toggleDashboardLists: -> @set 'show_lists', !@get('show_lists')
|
||||
toggleDashboardOrders: ->@set 'show_orders', !@get('show_orders')
|
||||
|
||||
showList: (id)->
|
||||
@transitionToRoute 'list', id
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
attr = DS.attr
|
||||
App.Order = DS.Model.extend
|
||||
state: attr('string')
|
||||
list: DS.belongsTo('list')
|
||||
price: attr('number')
|
||||
section: DS.belongsTo('section')
|
||||
section_id: attr('string')
|
||||
product_orders: DS.hasMany('product_order')
|
||||
|
||||
list: DS.belongsTo('list', async: false)
|
||||
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')
|
||||
delivered: (-> @get('state') == 'delivered').property('state')
|
||||
|
||||
@@ -6,8 +6,7 @@ App.User= DS.Model.extend
|
||||
avatar: attr('string')
|
||||
list: DS.belongsTo('list') # in ember scope not many to many (yet)
|
||||
join_requests: DS.hasMany('join_request')
|
||||
avatar_tag: (->
|
||||
return unless avatar = @get('avatar')
|
||||
avatar_tag: Ember.computed 'avatar', 'name', ->
|
||||
avatar = @get('avatar') || "#{$asset_path}/supplier/unknown-avatar.png"
|
||||
name = @get('name')
|
||||
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider')}'>".htmlSafe()
|
||||
).property('avatar', 'name')
|
||||
"<img src='#{avatar}' alt='#{name}' title='#{name}' class='user-avatar-image #{@get('provider', '')}'>".htmlSafe()
|
||||
|
||||
@@ -17,7 +17,7 @@ App.ApplicationRoute = Ember.Route.extend
|
||||
#@sections = @store.findAll 'section'
|
||||
#Ember.RSVP.all([@product_categories, @sections]).then (results)=>
|
||||
@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'
|
||||
# product_categories = controller.set 'product_categories', @store.peekAll('product_category')
|
||||
#@store.findAll 'order', state: 'active' included in list
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
td.user-info.show-for-large-up
|
||||
h3= list.users.length
|
||||
each list.users as |user|
|
||||
= user.avatar_tag
|
||||
= user.avatar_tag
|
||||
td.status-icons
|
||||
if list.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.currency.total_list_amount=currency list.total
|
||||
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-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.show-list.button{action "showList" list.id}: span
|
||||
button.show-list.button{action "showList" list}: span
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
td.user-info.show-for-large-up
|
||||
each order.list.users as |user|
|
||||
= user.avatar_tag
|
||||
td.user-info.show-for-large-up= order.user.avatar_tag
|
||||
td.status-icons
|
||||
if order.active
|
||||
span.active-order.fa.fa-check.fa-lg
|
||||
span.active-order
|
||||
td= order.display
|
||||
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
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
th.actions
|
||||
tbody
|
||||
each active_lists as |list|
|
||||
tr
|
||||
td= list.users.length
|
||||
= dashboard-active-list list=list
|
||||
.page-header
|
||||
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
|
||||
$current-color: #fc3
|
||||
$active-color: #fc3
|
||||
$button-spacing: 8px
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//= require qtip
|
||||
//= require_directory ../base1-shared
|
||||
//= require pickdate
|
||||
//= require fullcalendar
|
||||
// bourbon for animation
|
||||
@@ -13,6 +12,7 @@
|
||||
@import ./qdisplays
|
||||
@import ./form_actions
|
||||
@import ./components/*
|
||||
@import ./resources/*
|
||||
@import ./qsections
|
||||
@import ./section_tab_headers
|
||||
@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
|
||||
cursor: pointer
|
||||
.icon
|
||||
@@ -36,3 +41,20 @@ $button-spacing: 8px
|
||||
span
|
||||
@extend .fa
|
||||
@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
|
||||
@lists = List.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25)
|
||||
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[
|
||||
orders
|
||||
orders.list
|
||||
orders.user
|
||||
orders.product_orders
|
||||
orders.product_orders.order
|
||||
orders.product_orders.product
|
||||
users
|
||||
join_requests
|
||||
|
||||
@@ -5,8 +5,16 @@ module Suppliers
|
||||
end
|
||||
|
||||
def show
|
||||
[current_supplier].include_relations(sections: :tables, product_categories: {products: :product_variants})
|
||||
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer) #.new(current_supplier).as_json
|
||||
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, 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
|
||||
|
||||
def update
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ class User
|
||||
|
||||
# This is the user name as it is shown to the supplier
|
||||
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
|
||||
|
||||
# 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_many :product_orders, serializer: Suppliers::ProductOrderSerializer
|
||||
has_one :user, serializer: Suppliers::UserSerializer
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Suppliers::ProductSerializer
|
||||
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
|
||||
if object.image.present?
|
||||
{small: object.image.url(:small)}
|
||||
@@ -10,4 +10,5 @@ class Suppliers::ProductSerializer
|
||||
end
|
||||
|
||||
has_many :product_variants, serializer: Suppliers::ProductVariantSerializer
|
||||
has_one :product_category, serializer: Suppliers::ProductSerializer
|
||||
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
|
||||
has_one :section, serializer: Suppliers::SectionSerializer
|
||||
end
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class Suppliers::SectionSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
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
|
||||
|
||||
@@ -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.orders, each_serializer: OrderSerializer, root: :orders).as_json)
|
||||
#end
|
||||
=begin
|
||||
class UserExtendedListSerializer < Qwaiter::Serializer
|
||||
# user ids for facebook pictures
|
||||
self.root = :list
|
||||
@@ -30,3 +31,4 @@ class UserExtendedListSerializer < Qwaiter::Serializer
|
||||
true
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
@@ -248,3 +248,4 @@ en:
|
||||
link: My schedule
|
||||
schedule:
|
||||
title: Schedule for %{name}
|
||||
unknown_user_name: "?"
|
||||
|
||||
@@ -251,3 +251,4 @@ nl:
|
||||
link: Mijn schema
|
||||
schedule:
|
||||
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