@netgrif/components-core
Version:
Netgrif Application engine frontend core Angular library
186 lines (185 loc) • 8.98 kB
TypeScript
import { OnDestroy } from '@angular/core';
import { Filter } from '../../filter/models/filter';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { Predicate } from '../models/predicate/predicate';
import { SimpleFilter } from '../../filter/models/simple-filter';
import { PredicateRemovalEvent } from '../models/predicate-removal-event';
import { Query } from '../models/query/query';
import { EditableClausePredicateWithGenerators } from '../models/predicate/editable-clause-predicate-with-generators';
import { Category } from '../models/category/category';
import { PredicateTreeMetadata } from '../models/persistance/generator-metadata';
import { BaseFilter } from '../models/base-filter';
import { LoggerService } from '../../logger/services/logger.service';
import { CategoryFactory } from '../category-factory/category-factory';
import { FilterType } from '../../filter/models/filter-type';
import { LoadingEmitter } from '../../utility/loading-emitter';
import { FilterMetadata } from '../models/persistance/filter-metadata';
import { FilterTextSegment } from '../models/persistance/filter-text-segment';
import * as i0 from "@angular/core";
/**
* Holds information about the filter that is currently applied to the view component, that provides this services.
*/
export declare class SearchService implements OnDestroy {
protected _log: LoggerService;
protected _categoryFactory: CategoryFactory;
/**
* {@link Filter} that is applied to the view, even if the user doesn't search anything.
*/
protected _baseFilter: Filter;
/**
* Holds the {@link Predicate} tree root for user search queries.
*/
protected _rootPredicate: EditableClausePredicateWithGenerators;
/**
* Holds the {@link Filter} that is currently being applied to the view.
*/
protected _activeFilter: BehaviorSubject<Filter>;
/**
* Holds the full text {@link Filter} if set, `undefined` otherwise.
*/
protected _fullTextFilter: SimpleFilter | undefined;
/**
* The index of a removed {@link Predicate} is emmited into this stream
*/
protected _predicateRemoved$: Subject<PredicateRemovalEvent>;
protected _loadingFromMetadata$: LoadingEmitter;
/**
* The `rootPredicate` uses this stream to notify the search service about changes to the held query
*/
private readonly _predicateQueryChanged$;
private readonly subFilter;
/**
* The {@link Predicate} tree root uses an [AND]{@link BooleanOperator#AND} operator to combine the Predicates.
* @param _log {@link LoggerService}
* @param _categoryFactory a {@link CategoryFactory} instance. This dependency is optional.
* It is required if we want to load predicate filter from saved metadata
* @param baseFilter Filter that should be applied to the view when no searching is being performed.
* Injected trough the {@link NAE_BASE_FILTER} injection token.
*/
constructor(_log: LoggerService, _categoryFactory: CategoryFactory, baseFilter: BaseFilter);
ngOnDestroy(): void;
/**
* @returns the Filter that is currently applied to the view
*/
get activeFilter(): Filter;
/**
* @returns an `Observable` that updates every time the active Filter changes.
*/
get activeFilter$(): Observable<Filter>;
/**
* @returns `true` if a filter other than the base filter is currently applied.
* Returns `false` if only the base filter is currently applied.
*/
get additionalFiltersApplied(): boolean;
/**
* @returns `true` if any visible predicates are applied.
* Returns `false` if there are no predicates, or if there are only hidden predicates applied
*/
get hasVisiblePredicates(): boolean;
/**
* @returns a copy of the base filter
*/
get baseFilter(): Filter;
/**
* @returns an Observable that emits the index of the removed predicate whenever a predicate is removed
*/
get predicateRemoved$(): Observable<PredicateRemovalEvent>;
/**
* @returns the root predicate of the search service, that can be used to generate search requests with custom queries
*/
get rootPredicate(): EditableClausePredicateWithGenerators;
/**
* @returns the type of the filter held in this search service instance
*/
get filterType(): FilterType;
/**
* @returns whether the search service is currently loading its state from metadata or not.
*
* See [loadFromMetadata()]{@link SearchService#loadFromMetadata}
*/
get loadingFromMetadata(): boolean;
/**
* @returns an `Observable` that emits `true` if the search service is currently loading its state from metadata,
* emits `false` otherwise.
*
* See [loadFromMetadata()]{@link SearchService#loadFromMetadata}
*/
get loadingFromMetadata$(): Observable<boolean>;
/**
* @returns an Observable that emits whenever the root predicates query changes
*/
protected get predicateQueryChanged$(): Observable<Query>;
/**
* Adds a {@link Predicate} to the Predicate root and updates the active Filter.
*
* Predicates added this way will not be visible in the search GUI.
* If you want to make sure your predicates are visible (and editable)
* use the [addGeneratedLeafPredicate()]{@link SearchService#addGeneratedLeafPredicate} method instead.
* @param newPredicate Predicate that should be added to the search queries.
* @returns the index of the added Predicate
*/
addPredicate(newPredicate: Predicate): number;
/**
* Adds a new hidden branch of the predicate tree with a singular leaf node containing the provided Query.
*
* This can be used to add predicates to the search tree (think header search),
* which can be made visible and editable in the search GUI later.
* @param generator the generator that is in such state, that it generates the Query, that should be added as branch/leaf.
* If the generator doesn't currently generate a query a node with an empty query will be added.
*/
addGeneratedLeafPredicate(generator: Category<any>): number;
/**
* Removes the {@link Predicate} object from the provided index. If the index is invalid does nothing.
* Updates the the active Filter if the Predicate tree was affected.
* @param index index of the Predicate that should be removed
* @param clearInput whether the input, that corresponds to the predicate should be cleared
*/
removePredicate(index: number, clearInput?: boolean): void;
/**
* Removes all {@link Predicate} objects that contribute to the search. Updates the active Filter if it was affected.
*
* @param clearHidden whether the hidden predicates should be cleared as well
*/
clearPredicates(clearHidden?: boolean): void;
/**
* Adds a {@link Filter} with the [fullText]{@link CaseSearchRequestBody#fullText} attribute set to the provided value.
* If full text filter is already set, it will be replaced.
* @param searchedSubstring value that should be searched on all full text fields
*/
setFullTextFilter(searchedSubstring: string): void;
/**
* Clears the full text filter (if set). If the full text filter is not set, does nothing.
*/
clearFullTextFilter(): void;
/**
* Shows the predicates with the given ids. Skips ids that don't exist.
* @param predicateIds the ids of the predicates that should be shown.
*/
show(predicateIds: Array<number>): void;
/**
* Reads the current query from the predicate tree, combines it with the base Filter and full text Filter (if set)
* and updates the active Filter.
*/
protected updateActiveFilter(): void;
/**
* @returns `undefined` if the predicate tree contains no complete query.
* Otherwise returns the serialized form of the completed queries in the predicate tree.
*/
createPredicateMetadata(): PredicateTreeMetadata | undefined;
/**
* Replaces the current predicate filter by the one corresponding to the provided generator metadata.
*
* The {@link CategoryFactory} instance must be provided for this service if we want to use this method. Logs an error and does nothing.
*
* The `filterType` of this search service must match the `filterType` of the provided metadata. Otherwise an error is thrown.
*
* @param metadata the serialized state of the predicate tree that should be restored to this search service
*/
loadFromMetadata(metadata: FilterMetadata): void;
/**
* @returns an Array of filter text segments that correspond to the currently displayed completed predicates
*/
createFilterTextSegments(): Array<FilterTextSegment>;
static ɵfac: i0.ɵɵFactoryDeclaration<SearchService, [null, { optional: true; }, null]>;
static ɵprov: i0.ɵɵInjectableDeclaration<SearchService>;
}