projects/netgrif-components-core/src/lib/filter/models/simple-filter.ts
Holds backend search request data and allows limited manipulation with it.
Methods |
|
constructor(id: string, type: FilterType, filterBody: CaseSearchRequestBody | TaskSearchRequestBody, title?: string, isPfql: boolean)
|
||||||||||||||||||||||||
|
Parameters :
|
| Public addFullTextFields | ||||||
addFullTextFields(fullTextFields: literal type)
|
||||||
|
Inherited from
Filter
|
||||||
|
Defined in
Filter:116
|
||||||
|
Parameters :
Returns :
void
|
| bodyContainsQuery |
bodyContainsQuery()
|
|
Inherited from
Filter
|
|
Defined in
Filter:102
|
|
Returns :
boolean
|
| Public clearFullTextFields |
clearFullTextFields()
|
|
Inherited from
Filter
|
|
Defined in
Filter:123
|
|
Returns :
void
|
| clone |
clone()
|
|
Inherited from
Filter
|
|
Defined in
Filter:87
|
|
See Filter.clone()
Returns :
Filter
|
| Public containsFullTextFields |
containsFullTextFields()
|
|
Inherited from
Filter
|
|
Defined in
Filter:130
|
|
Returns :
boolean
|
| Static empty | ||||||||
empty(type: FilterType)
|
||||||||
|
Create an empty filter of provided type
Parameters :
Returns :
Filter
a filter with empty body of the provided type. |
| Static emptyCaseFilter |
emptyCaseFilter()
|
|
Equivalent to calling
Returns :
Filter
a filter with empty body that can be used to search cases |
| Static emptyTaskFilter |
emptyTaskFilter()
|
|
Equivalent to calling
Returns :
Filter
a filter with empty body that can be used to search tasks |
| Static fromCaseQuery | ||||||||
fromCaseQuery(filterBody: CaseSearchRequestBody)
|
||||||||
|
Creates a case filter with the provided body
Parameters :
Returns :
Filter
a case filter with the given body. |
| Static fromQuery | ||||||||||||
fromQuery(filterBody: CaseSearchRequestBody | TaskSearchRequestBody, type: FilterType)
|
||||||||||||
|
Creates a filter with the provided body and the provided type
Parameters :
Returns :
Filter
a filter with the given body and type. |
| Static fromTaskQuery | ||||||||
fromTaskQuery(filterBody: TaskSearchRequestBody)
|
||||||||
|
Creates a task filter with the provided body
Parameters :
Returns :
Filter
a task filter with the given body. |
| Public getFullTextFields |
getFullTextFields()
|
|
Inherited from
Filter
|
|
Defined in
Filter:137
|
|
Returns :
literal type
|
| getRequestBody |
getRequestBody()
|
|
Inherited from
Filter
|
|
Defined in
Filter:109
|
| merge | |||||||||
merge(filter: Filter, operator: MergeOperator)
|
|||||||||
|
Inherited from
Filter
|
|||||||||
|
Defined in
Filter:94
|
|||||||||
|
See Filter.merge()
Parameters :
Returns :
MergedFilter
|
| Protected deepCopy | ||||||||
deepCopy(obj: object)
|
||||||||
|
Inherited from
Filter
|
||||||||
|
Defined in
Filter:118
|
||||||||
|
Creates a deep copy of a simple object.
Parameters :
Returns :
object
a deep copy of the argument |
| Public getRequestParams |
getRequestParams()
|
|
Inherited from
Filter
|
|
Defined in
Filter:109
|
|
Returns the necessary request params for the filter. Default implementation returns an empty object. The params are added on top of the request when sending it to the backend by the respective service methods.
Returns :
Params
an empty object |
import {Filter} from './filter';
import {MergeOperator} from './merge-operator';
import {MergedFilter} from './merged-filter';
import {TaskSearchRequestBody} from './task-search-request-body';
import {CaseSearchRequestBody} from './case-search-request-body';
import {FilterType} from './filter-type';
/**
* Holds backend search request data and allows limited manipulation with it.
*/
export class SimpleFilter extends Filter {
/**
* @ignore
* Stores the underlying filter data
*/
private readonly _filter: CaseSearchRequestBody | TaskSearchRequestBody;
/**
* Create an empty filter of provided type
* @param type type of resources that the filter can query
* @returns a filter with empty body of the provided type. `id` of the new filter is set to an empty string.
*/
public static empty(type: FilterType): Filter {
return new SimpleFilter('', type, {});
}
/**
* Equivalent to calling `SimpleFilter.empty(FilterType.CASE)`.
* @returns a filter with empty body that can be used to search cases
*/
public static emptyCaseFilter(): Filter {
return SimpleFilter.empty(FilterType.CASE);
}
/**
* Equivalent to calling `SimpleFilter.empty(FilterType.TASK)`.
* @returns a filter with empty body that can be used to search tasks
*/
public static emptyTaskFilter(): Filter {
return SimpleFilter.empty(FilterType.TASK);
}
/**
* Creates a filter with the provided body and the provided type
* @param filterBody the body of the new filter
* @param type the type of the new filter. Type must match the type of the body.
* @returns a filter with the given body and type. `id` of the new filter is set to an empty string.
*/
public static fromQuery(filterBody: CaseSearchRequestBody | TaskSearchRequestBody, type: FilterType): Filter {
return new SimpleFilter('', type, filterBody);
}
/**
* Creates a case filter with the provided body
* @param filterBody the body of the new filter
* @returns a case filter with the given body. `id` of the new filter is set to an empty string.
*/
public static fromCaseQuery(filterBody: CaseSearchRequestBody): Filter {
return SimpleFilter.fromQuery(filterBody, FilterType.CASE);
}
/**
* Creates a task filter with the provided body
* @param filterBody the body of the new filter
* @returns a task filter with the given body. `id` of the new filter is set to an empty string.
*/
public static fromTaskQuery(filterBody: TaskSearchRequestBody): Filter {
return SimpleFilter.fromQuery(filterBody, FilterType.TASK);
}
/**
* @param id identifier of the filter
* @param type type of resources that the filter can query
* @param filterBody search request matching this filter's `type`
* @param title human readable filter name
* @param isPfql true if the Filter should cooperate with PFQL API
*/
constructor(id: string, type: FilterType, filterBody: CaseSearchRequestBody | TaskSearchRequestBody, title?: string, isPfql: boolean = false) {
super(id, type, title, isPfql);
this._filter = this.deepCopy(filterBody);
}
/**
* See [Filter.clone()]{@link Filter#clone}
*/
clone(): Filter {
return new SimpleFilter(this.id, this.type, this._filter, this.title, this.isPfql);
}
/**
* See [Filter.merge()]{@link Filter#merge}
*/
merge(filter: Filter, operator: MergeOperator): MergedFilter {
const temp = new MergedFilter(this.id, this.type, [this._filter], operator, this.title, this.isPfql);
return temp.merge(filter, operator);
}
/**
* See [Filter.bodyContainsQuery()]{@link Filter#bodyContainsQuery}
*/
bodyContainsQuery(): boolean {
return this._filter.query !== undefined && this._filter.query !== null;
}
/**
* See [Filter.getRequestBody()]{@link Filter#getRequestBody}
*/
getRequestBody(): TaskSearchRequestBody | CaseSearchRequestBody {
return this.deepCopy(this._filter) as CaseSearchRequestBody | TaskSearchRequestBody;
}
/**
* See [Filter.addFullTextFields()]{@link Filter#addFullTextFields}
*/
public addFullTextFields(fullTextFields: { [fieldId: string]: number; }): void {
this._filter.fullTextFields = fullTextFields;
}
/**
* See [Filter.clearFullTextFields()]{@link Filter#clearFullTextFields}
*/
public clearFullTextFields(): void {
this._filter.fullTextFields = undefined;
}
/**
* See [Filter.containsFullTextFields()]{@link Filter#containsFullTextFields}
*/
public containsFullTextFields(): boolean {
return !!this._filter.fullTextFields && Object.keys(this._filter.fullTextFields).length > 0;
}
/**
* See [Filter.getFullTextFields()]{@link Filter#getFullTextFields}
*/
public getFullTextFields(): {[fieldId: string]: number} {
return this._filter.fullTextFields;
}
}