mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-20 04:59:16 +00:00
Spiking AMS implementation of data
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -28,6 +28,7 @@ gem 'andand'
|
||||
gem 'truncate_html'
|
||||
gem 'representative_view'
|
||||
gem 'rabl'
|
||||
gem "active_model_serializers"
|
||||
gem 'oj'
|
||||
gem 'deface', :github => 'spree/deface', :ref => '1110a13'
|
||||
gem 'paperclip'
|
||||
|
||||
@@ -118,6 +118,8 @@ GEM
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
active_link_to (1.0.0)
|
||||
active_model_serializers (0.8.1)
|
||||
activemodel (>= 3.0)
|
||||
active_utils (2.0.2)
|
||||
activesupport (>= 2.3.11)
|
||||
i18n
|
||||
@@ -492,6 +494,7 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
active_model_serializers
|
||||
andand
|
||||
angular-rails-templates
|
||||
angularjs-rails
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
module SharedHelper
|
||||
def inject_enterprises
|
||||
inject_json "enterprises" , "enterprises"
|
||||
inject_json_ams "enterprises", Enterprise.visible
|
||||
end
|
||||
|
||||
def inject_json(name, partial, opts = {})
|
||||
render partial: "json/injection", locals: {name: name, partial: partial}.merge(opts)
|
||||
end
|
||||
|
||||
def inject_json_ams(name, data)
|
||||
render partial: "json/injection_ams", locals: {name: name, data: data}
|
||||
end
|
||||
|
||||
def distributor_link_class(distributor)
|
||||
cart = current_order(true)
|
||||
@active_distributors ||= Enterprise.distributors_with_active_order_cycles
|
||||
|
||||
7
app/serializers/enterprise_serializer.rb
Normal file
7
app/serializers/enterprise_serializer.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class EnterpriseSerializer < ActiveModel::Serializer
|
||||
#attributes :name, :id, :description, :latitude, :longitude,
|
||||
#:long_description, :website, :instagram, :linkedin, :twitter,
|
||||
#:facebook, :is_primary_producer, :is_distributor, :phone
|
||||
|
||||
has_many :distributed_taxons, root: :taxons, serializer: Spree::DistributedTaxonSerializer
|
||||
end
|
||||
3
app/serializers/spree/address_serializer.rb
Normal file
3
app/serializers/spree/address_serializer.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Spree::AddressSerializer < ActiveModel::Serializer
|
||||
attributes :id
|
||||
end
|
||||
3
app/serializers/spree/distributed_taxon_serializer.rb
Normal file
3
app/serializers/spree/distributed_taxon_serializer.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Spree::DistributedTaxonSerializer < ActiveModel::Serializer
|
||||
attributes :id, :name, :permalink
|
||||
end
|
||||
2
app/views/json/_injection_ams.html.haml
Normal file
2
app/views/json/_injection_ams.html.haml
Normal file
@@ -0,0 +1,2 @@
|
||||
:javascript
|
||||
angular.module('Darkswarm').value("#{name.to_s}", #{ActiveModel::ArraySerializer.new(data, each_serializer: EnterpriseSerializer).to_json}"})
|
||||
2
config/initializers/serializers.rb
Normal file
2
config/initializers/serializers.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
ActiveModel::ArraySerializer.root = false
|
||||
ActiveModel::Serializer.root = false
|
||||
Reference in New Issue
Block a user