Add column sorting to table

This commit is contained in:
Matt-Yorkley
2018-09-17 12:13:57 +01:00
parent 2112f296e4
commit 9da6a5a9b3
2 changed files with 50 additions and 9 deletions

View File

@@ -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)

View File

@@ -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"}