Save filter params to sessionStorage for orders list

- Use sessionStorage to save the filters params each time a filter is modified
This commit is contained in:
Jean-Baptiste Bellet
2021-05-20 15:12:24 +02:00
parent 088ae496cc
commit c5a2d183d8
7 changed files with 55 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ angular.module("ofn.admin", [
"admin.dropdown",
"admin.products",
"admin.taxons",
"infinite-scroll"
"infinite-scroll",
"admin.orders"
]).config ($httpProvider) ->
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"

View File

@@ -110,5 +110,8 @@
// foundation
//= require ../shared/mm-foundation-tpls-0.9.0-20180826174721.min.js
// LocalStorage
//= require ../shared/angular-local-storage.js
// requires the rest of the JS code in this folder
//= require_tree .

View File

@@ -1,4 +1,4 @@
angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, RequestMonitor, Orders, SortOptions, $window, $filter) ->
angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, RequestMonitor, Orders, SortOptions, $window, $filter, $location, QueryPersistence) ->
$scope.RequestMonitor = RequestMonitor
$scope.pagination = Orders.pagination
$scope.orders = Orders.all
@@ -15,11 +15,16 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
$scope.poll = 0
$scope.rowStatus = {}
QueryPersistence.storageKey = 'ordersFilters'
QueryPersistence.storableFilters = ["q", "sorting", "shipping_method_id", "page", "per_page"]
$scope.initialise = ->
$scope.per_page = 15
$scope.q = {
completed_at_not_null: true
}
unless QueryPersistence.restoreFilters($scope)
$scope.per_page = 15
$scope.q = {
completed_at_not_null: true
}
$scope.fetchResults()
$scope.fetchResults = (page=1) ->
@@ -44,10 +49,12 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
per_page: $scope.per_page,
page: page
}
QueryPersistence.setStoredFilters($scope)
RequestMonitor.load(Orders.index(params).$promise)
$scope.appendStringIfNotEmpty = (baseString, stringToAppend) ->
return baseString unless baseString
return baseString if baseString.endsWith(stringToAppend)
baseString + stringToAppend

View File

@@ -1 +1 @@
angular.module("admin.orders", ['admin.indexUtils', 'ngResource', 'mm.foundation'])
angular.module("admin.orders", ['admin.indexUtils', 'ngResource', 'mm.foundation', "OFNShared"])

View File

@@ -0,0 +1,27 @@
angular.module("admin.indexUtils").factory 'QueryPersistence', (localStorageService)->
new class QueryPersistence
storageKey: ''
storableFilters: []
constructor: ->
localStorageService.setStorageType("sessionStorage")
getStoredFilters: ->
localStorageService.get(@storageKey) || {}
setStoredFilters: (scope) ->
filters = {}
for key in @storableFilters
filters[key] = scope[key]
localStorageService.set(@storageKey, filters)
restoreFilters: (scope) ->
storedFilters = @getStoredFilters()
if storedFilters
for k,v of storedFilters
scope[k] = v
return true
false

View File

@@ -1,4 +1,5 @@
window.OFNShared = angular.module("OFNShared", [
"mm.foundation"
"mm.foundation",
"LocalStorageModule"
]).config ($httpProvider) ->
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"

View File

@@ -1,10 +1,16 @@
= csrf_meta_tags
- content_for :main_ng_app_name do
= "ofn.admin"
- content_for :page_actions do
- if can?(:fire, @order)
%li= event_links
= render partial: 'spree/admin/shared/order_links'
- if can?(:admin, Spree::Order)
%li= button_link_to t(:back_to_orders_list), admin_orders_path, :icon => 'icon-arrow-left'
%li{"ng-controller" => "ordersCtrl"}
%a.button.icon-arrow-left{icon: 'icon-arrow-left', ng: { href: admin_orders_path }}
= t(:back_to_orders_list)
= render partial: "spree/admin/shared/order_page_title"
= render partial: "spree/admin/shared/order_tabs", locals: { current: 'Order Details' }
@@ -17,7 +23,7 @@
= admin_inject_shops(module: 'admin.orders')
= admin_inject_order_cycles
%div{"ng-app" => "admin.orders", "ng-controller" => "orderCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
%div{"ng-controller" => "orderCtrl", "ofn-distributor-id" => @order.distributor_id, "ofn-order-cycle-id" => @order.order_cycle_id}
= render :partial => 'add_product' if can?(:update, @order)