-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4166fe
commit 5fe9f8a
Showing
5 changed files
with
135 additions
and
79 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
lib/public/components/Filters/RunsFilter/RunDefinitionFilterModel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { RunDefinition } from '../../../domain/enums/RunDefinition.js'; | ||
import { FilterModel } from '../common/FilterModel.js'; | ||
|
||
/** | ||
* Run definition filter model | ||
*/ | ||
export class RunDefinitionFilterModel extends FilterModel { | ||
/** | ||
* Constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
this._definitions = []; | ||
} | ||
|
||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* @inheritDoc | ||
*/ | ||
reset() { | ||
this._definitions = []; | ||
} | ||
|
||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* @inheritDoc | ||
*/ | ||
get isEmpty() { | ||
return this._definitions.length === 0; | ||
} | ||
|
||
// eslint-disable-next-line valid-jsdoc | ||
/** | ||
* @inheritDoc | ||
*/ | ||
get normalized() { | ||
return this._definitions.join(','); | ||
} | ||
|
||
/** | ||
* States if the given definition is currently in the run definition filter | ||
* | ||
* @param {string} definition the run definition to look for | ||
* @return {boolean} true if the definition is included in the filter | ||
*/ | ||
isDefinitionInFilter(definition) { | ||
return this._definitions.includes(definition); | ||
} | ||
|
||
/** | ||
* Add a given definition in the current run definition filter if it is not already present | ||
* | ||
* @param {string} definition the run definition to add | ||
* @return {void} | ||
*/ | ||
addDefinition(definition) { | ||
if (!this.isDefinitionInFilter(definition)) { | ||
this._definitions.push(definition); | ||
this.notify(); | ||
} | ||
} | ||
|
||
/** | ||
* Remove a given definition from the current run definition filter if it is in it (else do nothing) | ||
* | ||
* @param {string} definition the definition to add | ||
* @return {void} | ||
*/ | ||
removeDefinition(definition) { | ||
const originalLength = this._definitions._definitions; | ||
this._definitions = this._definitions.filter((existingDefinition) => definition !== existingDefinition); | ||
if (this._definitions.length !== originalLength) { | ||
this.notify(); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the current filter to physics only | ||
* | ||
* @return {void} | ||
*/ | ||
setPhysicsOnly() { | ||
if (!this.isPhysicsOnly()) { | ||
this._definitions = [RunDefinition.Physics]; | ||
this.notify(); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the current filter is physics only | ||
* | ||
* @return {boolean} true if filter is physics only | ||
*/ | ||
isPhysicsOnly() { | ||
return this._definitions.length === 1 && this._definitions[0] === RunDefinition.Physics; | ||
} | ||
|
||
/** | ||
* Empty the current filter | ||
* | ||
* @return {void} | ||
*/ | ||
setEmpty() { | ||
if (!this.isEmpty) { | ||
this.reset(); | ||
this.notify(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters