Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
*/

import { beamTypesProvider } from '../../../services/beamTypes/beamTypesProvider.js';
import { SelectionFilterModel } from '../common/filters/SelectionFilterModel.js';
import { SelectionModel } from '../../common/selection/SelectionModel.js';

/**
* Beam type filter model
*/
export class BeamTypeFilterModel extends SelectionFilterModel {
export class BeamTypeFilterModel extends SelectionModel {
/**
* Constructor
*/
Expand All @@ -28,7 +28,7 @@ export class BeamTypeFilterModel extends SelectionFilterModel {
beamTypesProvider.items$.getCurrent().apply({
Success: (types) => {
const beamTypes = types.map((type) => ({ value: type.beam_type }));
this._selectionModel.setAvailableOptions(beamTypes);
this.setAvailableOptions(beamTypes);
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ import { checkboxes } from '../common/filters/checkboxFilter.js';
* @param {BeamTypeFilterModel} beamTypeFilterModel beamTypeFilterModel
* @return {Component} the filter
*/
export const beamTypeFilter = (beamTypeFilterModel) =>
checkboxes(
beamTypeFilterModel.selectionModel,
{ selector: 'beam-types' },
);
export const beamTypeFilter = (beamTypeFilterModel) => checkboxes(beamTypeFilterModel, { selector: 'beam-types' });
37 changes: 2 additions & 35 deletions lib/public/components/Filters/RunsFilter/BeamModeFilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,17 @@
*/

import { ObservableBasedSelectionDropdownModel } from '../../detector/ObservableBasedSelectionDropdownModel.js';
import { FilterModel } from '../common/FilterModel.js';

/**
* Beam mode filter model
*/
export class BeamModeFilterModel extends FilterModel {
export class BeamModeFilterModel extends ObservableBasedSelectionDropdownModel {
/**
* Constructor
*
* @param {ObservableData<RemoteData<{name: string}, ApiError>>} beamModes$ observable remote data of objects representing beam modes
*/
constructor(beamModes$) {
super();
this._selectionDropdownModel = new ObservableBasedSelectionDropdownModel(beamModes$, ({ name }) => ({ value: name }));
this._addSubmodel(this._selectionDropdownModel);
}

/**
* @inheritDoc
*/
reset() {
this._selectionDropdownModel.reset();
}

/**
* @inheritDoc
*/
get isEmpty() {
return this._selectionDropdownModel.isEmpty;
}

/**
* Return the underlying dropdown model
*
* @return {ObservableDropDownModel} the underlying dropdown model
*/
get selectionDropdownModel() {
return this._selectionDropdownModel;
}

/**
* @inheritDoc
*/
get normalized() {
return this._selectionDropdownModel.selected;
super(beamModes$, ({ name }) => ({ value: name }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export class DetectorsFilterModel extends FilterModel {
return normalized;
}

/**
* @inheritDoc
*/
set normalized({ operator, values }) {
this._combinationOperatorModel.normalized = operator;
this._dropdownModel.normalized = values;
}

/**
* Return true if the current combination operator is none
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export class EorReasonFilterModel extends FilterModel {
return ret;
}

/**
* @inheritDoc
*/
set normalized({ category, title, description }) {
this._category = category;
this._title = title;
this._description = description;
}

/**
* Returns the EOR reason filter category
*
Expand Down
8 changes: 8 additions & 0 deletions lib/public/components/Filters/RunsFilter/GaqFilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export class GaqFilterModel extends FilterModel {
return normalized;
}

/**
* @inheritDoc
*/
set normalized({ notBadFraction, mcReproducibleAsNotBad }) {
this._notBadFraction.normalized = notBadFraction;
this._mcReproducibleAsNotBad.normalized = mcReproducibleAsNotBad;
}

/**
* Return the underlying notBadFraction model
*
Expand Down
75 changes: 23 additions & 52 deletions lib/public/components/Filters/RunsFilter/MagnetsFilteringModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,86 +11,57 @@
* or submit itself to any jurisdiction.
*/

import { FilterModel } from '../common/FilterModel.js';
import { ObservableBasedSelectionDropdownModel } from '../../detector/ObservableBasedSelectionDropdownModel.js';

/**
* Return the option value corresponding to a given magnets current level
*
* @param {MagnetsCurrentLevels} currentLevels the current levels
* @return {string} the option's value
* @return {object<value: string>} the option's value
*/
const magnetsCurrentLevelsToOptionValue = ({ l3, dipole }) => `${l3}kA/${dipole}kA`;
const magnetsCurrentLevelsToKey = ({ l3, dipole }) => ({ value: `${l3}kA/${dipole}kA` });

/**
* Return the magnets current lever based on a key string
*
* @param {object} option string containing the current levels
* @param {string} option.value string containing the current levels
* @return {MagnetsCurrentLevels}
*/
const keyToMagnetsCurrentLevels = (value) => {
const [l3, dipole] = value.split('/').map((str) => parseFloat(str.slice(0, -2)));
return { l3, dipole };
};

/**
* AliceL3AndDipoleFilteringModel
*/
export class MagnetsFilteringModel extends FilterModel {
export class MagnetsFilteringModel extends ObservableBasedSelectionDropdownModel {
/**
* Constructor
*
* @param {ObservableData<RemoteData<MagnetsCurrentLevels[], ApiError>>} magnetsCurrentLevels$ observable remote data of magnets current
* levels
*/
constructor(magnetsCurrentLevels$) {
super();
this._selectionDropdownModel = new ObservableBasedSelectionDropdownModel(
magnetsCurrentLevels$,
(magnetsCurrentLevels) => ({ value: magnetsCurrentLevelsToOptionValue(magnetsCurrentLevels) }),
{ multiple: false },
);
this._addSubmodel(this._selectionDropdownModel);

this._valueToFilteringParamsMap = new Map();
magnetsCurrentLevels$.observe(() => {
magnetsCurrentLevels$.getCurrent().match({

/**
* Fill map indexing current level by their corresponding value
*
* @param {MagnetsCurrentLevels[]} currentLevels the current levels to map
* @return {void}
*/
Success: (currentLevels) => {
this._valueToFilteringParamsMap = new Map(currentLevels.map(({ l3, dipole }) => [
magnetsCurrentLevelsToOptionValue({ l3, dipole }),
{ l3, dipole },
]));
},
Other: () => {
this._valueToFilteringParamsMap = new Map();
},
});
});
}

/**
* @inheritDoc
*/
reset() {
this._selectionDropdownModel.reset();
}

/**
* @inheritDoc
*/
get isEmpty() {
return this._selectionDropdownModel.isEmpty;
super(magnetsCurrentLevels$, magnetsCurrentLevelsToKey, { multiple: false });
}

/**
* @inheritDoc
*/
get normalized() {
return this._valueToFilteringParamsMap.get(this._selectionDropdownModel.selected[0]) ?? null;
const [selectedOption] = this.selected;
return keyToMagnetsCurrentLevels(selectedOption);
Comment thread
isaachilly marked this conversation as resolved.
}

/**
* Return the underlying selection dropdown model
* Sets selected options based on an object containing l3 and dipole fields.
* Accounts for the options being either RemoteData or an array.
*
* @return {SelectionDropdownModel} the dropdown model
* @param {object}
*/
get selectionDropdownModel() {
return this._selectionDropdownModel;
set normalized(value) {
super.normalized = magnetsCurrentLevelsToKey(value).value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@ export class MultiCompositionFilterModel extends FilterModel {

return normalized;
}

/**
* @inheritDoc
*/
set normalized(filters) {
for (const [key, value] of Object.entries(filters)) {
if (key in this._filters) {
this._filters[key].normalized = value;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RUN_DEFINITIONS, RunDefinition } from '../../../domain/enums/RunDefinition.js';
import { SelectionFilterModel } from '../common/filters/SelectionFilterModel.js';
import { SelectionModel } from '../../common/selection/SelectionModel.js';

/**
* Run definition filter model
*/
export class RunDefinitionFilterModel extends SelectionFilterModel {
export class RunDefinitionFilterModel extends SelectionModel {
/**
* Constructor
*/
Expand All @@ -18,7 +18,7 @@ export class RunDefinitionFilterModel extends SelectionFilterModel {
* @return {boolean} true if filter is physics only
*/
isPhysicsOnly() {
const selectedOptions = this._selectionModel.selected;
const selectedOptions = this.selected;
return selectedOptions.length === 1 && selectedOptions[0] === RunDefinition.Physics;
}

Expand All @@ -29,8 +29,8 @@ export class RunDefinitionFilterModel extends SelectionFilterModel {
*/
setPhysicsOnly() {
if (!this.isPhysicsOnly()) {
this._selectionModel.selectedOptions = [];
this._selectionModel.select(RunDefinition.Physics);
this.selectedOptions = [];
this.select(RunDefinition.Physics);
this.notify();
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/public/components/Filters/RunsFilter/TimeRangeFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export class TimeRangeFilterModel extends FilterModel {
return normalized;
}

/**
* @inheritDoc
*/
set normalized({ from, to }) {
this._timeRangeInputModel.normalized = { from, to };
}

/**
* Return the underlying time range input model
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ import { checkboxes } from '../common/filters/checkboxFilter.js';
* @param {RunDefinitionFilterModel} runDefinitionFilterModel run definition filter model
* @return {Component} the filter
*/
export const runDefinitionFilter = (runDefinitionFilterModel) => checkboxes(
runDefinitionFilterModel.selectionModel,
{ selector: 'run-definition' },
);
export const runDefinitionFilter = (runDefinitionFilterModel) => checkboxes(runDefinitionFilterModel, { selector: 'run-definition' });
11 changes: 11 additions & 0 deletions lib/public/components/Filters/common/FilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ export class FilterModel extends Observable {
throw new Error('Abstract function call');
}

/**
* Sets filters from normalised values to submodels in needed.
*
* @param {string|number|object|string[]|number[]|null} _value The value used to set filters
* @return {void} the normalized value
* @abstract
*/
set normalized(_value) {
throw new Error('Abstract function call');
}

/**
* Returns the observable notified any time there is a visual change which has no impact on the actual filter value
*
Expand Down
10 changes: 9 additions & 1 deletion lib/public/components/Filters/common/TagFilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,19 @@ export class TagFilterModel extends FilterModel {
*/
get normalized() {
return {
values: this.selected.join(),
values: this._selectionModel.normalized,
operation: this.combinationOperator,
};
}

/**
* @inheritDoc
*/
set normalized({ values, operation }) {
this._selectionModel.normalized = values;
this._combinationOperatorModel.normalized = operation;
}

/**
* Return the model handling tag selection state
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class NumericalComparisonFilterModel extends FilterModel {
constructor(options) {
super();
const { scale = 1, integer = false } = options || {};
this._scale = scale;

this._operatorSelectionModel = new ComparisonSelectionModel();
this._operatorSelectionModel.visualChange$.bubbleTo(this._visualChange$);
Expand Down Expand Up @@ -82,11 +83,24 @@ export class NumericalComparisonFilterModel extends FilterModel {
*/
get normalized() {
return {
operator: this._operatorSelectionModel.current,
limit: this._operandInputModel.value,
operator: this._operatorSelectionModel.normalized,
limit: this._operandInputModel.normalized,
};
}

/**
* @inheritDoc
*/
set normalized({ operator, limit }) {
const parsedLimit = parseFloat(limit) / this._scale;

if (!isNaN(parsedLimit)) {
this._operandInputModel.normalized = parsedLimit;
}

this._operatorSelectionModel.normalized = operator;
}

/**
* @inheritDoc
*/
Expand Down
Loading
Loading