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