1111 * or submit itself to any jurisdiction.
1212 */
1313
14+ import { FilteringModel } from '../../../components/Filters/common/FilteringModel.js' ;
1415import { OverviewPageModel } from '../../../models/OverviewModel.js' ;
16+ import { debounce } from '../../../utilities/debounce.js' ;
1517
1618/**
1719 * Environment overview page model
1820 */
1921export 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