@@ -41,8 +41,12 @@ export class RunDetailsModel extends Observable {
4141
4242 this . _runNumber = null ;
4343 this . _runId = null ;
44+
4445 this . _runDetails = RemoteData . notAsked ( ) ;
4546 this . _eorReasonTypes = RemoteData . notAsked ( ) ;
47+ this . _ctpTriggerCounters = RemoteData . notAsked ( ) ; // Trigger counters are pre-fetched because they are used
48+ this . _luminosityValues = RemoteData . notAsked ( ) ;
49+
4650 this . _detectors$ = detectorsProvider . dataTaking$ ;
4751 this . _detectors$ . bubbleTo ( this ) ;
4852
@@ -53,29 +57,40 @@ export class RunDetailsModel extends Observable {
5357 this . _tabbedPanelModel = new RunDetailsTabbedPanelModel ( ) ;
5458 this . _tabbedPanelModel . bubbleTo ( this ) ;
5559
60+ /** @var {ApiError[]} */
5661 this . _updateErrors = [ ] ;
5762 }
5863
5964 /**
6065 * Fetch all data related to run details
61- * @param {number } [params.runNumber = null] the run Number of the run to display
62- * @param {number } [params.runId = null] this parameter is deprecated, use runNumber instead if feasible
63- * @param {string } [params.panelKey = null] the key of the current panel
66+ * @param {object } params page parameters
67+ * @param {number|null } [params.runNumber = null] the run Number of the run to display
68+ * @param {number|null } [params.runId = null] this parameter is deprecated, use runNumber instead if feasible
69+ * @param {string|null } [params.panelKey = null] the key of the current panel
6470 * @return {Promise<void> } promise
6571 */
6672 async clearAndLoad ( { runNumber = null , runId = null , panelKey = null } ) {
6773 this . tabbedPanelModel . currentPanelKey = panelKey ;
6874 this . _updateErrors = [ ] ;
6975 this . _runDetails = RemoteData . notAsked ( ) ;
7076 this . _eorReasonTypes = RemoteData . notAsked ( ) ;
77+ this . _ctpTriggerCounters = RemoteData . notAsked ( ) ;
7178
7279 if ( this . _runNumber !== runNumber || this . _runId !== runId ) {
7380 this . clearAllEditors ( ) ;
7481 }
7582 this . _runId = runId ;
7683 this . _runNumber = runNumber ;
77- this . _fetchReasonTypes ( ) ;
78- this . _fetchOneRun ( ) ;
84+
85+ const fetchOneRunPromise = this . _fetchOneRun ( ) ;
86+ const fetchCtpTriggerCounters = this . _fetchCtpTriggerCounters ( ) ;
87+
88+ // Load luminosity values
89+ await Promise . all ( [
90+ this . _fetchReasonTypes ( ) ,
91+ fetchOneRunPromise ,
92+ fetchCtpTriggerCounters ,
93+ ] ) ;
7994 }
8095
8196 /**
@@ -103,6 +118,15 @@ export class RunDetailsModel extends Observable {
103118 return this . _eorReasonTypes ;
104119 }
105120
121+ /**
122+ * Return the remote CTP trigger counters
123+ *
124+ * @return {RemoteData<CtpTriggerCounters[], ApiError> } the remote CTP trigger counters
125+ */
126+ get ctpTriggerCounters ( ) {
127+ return this . _ctpTriggerCounters ;
128+ }
129+
106130 /**
107131 * Getter for all detectors
108132 *
@@ -115,24 +139,29 @@ export class RunDetailsModel extends Observable {
115139 /**
116140 * Retrieve a specified run from the API
117141 *
118- * @return {Promise<void > } resolves once the run has been fetched
142+ * @return {Promise<Run > } resolves once the run has been fetched
119143 */
120144 async _fetchOneRun ( ) {
121145 this . _runDetails = RemoteData . loading ( ) ;
122146 this . notify ( ) ;
123- if ( this . _runNumber !== null ) {
124- return this . _handleFetchRemoteRun ( ( ) => getRemoteData ( `/api/runs/${ this . _runNumber } ` ) ) ;
125- } else {
126- return this . _handleFetchRemoteRun ( ( ) => getRemoteData ( `/api/legacy/runs/${ this . _runId } ` ) ) ;
127- }
147+
148+ const runsApiUrl = this . _runNumber !== null
149+ ? `/api/runs/${ this . _runNumber } `
150+ : `/api/legacy/runs/${ this . _runId } ` ;
151+
152+ return this . _handleFetchRemoteRun ( ( ) => getRemoteData ( runsApiUrl ) ) ;
128153 }
129154
130155 /**
131156 * Send updated RUN to be saved
157+ *
132158 * @return {void }
133159 */
134160 async updateOneRun ( ) {
135- const { runNumber } = this . _runDetails . payload ;
161+ if ( this . _runNumber === null ) {
162+ this . _updateErrors = [ { title : 'No run number specified' } ] ;
163+ }
164+
136165 this . _runDetails = RemoteData . loading ( ) ;
137166 this . _updateErrors = [ ] ;
138167 this . notify ( ) ;
@@ -147,7 +176,7 @@ export class RunDetailsModel extends Observable {
147176 } ;
148177
149178 try {
150- await jsonFetch ( `/api/runs/${ runNumber } ` , options ) ;
179+ await jsonFetch ( `/api/runs/${ this . _runNumber } ` , options ) ;
151180 } catch ( e ) {
152181 this . _updateErrors = e ;
153182 }
@@ -210,8 +239,13 @@ export class RunDetailsModel extends Observable {
210239 */
211240 addNewEorReason ( ) {
212241 const { category, title, description } = this . newEorReason ;
213- const reasonType =
214- this . _eorReasonTypes . payload . find ( ( eorReasonType ) => eorReasonType . category === category && eorReasonType . title === title ) ;
242+ const reasonType = this . _eorReasonTypes . match ( {
243+ Success : ( eorReasonTypes ) => eorReasonTypes . find (
244+ ( eorReasonType ) => eorReasonType . category === category && eorReasonType . title === title ,
245+ ) ,
246+ Other : ( ) => null ,
247+ } ) ;
248+
215249 if ( reasonType ) {
216250 this . runPatch . addEorReason ( { reasonTypeId : reasonType . id , description } ) ;
217251 }
@@ -220,7 +254,7 @@ export class RunDetailsModel extends Observable {
220254 /**
221255 * Returns the model handling the tag picking for run update
222256 *
223- * @return {PickerModel } the picker model
257+ * @return {TagSelectionDropdownModel } the picker model
224258 */
225259 get editionTagPickerModel ( ) {
226260 return this . _editionTagPickerModel ;
@@ -229,7 +263,7 @@ export class RunDetailsModel extends Observable {
229263 /**
230264 * Set the current edition tag picker model and register required observers
231265 *
232- * @param {PickerModel } editionTagPickerModel the new tag picker model
266+ * @param {TagSelectionDropdownModel } editionTagPickerModel the new tag picker model
233267 */
234268 set editionTagPickerModel ( editionTagPickerModel ) {
235269 this . _editionTagPickerModel = editionTagPickerModel ;
@@ -258,7 +292,7 @@ export class RunDetailsModel extends Observable {
258292 * Wrap the call to a function that fetch runs and update the model with the received data
259293 *
260294 * @param {function } fetchRuns the function that actually fetch runs
261- * @return {Promise<void > } resolves once the runs are fetched and the model has been updated accordingly
295+ * @return {Promise<Run > } resolves once the runs are fetched and the model has been updated accordingly
262296 * @private
263297 */
264298 async _handleFetchRemoteRun ( fetchRuns ) {
@@ -267,14 +301,15 @@ export class RunDetailsModel extends Observable {
267301 this . _runDetails = RemoteData . success ( run ) ;
268302 this . _runPatch = new RunPatch ( run ) ;
269303 this . _runPatch . bubbleTo ( this ) ;
304+
270305 this . editionTagPickerModel = new TagSelectionDropdownModel ( { defaultSelection : run . tags . map ( tagToOption ) } ) ;
271306 this . _tabbedPanelModel . runNumber = run . runNumber ;
272307 this . _runNumber = run . runNumber ;
308+ this . notify ( ) ;
309+ return run ;
273310 } catch ( error ) {
274311 this . _runDetails = RemoteData . failure ( error ) ;
275312 }
276-
277- this . notify ( ) ;
278313 }
279314
280315 /**
@@ -295,6 +330,28 @@ export class RunDetailsModel extends Observable {
295330
296331 this . notify ( ) ;
297332 }
333+
334+ /**
335+ * Fetch the trigger counters data for the current run
336+ *
337+ * @return {Promise<void> } resolves once data has been fetched or request failed
338+ * @private
339+ */
340+ async _fetchCtpTriggerCounters ( ) {
341+ if ( this . _runNumber !== null ) {
342+ this . _ctpTriggerCounters = RemoteData . loading ( ) ;
343+ this . notify ( ) ;
344+
345+ try {
346+ const { data : ctpTriggerCountersOfRun } = await getRemoteData ( `/api/ctp-trigger-counters/${ this . _runNumber } ` ) ;
347+ this . _ctpTriggerCounters = RemoteData . success ( ctpTriggerCountersOfRun ) ;
348+ } catch ( error ) {
349+ this . _ctpTriggerCounters = RemoteData . failure ( error ) ;
350+ }
351+
352+ this . notify ( ) ;
353+ }
354+ }
298355}
299356
300357/**
@@ -334,9 +391,6 @@ class RunDetailsTabbedPanelModel extends TabbedPanelModel {
334391 case RUN_DETAILS_PANELS_KEYS . DPL_PROCESSES :
335392 this . _fetchDplTasksPanelData ( ) ;
336393 break ;
337- case RUN_DETAILS_PANELS_KEYS . CTP_TRIGGER_COUNTERS :
338- this . _fetchCtpTriggerCountersPanelData ( ) ;
339- break ;
340394 }
341395 }
342396
@@ -409,28 +463,6 @@ class RunDetailsTabbedPanelModel extends TabbedPanelModel {
409463 this . notify ( ) ;
410464 }
411465 }
412-
413- /**
414- * Fetch the trigger counters data for the current run
415- *
416- * @return {void } resolves once data has been fetched or request failed
417- * @private
418- */
419- async _fetchCtpTriggerCountersPanelData ( ) {
420- this . currentPanelData = RemoteData . loading ( ) ;
421- this . notify ( ) ;
422-
423- if ( this . _runNumber !== null ) {
424- try {
425- const { data : ctpTriggerCountersOfRun } = await getRemoteData ( `/api/ctp-trigger-counters/${ this . _runNumber } ` ) ;
426- this . currentPanelData = RemoteData . success ( ctpTriggerCountersOfRun ) ;
427- } catch ( error ) {
428- this . currentPanelData = RemoteData . failure ( error ) ;
429- }
430- }
431-
432- this . notify ( ) ;
433- }
434466}
435467
436468/**
0 commit comments