@fleetbase/ember-core 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/services/filters.js +31 -11
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import { isBlank } from '@ember/utils';
|
|
|
6
6
|
import { computed, action, set, get } from '@ember/object';
|
|
7
7
|
import { getOwner } from '@ember/application';
|
|
8
8
|
import { format } from 'date-fns';
|
|
9
|
+
import getWithDefault from '../utils/get-with-default';
|
|
9
10
|
|
|
10
11
|
export default class FiltersService extends Service {
|
|
11
12
|
@service router;
|
|
@@ -74,7 +75,7 @@ export default class FiltersService extends Service {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
@action apply(controller) {
|
|
77
|
-
const currentQueryParams = this.getQueryParams();
|
|
78
|
+
const currentQueryParams = this.getQueryParams(controller);
|
|
78
79
|
const updatableQueryParams = { ...currentQueryParams, ...this.pendingQueryParams };
|
|
79
80
|
|
|
80
81
|
for (let queryParam in updatableQueryParams) {
|
|
@@ -88,8 +89,10 @@ export default class FiltersService extends Service {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
@action reset(controller) {
|
|
91
|
-
this.
|
|
92
|
-
|
|
92
|
+
const queryParams = this.getQueryParams(controller);
|
|
93
|
+
|
|
94
|
+
Object.keys(queryParams).forEach((queryParam) => {
|
|
95
|
+
this.removeFromController(controller, queryParam, undefined);
|
|
93
96
|
});
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -103,20 +106,18 @@ export default class FiltersService extends Service {
|
|
|
103
106
|
return this.clear(queryParam, callback);
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
if (isBlank(queryParam)) {
|
|
109
|
+
if (isBlank(queryParam) && Object.keys(currentQueryParams).length > 0) {
|
|
107
110
|
return Object.keys(currentQueryParams).forEach((qp) => this.clear(callback, qp));
|
|
108
111
|
}
|
|
109
112
|
|
|
110
|
-
if (isArray(queryParam)) {
|
|
113
|
+
if (isArray(queryParam) && !isBlank(queryParam)) {
|
|
111
114
|
return queryParam.forEach((qp) => this.clear(callback, qp));
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
if (typeof queryParam
|
|
115
|
-
|
|
117
|
+
if (typeof queryParam === 'string') {
|
|
118
|
+
set(this.pendingQueryParams, queryParam, undefined);
|
|
116
119
|
}
|
|
117
120
|
|
|
118
|
-
set(this.pendingQueryParams, queryParam, undefined);
|
|
119
|
-
|
|
120
121
|
if (typeof callback == 'function') {
|
|
121
122
|
callback(queryParam);
|
|
122
123
|
}
|
|
@@ -153,10 +154,29 @@ export default class FiltersService extends Service {
|
|
|
153
154
|
return currentRoute.queryParams;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
@action getQueryParams() {
|
|
157
|
+
@action getQueryParams(controller) {
|
|
158
|
+
const queryParams = {};
|
|
159
|
+
|
|
160
|
+
if (controller) {
|
|
161
|
+
const controllerQueryParams = getWithDefault(controller, 'queryParams', []);
|
|
162
|
+
|
|
163
|
+
if (isArray(controllerQueryParams)) {
|
|
164
|
+
for (let i = 0; i < controllerQueryParams.length; i++) {
|
|
165
|
+
const qp = controllerQueryParams.objectAt(i);
|
|
166
|
+
|
|
167
|
+
if (this.managedQueryParams.includes(qp)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
queryParams[qp] = get(controller, qp);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return queryParams;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
const currentRoute = this.lookupCurrentRoute();
|
|
158
179
|
const currentRouteQueryParams = Object.keys(currentRoute.queryParams);
|
|
159
|
-
const queryParams = {};
|
|
160
180
|
|
|
161
181
|
for (let i = 0; i < currentRouteQueryParams.length; i++) {
|
|
162
182
|
const queryParam = currentRouteQueryParams.objectAt(i);
|
package/package.json
CHANGED