Angularise filters

This commit is contained in:
Matt-Yorkley
2018-09-13 12:33:10 +01:00
parent 3b9d9db16b
commit 2112f296e4
4 changed files with 80 additions and 56 deletions

View File

@@ -7,16 +7,31 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
$scope.order_cycle_id = parseInt($attrs.ofnOrderCycleId)
$scope.RequestMonitor = RequestMonitor
$scope.orders = Orders.all
$scope.pagination = Orders.pagination
$scope.orders = Orders.all
$scope.initialise = ->
$scope.q = {
completed_at_not_null: true
}
$scope.fetchResults()
$scope.fetchResults = ->
$scope.fetchResults = (page=1) ->
Orders.index({
'q[created_at_lt]': $scope['q']['created_at_lt'],
'q[created_at_gt]': $scope['q']['created_at_gt'],
'q[state_eq]': $scope['q']['state_eq'],
'q[number_cont]': $scope['q']['number_cont'],
'q[email_cont]': $scope['q']['email_cont'],
'q[bill_address_firstname_start]': $scope['q']['bill_address_firstname_start'],
'q[bill_address_lastname_start]': $scope['q']['bill_address_lastname_start'],
'q[completed_at_not_null]': $scope['q']['completed_at_not_null'],
'q[inventory_units_shipment_id_null]': $scope['q']['inventory_units_shipment_id_null'],
'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'],
per_page: $scope.per_page || 15,
page: $scope.page || 1
page: page
})
$scope.validOrderCycle = (oc) ->
@@ -34,8 +49,7 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
$scope.changePage = (newPage) ->
$scope.page = newPage
Orders.resetData()
$scope.fetchResults()
$scope.fetchResults(newPage)
for oc in $scope.orderCycles
oc.name_and_status = "#{oc.name} (#{oc.status})"

View File

@@ -1,5 +1,6 @@
angular.module("admin.resources").factory 'Orders', ($q, OrderResource, RequestMonitor) ->
new class Orders
all: []
byID: {}
pristineByID: {}
pagination: {}
@@ -13,10 +14,17 @@ angular.module("admin.resources").factory 'Orders', ($q, OrderResource, RequestM
load: (data) ->
angular.extend(@pagination, data.pagination)
@clearData()
for order in data.orders
@all.push order
@byID[order.id] = order
@pristineByID[order.id] = angular.copy(order)
clearData: ->
@all.length = 0
@byID = {}
@pristineByID = {}
save: (order) ->
deferred = $q.defer()
order.$update({id: order.number})

View File

@@ -0,0 +1,51 @@
%div{"data-hook" => "admin_orders_index_search"}
= search_form_for [:admin, @search], html: { name: "orders_form", "ng-submit" => "fetchResults()"} do |f|
.field-block.alpha.four.columns
.date-range-filter.field
= label_tag nil, t(:date_range)
.date-range-fields
= f.text_field :created_at_gt, class: 'datepicker', datepicker: 'q.created_at_gt', 'ng-model' => 'q.created_at_gt', :value => params[:q][:created_at_gt], :placeholder => t(:start)
%span.range-divider
%i.icon-arrow-right
= f.text_field :created_at_lt, class: 'datepicker', datepicker: 'q.created_at_lt', 'ng-model' => 'q.created_at_lt', :value => params[:q][:created_at_lt], :placeholder => t(:stop)
.field
= label_tag nil, t(:status)
= f.select :state_eq, Spree::Order.state_machines[:state].states.collect {|s| [t("order_state.#{s.name}"), s.value]}, {:include_blank => true}, :class => 'select2', 'ng-model' => 'q.state_eq'
.four.columns
.field
= label_tag nil, t(:order_number)
= f.text_field :number_cont, 'ng-model' => 'q.number_cont'
.field
= label_tag nil, t(:email)
= f.email_field :email_cont, 'ng-model' => 'q.email_cont'
.four.columns
.field
= label_tag nil, t(:first_name_begins_with)
= f.text_field :bill_address_firstname_start, :size => 25, 'ng-model' => 'q.bill_address_firstname_start'
.field
= label_tag nil, t(:last_name_begins_with)
= f.text_field :bill_address_lastname_start, :size => 25, 'ng-model' => 'q.bill_address_lastname_start'
.omega.four.columns
.field.checkbox
%label
= f.check_box :completed_at_not_null, {:checked => @show_only_completed, 'ng-model' => 'q.completed_at_not_null'}, '1', ''
= t(:show_only_complete_orders)
.field.checkbox
%label
= f.check_box :inventory_units_shipment_id_null, {'ng-model' => 'q.inventory_units_shipment_id_null'}, '1', '0'
= t(:show_only_unfulfilled_orders)
.field-block.alpha.eight.columns
= label_tag nil, t(:distributors)
= select_tag("q[distributor_id_in]",
options_for_select(Enterprise.is_distributor.managed_by(spree_current_user).map {|e| [e.name, e.id]}, params[:distributor_ids]),
{class: "select2 fullwidth", multiple: true, 'ng-model' => 'q.distributor_id_in'})
.field-block.omega.eight.columns
= label_tag nil, t(:order_cycles)
= select_tag("q[order_cycle_id_in]",
options_for_select(OrderCycle.managed_by(spree_current_user).where('order_cycles.orders_close_at is not null').order('order_cycles.orders_close_at DESC').map {|oc| [oc.name, oc.id]}, params[:order_cycle_ids]),
{class: "select2 fullwidth", multiple: true, 'ng-model' => 'q.order_cycle_id_in'})
.clearfix
.actions.filter-actions
%div
%a.button.icon-search{'ng-click' => 'fetchResults()'}
= t(:filter_results)

View File

@@ -14,57 +14,8 @@
= t(:search)
- content_for :table_filter do
%div{"data-hook" => "admin_orders_index_search"}
= search_form_for [:admin, @search] do |f|
.field-block.alpha.four.columns
.date-range-filter.field
= label_tag nil, t(:date_range)
.date-range-fields
= f.text_field :created_at_gt, :class => 'datepicker datepicker-from', :value => params[:q][:created_at_gt], :placeholder => t(:start)
%span.range-divider
%i.icon-arrow-right
= f.text_field :created_at_lt, :class => 'datepicker datepicker-to', :value => params[:q][:created_at_lt], :placeholder => t(:stop)
.field
= label_tag nil, t(:status)
= f.select :state_eq, Spree::Order.state_machines[:state].states.collect {|s| [t("order_state.#{s.name}"), s.value]}, {:include_blank => true}, :class => 'select2'
.four.columns
.field
= label_tag nil, t(:order_number)
= f.text_field :number_cont
.field
= label_tag nil, t(:email)
= f.email_field :email_cont
.four.columns
.field
= label_tag nil, t(:first_name_begins_with)
= f.text_field :bill_address_firstname_start, :size => 25
.field
= label_tag nil, t(:last_name_begins_with)
= f.text_field :bill_address_lastname_start, :size => 25
.omega.four.columns
.field.checkbox
%label
= f.check_box :completed_at_not_null, {:checked => @show_only_completed}, '1', ''
= t(:show_only_complete_orders)
.field.checkbox
%label
= f.check_box :inventory_units_shipment_id_null, { }, '1', '0'
= t(:show_only_unfulfilled_orders)
.field-block.alpha.eight.columns
= label_tag nil, t(:distributors)
= select_tag("q[distributor_id_in]",
options_for_select(Enterprise.is_distributor.managed_by(spree_current_user).map {|e| [e.name, e.id]}, params[:distributor_ids]),
{class: "select2 fullwidth", multiple: true})
.field-block.omega.eight.columns
= label_tag nil, t(:order_cycles)
= select_tag("q[order_cycle_id_in]",
options_for_select(OrderCycle.managed_by(spree_current_user).where('order_cycles.orders_close_at is not null').order('order_cycles.orders_close_at DESC').map {|oc| [oc.name, oc.id]}, params[:order_cycle_ids]),
{class: "select2 fullwidth", multiple: true})
.clearfix
.actions.filter-actions
%div{"data-hook" => "admin_orders_index_search_buttons"}
= button t(:filter_results), 'icon-search'
= render partial: 'filters'
%table#listing_orders.index.responsive{"data-hook" => "", width: "100%", 'ng-init' => 'initialise()', 'ng-show' => "!RequestMonitor.loading && orders.length > 0" }
%colgroup
%col{style: "width: 10%"}