-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathLhcFillsOverviewModel.js
More file actions
135 lines (122 loc) · 4.55 KB
/
Copy pathLhcFillsOverviewModel.js
File metadata and controls
135 lines (122 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { buildUrl } from '/js/src/index.js';
import { FilteringModel } from '../../../components/Filters/common/FilteringModel.js';
import { RawTextFilterModel } from '../../../components/Filters/common/filters/RawTextFilterModel.js';
import { OverviewPageModel } from '../../../models/OverviewModel.js';
import { addStatisticsToLhcFill } from '../../../services/lhcFill/addStatisticsToLhcFill.js';
import { BeamTypeFilterModel } from '../../../components/Filters/LhcFillsFilter/BeamTypeFilterModel.js';
import { TextComparisonFilterModel } from '../../../components/Filters/common/filters/TextComparisonFilterModel.js';
import { TimeRangeFilterModel } from '../../../components/Filters/RunsFilter/TimeRangeFilter.js';
import { ToggleFilterModel } from '../../../components/Filters/common/filters/ToggleFilterModel.js';
/**
* Model for the LHC fills overview page
*
* @implements {OverviewModel}
*/
export class LhcFillsOverviewModel extends OverviewPageModel {
/**
* Constructor
*
* @param {QueryRouter} router router that controls the application's page navigation
* @param {boolean} [stableBeamsOnly=false] if true, overview will load stable beam only
* @param {string} pageIdentifier string that indicates what page this model represents
*/
constructor(router, stableBeamsOnly = false, pageIdentifier) {
super();
this._filteringModel = new FilteringModel(
router,
{
fillNumbers: new RawTextFilterModel(),
beamDuration: new TextComparisonFilterModel(),
runDuration: new TextComparisonFilterModel(),
hasStableBeams: new ToggleFilterModel(stableBeamsOnly, true),
stableBeamsStart: new TimeRangeFilterModel(),
stableBeamsEnd: new TimeRangeFilterModel(),
beamTypes: new BeamTypeFilterModel(),
schemeName: new RawTextFilterModel(),
},
);
this._filteringModel.pageIdentifier = pageIdentifier;
this._filteringModel.observe(() => this._applyFilters());
this._filteringModel.visualChange$.bubbleTo(this);
}
/**
* @inheritDoc
*/
processItems(items) {
for (const item of items) {
addStatisticsToLhcFill(item);
}
return items;
}
/**
* @inheritDoc
*/
getRootEndpoint() {
return buildUrl('/api/lhcFills', { filter: this.filteringModel.normalized });
}
/**
* Set underlying FilteringModel's filters from the query parameters in the URL
*
* @param {boolean} notify if the FilteringModel should notify it's observers after finishing setting the filters
*/
setFilterFromURL(notify) {
this._filteringModel.setFilterFromURL(notify);
}
/**
* Returns all filtering, sorting and pagination settings to their default values
* @param {boolean} [fetch = true] whether to refetch all data after filters have been reset
* @return {void}
*/
reset(fetch = true) {
super.reset();
this.resetFiltering(fetch);
}
/**
* Reset all filtering models
* @param {boolean} fetch Whether to refetch all data after filters have been reset
* @param {boolean} [clearUrl=false] if true filters will be removed from the url
* @return {void}
*/
resetFiltering(fetch = true, clearUrl = false) {
this._filteringModel.reset(false, clearUrl);
if (fetch) {
this._applyFilters();
}
}
/**
* Checks if any filter value has been modified from their default (empty)
* @return {Boolean} If any filter is active
*/
isAnyFilterActive() {
return this._filteringModel.isAnyFilterActive();
}
/**
* Return the filtering model
*
* @return {FilteringModel} the filtering model
*/
get filteringModel() {
return this._filteringModel;
}
/**
* Apply the current filtering and update the remote data list
*
* @return {void}
*/
_applyFilters() {
this._pagination.currentPage = 1;
this.load();
}
}