-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlockPage.js
More file actions
193 lines (184 loc) · 7.64 KB
/
lockPage.js
File metadata and controls
193 lines (184 loc) · 7.64 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
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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 {h} from '/js/src/index.js';
import {detectorHeader} from '../common/detectorHeader.js';
import {detectorLockActionButton} from './../common/detectorLock/detectionLockActionButton.js';
import {detectorLockButton} from './lockButton.js';
import {ROLES} from './../workflow/constants.js';
import errorPage from './../common/errorPage.js';
import loading from './../common/loading.js';
import {DetectorLockAction} from '../common/enums/DetectorLockAction.enum.js';
import {isUserAllowedRole} from './../common/userRole.js';
import { getDetectorListWithTstAtEnd, TST_DETECTOR_NAME } from '../common/detectorUtils.js';
import { DetectorState, DetectorStateStyle } from '../common/enums/DetectorState.enum.js';
const LOCK_TABLE_HEADER_KEYS = ['Detector', 'Owner', 'Active'];
const DETECTOR_ALL = 'ALL';
/**
* @file Page that displays detector lock details, states and allows users to take / release one or multiple locks
*/
/**
* Header of the lock page
* @return {vnode}
*/
export const header = () => [
h('.w-100.text-center', [
h('h4', 'Locks')
]),
];
/**
* Content - displays table with detector locks and associated actions
* @param {Model} model - root model of the application
* @return {vnode}
*/
export const content = (model) => {
const {lock: lockModel, detectors: detectorsService} = model;
const { padlockState } = lockModel;
return [
detectorHeader(model),
h('.text-center.scroll-y.absolute-fill', {
style: 'top: 40px',
oncreate: () => detectorsService.getActiveDetectors(),
}, [
padlockState.match({
NotAsked: () => null,
Loading: () => loading(3),
Failure: (error) => errorPage(error),
Success: (detectorsLocksState) => h('.flex-column', [
detectorsService.isGlobalView() && [
h('.flex-row.g2.p2', [
isUserAllowedRole(ROLES.Admin) && [
h('strong', 'Admin actions: '),
detectorLockActionButton(
lockModel, DETECTOR_ALL, {}, DetectorLockAction.RELEASE, true, 'Force Release ALL'
),
detectorLockActionButton(
lockModel, DETECTOR_ALL, {}, DetectorLockAction.TAKE, true, 'Force Take ALL'
),
],
isUserAllowedRole(ROLES.Global) && [
h('strong', 'Global actions: '),
detectorLockActionButton(
lockModel, DETECTOR_ALL, {}, DetectorLockAction.RELEASE, false, 'Release ALL*'
),
detectorLockActionButton(
lockModel, DETECTOR_ALL, {}, DetectorLockAction.TAKE, false, 'Take ALL*'
),
],
]),
],
detectorLocksTable(model, detectorsLocksState, detectorsService.activeDetectors)
])
})
])
]
};
/**
* Table with lock status details, buttons to lock them, and admin actions such us "Force release"
* @param {Model} model - root model of the application
* @param {Object<String, DetectorLock>} detectorsLockState - state of the detectors lock
* @param {RemoteData} activeDetectorsRemote - remote data with the list of active detectors
* @return {vnode}
*/
const detectorLocksTable = (model, detectorLocksState, activeDetectorsRemote) => {
const { detectors: detectorsService, lock: lockModel } = model;
const isUserGlobal = isUserAllowedRole(ROLES.Global);
const detectorKeysWithTstLast = getDetectorListWithTstAtEnd(Object.keys(detectorLocksState));
const detectorRows = detectorKeysWithTstLast
.filter((detectorName) => {
const isSelectedDetectorViewGlobalOrCurrent = (
detectorsService.isGlobalView() || detectorsService.selected === detectorName
);
const isUserAllowedDetector = detectorsService.authed.includes(detectorName);
return (isUserGlobal && isSelectedDetectorViewGlobalOrCurrent) || isUserAllowedDetector;
})
.map((detectorName) => {
const detectorActivityState = _getDetectorState(activeDetectorsRemote, detectorName);
if (detectorName.toLocaleUpperCase().includes(TST_DETECTOR_NAME)) {
return [
emptyRowSeparator(),
detectorLockRow(lockModel, detectorName, detectorLocksState[detectorName], detectorActivityState)
];
} else {
return detectorLockRow(lockModel, detectorName, detectorLocksState[detectorName], detectorActivityState)
}
});
return h('table.table.table-sm',
h('thead',
h('tr',
LOCK_TABLE_HEADER_KEYS.map((header) => h('th', header)),
isUserAllowedRole(ROLES.Global) && h('th', 'Global actions')
)
),
h('tbody', [
detectorRows.length > 0
? detectorRows
: h('tr',
h('td.ph2.warning', { colspan: LOCK_TABLE_HEADER_KEYS.length } , [
'Missing Role permissions needed for being allowed to own locks',
' If you have just started your shift, please allow a few minutes for the system ',
'to update before trying again or calling an FLP expert.'
])
)
])
);
};
/**
* Build a vnode for a row in the detector lock table which contains state of the lock and owner
* @param {LockModel} lockModel - model of the lock state and actions
* @param {String} detector - detector name
* @param {DetectorLock} lockState - state of the lock {owner: {fullName: String}, isLocked: Boolean
* @param {DetectorState} detectorActivityState - state of the detector as per AliECS (Active, Inactive, Unknown)
* @return {vnode}
*/
const detectorLockRow = (lockModel, detector, lockState, detectorActivityState) => {
const ownerName = lockState?.owner?.fullName || '-';
return h('tr', {
id: `detector-row-${detector}`,
}, [
h('td',
h('.flex-row.g2.items-center.f5', [
detectorLockButton(lockModel, detector, lockState, false, detectorActivityState === DetectorState.ACTIVE),
detector
])
),
h('td', ownerName),
h(`td`, {
class: DetectorStateStyle[detectorActivityState]
}, detectorActivityState),
isUserAllowedRole(ROLES.Global) && h('td', [
detectorLockActionButton(lockModel, detector, lockState, DetectorLockAction.RELEASE, true, 'Force Release'),
detectorLockActionButton(lockModel, detector, lockState, DetectorLockAction.TAKE, true, 'Force Take')
])
]);
};
/**
* Empty table row separator vnode
* @return {vnode}
*/
const emptyRowSeparator = () => h('tr', h('td', {colspan: LOCK_TABLE_HEADER_KEYS.length}, h('hr')));
/**
* Helper function to get the state of the detector (Active, Inactive, Unknown) based on the activeDetectorsRemote data
* @param {RemoteData} activeDetectorsRemote - remote data with the list of active detectors
* @param {String} detectorName - name of the detector to get the state for
* @return {String} state of the detector (Active, Inactive, Unknown)
*/
const _getDetectorState = (activeDetectorsRemote, detectorName) => {
return activeDetectorsRemote.match({
NotAsked: () => DetectorState.UNDEFINED,
Loading: () => DetectorState.UNDEFINED,
Failure: () => DetectorState.ERROR,
Success: (activeDetectors) =>
activeDetectors.includes(detectorName) ? DetectorState.ACTIVE : DetectorState.UNDEFINED
})
}