mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Prepare angular controller and serialized data
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, $compile, $attrs, shops, orderCycles) ->
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, $compile, $attrs, Orders) ->
|
||||
$scope.$compile = $compile
|
||||
$scope.shops = shops
|
||||
$scope.orderCycles = orderCycles
|
||||
@@ -6,6 +6,10 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $compile, $attr
|
||||
$scope.distributor_id = parseInt($attrs.ofnDistributorId)
|
||||
$scope.order_cycle_id = parseInt($attrs.ofnOrderCycleId)
|
||||
|
||||
$scope.orders = Orders.all
|
||||
|
||||
Orders.index(per_page: 15)
|
||||
|
||||
$scope.validOrderCycle = (oc) ->
|
||||
$scope.orderCycleHasDistributor oc, parseInt($scope.distributor_id)
|
||||
|
||||
|
||||
@@ -100,18 +100,17 @@ Spree::Admin::OrdersController.class_eval do
|
||||
private
|
||||
|
||||
def orders
|
||||
if json_request?
|
||||
@search = OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(params[:q])
|
||||
@search.result.reorder('id ASC')
|
||||
else
|
||||
@search = Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
|
||||
@search = if json_request?
|
||||
OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(params[:q])
|
||||
else
|
||||
Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
|
||||
end
|
||||
|
||||
# Replaced this search to filter orders to only show those distributed by current user (or all for admin user)
|
||||
@search.result.includes([:user, :shipments, :payments]).
|
||||
distributed_by_user(spree_current_user).
|
||||
page(params[:page]).
|
||||
per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
end
|
||||
# Replaced this search to filter orders to only show those distributed by current user (or all for admin user)
|
||||
@search.result.includes([:user, :shipments, :payments]).
|
||||
distributed_by_user(spree_current_user).
|
||||
page(params[:page]).
|
||||
per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
end
|
||||
|
||||
def require_distributor_abn
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Api::Admin::OrderSerializer < ActiveModel::Serializer
|
||||
attributes :id, :number, :full_name, :email, :phone, :completed_at
|
||||
attributes :id, :number, :full_name, :email, :phone, :completed_at, :payment_total
|
||||
|
||||
has_one :distributor, serializer: Api::Admin::IdSerializer
|
||||
has_one :order_cycle, serializer: Api::Admin::IdSerializer
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
- content_for :page_title do
|
||||
= t(:listing_orders)
|
||||
|
||||
- content_for :page_actions do
|
||||
%li
|
||||
= button_link_to t(:new_order), new_admin_order_url, :icon => 'icon-plus', :id => 'admin_new_order'
|
||||
|
||||
= render partial: 'spree/admin/shared/order_sub_menu'
|
||||
|
||||
- content_for :app_wrapper_attrs do
|
||||
= "ng-app='admin.orders'"
|
||||
|
||||
- content_for :table_filter_title do
|
||||
= t(:search)
|
||||
|
||||
- content_for :table_filter do
|
||||
%div{"data-hook" => "admin_orders_index_search"}
|
||||
= search_form_for [:admin, @search] do |f|
|
||||
@@ -59,7 +66,7 @@
|
||||
= button t(:filter_results), 'icon-search'
|
||||
|
||||
- unless @orders.empty?
|
||||
%table#listing_orders.index.responsive{"data-hook" => "", width: "100%", "ng-app" => "ofn.admin"}
|
||||
%table#listing_orders.index.responsive{"data-hook" => "", width: "100%", "ng-controller" => "ordersCtrl"}
|
||||
%colgroup
|
||||
%col{style: "width: 10%"}
|
||||
%thead
|
||||
|
||||
Reference in New Issue
Block a user