Skip to content

Commit 0be8441

Browse files
committed
[O2B-1489] Add filtering support to EnvironmentOverviewModel
Adds FilteringModel to EnvironmentOverviewModel, enabling filter state management.
1 parent 305faf2 commit 0be8441

2 files changed

Lines changed: 83 additions & 3 deletions

File tree

lib/public/views/Environments/EnvironmentModel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import { EnvironmentDetailsModel } from './Details/EnvironmentDetailsModel.js';
2323
export class EnvironmentModel extends Observable {
2424
/**
2525
* The constructor of the Overview model object
26+
* @param {Model} model global model
2627
*/
27-
constructor() {
28+
constructor(model) {
2829
super();
2930

3031
// Sub-models
31-
this._overviewModel = new EnvironmentOverviewModel();
32+
this._overviewModel = new EnvironmentOverviewModel(model);
3233
this._overviewModel.bubbleTo(this);
3334

3435
this._detailsModel = new EnvironmentDetailsModel();

lib/public/views/Environments/Overview/EnvironmentOverviewModel.js

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,34 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14+
import { FilteringModel } from '../../../components/Filters/common/FilteringModel.js';
1415
import { OverviewPageModel } from '../../../models/OverviewModel.js';
16+
import { debounce } from '../../../utilities/debounce.js';
1517

1618
/**
1719
* Environment overview page model
1820
*/
1921
export class EnvironmentOverviewModel extends OverviewPageModel {
2022
/**
2123
* Constructor
24+
* @param {Model} model global model
2225
*/
23-
constructor() {
26+
constructor(model) {
2427
super();
28+
29+
this._filteringModel = new FilteringModel({
30+
});
31+
32+
this._filteringModel.observe(() => this._applyFilters(true));
33+
this._filteringModel.visualChange$?.bubbleTo(this);
34+
35+
this.reset(false);
36+
const updateDebounceTime = () => {
37+
this._debouncedLoad = debounce(this.load.bind(this), model.inputDebounceTime);
38+
};
39+
40+
model.appConfiguration$.observe(() => updateDebounceTime());
41+
updateDebounceTime();
2542
}
2643

2744
/**
@@ -31,6 +48,16 @@ export class EnvironmentOverviewModel extends OverviewPageModel {
3148
return '/api/environments';
3249
}
3350

51+
/**
52+
* @inheritDoc
53+
*/
54+
async getLoadParameters() {
55+
return {
56+
...await super.getLoadParameters(),
57+
filter: this._filteringModel.normalized,
58+
};
59+
}
60+
3461
/**
3562
* Returns the current environments list as remote data
3663
*
@@ -39,4 +66,56 @@ export class EnvironmentOverviewModel extends OverviewPageModel {
3966
get environments() {
4067
return this.items;
4168
}
69+
70+
/**
71+
* Returns all filtering, sorting and pagination settings to their default values
72+
* @param {boolean} [fetch = true] whether to refetch all data after filters have been reset
73+
* @return {void}
74+
*/
75+
reset(fetch = true) {
76+
super.reset();
77+
this.resetFiltering(fetch);
78+
}
79+
80+
/**
81+
* Reset all filtering models
82+
* @param {boolean} fetch Whether to refetch all data after filters have been reset
83+
* @return {void}
84+
*/
85+
resetFiltering(fetch = true) {
86+
this._filteringModel.reset();
87+
88+
if (fetch) {
89+
this._applyFilters(true);
90+
}
91+
}
92+
93+
/**
94+
* Checks if any filter value has been modified from their default (empty)
95+
* @return {Boolean} If any filter is active
96+
*/
97+
isAnyFilterActive() {
98+
return this._filteringModel.isAnyFilterActive();
99+
}
100+
101+
/**
102+
* Return the filtering model
103+
*
104+
* @return {FilteringModel} the filtering model
105+
*/
106+
get filteringModel() {
107+
return this._filteringModel;
108+
}
109+
110+
/**
111+
* Apply the current filtering and update the remote data list
112+
*
113+
* @param {boolean} now if true, filtering will be applied now without debouncing
114+
*
115+
* @return {void}
116+
*/
117+
_applyFilters(now = false) {
118+
this._pagination.currentPage = 1;
119+
now ? this.load() : this._debouncedLoad(true);
120+
}
42121
}

0 commit comments

Comments
 (0)