File

projects/netgrif-components-core/src/lib/search/search-clause-component/abstract-search-clause.component.ts

Description

Is responsible for the interactive creation of an OR ClausePredicate object instance. The nested Predicates are ElementaryPredicate instances created by AbstractSearchPredicateComponent.

Implements

OnInit OnDestroy

Metadata

selector ncc-abstract-search-clause

Index

Properties
Methods
Inputs

Constructor

Protected constructor()

Inputs

editable
Type : boolean
Default value : true

Whether the contents displayed in this component can be edited by the user or not.

Defaults to true

predicate
Type : EditableClausePredicateWithGenerators
predicateId
Type : number
remove$
Type : Subject<number>

Methods

Public addChildPredicate
addChildPredicate()
Returns : void
Public getPredicateMap
getPredicateMap()
Returns : Map<number, PredicateWithGenerator>
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public removeChildAt
removeChildAt(id: number)
Parameters :
Name Type Optional
id number No
Returns : void

Properties

editable
Default value : true
Decorators :
@Input()

Whether the contents displayed in this component can be edited by the user or not.

Defaults to true

predicate
Type : EditableClausePredicateWithGenerators
Decorators :
@Input()
predicateId
Type : number
Decorators :
@Input()
remove$
Type : Subject<number>
Decorators :
@Input()
Public removeChild$
Type : Subject<number>
Public trackByPredicates
Default value : () => {...}
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Subject} from 'rxjs';
import {KeyValue} from '@angular/common';
import {EditableClausePredicateWithGenerators} from '../models/predicate/editable-clause-predicate-with-generators';
import {PredicateWithGenerator} from '../models/predicate/predicate-with-generator';


/**
 * Is responsible for the interactive creation of an OR {@link ClausePredicate} object instance.
 * The nested Predicates are {@link ElementaryPredicate} instances created by {@link AbstractSearchPredicateComponent}.
 */
@Component({
    selector: 'ncc-abstract-search-clause',
    template: ''
})
export abstract class AbstractSearchClauseComponent implements OnInit, OnDestroy {

    /**
     * Whether the contents displayed in this component can be edited by the user or not.
     *
     * Defaults to `true`
     */
    @Input() editable = true;
    @Input() predicate: EditableClausePredicateWithGenerators;
    @Input() predicateId: number;
    @Input() remove$: Subject<number>;
    public removeChild$: Subject<number>;

    protected constructor() {
        this.removeChild$ = new Subject<number>();
        this.removeChild$.subscribe(id => this.removeChildAt(id));
    }

    ngOnInit(): void {
        if (this.getPredicateMap().size === 0) {
            this.addChildPredicate();
        }
    }

    ngOnDestroy(): void {
        this.removeChild$.complete();
    }

    public trackByPredicates = (a: number, b: KeyValue<number, PredicateWithGenerator>) => b.value;

    public getPredicateMap(): Map<number, PredicateWithGenerator> {
        const map = new Map<number, PredicateWithGenerator>();

        for (const [key, value] of this.predicate.getPredicateMap().entries()) {
            if (value.isVisible) {
                map.set(key, value);
            }
        }

        return map;
    }

    public removeChildAt(id: number): void {
        this.predicate.removePredicate(id);
        if (this.predicate.getPredicateMap().size === 0) {
            this.remove$.next(this.predicateId);
        }
    }

    public addChildPredicate(): void {
        this.predicate.addNewElementaryPredicate();
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""