projects/netgrif-components-core/src/lib/search/models/category/case/case-dataset.ts
constructor(operators: OperatorService, logger: LoggerService, _optionalDependencies: OptionalDependencies)
|
||||||||||||
|
Parameters :
|
| Protected _allowedNetsSub |
Type : Subscription
|
| Protected _configurationInputs$ |
Type : BehaviorSubject<Array<ConfigurationInput>>
|
| Protected Readonly _DATAFIELD_INPUT |
Type : ConfigurationInput
|
| Protected _datafieldOptions |
Type : Map<string | Array<Datafield>>
|
| Protected _datafieldOptionsInitialized$ |
Type : ReplaySubject<void>
|
| Protected _isLoadedFromPfql |
Type : boolean
|
Default value : false
|
| Protected _operatorWasLoadedFromPfql |
Default value : false
|
| Protected _processCategory |
Type : CaseProcess
|
| Protected _userAutocomplete |
Type : UserAutocomplete
|
| Protected Static Readonly DATAFIELD_METADATA |
Type : string
|
Default value : 'datafield'
|
| Protected _generatedPredicate$ |
Type : BehaviorSubject<ElementaryPredicate | undefined>
|
|
Inherited from
Category
|
|
Defined in
Category:70
|
|
Emit a new |
| Protected _operandsFormControls |
Type : Array<FormControl>
|
|
Inherited from
Category
|
|
Defined in
Category:49
|
|
Stores the |
| Protected _operandsFormControls$ |
Type : ReplaySubject<Array | undefined>
|
|
Inherited from
Category
|
|
Defined in
Category:54
|
|
Contains the |
| Protected Readonly _OPERATOR_INPUT |
Type : ConfigurationInput
|
|
Inherited from
Category
|
|
Defined in
Category:75
|
|
Utility variable that can be used as value for the configurationInputs$ |
| Protected _operatorFormControl |
Type : FormControl
|
|
Inherited from
Category
|
|
Defined in
Category:44
|
|
Contains the The category can subscribe to it if it wishes to react to the selection change by the user. |
| Protected _operatorTemplate$ |
Type : BehaviorSubject<Array | undefined>
|
|
Inherited from
Category
|
|
Defined in
Category:59
|
|
Contains the operator template parts that make up the operands GUI. |
| Protected _trackByIdGenerator |
Type : IncrementingCounter
|
|
Inherited from
Category
|
|
Defined in
Category:64
|
|
Generates IDs for template parts supplied to ng for. |
| Public Readonly translationPath |
Type : string
|
|
Inherited from
Category
|
|
Defined in
Category:91
|
|
path to the translation string
|
| Protected addToDatafieldOptionsMap | ||||||||||||
addToDatafieldOptionsMap(key: string, value: Datafield)
|
||||||||||||
|
Adds a new entry or pushes value into an existing entry. When a new entry is created, it is created as an Array of one element.
Parameters :
Returns :
void
|
| Protected createConfigurationFilterTextSegments |
createConfigurationFilterTextSegments()
|
|
Inherited from
Category
|
|
Defined in
Category:519
|
|
Returns :
Array<FilterTextSegment>
|
| Protected createDatafieldOptions |
createDatafieldOptions()
|
|
Returns :
void
|
| Protected deserializeOperandValue | ||||
deserializeOperandValue(value)
|
||||
|
Inherited from
Category
|
||||
|
Defined in
Category:507
|
||||
|
Parameters :
Returns :
Observable<any>
|
| destroy |
destroy()
|
|
Inherited from
Category
|
|
Defined in
Category:152
|
|
Returns :
void
|
| duplicate |
duplicate()
|
|
Inherited from
Category
|
|
Defined in
Category:273
|
|
Returns :
CaseDataset
|
| Static FieldTypeToInputType | ||||||
FieldTypeToInputType(fieldType: string)
|
||||||
|
Parameters :
Returns :
SearchInputType
|
| Protected generateNetConstraint | ||||||
generateNetConstraint(datafield: Datafield)
|
||||||
|
Parameters :
Returns :
Query
|
| Protected generateQuery | ||||||
generateQuery(userInput: Array<>)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:299
|
||||||
|
Parameters :
Returns :
Query
|
| Protected isNullOperatorQueryGenerationStrategy | ||||||
isNullOperatorQueryGenerationStrategy(datafield: Datafield)
|
||||||
|
Parameters :
Returns :
Query
|
| Protected isOperandValueSelected | ||||||
isOperandValueSelected(newValue: any)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:423
|
||||||
|
Parameters :
Returns :
boolean
|
| Public loadFromPfqlExpression | ||||||
loadFromPfqlExpression(expression: SimpleExpression)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:477
|
||||||
|
Parameters :
Returns :
Observable<void>
|
| Public reset |
reset()
|
|
Inherited from
Category
|
|
Defined in
Category:268
|
|
Returns :
void
|
| Public selectDatafields | ||||||||||||
selectDatafields(datafieldMapKey: string, selectDefaultOperator)
|
||||||||||||
|
Parameters :
Returns :
void
|
| Public selectDataFieldsByPfqlExpression | ||||||
selectDataFieldsByPfqlExpression(expression: DataSimpleExpression)
|
||||||
|
Parameters :
Returns :
void
|
| serializeClass |
serializeClass()
|
|
Inherited from
Category
|
|
Defined in
Category:461
|
|
Returns :
Categories | string
|
| Protected serializeOperandValue | ||||||
serializeOperandValue(valueFormControl: FormControl)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:465
|
||||||
|
Parameters :
|
| Protected standardQueryGenerationStrategy | ||||||||||||||||
standardQueryGenerationStrategy(datafield: Datafield, userInput: Array<>, escapeInput)
|
||||||||||||||||
|
Parameters :
Returns :
Query
|
| Protected transformCategoryValue | ||||||||
transformCategoryValue(value: any)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:454
|
||||||||
|
Performs a transformation of the attribute. Otherwise performs an identity operation.
Parameters :
Returns :
any
If the selected data field has input type |
| Public clearOperatorSelection |
clearOperatorSelection()
|
|
Inherited from
Category
|
|
Defined in
Category:391
|
|
Deselects the currently selected operator (if any)
Returns :
void
|
| Public createFilterTextSegments |
createFilterTextSegments()
|
|
Inherited from
Category
|
|
Defined in
Category:556
|
|
Returns :
Array<FilterTextSegment>
an Array containing text segments representing the content of the predicate generated by this category |
| Protected createOperandFilterTextSegment | ||||||
createOperandFilterTextSegment(operandIndex: number)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:592
|
||||||
|
Parameters :
Returns :
FilterTextSegment
filter text segment representing the operand value at the specified index |
| Protected createOperatorFilterTextSegments |
createOperatorFilterTextSegments()
|
|
Inherited from
Category
|
|
Defined in
Category:575
|
|
Returns :
Array<FilterTextSegment>
an Array containing text segments representing the operators with operands of this category |
| Public generatePredicate | ||||||||
generatePredicate(userInput: Array
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:356
|
||||||||
|
Calls the generateQuery method and creates an ElementaryPredicate with the result. arity of the selected Operator.
Parameters :
Returns :
ElementaryPredicate
Predicate with {@link Query} generated by this object's [generateQuery]{@link Category.generateQuery} method |
| Protected initializeCategory |
initializeCategory()
|
|
Inherited from
Category
|
|
Defined in
Category:448
|
|
This method is calle in the constructor. Apart from calling this method, the constructor only creates instances to fill the protected fields of this class. The default implementation manages creation of operand You can override this method to change the initialization of your category without having to rewrite the base constructor from scratch.
Returns :
void
|
| Public isOperatorSelected |
isOperatorSelected()
|
|
Inherited from
Category
|
|
Defined in
Category:384
|
|
Returns :
boolean
whether an operator is currently selected or not. |
| Protected isSelectedOperator | ||||||||
isSelectedOperator(operatorClass: Type
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:617
|
||||||||
|
Checks for selected operator
Parameters :
Returns :
boolean
boolean of the statement |
| Protected operandValueChanges | ||||||||
operandValueChanges(operandIndex: number)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:487
|
||||||||
|
The method that is (by default) called whenever an operand
Parameters :
Returns :
void
|
| Public selectDefaultOperator |
selectDefaultOperator()
|
|
Inherited from
Category
|
|
Defined in
Category:367
|
|
Selects the default operator that should be used for query generation, when no Operator selection is provided to the user. The default implementation selects the first operator in the _allowedOperators array. See selectOperator() for more information.
Returns :
void
|
| Public selectOperator | ||||||||
selectOperator(operatorIndex: number)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:286
|
||||||||
|
Changes the state of the Category. Category can create queries when an Operator is selected. This method is useful if you want to use the Category class as predicate builder. should be selected
Parameters :
Returns :
void
|
| Protected selectOperatorFromPfqlExpression | ||||||||
selectOperatorFromPfqlExpression(expression: SimpleExpression)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:429
|
||||||||
|
Selects an operator from the category's allowed operators based on the PFQL expression's operator type. This method searches for an operator in the allowed operators array that matches the type specified in the PFQL expression. If a matching operator is found, it is selected. If no match is found, an error is logged.
Parameters :
Returns :
boolean
|
| Public setOperands | ||||||||
setOperands(userInput: Array
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:304
|
||||||||
|
Changes the state of the Category and generates a query if all necessary operands were set. If you are using the category as a builder. Consider using the generatePredicate() method instead. arity of the selected Operator.
Parameters :
Returns :
void
|
| configurationInputs$ |
getconfigurationInputs$()
|
| inputType |
getinputType()
|
| allowedOperators |
getallowedOperators()
|
|
The allowed operators are dependant on the selected data field. Beware that if you want to change the order of the allowed operators, then you must also update the selectDefaultOperator() method, so that default operator for each data field type matches the default operator of the CaseSimpleDataset search category. Otherwise the transition of header search into the search GUI won't work properly.
Returns :
Array<Operator<any>>
|
| displayBold |
getdisplayBold()
|
|
Returns :
boolean
|
| hasSelectedDatafields |
gethasSelectedDatafields()
|
| _selectedDatafields |
get_selectedDatafields()
|
| pfqlKeywords |
getpfqlKeywords()
|
| inputPlaceholder |
getinputPlaceholder()
|
| datafieldOptionsInitialized$ |
getdatafieldOptionsInitialized$()
|
import { OperatorService } from '../../../operator-service/operator.service';
import { LoggerService } from '../../../../logger/services/logger.service';
import { Operator } from '../../operator/operator';
import { Query } from '../../query/query';
import { OptionalDependencies } from '../../../category-factory/optional-dependencies';
import { SearchInputType } from '../search-input-type';
import { DatafieldMapKey } from '../../datafield-map-key';
import { SearchAutocompleteOption } from '../search-autocomplete-option';
import { BooleanOperator } from '../../boolean-operator';
import { CaseProcess } from './case-process';
import { EqualsDate } from '../../operator/equals-date';
import { Substring } from '../../operator/substring';
import { EqualsDateTime } from '../../operator/equals-date-time';
import { Equals } from '../../operator/equals';
import {BehaviorSubject, Observable, of, ReplaySubject, Subject, Subscription} from 'rxjs';
import { Category } from '../category';
import { NotEquals } from '../../operator/not-equals';
import { IsNull } from '../../operator/is-null';
import { Like } from '../../operator/like';
import { MoreThan } from '../../operator/more-than';
import { LessThan } from '../../operator/less-than';
import { InRange } from '../../operator/in-range';
import { NotEqualsDate } from '../../operator/not-equals-date';
import { MoreThanDate } from '../../operator/more-than-date';
import { LessThanDate } from '../../operator/less-than-date';
import { InRangeDate } from '../../operator/in-range-date';
import { MoreThanDateTime } from '../../operator/more-than-date-time';
import { LessThanDateTime } from '../../operator/less-than-date-time';
import { InRangeDateTime } from '../../operator/in-range-date-time';
import { AutocompleteOptions } from '../autocomplete-options';
import { ConfigurationInput } from '../../configuration-input';
import { Categories } from '../categories';
import { FormControl } from '@angular/forms';
import moment, { Moment } from 'moment';
import { MoreThanEqual } from '../../operator/more-than-equal';
import { LessThanEqual } from '../../operator/less-than-equal';
import { MoreThanEqualDate } from '../../operator/more-than-equal-date';
import { LessThanEqualDate } from '../../operator/less-than-equal-date';
import { MoreThanEqualDateTime } from '../../operator/more-than-equal-date-time';
import { LessThanEqualDateTime } from '../../operator/less-than-equal-date-time';
import { FilterTextSegment } from '../../persistance/filter-text-segment';
import { UserAutocomplete } from '../user-autocomplete';
import {ResourceTypeQueryPrefix} from "../resource-type-query-prefix";
import {FieldTypeResource} from "../../../../task-content/model/field-type-resource";
import {SimpleExpression} from "../../../../pfql/model/simple-expression";
import {DataSimpleExpression} from "../../../../pfql/model/data-simple-expression";
import {take, map, debounceTime} from "rxjs/operators";
interface Datafield {
netIdentifier: string;
fieldId: string;
fieldType: string;
}
export class CaseDataset extends Category<Datafield> implements AutocompleteOptions {
private static readonly _i18n = 'search.category.case.dataset';
protected static DISABLED_TYPES = [FieldTypeResource.BUTTON.valueOf(), FieldTypeResource.TASK_REF.valueOf(),
FieldTypeResource.CASE_REF.valueOf(), FieldTypeResource.CASE_FILTER.valueOf(), FieldTypeResource.TASK_FILTER.valueOf(),
FieldTypeResource.PROCESS_FILTER.valueOf()];
protected static readonly DATAFIELD_METADATA = 'datafield';
private static readonly AUTOCOMPLETE_ICON = 'account_circle';
protected readonly _DATAFIELD_INPUT: ConfigurationInput;
protected _processCategory: CaseProcess;
protected _configurationInputs$: BehaviorSubject<Array<ConfigurationInput>>;
protected _datafieldOptions: Map<string, Array<Datafield>>;
protected _datafieldOptionsInitialized$: ReplaySubject<void>;
protected _allowedNetsSub: Subscription;
protected _userAutocomplete: UserAutocomplete;
protected _isLoadedFromPfql: boolean = false;
protected _operatorWasLoadedFromPfql = false;
public static FieldTypeToInputType(fieldType: string): SearchInputType {
switch (fieldType) {
case FieldTypeResource.DATE.valueOf():
return SearchInputType.DATE;
case FieldTypeResource.DATE_TIME.valueOf():
return SearchInputType.DATE_TIME;
case FieldTypeResource.NUMBER.valueOf():
return SearchInputType.NUMBER;
case FieldTypeResource.BOOLEAN.valueOf():
return SearchInputType.BOOLEAN;
case FieldTypeResource.USER.valueOf():
return SearchInputType.AUTOCOMPLETE;
default:
return SearchInputType.TEXT;
}
}
constructor(operators: OperatorService, logger: LoggerService, protected _optionalDependencies: OptionalDependencies) {
super(undefined,
undefined,
`${CaseDataset._i18n}.name`,
undefined,
logger,
operators,
ResourceTypeQueryPrefix.CASES);
this._processCategory = this._optionalDependencies.categoryFactory.get(CaseProcess) as CaseProcess;
this._processCategory.selectDefaultOperator();
this._datafieldOptions = new Map<string, Array<Datafield>>();
this._userAutocomplete = new UserAutocomplete(this._optionalDependencies);
this.createDatafieldOptions();
let dataFieldInputDebounceTime = 0;
if (!!this._optionalDependencies.ignoreNetsOnAutocompleteCategories) {
this._DATAFIELD_INPUT = new ConfigurationInput(
SearchInputType.TEXT,
'search.category.case.dataset.placeholder.plainField',
true,
new Map<string, Array<unknown>>(),
() => { return [] }
);
dataFieldInputDebounceTime = 500;
} else {
this._DATAFIELD_INPUT = new ConfigurationInput(
SearchInputType.AUTOCOMPLETE,
'search.category.case.dataset.placeholder.field',
true,
this._datafieldOptions,
(mapKeys, newValue) => {
return mapKeys.map(serializedMapKey => DatafieldMapKey.parse(serializedMapKey))
.filter(mapKey => mapKey.title.toLocaleLowerCase().startsWith(newValue));
}
);
}
this._configurationInputs$ = new BehaviorSubject<Array<ConfigurationInput>>([this._DATAFIELD_INPUT]);
this._DATAFIELD_INPUT.valueChanges$().pipe(debounceTime(dataFieldInputDebounceTime)).subscribe(newValue => {
if (newValue === undefined
|| (this._DATAFIELD_INPUT.type === SearchInputType.AUTOCOMPLETE && typeof newValue === 'string')) {
this._configurationInputs$.next([this._DATAFIELD_INPUT]);
} else if (this._configurationInputs$.getValue().length === 1
|| (this._DATAFIELD_INPUT.type === SearchInputType.TEXT && typeof newValue === 'string')) {
this._configurationInputs$.next([this._DATAFIELD_INPUT, this._OPERATOR_INPUT]);
}
if (this._operatorWasLoadedFromPfql) {
this._operatorWasLoadedFromPfql = false;
} else {
this._operatorFormControl.setValue(undefined);
}
});
}
destroy() {
super.destroy();
this._configurationInputs$.complete();
this._datafieldOptionsInitialized$.complete();
if (this._allowedNetsSub && !this._allowedNetsSub.closed) {
this._allowedNetsSub.unsubscribe();
}
this._processCategory.destroy();
}
get configurationInputs$(): Observable<Array<ConfigurationInput>> {
return this._configurationInputs$.asObservable();
}
public get inputType(): SearchInputType {
if (!this.hasSelectedDatafields) {
throw new Error('Input type of arguments cannot be determined before selecting a data field during the configuration.');
}
if (!this._selectedDatafields) {
return SearchInputType.TEXT;
}
return CaseDataset.FieldTypeToInputType(this._selectedDatafields[0].fieldType);
}
/**
* The allowed operators are dependant on the selected data field.
*
* Beware that if you want to change the order of the allowed operators, then you must also update the
* [selectDefaultOperator()]{@link Category#selectDefaultOperator} method, so that default operator for each data field type matches
* the default operator of the {@link CaseSimpleDataset} search category. Otherwise the transition of header search into the search GUI
* won't work properly.
*/
public get allowedOperators(): Array<Operator<any>> {
if (!this.hasSelectedDatafields) {
return [];
}
const defaultOperators = [
this._operatorService.getOperator(Substring),
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals),
this._operatorService.getOperator(MoreThan),
this._operatorService.getOperator(MoreThanEqual),
this._operatorService.getOperator(LessThan),
this._operatorService.getOperator(LessThanEqual),
this._operatorService.getOperator(IsNull),
this._operatorService.getOperator(Like)
];
if (!this._selectedDatafields) {
return defaultOperators;
}
switch (this._selectedDatafields[0].fieldType) {
case FieldTypeResource.NUMBER.valueOf():
return [
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals),
this._operatorService.getOperator(MoreThan),
this._operatorService.getOperator(MoreThanEqual),
this._operatorService.getOperator(LessThan),
this._operatorService.getOperator(LessThanEqual),
this._operatorService.getOperator(InRange),
this._operatorService.getOperator(IsNull)
];
case FieldTypeResource.BOOLEAN.valueOf():
return [
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals)
];
case FieldTypeResource.USER.valueOf():
case FieldTypeResource.USER_LIST.valueOf():
return [
this._operatorService.getOperator(Equals),
this._operatorService.getOperator(NotEquals),
this._operatorService.getOperator(IsNull)
];
case FieldTypeResource.DATE.valueOf():
return [
this._operatorService.getOperator(EqualsDate),
this._operatorService.getOperator(NotEqualsDate),
this._operatorService.getOperator(MoreThanDate),
this._operatorService.getOperator(MoreThanEqualDate),
this._operatorService.getOperator(LessThanDate),
this._operatorService.getOperator(LessThanEqualDate),
this._operatorService.getOperator(InRangeDate),
this._operatorService.getOperator(IsNull)
];
case FieldTypeResource.DATE_TIME.valueOf():
return [
this._operatorService.getOperator(EqualsDateTime),
this._operatorService.getOperator(MoreThanDateTime),
this._operatorService.getOperator(MoreThanEqualDateTime),
this._operatorService.getOperator(LessThanDateTime),
this._operatorService.getOperator(LessThanEqualDateTime),
this._operatorService.getOperator(InRangeDateTime),
this._operatorService.getOperator(IsNull)
];
default:
return defaultOperators;
}
}
/**
* @returns `CaseDataset` category is not displayed in bold for better readability
*/
get displayBold(): boolean {
return false;
}
public get hasSelectedDatafields(): boolean {
return this._DATAFIELD_INPUT.isOptionSelected;
}
protected get _selectedDatafields(): Array<Datafield> {
return this._datafieldOptions.get(this._DATAFIELD_INPUT.formControl.value.value);
}
public reset() {
super.reset();
this._DATAFIELD_INPUT.clear();
}
duplicate(): CaseDataset {
return new CaseDataset(this._operatorService, this._log, this._optionalDependencies);
}
protected get pfqlKeywords(): Array<string> {
if (!this.hasSelectedDatafields) {
return [];
} else if (!this._selectedDatafields) {
const fieldId: string = this._DATAFIELD_INPUT.formControl.value
return [`data.${fieldId}.value`];
} else {
return this._selectedDatafields.map(dataField => `data.${dataField.fieldId}.value`);
}
}
get inputPlaceholder(): string {
if (!this.hasSelectedDatafields) {
return `${CaseDataset._i18n}.placeholder.field`;
}
return `${CaseDataset._i18n}.placeholder.value`;
}
protected get datafieldOptionsInitialized$(): Observable<void> {
return this._datafieldOptionsInitialized$.asObservable();
}
protected generateQuery(userInput: Array<unknown>): Query {
let queryGenerationStrategy;
if (this.isSelectedOperator(IsNull)) {
queryGenerationStrategy = (d, _) => this.isNullOperatorQueryGenerationStrategy(d);
} else if (this.inputType === SearchInputType.AUTOCOMPLETE) {
queryGenerationStrategy = (d, ui) => this.standardQueryGenerationStrategy(d, ui[0], false);
} else {
queryGenerationStrategy = (d, ui) => this.standardQueryGenerationStrategy(d, ui);
}
let queries;
if (!this._selectedDatafields) {
queries = [queryGenerationStrategy({
netIdentifier: undefined,
fieldId: this._DATAFIELD_INPUT.formControl.value,
fieldType: 'string'}, userInput)];
} else {
queries = this._selectedDatafields.map(datafield => queryGenerationStrategy(datafield, userInput));
}
return Query.combineQueries(queries, BooleanOperator.OR);
}
protected standardQueryGenerationStrategy(datafield: Datafield, userInput: Array<unknown>, escapeInput = true): Query {
const valueQuery = this.selectedOperator.createQuery(this.pfqlKeywords, userInput, escapeInput);
const netQuery = this.generateNetConstraint(datafield);
const query: Query = Query.combineQueries([valueQuery, netQuery], BooleanOperator.AND);
return query.ensurePrefixAndGet(ResourceTypeQueryPrefix.CASES);
}
protected isNullOperatorQueryGenerationStrategy(datafield: Datafield): Query {
const constraint = this.generateNetConstraint(datafield);
return (this._operatorService.getOperator(IsNull) as IsNull).createQueryWithConstraint(this.pfqlKeywords, constraint)
.ensurePrefixAndGet(ResourceTypeQueryPrefix.CASES);
}
protected generateNetConstraint(datafield: Datafield): Query {
return this._isLoadedFromPfql || this._DATAFIELD_INPUT.type === SearchInputType.TEXT ? new Query(undefined, ResourceTypeQueryPrefix.CASES, true)
: this._processCategory.generatePredicate([[datafield.netIdentifier]]).query;
}
protected createDatafieldOptions(): void {
this._datafieldOptionsInitialized$ = new ReplaySubject<void>(1);
this._allowedNetsSub = this._optionalDependencies.allowedNetsService.allowedNets$.subscribe(allowedNets => {
allowedNets.forEach(petriNet => {
petriNet.immediateData
.filter(immediateData => {
return immediateData.title !== undefined
&& immediateData.title.trim().length > 0
&& !CaseDataset.DISABLED_TYPES?.includes(immediateData.type);
})
.forEach(immediateData => {
let type = immediateData.type;
// for search purposes, enumeration and multichoice maps are equivalent to their simpler counterparts
if (type === FieldTypeResource.ENUMERATION_MAP.valueOf()) {
type = 'enumeration';
} else if (type === FieldTypeResource.MULTICHOICE_MAP.valueOf()) {
type = 'multichoice';
}
this.addToDatafieldOptionsMap(DatafieldMapKey.serializedForm(immediateData.type, immediateData.title), {
netIdentifier: petriNet.identifier,
fieldId: immediateData.stringId,
fieldType: immediateData.type,
});
});
});
this._datafieldOptionsInitialized$.next();
});
}
filterOptions(userInput: Observable<string | SearchAutocompleteOption<Array<string>>>):
Observable<Array<SearchAutocompleteOption<Array<string>>>> {
if (!this.hasSelectedDatafields) {
throw new Error('The category must be fully configured before attempting to get autocomplete options!');
}
if (this.inputType !== SearchInputType.AUTOCOMPLETE) {
throw new Error('Cannot filter options of non-autocomplete operands');
}
return this._userAutocomplete.filterOptions(userInput);
}
public selectDatafields(datafieldMapKey: string, selectDefaultOperator = true): void {
if (!this._datafieldOptions.has(datafieldMapKey)) {
this._log.warn(`The provided 'datafieldMapKey' (${datafieldMapKey}) does not exist.`);
return;
}
this._DATAFIELD_INPUT.formControl.setValue(DatafieldMapKey.parse(datafieldMapKey));
if (selectDefaultOperator) {
this.selectDefaultOperator();
}
}
public selectDataFieldsByPfqlExpression(expression: DataSimpleExpression): void {
let dataFieldMapKey: string | undefined;
for (const [key, dataFields] of this._datafieldOptions.entries()) {
if (dataFields.some(dataField => dataField.fieldId === expression.dataFieldId)) {
dataFieldMapKey = key;
break;
}
}
if (dataFieldMapKey === undefined) {
this._log.warn(`No data field option found for dataFieldId '${expression.dataFieldId}'`);
return;
}
this._DATAFIELD_INPUT.formControl.setValue(DatafieldMapKey.parse(dataFieldMapKey));
}
/**
* Adds a new entry or pushes value into an existing entry.
* When a new entry is created, it is created as an Array of one element.
* @param key where in the map should the value be added
* @param value the value that should be added to the map
*/
protected addToDatafieldOptionsMap(key: string, value: Datafield): void {
if (this._datafieldOptions.has(key)) {
this._datafieldOptions.get(key).push(value);
} else {
this._datafieldOptions.set(key, [value]);
}
}
protected isOperandValueSelected(newValue: any): boolean {
if (!this.isOperatorSelected()) {
return false;
}
let inputType: SearchInputType;
try {
inputType = this.inputType;
} catch (e) {
return false;
}
switch (inputType) {
case SearchInputType.NUMBER:
return typeof newValue === 'number';
case SearchInputType.BOOLEAN:
return typeof newValue === 'boolean';
case SearchInputType.AUTOCOMPLETE:
return !(!newValue || typeof newValue === 'string');
default:
return !!newValue;
}
}
/**
* Performs a transformation of the `FormControl` value before passing it into the selected `Operator` for query generation.
* It is mostly useful only for AutocompleteCategories, where the selected value of the FormControl is an object.
*
* @param value the FormControlValue
* @returns If the selected data field has input type `AUTOCOMPLETE` then returns the {@link SearchAutocompleteOption} `value`
* attribute. Otherwise performs an identity operation.
*/
protected transformCategoryValue(value: any): any {
if (this.inputType === SearchInputType.AUTOCOMPLETE) {
return (value as SearchAutocompleteOption<Array<number>>).value;
}
return value;
}
serializeClass(): Categories | string {
return Categories.CASE_DATASET;
}
protected serializeOperandValue(valueFormControl: FormControl): unknown {
switch (this.inputType) {
case SearchInputType.AUTOCOMPLETE:
return this._userAutocomplete.serializeOperandValue(valueFormControl);
case SearchInputType.DATE:
case SearchInputType.DATE_TIME:
return (valueFormControl.value as Moment).valueOf();
default:
return super.serializeOperandValue(valueFormControl);
}
}
public override loadFromPfqlExpression(expression: SimpleExpression): Observable<void> {
if (!(expression instanceof DataSimpleExpression)) {
this._log.error("Cannot load category CaseDataSet from wrong PFQL expression")
return of(undefined);
}
if (this._DATAFIELD_INPUT.type === SearchInputType.TEXT) {
this._DATAFIELD_INPUT.formControl.setValue(expression.dataFieldId);
this._DATAFIELD_INPUT.confirmInput();
if (!this.selectOperatorFromPfqlExpression(expression)) {
return of(undefined);
}
this._operatorWasLoadedFromPfql = true;
this.setOperands([expression.operandValue]);
return of(undefined);
}
return this._datafieldOptionsInitialized$.pipe(
take(1),
map(() => {
this._isLoadedFromPfql = true;
this.selectDataFieldsByPfqlExpression(expression);
if (!this.selectOperatorFromPfqlExpression(expression)) {
return;
}
this.setOperands(Array.isArray(expression.operandValue) ? expression.operandValue : [expression.operandValue]);
})
);
}
protected deserializeOperandValue(value: unknown): Observable<any> {
switch (this.inputType) {
case SearchInputType.AUTOCOMPLETE:
return this._userAutocomplete.deserializeOperandValue(value as SearchAutocompleteOption<Array<string>>);
case SearchInputType.DATE:
case SearchInputType.DATE_TIME:
return of(moment(value as string));
default:
return super.deserializeOperandValue(value);
}
}
protected createConfigurationFilterTextSegments(): Array<FilterTextSegment> {
const configInput = this._configurationInputs$.value[0];
let dataFieldId: string = configInput.formControl.value.text;
if (!dataFieldId) {
dataFieldId = configInput.formControl.value
}
return [{segment: dataFieldId, bold: true}];
}
}