Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/public/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Detectors from './views/detectors/Detectors.js';
import Runs from './views/runs/Runs.js';
import PeriodsModel from './views/periods/PeriodsModel.js';
import UserPreferences from './model/UserPreferences.js';
import RunsPerPeriodModel from './views/runs/newRunsPerPeriod/RunsPerPeriodModel.js';
const { roles, dataAccess, pageNames } = RCT;

export default class Model extends Observable {
Expand Down Expand Up @@ -49,6 +50,9 @@ export default class Model extends Observable {
this.periods = new PeriodsModel(this);
this.periods.bubbleTo(this);

this.runsPerPeriod = new RunsPerPeriodModel(this);
this.runsPerPeriod.bubbleTo(this);

this.runs = new Runs(this);
this.runs.bubbleTo(this);

Expand Down Expand Up @@ -77,6 +81,11 @@ export default class Model extends Observable {
case pageNames.periods:
await this.periods.fetchCurrentPagePeriods();
break;
case pageNames.runsPerPeriod:
if (this.router.params.periodId) {
await this.runsPerPeriod.fetchSelectedPeriod(this.router.params.periodId);
}
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion app/public/views/periods/PeriodsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class PeriodsModel extends Observable {
'page[limit]': this._pagination.itemsPerPage,
};

this._allPeriods = RemoteData.notAsked();
this._currentPagePeriods = RemoteData.notAsked();

const endpoint = `/api/periods?${new URLSearchParams(params).toString()}`;
try {
Expand Down
126 changes: 126 additions & 0 deletions app/public/views/runs/newRunsPerPeriod/RunsModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* @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 { Observable, RemoteData } from '/js/src/index.js';
import { PaginationModel } from '../../../components/table/pagination/PaginationModel.js';
import { RCT } from '../../../config.js';
import { getRemoteDataSlice } from '../../../utils/fetch/getRemoteDataSlice.js';

/**
* Model representing handlers for periods page
*
* @implements {Observable}
*/
export default class RunsModel extends Observable {
/**
* The constructor of the Overview model object
* @param {Model} model Pass the model to access the defined functions
* @param {RemoteData} period period that the runs are anchored to
* @returns {Object} Constructs the Overview model
*/
constructor(model, period) {
super();
this.model = model;
this.period = period;

this._pagination = new PaginationModel(model.userPreferences);
this._pagination.observe(() => {
this.fetchCurrentPageRuns();
this.notify();
});

this._fields = Object.keys(RCT.fieldNames.runs).map((field) => ({ name: field, visible: true }));

this._sortingRowVisible = false;

this._allRuns = RemoteData.notAsked();
this._currentPageRuns = RemoteData.notAsked();
}

/**
* Fetch all the relevant runs from the API
* @return {Promise<void>} void
*/
async fetchAllRuns() {
/**
* @type {Run[]}
*/
this._allRuns = RemoteData.loading();
this.notify();

this._allRuns = RemoteData.notAsked();

const endpoint = `/api/periods/${this.period.id}/runs`;
try {
const { items, totalCount } = await getRemoteDataSlice(endpoint);
this._allRuns = RemoteData.success([...items]);
this._pagination.itemsCount = totalCount;
} catch (errors) {
this._allRuns = RemoteData.failure(errors);
}

this.notify();
}

/**
* Fetch all the relevant runs from the API
* @return {Promise<void>} void
*/
async fetchCurrentPageRuns() {
/**
* @type {Run[]}
*/

if (this._allRuns.kind === 'NotAsked') {
await this.fetchAllRuns();
}

this._currentPageRuns = RemoteData.loading();
this.notify();

const params = {
'page[offset]': this._pagination.firstItemOffset,
'page[limit]': this._pagination.itemsPerPage,
};

this._currentPageRuns = RemoteData.notAsked();

const endpoint = `/api/periods/${this.period.id}/runs/?${new URLSearchParams(params).toString()}`;
try {
const { items, totalCount } = await getRemoteDataSlice(endpoint);
this._currentPagePeriods = RemoteData.success([...items]);
this._pagination.currentPageItemsCount = totalCount;
} catch (errors) {
this._currentPagePeriods = RemoteData.failure(errors);
}

this.notify();
}

/**
* Fetch all the relevant data from the API
*
* @return {Promise<void>} void
*/
async fetchCurrentPageData() {
await this.fetchCurrentPageRuns();
}

get fields() {
return this._fields;
}

get allRuns() {
return this._allRuns;
}
}
97 changes: 97 additions & 0 deletions app/public/views/runs/newRunsPerPeriod/RunsPerPeriodModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @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 { Observable, RemoteData } from '/js/src/index.js';
import { RCT } from '../../../config.js';
import { pageTitle } from '../../../components/common/pageTitle.js';
import { getRemoteDataSlice } from '../../../utils/fetch/getRemoteDataSlice.js';
import RunsModel from './RunsModel.js';

/**
* Model representing handlers for periods page
*
* @implements {OverviewModel}
*/
export default class RunsPerPeriodModel extends Observable {
/**
* The constructor of the Overview model object
* @param {Model} model Pass the model to access the defined functions
* @returns {Object} Constructs the Overview model
*/
constructor(model) {
super();
this.model = model;
this.name = pageTitle(RCT.pageNames.runsPerPeriod, RCT.pageNames);

this._selectedPeriod = RemoteData.notAsked();
this._periods = {};
this._allRuns = {};
}

/**
* Fetch all the relevant periods from the API
* @param {string} periodId id of the period that the runs are anchored to
* @return {Promise<void>} void
*/
async fetchSelectedPeriod(periodId) {
this._selectedPeriod = RemoteData.loading();
this.notify();

this._selectedPeriod = RemoteData.notAsked();

const endpoint = `api/periods/?filter[id]=${periodId}`;
try {
const { items } = await getRemoteDataSlice(endpoint);
this._selectedPeriod = RemoteData.success([...items]);
this._periods[periodId] = this._selectedPeriod.payload.find((e) => Boolean(e));
// Console.log(this._periods);
} catch (errors) {
this._selectedPeriod = RemoteData.failure(errors);
}

await this.fetchCurrentPageData(periodId);

this.notify();
}

/**
* Fetch all the relevant periods from the API
* @param {string} periodId id of the period that the runs are anchored to
* @return {Promise<void>} void
*/
async fetchCurrentPageRunsPerPeriod(periodId) {
this._allRuns[periodId] = new RunsModel(this.model, this._selectedPeriod.payload.find((e) => e));
await this._allRuns[periodId].fetchCurrentPageRuns();
}

/**
* Fetch all the relevant data from the API
* @param {string} periodId id of the period that the runs are anchored to
* @return {Promise<void>} void
*/
async fetchCurrentPageData(periodId) {
await this.fetchCurrentPageRunsPerPeriod(periodId);
}

get selectedPeriod() {
return this._selectedPeriod;
}

get periods() {
return this._periods;
}

get allRuns() {
return this._allRuns;
}
}
4 changes: 2 additions & 2 deletions app/public/views/runs/runsPerPeriod/overview/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import content from './content.js';

export default function panel(model, runs, detectors) {
const urlParams = model.router.getUrl().searchParams;
const periodName = urlParams.get('index');
const index = urlParams.get('index');

return periodName
return index
? content(model, runs, detectors)
: noSubPageSelected(model);
}