Skip to content
Draft
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
12 changes: 12 additions & 0 deletions lib/database/repositories/LhcFillRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const getFillNumbersWithStableBeamsEndedInPeriodQuery = (period) => `
AND stable_beams_start IS NOT NULL
`;

const getLhcFillDistinctBeamTypesQuery = () => `
SELECT DISTINCT beam_type FROM bookkeeping.lhc_fills
`;

/**
* Sequelize implementation of the RunRepository.
*/
Expand All @@ -45,6 +49,14 @@ class LhcFillRepository extends Repository {
super(LhcFill);
}

/**
* Return the list of LHC fills distict beam types.
* @returns {Promise<object[]>}
*/
async getLhcFillDistinctBeamTypes() {
return await sequelize.query(getLhcFillDistinctBeamTypesQuery(), { type: QueryTypes.SELECT, raw: true });
}

/**
* Return the list of LHC fills numbers for fills with stable beams that ended in the given period
*
Expand Down
35 changes: 34 additions & 1 deletion lib/database/utilities/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Sets an exact match filter using the provided value.
*
* @param {*} value The required value.

Check warning on line 36 in lib/database/utilities/QueryBuilder.js

View workflow job for this annotation

GitHub Actions / linter

Prefer a more specific type to `*`
* @returns {QueryBuilder} The current QueryBuilder instance.
*/
is(value) {
Expand All @@ -54,7 +54,7 @@
* or
* * if value is null
*
* @param {*} value The required value.

Check warning on line 57 in lib/database/utilities/QueryBuilder.js

View workflow job for this annotation

GitHub Actions / linter

Prefer a more specific type to `*`
* @returns {QueryBuilder} The current QueryBuilder instance.
*/
isOrNull(value) {
Expand All @@ -72,7 +72,7 @@
/**
* Sets an **AND** match filter using the provided values.
*
* @param {...any} values The required values.

Check warning on line 75 in lib/database/utilities/QueryBuilder.js

View workflow job for this annotation

GitHub Actions / linter

Prefer a more specific type to `any`
* @returns {QueryBuilder} The current QueryBuilder instance.
*/
allOf(...values) {
Expand All @@ -88,7 +88,7 @@
}

/**
* Sets an **OR** match filter using the provided values.
* Sets an **IN** match filter using the provided values.
*
* @param {...any} values The required values.
* @returns {QueryBuilder} The current QueryBuilder instance.
Expand All @@ -104,6 +104,39 @@
return this._op(operation);
}

/**
* Sets an **OR** match filter using the provided values.
* Adds an **OR NULL** filter.
* If the spread returns empty array the filter becomes an **IS NULL** filter (**OR** is not valid anymore)
*
* @param {...any} values The required values.
* @returns {QueryBuilder} The current QueryBuilder instance.
*/
oneOfOrNull(...values) {
let operation;
if (this.notFlag) {
operation = values[0]?.length === 0 ? {
[Op.not]: null,
} : {
[Op.or]: {
[Op.notIn]: values,
[Op.not]: null,
},
};
} else {
operation = values[0]?.length === 0 ? {
[Op.is]: null,
} : {
[Op.or]: {
[Op.in]: values,
[Op.is]: null,
},
};
}

return this._op(operation);
}

/**
* Set a max range limit using the provided value
*
Expand Down
28 changes: 28 additions & 0 deletions lib/domain/dtos/GetAllBeamsTypesDto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @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.
*/

const Joi = require('joi');
const PaginationDto = require('./PaginationDto');

const QueryDto = Joi.object({
page: PaginationDto,
token: Joi.string(),
});

const GetAllBeamsTypesDto = Joi.object({
body: Joi.object({}),
params: Joi.object({}),
query: QueryDto,
});

module.exports = GetAllBeamsTypesDto;
1 change: 1 addition & 0 deletions lib/domain/dtos/filters/LhcFillsFilterDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ exports.LhcFillsFilterDto = Joi.object({
'any.invalid': '{{#message}}',
}),
runDurationOperator: Joi.string().trim().min(1).max(2),
beamsType: Joi.string(),
});
2 changes: 2 additions & 0 deletions lib/domain/dtos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const CreateLhcFillDto = require('./CreateLhcFillDto');
const CreateLogDto = require('./CreateLogDto');
const CreateTagDto = require('./CreateTagDto');
const EntityIdDto = require('./EntityIdDto');
const GetAllBeamsTypesDto = require('./GetAllBeamsTypesDto.js');
const GetAllEnvironmentsDto = require('./GetAllEnvironmentsDto');
const GetAllLhcFillsDto = require('./GetAllLhcFillsDto');
const GetAllLogAttachmentsDto = require('./GetAllLogAttachmentsDto');
Expand Down Expand Up @@ -56,6 +57,7 @@ module.exports = {
CreateTagDto,
EndRunDto,
EntityIdDto,
GetAllBeamsTypesDto,
GetAllEnvironmentsDto,
GetAllLhcFillsDto,
GetAllLogAttachmentsDto,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE Trg. 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-Trg.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 { beamsTypesProvider } from '../../../services/beamsTypes/beamsTypesProvider.js';
import { SelectionModel } from '../../common/selection/SelectionModel.js';

/**
* Beam type filter model
*/
export class BeamsTypeFilterModel extends SelectionModel {
/**
* Constructor
*/
constructor() {
let beamTypes = [];
super({ availableOptions: beamTypes,
defaultSelection: [],
multiple: true,
allowEmpty: true });

beamsTypesProvider.items$.observe(() => {
beamsTypesProvider.items$.getCurrent().apply({
Success: (types) => {
beamTypes = types.map((type) => ({ value: String(type.beam_type) }));
this.setAvailableOptions(beamTypes);
},
});
});
}

/**
* Get normalized selected option
*/
get normalized() {
return this.selected.join(',');
}

/**
* Reset the filter to default values
*
* @return {void}
*/
resetDefaults() {
if (!this.isEmpty) {
this.reset();
this.notify();
}
}
}
26 changes: 26 additions & 0 deletions lib/public/components/Filters/LhcFillsFilter/beamsTypeFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @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 { checkboxes } from '../common/filters/checkboxFilter.js';

/**
* Renders a list of checkboxes that lets the user look for beam types
*
* @param {BeamsTypeFilterModel} beamsTypeFilterModel beamsTypeFilterModel
* @return {Component} the filter
*/
export const beamsTypeFilter = (beamsTypeFilterModel) =>
checkboxes(
beamsTypeFilterModel,
{ selector: 'beams-types' },
);
30 changes: 30 additions & 0 deletions lib/public/services/beamsTypes/beamsTypesProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @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 { getRemoteData } from '../../utilities/fetch/getRemoteData.js';
import { RemoteDataProvider } from '../RemoteDataProvider.js';

/**
* Service class to fetch beams types from the backend
*/
export class BeamsTypesProvider extends RemoteDataProvider {
/**
* @inheritDoc
*/
async getRemoteData() {
const { data } = await getRemoteData('/api/beamsTypes');
return data;
}
}

export const beamsTypesProvider = new BeamsTypesProvider();
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { toggleStableBeamOnlyFilter } from '../../../components/Filters/LhcFills
import { fillNumberFilter } from '../../../components/Filters/LhcFillsFilter/fillNumberFilter.js';
import { beamDurationFilter } from '../../../components/Filters/LhcFillsFilter/beamDurationFilter.js';
import { runDurationFilter } from '../../../components/Filters/LhcFillsFilter/runDurationFilter.js';
import { beamsTypeFilter } from '../../../components/Filters/LhcFillsFilter/beamsTypeFilter.js';

/**
* List of active columns for a lhc fills table
Expand Down Expand Up @@ -170,6 +171,7 @@ export const lhcFillsActiveColumns = {
visible: true,
size: 'w-8',
format: (value) => formatBeamType(value),
filter: (lhcFillModel) => beamsTypeFilter(lhcFillModel.filteringModel.get('beamsType')),
},
collidingBunches: {
name: 'Colliding bunches',
Expand Down
11 changes: 11 additions & 0 deletions lib/public/views/LhcFills/Overview/LhcFillsOverviewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { StableBeamFilterModel } from '../../../components/Filters/LhcFillsFilte
import { RawTextFilterModel } from '../../../components/Filters/common/filters/RawTextFilterModel.js';
import { OverviewPageModel } from '../../../models/OverviewModel.js';
import { addStatisticsToLhcFill } from '../../../services/lhcFill/addStatisticsToLhcFill.js';
import { BeamsTypeFilterModel } from '../../../components/Filters/LhcFillsFilter/BeamsTypeFilterModel.js';

const defaultBeamDurationOperator = '=';
const defaultRunDurationOperator = '=';
Expand All @@ -35,11 +36,14 @@ export class LhcFillsOverviewModel extends OverviewPageModel {
constructor(stableBeamsOnly = false) {
super();

this._beamsTypes = [];

this._filteringModel = new FilteringModel({
fillNumbers: new RawTextFilterModel(),
beamDuration: new RawTextFilterModel(),
runDuration: new RawTextFilterModel(),
hasStableBeams: new StableBeamFilterModel(),
beamsType: new BeamsTypeFilterModel(),
});

this._beamDurationOperator = defaultBeamDurationOperator;
Expand Down Expand Up @@ -81,6 +85,13 @@ export class LhcFillsOverviewModel extends OverviewPageModel {
return buildUrl('/api/lhcFills', params);
}

/**
* Getter
*/
getBeamsTypes() {
return this._beamsTypes;
}

/**
* Setter function for runDurationOperator
*/
Expand Down
62 changes: 62 additions & 0 deletions lib/server/controllers/beamsTypes.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @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.
*/

const {
beamsType: {
GetAllBeamsTypesUseCase,
},
} = require('../../usecases/index.js');
const {
dtos: {
GetAllBeamsTypesDto,
},
} = require('../../domain/index.js');
const { dtoValidator } = require('../utilities/index.js');
const { ApiConfig } = require('../../config/index.js');

/**
* Get all beams types.
*
* @param {Object} request The *request* object represents the HTTP request and has properties for the request query
* string, parameters, body, HTTP headers, and so on.
* @param {Object} response The *response* object represents the HTTP response that an Express app sends when it gets an
* HTTP request.
* @returns {undefined}
*/
const listBeamsTypes = async (request, response) => {
const value = await dtoValidator(GetAllBeamsTypesDto, request, response);
if (!value) {
return;
}

const { count, beamsTypes } = await new GetAllBeamsTypesUseCase()
.execute(value);

const { query: { page: { limit = ApiConfig.pagination.limit } = {} } } = value;
const totalPages = Math.ceil(count / limit);

response.status(200).json({
data: beamsTypes,
meta: {
page: {
pageCount: totalPages,
totalCount: count,
},
},
});
};

module.exports = {
listBeamsTypes,
};
2 changes: 2 additions & 0 deletions lib/server/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const AttachmentsController = require('./attachments.controller');
const BeamsTypeController = require('./beamsTypes.controller.js');
const ConfigurationController = require('./configuration.controller.js');
const DetectorsController = require('./detectors.controller');
const EnvironmentsController = require('./environments.controller');
Expand All @@ -26,6 +27,7 @@ const CtpTriggerCountersController = require('./ctpTriggerCounters.controller');

module.exports = {
AttachmentsController,
BeamsTypeController,
ConfigurationController,
DetectorsController,
EnvironmentsController,
Expand Down
20 changes: 20 additions & 0 deletions lib/server/routers/beamsTypes.router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @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.
*/

const { BeamsTypeController } = require('../controllers');

exports.beamsTypesRouter = {
path: '/beamsTypes',
controller: BeamsTypeController.listBeamsTypes,
method: 'get',
};
Loading
Loading