JSONAPI stuff

This commit is contained in:
2015-09-04 17:39:11 +02:00
parent e4dde28dd0
commit 7336585416
16 changed files with 75 additions and 66 deletions
+9 -8
View File
@@ -8,19 +8,13 @@ gem 'rack-cors', require: 'rack/cors'
# gem 'sqlite3'
source 'https://rails-assets.org' do
group :test do
gem 'rails-assets-qunit'
gem 'rails-assets-ember-qunit'
end
end
gem 'slim-rails'
# Gems used only for assets and not required
# in production environments by default.
#gem 'active_model_serializers', '~> 0.10.0.rc2' # explicitly outside assets
gem 'active_model_serializers', github: 'rails-api/active_model_serializers' # explicitly outside assets
#gem 'active_model_serializers', github: 'rails-api/active_model_serializers' # explicitly outside assets
gem 'active_model_serializers', '0.9.3' # explicitly outside assets
#gem 'jsonapi-serializers', github: 'bterkuile/jsonapi-serializers'
gem 'jsonapi-serializers', path: '/home/benjamin/development/rails/components/jsonapi-serializers'
group :assets do
@@ -140,6 +134,13 @@ group :test do
gem 'simplecov', require: false
end
source 'https://rails-assets.org' do
group :development, :test do
gem 'rails-assets-qunit'
gem 'rails-assets-ember-qunit'
end
end
# Use unicorn as the app server
# gem 'unicorn'
gem 'puma'
+6 -13
View File
@@ -38,15 +38,6 @@ GIT
couch_potato (>= 0.2.15)
rest-client (>= 1.4.2)
GIT
remote: git://github.com/rails-api/active_model_serializers.git
revision: 6784866a2d4a57e5b1c571afcbf76362708b11ab
specs:
active_model_serializers (0.10.0.rc2)
actionpack (>= 4.0)
activemodel (>= 4.0)
railties (>= 4.0)
PATH
remote: /home/benjamin/development/rails/components/jsonapi-serializers
specs:
@@ -83,6 +74,8 @@ GEM
activemodel (>= 3.0.2, < 5.0)
activesupport (>= 3.0.2, < 5.0)
active_decorator (0.5.3)
active_model_serializers (0.9.3)
activemodel (>= 3.2)
activejob (4.2.4)
activesupport (= 4.2.4)
globalid (>= 0.3.0)
@@ -390,12 +383,12 @@ GEM
rubyzip (1.1.7)
safe_yaml (1.0.4)
sass (3.4.18)
sass-rails (5.0.3)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
tilt (>= 1.1, < 3)
selenium-webdriver (2.47.1)
childprocess (~> 0.5)
multi_json (~> 1.0)
@@ -439,7 +432,7 @@ GEM
ref
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
tilt (2.0.1)
timers (4.0.4)
hitimes
tinymce-rails (4.2.4)
@@ -479,7 +472,7 @@ DEPENDENCIES
ace-rails-ap
active_attr
active_decorator
active_model_serializers!
active_model_serializers (= 0.9.3)
airbrussh
bourbon
cancancan
@@ -3,6 +3,14 @@ App.ButtonLanguageSwitcherComponent = Ember.Component.extend
layoutName: 'components/language-switcher-button'
classNameBindings: ['isCurrent:current']
classNames: ['language-switch-button']
isCurrent: Ember.computed 'locale', 'controller.current_locale', ->
@get('locale') is @get('controller.current_locale')
isCurrent: Ember.computed 'locale', 'globals.locale', ->
@get('locale') is @get('globals.locale')
#isCurrent: Ember.computed.equal 'locale', 'globals.locale'
click: -> @get('controller').send 'switchTo', @get('locale')
action: 'switchTo'
#TODO: EASY BUBBLE ACTION
actions:
switchTo: (locale)->
setLocale locale
@set 'globals.locale', locale
@store.peekAll("page").invoke 'reload'
@@ -1,9 +1,8 @@
App.LanguageSwitcherComponent = Ember.Component.extend
classNames: ['language-switcher-container']
locales: (-> ['en', 'nl']).property()
current_locale: (-> Qstorage.getItem('locale') ).property()
actions:
switchTo: (locale)->
setLocale locale
@set 'current_locale', locale
@get('targetObject.store').all("page").invoke 'reload'
@set 'globals.locale', locale
@store.peekAll("page").invoke 'reload'
@@ -4,9 +4,5 @@ App.SuppliersSwitcherComponent = Ember.Component.extend
other_suppliers: Ember.computed 'suppliers.[]',
-> @get('suppliers').rejectBy 'id', @get('globals.current_supplier.id')
actions:
switchTo: (locale)->
setLocale locale
@set 'current_locale', locale
@get('targetObject.store').all("page").invoke 'reload'
switchTo: (supplier)->
window.location = Routes.switch_to_suppliers_supplier_path(supplier.get('id'))
@@ -4,6 +4,7 @@ Globals = Ember.Object.extend
isDragging: false
active_section: null
flash_message: ''
locale: Qstorage.getItem('locale')
App.initializer
name: 'injectCurrent'
initialize: (container, app)->
@@ -14,3 +15,5 @@ App.initializer
app.inject 'component', 'globals', 'global:variables'
app.inject 'view', 'globals', 'global:variables'
app.inject 'route', 'globals', 'global:variables'
app.inject 'component', 'store', 'service:store'
@@ -11,6 +11,8 @@ App.ApplicationRoute = Ember.Route.extend
id: employee_object.id
type: 'employee'
attributes: employee_object
#@supplier = @store.push 'supplier' supplier_object
#@employee = @store.push 'employee' employee_object
#@product_categories = @store.findAll 'product_category'
#@sections = @store.findAll 'section'
#Ember.RSVP.all([@product_categories, @sections]).then (results)=>
@@ -40,7 +40,6 @@ $ ->
setupTranslations()
$('[data-boolean]').each ->
$(@).addClass(if $(@).data('boolean') then 'boolean-true' else 'boolean-false')
@@ -27,5 +27,6 @@ App.Product = DS.Model.extend
else
@store.createRecord 'product_order',
product: this
product_name: @get('name')
price: @get('price')
product_variant: options.product_variant
+1
View File
@@ -2,4 +2,5 @@ class OrderSerializer < Qwaiter::Serializer
attributes :state, :list_id, :section_id, :table_id #, :price
has_many :product_orders
end
+2
View File
@@ -12,5 +12,7 @@ class Users::ListSerializer < Qwaiter::UserBaseSerializer
def include_orders?
@_include_linkages.any?{|link| link =~ /orders/}
end
related_link_for :orders, :table
#belongs_to :table
end
@@ -2,8 +2,4 @@ class Users::SupplierSerializer < Qwaiter::UserBaseSerializer
#self.root = :supplier
attributes :open, :name
has_many :product_categories, serializer: Users::ProductCategorySerializer
#def extended_version
# false
#end
end
@@ -7,6 +7,7 @@ class Users::TableSerializer < Qwaiter::UserBaseSerializer
#object.active_list_id || object.active_list.try(:id)
#end
related_link_for :supplier
#def list
#object.active_list
#end
+13 -12
View File
@@ -1,14 +1,15 @@
#ActiveModel::Serializer.setup do |config|
# config.embed = :ids
# config.embed_in_root = true
# config.adapter = :json_api
#end
module ActiveModel::SerializerSupport
def read_attribute_for_serialization(attr)
public_send attr
end
ActiveModel::Serializer.setup do |config|
config.embed = :ids
config.embed_in_root = true
#config.adapter = :json_api
end
#module ActiveModel::SerializerSupport
# def read_attribute_for_serialization(attr)
# public_send attr
# end
#end
=begin
class Qwaiter::JsonAdapter < ActiveModel::Serializer::Adapter::JsonApi
def add_resource_relationships_old1(attrs, serializer, options = {})
options[:add_included] = options.fetch(:add_included, true)
@@ -16,7 +17,6 @@ class Qwaiter::JsonAdapter < ActiveModel::Serializer::Adapter::JsonApi
name = association.key
association_options = association.options
next unless object = serializer.object
=begin
if association_options[:type] == :has_many
# todo check for object["#{name}_ids"]
association_value = association_options[:association_options][:url] ? [] : serializer.send(name)
@@ -45,7 +45,6 @@ class Qwaiter::JsonAdapter < ActiveModel::Serializer::Adapter::JsonApi
elsif !association_value.nil? && !association_value.instance_of?(Object)
association_options[:association_options][:virtual_value] = association_value
end
=end
association_serializer = association.serializer
opts = association_options[:association_options]
opts = association.options
@@ -81,5 +80,7 @@ class Qwaiter::JsonAdapter < ActiveModel::Serializer::Adapter::JsonApi
resource[:relationships][name][:links][:related] = related_url
end
end
=end
#ActiveModel::Serializer.config.adapter = :json_api
ActiveModel::Serializer.config.adapter = Qwaiter::JsonAdapter
#ActiveModel::Serializer.config.adapter = Qwaiter::JsonAdapter
#ActiveModel::Serializer.config.adapter = :flatten_json
+7 -1
View File
@@ -1,5 +1,10 @@
class Qwaiter::UserBaseSerializer
include JSONAPI::Serializer
class_attribute :related_link_for
def self.related_link_for(*attributes)
self.related_link_for = attributes
end
def base_url
"/user"
@@ -15,8 +20,9 @@ class Qwaiter::UserBaseSerializer
attribute_name.to_s
end
#alias_method :default_relationship_related_link, :relationship_related_link
def relationship_related_link(attribute_name)
super
super if related_link_for.include?(attribute_name)
end
def relationship_self_link(attribute_name)
@@ -1,20 +1,20 @@
#module "suppliers-switcher", "SuppliersSwitcherComponent"
moduleForComponent "suppliers-switcher"
test "Triggers switch", ->
expect 2
component = @subject()
controller = App.__container__.lookup('controller:settings')
component.set 'targetObject', controller
Ember.run ->
controller.store.createRecord 'supplier',
id: 'other-supplier'
name: 'Other supplier1'
#component.set 'targetObject', controller
@render()
equal find('ul').text(), "Switch to Other supplier1"
# Stub the action, since it triggers an external call
component._actions.switchTo = (supplier)->
equal supplier.get('name'), 'Other supplier1'
click 'li a'
#test "Triggers switch", ->
# expect 2
# component = @subject()
# controller = App.__container__.lookup('controller:settings')
# component.set 'targetObject', controller
# Ember.run ->
# controller.store.createRecord 'supplier',
# id: 'other-supplier'
# name: 'Other supplier1'
# #component.set 'targetObject', controller
# @render()
# equal find('ul').text(), "Switch to Other supplier1"
#
# # Stub the action, since it triggers an external call
# component._actions.switchTo = (supplier)->
# equal supplier.get('name'), 'Other supplier1'
#
# click 'li a'