File

projects/netgrif-components-core/src/lib/search/models/predicate/clause-predicate.ts

Description

Represents a clause of Predicates combined with a BooleanOperator.

Extends

Predicate

Index

Properties
Methods
Accessors

Constructor

constructor(predicates: Array<Predicate>, _operator: BooleanOperator, initiallyVisible, _bracketSubPredicateText)

is generated

Parameters :
Name Type Optional Description
predicates Array<Predicate> No

Predicates that should be combined into one

_operator BooleanOperator No

Operator that is used to combine the predicates

initiallyVisible No

whether the predicate should be initially displayed or not

_bracketSubPredicateText No

whether the individual sub predicates are wrapped in brackets when a textual representation is generated

Properties

Protected _predicates
Type : Array<Predicate>

Stores the Predicates that this Predicate combines.

Protected _query
Type : Query

Stores the resulting query of this Predicate.

Protected _filterTextSegmentsGenerator
Type : function
Inherited from Predicate
Defined in Predicate:14
Protected _visible
Type : boolean
Inherited from Predicate
Defined in Predicate:13

Methods

Public addPredicate
addPredicate(newPredicate: Predicate)

Adds another Predicate to the clause and updates this Predicate's Query. Note that removing predicates with a lower index shifts the order of indices.

Parameters :
Name Type Optional Description
newPredicate Predicate No
  • the Predicate that should be added to the clause
Returns : number

the index of the added Predicate, that can be used to remove it. Note that removing predicates with a lower index shifts the order of indices.

Public removePredicate
removePredicate(index: number)

Removes the Predicate at the given index from this clause and updates this Predicate's Query. If the index is invalid does nothing.

Parameters :
Name Type Optional Description
index number No

index of the Predicate in this clause that should be removed

Returns : boolean

whether a predicate was removed, or not

Public showAll
showAll()

Sets this predicate and all its sub-predicates to visible.

Returns : void
Protected updateQuery
updateQuery()

Updates the value of the _query attribute.

See combineQueries() for more information.

Returns : void
Static combineTextSegmentsWithBooleanOperator
combineTextSegmentsWithBooleanOperator(predicates: IterableIterator<Predicate> | Array<Predicate>, operator: BooleanOperator, wrapWithBrackets)
Inherited from Predicate
Defined in Predicate:46

Combines the text segments of the predicates with the given operator and wraps the individual predicates in brackets optionaly (if only one predicate is provided it is never wrapped)

Parameters :
Name Type Optional Default value Description
predicates IterableIterator<Predicate> | Array<Predicate> No

sources of text segments that are to be combined with a boolean operator

operator BooleanOperator No

boolean operator used to combine the individual predicate text segments

wrapWithBrackets No false

whether the individual predicate text segments should be wrapped in braces or not (if only one predicate is provided it is never wrapped)

Public createFilterTextSegments
createFilterTextSegments()
Inherited from Predicate
Defined in Predicate:93

The default implementation returns an empty array.

an Array containing text segments representing the content of this predicate. The default implementation returns an empty array.

Public setFilterTextSegmentsGenerator
setFilterTextSegmentsGenerator(filterTextSegmentsGenerator: () => void)
Inherited from Predicate
Defined in Predicate:85
Parameters :
Name Type Optional
filterTextSegmentsGenerator function No
Returns : void
Public show
show()
Inherited from Predicate
Defined in Predicate:81

Sets the predicates state to visible

Returns : void

Accessors

query
getquery()
queries
getqueries()
Returns : Array<Query>
import {Predicate} from './predicate';
import {Query} from '../query/query';
import {BooleanOperator} from '../boolean-operator';

/**
 * Represents a clause of {@link Predicate}s combined with a {@link BooleanOperator}.
 */
export class ClausePredicate extends Predicate {

    /**
     * Stores the {@link Predicate}s that this Predicate combines.
     */
    protected _predicates: Array<Predicate>;
    /**
     * Stores the resulting query of this Predicate.
     */
    protected _query: Query;

    /**
     * @param predicates Predicates that should be combined into one
     * @param _operator Operator that is used to combine the predicates
     * @param initiallyVisible whether the predicate should be initially displayed or not
     * @param _bracketSubPredicateText whether the individual sub predicates are wrapped in brackets when a textual representation
     * is generated
     */
    constructor(predicates: Array<Predicate>,
                protected _operator: BooleanOperator,
                initiallyVisible = true,
                protected _bracketSubPredicateText = false) {
        super(initiallyVisible);
        this._predicates = [];
        this._predicates.push(...predicates);
        this.updateQuery();
        this.initializeFilterTextSegmentsGenerator();
    }

    get query(): Query {
        return this._query;
    }

    /**
     * Adds another {@link Predicate} to the clause and updates this {@link Predicate}'s {@link Query}.
     * @param newPredicate - the Predicate that should be added to the clause
     * @returns the index of the added Predicate, that can be used to remove it.
     * Note that removing predicates with a lower index shifts the order of indices.
     */
    public addPredicate(newPredicate: Predicate): number {
        this._predicates.push(newPredicate);
        this.updateQuery();
        return this._predicates.length - 1;
    }

    /**
     * Removes the {@link Predicate} at the given `index` from this clause and updates this {@link Predicate}'s {@link Query}.
     * If the `index` is invalid does nothing.
     * @param index index of the {@link Predicate} in this clause that should be removed
     * @returns whether a predicate was removed, or not
     */
    public removePredicate(index: number): boolean {
        if (index >= 0 && index < this._predicates.length) {
            this._predicates.splice(index, 1);
            this.updateQuery();
            return true;
        }
        return false;
    }

    /**
     * Sets this predicate and all its sub-predicates to visible.
     */
    public showAll(): void {
        this.show();
        this._predicates.forEach(p => p.show());
    }

    /**
     * Updates the value of the [_query]{@link ClausePredicate#_query} attribute.
     *
     * See [combineQueries()]{@link Query#combineQueries} for more information.
     */
    protected updateQuery(): void {
        this._query = Query.combineQueries(this.queries, this._operator);
    }

    /**
     * @returns the `Array` of {@link Query} objects stored within this object's [_predicates]{@link ClausePredicate#_predicates} attribute.
     */
    protected get queries(): Array<Query> {
        return this._predicates.map(p => p.query);
    }

    private initializeFilterTextSegmentsGenerator() {
        this._filterTextSegmentsGenerator = () => {
            return Predicate.combineTextSegmentsWithBooleanOperator(this._predicates, this._operator, this._bracketSubPredicateText);
        };
    }
}

results matching ""

    No results matching ""