@@ -14,6 +14,7 @@ import { buildUrl, RemoteData } from '/js/src/index.js';
1414import { TabbedPanelModel } from '../../../components/TabbedPanel/TabbedPanelModel.js' ;
1515import { detectorsProvider } from '../../../services/detectors/detectorsProvider.js' ;
1616import { jsonFetch } from '../../../utilities/fetch/jsonFetch.js' ;
17+ import { ObservableData } from '../../../utilities/ObservableData.js' ;
1718import { FixedPdpBeamTypeRunsOverviewModel } from '../Overview/FixedPdpBeamTypeRunsOverviewModel.js' ;
1819
1920export const RUNS_PER_LHC_PERIOD_PANELS_KEYS = {
@@ -35,38 +36,73 @@ export class RunsPerLhcPeriodOverviewModel extends FixedPdpBeamTypeRunsOverviewM
3536 this . _detectors$ = detectorsProvider . physical$ ;
3637 this . _detectors$ . bubbleTo ( this ) ;
3738
39+ this . _lhcPeriodId = null ;
40+ this . _lhcPeriod$ = new ObservableData ( RemoteData . notAsked ( ) ) ;
41+ this . _lhcPeriod$ . bubbleTo ( this ) ;
42+
3843 this . _tabbedPanelModel = new RunsPerLhcPeriodTabbedPanelModel ( ) ;
3944 this . _tabbedPanelModel . bubbleTo ( this ) ;
4045 }
4146
47+ /**
48+ * Fetch LHC period data which runs are fetched
49+ * @return {Promise<void> } promise
50+ */
51+ async _fetchLhcPeriod ( ) {
52+ this . _lhcPeriod$ . setCurrent ( RemoteData . loading ( ) ) ;
53+ try {
54+ const { data : [ lhcPeriod ] } = await jsonFetch ( `/api/lhcPeriodsStatistics?filter[ids][]=${ this . _lhcPeriodId } ` ) ;
55+ this . _lhcPeriod$ . setCurrent ( RemoteData . success ( lhcPeriod ) ) ;
56+ } catch ( error ) {
57+ this . _lhcPeriod$ . setCurrent ( RemoteData . failure ( error ) ) ;
58+ }
59+ }
60+
61+ /**
62+ * @inheritdoc
63+ */
64+ async load ( ) {
65+ if ( ! this . _lhcPeriodId ) {
66+ return ;
67+ }
68+
69+ this . _fetchLhcPeriod ( ) . then ( ( ) =>
70+ this . _lhcPeriod$ . getCurrent ( ) . match ( {
71+ Success : ( { pdpBeamTypes } ) => this . setPdpBeamTypes ( pdpBeamTypes ) ,
72+ Other : ( ) => null ,
73+ } ) ) ;
74+
75+ super . load ( ) ;
76+ }
77+
4278 /**
4379 * @inheritdoc
4480 */
4581 getRootEndpoint ( ) {
4682 return buildUrl ( super . getRootEndpoint ( ) , {
4783 filter : {
48- lhcPeriods : this . _lhcPeriodName ,
84+ lhcPeriodIds : [ this . _lhcPeriodId ] ,
4985 runQualities : 'good' ,
5086 definitions : 'PHYSICS' ,
5187 } ,
5288 } ) ;
5389 }
5490
5591 /**
56- * Get name of current lhc period which runs are fetched
92+ * Get LHC period which runs are fetched
5793 */
58- get lhcPeriodName ( ) {
59- return this . _lhcPeriodName ;
94+ get lhcPeriod ( ) {
95+ return this . _lhcPeriod$ . getCurrent ( ) ;
6096 }
6197
6298 /**
63- * Set name of current lhc period which runs are fetched
99+ * Set id of current LHC period which runs are fetched
64100 *
65- * @param {string } lhcPeriodName name of LHC period
101+ * @param {string } lhcPeriodId id of a LHC period
66102 */
67- set lhcPeriodName ( lhcPeriodName ) {
68- this . _lhcPeriodName = lhcPeriodName ;
69- this . _tabbedPanelModel . lhcPeriodName = lhcPeriodName ;
103+ set lhcPeriodId ( lhcPeriodId ) {
104+ this . _lhcPeriodId = lhcPeriodId ;
105+ this . _tabbedPanelModel . lhcPeriodId = lhcPeriodId ;
70106 }
71107
72108 /**
@@ -119,17 +155,17 @@ class RunsPerLhcPeriodTabbedPanelModel extends TabbedPanelModel {
119155 * @return {Promise<void> } resolved once data are fetched
120156 */
121157 async _fetchSynchronousQcSummary ( ) {
122- if ( this . _lhcPeriodName ) {
158+ if ( this . _lhcPeriodId ) {
123159 this . currentPanelData = RemoteData . loading ( ) ;
124160 this . notify ( ) ;
125161 try {
126- const { data : [ lhcPeriod ] } = await jsonFetch ( `/api/lhcPeriodsStatistics?filter[names][]= ${ this . _lhcPeriodName } ` ) ;
127- if ( ! lhcPeriod ) {
128- this . currentPanelData = RemoteData . failure ( [ { title : `Cannot find LHC period with name ' ${ this . _lhcPeriodName } '` } ] ) ;
129- } else {
130- const { data : qcSummary } = await jsonFetch ( `/api/qcFlags/summary?lhcPeriodId= ${ lhcPeriod . id } ` ) ;
131- this . currentPanelData = RemoteData . success ( qcSummary ) ;
132- }
162+ const { data : qcSummary } = await jsonFetch ( buildUrl (
163+ '/api/qcFlags/summary' ,
164+ {
165+ lhcPeriodId : this . _lhcPeriodId ,
166+ } ,
167+ ) ) ;
168+ this . currentPanelData = RemoteData . success ( qcSummary ) ;
133169 } catch ( errors ) {
134170 this . currentPanelData = RemoteData . failure ( errors ) ;
135171 }
@@ -138,12 +174,12 @@ class RunsPerLhcPeriodTabbedPanelModel extends TabbedPanelModel {
138174 }
139175
140176 /**
141- * Set LHC period name
177+ * Set LHC period id
142178 *
143- * @param {string } lhcPeriodName name of LHC period
179+ * @param {id } lhcPeriodId id of LHC period
144180 */
145- set lhcPeriodName ( lhcPeriodName ) {
146- this . _lhcPeriodName = lhcPeriodName ;
181+ set lhcPeriodId ( lhcPeriodId ) {
182+ this . _lhcPeriodId = lhcPeriodId ;
147183 this . _fetchCurrentPanelData ( ) ;
148184 }
149185}
0 commit comments