mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Convert oc.rabl to oc serializer and use it in both haml file and controller
This commit is contained in:
@@ -27,12 +27,12 @@ class ShopController < BaseController
|
||||
if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id])
|
||||
current_order(true).set_order_cycle! oc
|
||||
@current_order_cycle = oc
|
||||
render partial: "json/order_cycle"
|
||||
render json: @current_order_cycle, serializer: Api::OrderCycleSerializer
|
||||
else
|
||||
render status: :not_found, json: ""
|
||||
end
|
||||
else
|
||||
render partial: "json/order_cycle"
|
||||
render json: current_order_cycle, serializer: Api::OrderCycleSerializer
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -61,6 +61,10 @@ module InjectionHelper
|
||||
inject_json_ams "currentOrder", current_order, Api::CurrentOrderSerializer, current_distributor: current_distributor, current_order_cycle: current_order_cycle
|
||||
end
|
||||
|
||||
def inject_current_order_cycle
|
||||
inject_json_ams "orderCycleData", current_order_cycle, Api::OrderCycleSerializer
|
||||
end
|
||||
|
||||
def inject_available_shipping_methods
|
||||
inject_json_ams "shippingMethods", available_shipping_methods,
|
||||
Api::ShippingMethodSerializer, current_order: current_order
|
||||
|
||||
11
app/serializers/api/order_cycle_serializer.rb
Normal file
11
app/serializers/api/order_cycle_serializer.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Api::OrderCycleSerializer < ActiveModel::Serializer
|
||||
attributes :order_cycle_id, :orders_close_at
|
||||
|
||||
def order_cycle_id
|
||||
object.id
|
||||
end
|
||||
|
||||
def orders_close_at
|
||||
object.orders_close_at.to_s
|
||||
end
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
object current_order_cycle
|
||||
attributes :orders_close_at
|
||||
attribute id: :order_cycle_id
|
||||
@@ -1,6 +1,5 @@
|
||||
- content_for :scripts do
|
||||
:javascript
|
||||
angular.module('Darkswarm').value('orderCycleData', #{render "json/order_cycle"})
|
||||
- content_for :injection_data do
|
||||
= inject_current_order_cycle
|
||||
|
||||
%ordercycle{"ng-controller" => "OrderCycleCtrl"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user