mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Add column sorting to table
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor, $compile, $attrs, Orders) ->
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, $injector, RequestMonitor, $compile, $attrs, Orders, SortOptions) ->
|
||||
$scope.$compile = $compile
|
||||
$scope.shops = shops
|
||||
$scope.orderCycles = orderCycles
|
||||
@@ -9,6 +9,7 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.pagination = Orders.pagination
|
||||
$scope.orders = Orders.all
|
||||
$scope.sortOptions = SortOptions
|
||||
|
||||
$scope.initialise = ->
|
||||
$scope.q = {
|
||||
@@ -30,10 +31,18 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
|
||||
'q[distributor_id_in]': $scope['q']['distributor_id_in'],
|
||||
'q[order_cycle_id_in]': $scope['q']['order_cycle_id_in'],
|
||||
'q[order_cycle_id_in]': $scope['q']['order_cycle_id_in'],
|
||||
'q[s]': $scope.sorting || 'id desc',
|
||||
per_page: $scope.per_page || 15,
|
||||
page: page
|
||||
})
|
||||
|
||||
$scope.$watch 'sortOptions', (sort) ->
|
||||
if sort.predicate != ""
|
||||
$scope.sorting = sort.predicate + ' desc' if sort.reverse
|
||||
$scope.sorting = sort.predicate + ' asc' if !sort.reverse
|
||||
$scope.fetchResults()
|
||||
, true
|
||||
|
||||
$scope.validOrderCycle = (oc) ->
|
||||
$scope.orderCycleHasDistributor oc, parseInt($scope.distributor_id)
|
||||
|
||||
|
||||
@@ -24,15 +24,47 @@
|
||||
%th
|
||||
= t(:products_distributor)
|
||||
- if @show_only_completed
|
||||
%th= sort_link @search, :completed_at, t(:completed_at, :scope => 'activerecord.attributes.spree/order')
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('completed_at')"}
|
||||
= t(:completed_at, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'completed_at asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'completed_at desc' || sorting === undefined"}= "▼".html_safe
|
||||
- else
|
||||
%th= sort_link @search, :created_at, t(:created_at, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :number, t(:number, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :state, t(:state, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :payment_state, t(:payment_state, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :shipment_state, t(:shipment_state, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :email, t(:email, :scope => 'activerecord.attributes.spree/order')
|
||||
%th= sort_link @search, :total, t(:total, :scope => 'activerecord.attributes.spree/order')
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('created_at')"}
|
||||
= t(:created_at, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'created_at asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'created_at desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('number')"}
|
||||
= t(:number, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'number asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'number desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('state')"}
|
||||
= t(:state, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'state asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'state desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('payment_state')"}
|
||||
= t(:payment_state, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'payment_state asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'payment_state desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('shipment_state')"}
|
||||
= t(:shipment_state, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'shipment_state asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'shipment_state desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('email')"}
|
||||
= t(:email, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'email asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'email desc'"}= "▼".html_safe
|
||||
%th
|
||||
%a{'ng-click' => "sortOptions.toggle('total')"}
|
||||
= t(:total, scope: 'activerecord.attributes.spree/order')
|
||||
%span{'ng-show' => "sorting == 'total asc'"}= "▲".html_safe
|
||||
%span{'ng-show' => "sorting == 'total desc'"}= "▼".html_safe
|
||||
%th.actions{"data-hook" => "admin_orders_index_header_actions"}
|
||||
%tbody
|
||||
%tr{ng: {repeat: 'order in orders track by $index', class: {even: "'even'", odd: "'odd'"}}, 'ng-class' => "'state-{{order.state}}'", "data-hook" => "admin_orders_index_rows"}
|
||||
|
||||
Reference in New Issue
Block a user