projects/netgrif-components-core/src/lib/search/models/category/case/case-simple-dataset.ts
This class aims to be a simpler more limited version of the CaseDataset Category implementation.
It can only generate "equality" queries for a single field. The category must be configured before it can be used to generate queries.
This category cannot be serialized. If you want to preserve this category's state convert it to CaseDataset with the transformToCaseDataset() method and serialize the result.
See configure for more information.
constructor(operators: OperatorService, logger: LoggerService, _optionalDependencies: OptionalDependencies)
|
||||||||||||
|
Parameters :
|
| Protected _fieldId |
Type : string
|
| Protected _fieldType |
Type : string
|
| Protected _netIdentifiers |
Type : Array<string>
|
| Protected _pfqlKeyword |
Type : string
|
| Protected _processCategory |
Type : CaseProcess
|
| 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
|
| Public configure | ||||||||||||
configure(fieldId: string, fieldType: string, netIdentifiers: Array
|
||||||||||||
|
Parameters :
Returns :
void
|
| destroy |
destroy()
|
|
Inherited from
Category
|
|
Defined in
Category:54
|
|
Returns :
void
|
| duplicate |
duplicate()
|
|
Inherited from
Category
|
|
Defined in
Category:99
|
|
Returns :
CaseSimpleDataset
|
| Protected generateQuery | ||||||
generateQuery(userInput: Array<>)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:119
|
||||||
|
Parameters :
Returns :
Query
|
| serializeClass |
serializeClass()
|
|
Inherited from
Category
|
|
Defined in
Category:128
|
|
Returns :
Categories | string
|
| Public transformToCaseDataset | ||||||||||||||||
transformToCaseDataset(fieldType: string, fieldTitle: string, userInput: Array
|
||||||||||||||||
|
Creates a CaseDataset instance and configures it so, that the query it generates targets the selected field, uses the default operator and its operands are what the user provided.
Parameters :
Returns :
CaseDataset
a new {@link CaseDataset} configured with the provided values |
| Protected createConfigurationFilterTextSegments |
createConfigurationFilterTextSegments()
|
|
Inherited from
Category
|
|
Defined in
Category:52
|
|
Returns :
Array<FilterTextSegment>
|
| getActiveInputFormControl | ||||||
getActiveInputFormControl(inputIndex: number)
|
||||||
|
Inherited from
NoConfigurationCategory
|
||||||
|
Defined in
NoConfigurationCategory:41
|
||||||
|
Parameters :
Returns :
FormControl
|
| Protected isOperandValueSelected | ||||||
isOperandValueSelected(newValue: any)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:48
|
||||||
|
Parameters :
Returns :
boolean
|
| 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 |
| Protected deserializeOperandValue | ||||||
deserializeOperandValue(value)
|
||||||
|
Inherited from
Category
|
||||||
|
Defined in
Category:531
|
||||||
|
This method may throw na error if the value cannot be deserialized.
Parameters :
Returns :
Observable<any>
an This method may throw na error if the value cannot be deserialized. |
| 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 |
| Public loadFromPfqlExpression | ||||||||
loadFromPfqlExpression(expression: SimpleExpression)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:412
|
||||||||
|
Loads the category state from a PFQL expression. This method attempts to select an operator based on the expression's operator type and then sets the operands from the expression's operand values. If the operator cannot be selected, the method returns immediately.
Parameters :
Returns :
Observable<void>
an Observable that emits void when the loading is complete |
| 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 reset |
reset()
|
|
Inherited from
Category
|
|
Defined in
Category:325
|
|
Resets the state of the Category, deselecting any selected category and removing other state information if the Category defines them. This method can be used to reset the state of the category after each predicate constructed, effectively turning the category instance into a predicate builder.
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
|
| Protected serializeOperandValue | ||||||||
serializeOperandValue(valueFormControl: FormControl)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:521
|
||||||||
|
Parameters :
|
| 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
|
| Protected transformCategoryValue | ||||||||
transformCategoryValue(value: any)
|
||||||||
|
Inherited from
Category
|
||||||||
|
Defined in
Category:549
|
||||||||
|
Performs a transformation of the The default implementation performs an identity transformation - returns the input.
Parameters :
Returns :
T
the value used for query generation |
| inputPlaceholder |
getinputPlaceholder()
|
| pfqlKeywords |
getpfqlKeywords()
|
| selectedOperator |
getselectedOperator()
|
import {OperatorService} from '../../../operator-service/operator.service';
import {LoggerService} from '../../../../logger/services/logger.service';
import {Query} from '../../query/query';
import {Operator} from '../../operator/operator';
import {Equals} from '../../operator/equals';
import {EqualsDate} from '../../operator/equals-date';
import {EqualsDateTime} from '../../operator/equals-date-time';
import {Substring} from '../../operator/substring';
import {CaseProcess} from './case-process';
import {OptionalDependencies} from '../../../category-factory/optional-dependencies';
import {BooleanOperator} from '../../boolean-operator';
import {NoConfigurationCategory} from '../no-configuration-category';
import {CaseDataset} from './case-dataset';
import {DatafieldMapKey} from '../../datafield-map-key';
import {Categories} from '../categories';
import {ResourceTypeQueryPrefix} from "../resource-type-query-prefix";
import {FieldTypeResource} from "../../../../task-content/model/field-type-resource";
/**
* This class aims to be a simpler more limited version of the {@link CaseDataset} {@link Category} implementation.
*
* It can only generate "equality" queries for a single field. The category must be configured before it can be used to generate queries.
*
* This category cannot be serialized. If you want to preserve this category's state convert it to {@link CaseDataset}
* with the [transformToCaseDataset()]{@link CaseSimpleDataset#transformToCaseDataset} method and serialize the result.
*
* See [configure]{@link CaseSimpleDataset#configure} for more information.
*/
export class CaseSimpleDataset extends NoConfigurationCategory<string> {
private static readonly _i18n = 'search.category.case.dataset';
protected _fieldId: string;
protected _fieldType: string;
protected _netIdentifiers: Array<string>;
protected _pfqlKeyword: string;
protected _processCategory: CaseProcess;
constructor(operators: OperatorService,
logger: LoggerService,
protected _optionalDependencies: OptionalDependencies) {
super(undefined,
undefined,
`${CaseSimpleDataset._i18n}.name`,
undefined,
logger,
operators,
ResourceTypeQueryPrefix.CASES);
this._processCategory = _optionalDependencies.categoryFactory.getWithDefaultOperator(CaseProcess) as CaseProcess;
}
destroy() {
super.destroy();
this._processCategory.destroy();
}
get inputPlaceholder(): string {
return '';
}
public configure(fieldId: string, fieldType: string, netIdentifiers: Array<string>): void {
if (!fieldId || !fieldType || !netIdentifiers || netIdentifiers.length === 0) {
this._log.error('CaseSimpleDataset must be configured with defined values and a non-empty array');
return;
}
this._fieldId = fieldId;
this._fieldType = fieldType;
this._netIdentifiers = netIdentifiers;
this._pfqlKeyword = `data.${fieldId}.value`
}
protected get pfqlKeywords(): Array<string> {
if (!this._fieldId) {
return [];
} else {
return [this._pfqlKeyword];
}
}
public get selectedOperator(): Operator<any> {
switch (this._fieldType) {
case FieldTypeResource.NUMBER.valueOf():
return this._operatorService.getOperator(Equals);
case FieldTypeResource.BOOLEAN.valueOf():
return this._operatorService.getOperator(Equals);
case FieldTypeResource.USER.valueOf():
return this._operatorService.getOperator(Equals);
case FieldTypeResource.DATE.valueOf():
return this._operatorService.getOperator(EqualsDate);
case FieldTypeResource.DATE_TIME.valueOf():
return this._operatorService.getOperator(EqualsDateTime);
default:
return this._operatorService.getOperator(Substring);
}
}
duplicate(): CaseSimpleDataset {
return new CaseSimpleDataset(this._operatorService, this._log, this._optionalDependencies);
}
/**
* Creates a {@link CaseDataset} instance and configures it so, that the query it generates targets
* the selected field, uses the default operator and its operands are what the user provided.
*
* @param fieldType the type of the field that should be targeted by the transformed Category
* @param fieldTitle the title of the field that should be targeted by the transformed Category
* @param userInput the operands for the queried field
* @returns a new {@link CaseDataset} configured with the provided values
*/
public transformToCaseDataset(fieldType: string, fieldTitle: string, userInput: Array<any>): CaseDataset {
const result = this._optionalDependencies.categoryFactory.get(CaseDataset) as CaseDataset;
result.selectDatafields(DatafieldMapKey.serializedForm(fieldType, fieldTitle));
result.setOperands(userInput);
return result;
}
protected generateQuery(userInput: Array<unknown>): Query {
const valueQuery = this.selectedOperator.createQuery(this.pfqlKeywords, userInput);
const netsQuery = Query.combineQueries(
this._netIdentifiers.map(id => this._processCategory.generatePredicate([[id]]).query),
BooleanOperator.OR
);
return Query.combineQueries([valueQuery, netsQuery], BooleanOperator.AND).ensurePrefixAndGet(ResourceTypeQueryPrefix.CASES);
}
serializeClass(): Categories | string {
return Categories.CASE_SIMPLE_DATASET;
}
}