Skip to content
Open
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
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 = 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);
}

/**
* Return the underlying selection dropdown model
* Sets selected options based on a comma-seperated string.
* Accounts for the options being either RemoteData or an array.
*
* @return {SelectionDropdownModel} the dropdown model
* @return {string}
*/
get selectionDropdownModel() {
return this._selectionDropdownModel;
set normalized(value) {
this.normalized = magnetsCurrentLevelsToKey(value).value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class MultiCompositionFilterModel extends FilterModel {
* @type {Object<string|number, FilterModel|SelectionModel>}
*/
this._filters = {};
this._normalizeBacklog = {};

Object.entries(filters).forEach(([key, filter]) => this.putFilter(key, filter));
}
Expand All @@ -39,12 +40,13 @@ export class MultiCompositionFilterModel extends FilterModel {
* @return {FilterModel} the subfilter
*/
putFilter(key, filterModel) {
if (key in this._filters) {
if (this.isInComposition(key)) {
return;
}

this._filters[key] = filterModel;
this._addSubmodel(filterModel);
this._applyBacklogEntry(key, filterModel);
}

/**
Expand All @@ -54,7 +56,7 @@ export class MultiCompositionFilterModel extends FilterModel {
* @param {FilterModel} filter the the subfilter
*/
getFilter(key) {
if (!(key in this._filters)) {
if (!this.isInComposition(key)) {
throw new Error(`No filter found with key ${key}`);
}

Expand Down Expand Up @@ -89,4 +91,40 @@ export class MultiCompositionFilterModel extends FilterModel {

return normalized;
}

/**
* Checks whether a filter with the given key exists in the composition.
*
* @param {string|number} key The key of the subfilter to check.
* @returns {boolean} `true` if a filter with the given key exists, otherwise `false`.
*/
isInComposition(key) {
return key in this._filters;
}

/**
* Apply any queued normalization value for a newly added filter
*
* @param {string|number} key
* @param {FilterModel} filterModel
*/
_applyBacklogEntry(key, filterModel) {
if (key in this._normalizeBacklog) {
filterModel.normalized = this._normalizeBacklog[key];
delete this._normalizeBacklog[key];
}
}

/**
* @inheritDoc
*/
set normalized(filters) {
for (const [key, value] of Object.entries(filters)) {
if (this.isInComposition(key)) {
this._filters[key].normalized = value;
} else {
this._normalizeBacklog[key] = 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
Loading
Loading