-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathModel.js
More file actions
423 lines (380 loc) · 14.6 KB
/
Model.js
File metadata and controls
423 lines (380 loc) · 14.6 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
* @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 { Loader, Observable, QueryRouter, sessionService } from '/js/src/index.js';
import { LogsModel } from './views/Logs/LogsModel.js';
import Tags from './views/Tags/Tags.js';
import { RunsModel } from './views/Runs/RunsModel.js';
import Flps from './views/Flps/Flps.js';
import { EnvironmentModel } from './views/Environments/EnvironmentModel.js';
import LhcFills from './views/LhcFills/LhcFills.js';
import RunTypeModel from './views/RunTypes/RunTypeModel.js';
import { ModalModel } from './components/modal/ModalModel.js';
import { debounce, INPUT_DEBOUNCE_TIME } from './utilities/debounce.js';
import { userPreferencesStore } from './utilities/userPreferencesStore.js';
import { registerFrontLinkListener } from './components/common/navigation/frontLinkListener.js';
import { EosReportModel } from './views/EosReport/EosReportModel.js';
import { AboutModel } from './views/About/About.js';
import { StatisticsPageModel } from './views/Statistics/StatisticsPageModel.js';
import { LhcPeriodsModel } from './views/lhcPeriods/LhcPeriodsModel.js';
import { HomePageModel } from './views/Home/Overview/HomePageModel.js';
import { DataPassesModel } from './views/DataPasses/DataPassesModel.js';
import { SimulationPassesModel } from './views/SimulationPasses/SimulationPassesModel.js';
import { QcFlagTypesModel } from './views/QcFlagTypes/QcFlagTypesModel.js';
import { QcFlagsModel } from './views/QcFlags/QcFlagsModel.js';
import { UserRoleSelectionModel } from './models/UserRoleSelectionModel.js';
import { ObservableData } from './utilities/ObservableData.js';
import { BkpRoles } from './domain/enums/BkpRoles.js';
import { getRoleForDetector } from './utilities/getRoleForDetector.js';
import { detectorsProvider } from './services/detectors/detectorsProvider.js';
import { ErrorModel } from './views/Error/ErrorModel.js';
/**
* Root of model tree
* Handle global events: keyboard, websocket and router location change
*/
export default class Model extends Observable {
/**
* Load all sub-models and bind event handlers
* @param {Object} window The window object from the HTML
* @param {Object} document The document object
*/
constructor(window, document) {
super();
// Bind window and document
this.document = document;
this.window = window;
// Bind session
this.session = sessionService.get();
this.session.personid = parseInt(this.session.personid, 10);
this.userRoleSelectionModel = new UserRoleSelectionModel();
if (this.session.personid === 0) { // Anonymous user has id 0
this.userRoleSelectionModel.observe(() => {
this.session.access = this.userRoleSelectionModel.selected;
this.notify();
});
}
// Bind user preferences
userPreferencesStore.bubbleTo(this);
this._qcDetectorsUserHasAccessTo = ObservableData.builder()
.source(detectorsProvider.qc$)
.apply((remoteDetectors) => remoteDetectors.apply({
Success: (detectors) => {
const { access = [] } = this.session;
return access.includes(BkpRoles.ADMIN)
? detectors
: detectors.filter(({ name }) => access.includes(getRoleForDetector(name)));
},
}))
.build();
this.userRoleSelectionModel.observe(() => this._qcDetectorsUserHasAccessTo.setCurrent(detectorsProvider.qc$.getCurrent()));
// Bind models
this.loader = new Loader(this);
this.loader.bubbleTo(this);
this.modalModel = new ModalModel();
this.modalModel.bubbleTo(this);
// App's configuration
this._appConfiguration$ = new Observable();
this._inputDebounceTime = INPUT_DEBOUNCE_TIME;
// Models
this.home = new HomePageModel(this);
this.home.bubbleTo(this);
this.lhcPeriods = new LhcPeriodsModel(this);
this.lhcPeriods.bubbleTo(this);
this.dataPasses = new DataPassesModel(this);
this.dataPasses.bubbleTo(this);
this.qcFlags = new QcFlagsModel(this);
this.qcFlags.bubbleTo(this);
this.simulationPasses = new SimulationPassesModel(this);
this.simulationPasses.bubbleTo(this);
this.qcFlagTypes = new QcFlagTypesModel(this);
this.qcFlagTypes.bubbleTo(this);
/**
* @type {LogsModel}
*/
this.logs = new LogsModel(this);
this.logs.bubbleTo(this);
/**
* @type {EnvironmentModel}
*/
this.envs = new EnvironmentModel(this);
this.envs.bubbleTo(this);
/**
* @type {LhcFills}
*/
this.lhcFills = new LhcFills(this);
this.lhcFills.bubbleTo(this);
/**
* @type {RunsModel}
*/
this._runs = new RunsModel(this);
this._runs.bubbleTo(this);
this.statisticsModel = new StatisticsPageModel();
this.statisticsModel.bubbleTo(this);
/**
* @type {TagModel}
*/
this.tags = new Tags(this);
this.tags.bubbleTo(this);
/**
* @type {Flps}
*/
this.flps = new Flps(this);
this.flps.bubbleTo(this);
/**
* @type {RunTypeModel}
*/
this.runTypes = new RunTypeModel();
this.runTypes.bubbleTo(this);
/**
* @type {EosReportModel}
*/
this.eosReportModel = new EosReportModel(this);
this.eosReportModel.bubbleTo(this);
/**
* @type {AboutModel}
*/
this.aboutModel = new AboutModel();
this.aboutModel.bubbleTo(this);
/**
* @type {ErrorModel}
*/
this.errorModel = new ErrorModel();
this.errorModel.bubbleTo(this);
// Setup router
this.router = new QueryRouter();
this.router.observe(this.handleLocationChange.bind(this));
this.router.bubbleTo(this);
registerFrontLinkListener((e) => this.router.handleLinkEvent(e));
// Init pages
this.handleLocationChange();
this.window.addEventListener('resize', debounce(() => this.notify(), 100));
// Navbar dropdown menus
this.dropdownMenu = false;
}
/**
* Delegates sub-model actions depending on new location of the page
* @returns {vnode} The page to be loaded
*/
async handleLocationChange() {
// Reset infinite scroll to prevent scroll listening on pages where it is disabled or not needed
window.onscroll = null;
switch (this.router.params.page) {
case 'home':
// Setting the rows per page also collects all the runs and logs
this.home.loadOverview();
break;
case 'lhc-period-overview':
this.lhcPeriods.loadOverview();
break;
case 'data-passes-per-simulation-pass-overview':
this.dataPasses.loadPerSimulationPassOverview(this.router.params);
break;
case 'data-passes-per-lhc-period-overview':
this.dataPasses.loadPerLhcPeriodOverview(this.router.params);
break;
case 'simulation-passes-per-lhc-period-overview':
this.simulationPasses.loadPerLhcPeriodOverview(this.router.params);
break;
case 'qc-flag-types-overview':
this.qcFlagTypes.loadOverview();
break;
case 'qc-flag-type-creation':
this.qcFlagTypes.loadCreation();
break;
case 'qc-flags-for-data-pass':
this.qcFlags.loadForDataPassOverview(this.router.params);
break;
case 'qc-flag-creation-for-data-pass':
this.qcFlags.loadCreationForDataPass(this.router.params);
break;
case 'qc-flags-for-simulation-pass':
this.qcFlags.loadForSimulationPassOverview(this.router.params);
break;
case 'qc-flag-details-for-data-pass':
this.qcFlags.loadDetailsForDataPass(this.router.params);
break;
case 'qc-flag-details-for-simulation-pass':
this.qcFlags.loadDetailsForSimulationPass(this.router.params);
break;
case 'qc-flag-creation-for-simulation-pass':
this.qcFlags.loadCreationForSimulationPass(this.router.params);
break;
case 'synchronous-qc-flags':
this.qcFlags.loadSynchronousOverview(this.router.params);
break;
case 'gaq-flags':
this.qcFlags.loadGaqOverview(this.router.params);
break;
case 'anchored-simulation-passes-overview':
this.simulationPasses.loadAnchoredOverview(this.router.params);
break;
case 'env-overview':
this.envs.loadOverview();
break;
case 'env-details':
this.envs.loadDetails(this.router.params);
break;
case 'lhc-fill-overview':
this.lhcFills.loadOverview();
break;
case 'lhc-fill-details':
this.lhcFills.loadDetails(this.router.params);
break;
case 'log-overview':
// Prevent loading extra rows when it's not necessary
this.logs.loadOverview();
break;
case 'log-detail':
this.logs.loadTreeView(this.router.params.id);
break;
case 'log-create':
this.logs.loadCreation(this.router.params);
break;
case 'log-reply':
this.logs.loadReply(this.router.params);
break;
case 'run-overview':
this._runs.loadOverview();
break;
case 'runs-per-lhc-period':
this._runs.loadPerLhcPeriodOverview(this.router.params);
break;
case 'runs-per-data-pass':
this._runs.loadPerDataPassOverview(this.router.params);
break;
case 'runs-per-simulation-pass':
this._runs.loadPerSimulationPassOverview(this.router.params);
break;
case 'run-detail':
this._runs.loadDetails(this.router.params);
break;
case 'statistics':
this.statisticsModel.load(this.router.params);
break;
case 'tag-overview':
break;
case 'tag-detail':
await this.tags.loadDetails(parseInt(this.router.params.id, 10), this.router.params.panel);
break;
case 'tag-create':
break;
case 'create-tag':
break;
case 'flp-overview':
// Prevent loading extra rows when it's not necessary
if (!this.flps.pagination.isInfiniteScrollEnabled) {
this.flps.fetchAllFlps();
}
break;
case 'flp-detail':
if (this.router.params.panel) {
this.flps.fetchOneFlp(this.router.params.id);
}
break;
case 'about-overview':
this.aboutModel.fetchAllServiceInfo();
break;
case 'eos-report-create':
this.eosReportModel.loadCreation(this.router.params.shiftType);
break;
case 'error':
break;
default:
if (this.router.params.page) {
this.errorModel.setError({
code: '404',
codeDescription: 'Page not found',
message: 'The page you are looking for might have been removed, had its name changed or is temorarily unavailable.',
});
this.router.params.page = 'error';
this.router.notify();
break;
} else {
this.router.go('?page=home');
break;
}
}
}
/**
* Toggle navbar dropdown
* @param {string} key referencing dropdown to be toggled
* @returns {void}
*/
toggleDropdownMenu(key) {
this.dropdownMenu = this.dropdownMenu === key ? null : key;
this.notify();
}
/**
* Clears all navbar dropdowns
* @returns {void}
*/
clearDropdownMenu() {
this.dropdownMenu = null;
this.notify();
}
/**
* To decided whether dropdown (referenced by the key) should be displayed as opened
* @param {string} key referencing dropdown
* @returns {boolean} if true dropdown should be opened
*/
isDropdownMenuOpened(key) {
return this.dropdownMenu === key;
}
/**
* Checks if the user is an admin user.
* @returns {boolean} If the user has the admin role
*/
isAdmin() {
return this.session.access.includes('admin');
}
/**
* Returns an observable notified once the app's configuration is modified
*/
get appConfiguration$() {
return this._appConfiguration$;
}
/**
* Disable input debounce for the whole application
* This is a test-purposed feature, it should not be used in actual browser
*
* @returns {void}
*/
disableInputDebounce() {
this._inputDebounceTime = 0;
this._appConfiguration$.notify();
}
/**
* Return the debounce time that should be applied to user inputs when it makes sense, such as text, number, range input
*
* @returns {number} the debounce time
*/
get inputDebounceTime() {
return this._inputDebounceTime;
}
/**
* Get detector which user can manage QC flags for
*
* @return {RemoteData<Detector[]>} detectors remote data
*/
get detectorsUserHasAccessTo() {
return this._qcDetectorsUserHasAccessTo.getCurrent();
}
// Submodels
/**
* Return the runs submodel
*
* @return {RunsModel} the runs submodel
*/
get runs() {
return this._runs;
}
}