File

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

Description

A universal search component that can be used to interactively create search predicates for anything with supported categories.

This component is responsible for the interactive creation of an AND ClausePredicate object instance. The nested Predicates are OR ClausePredicate instances created by AbstractSearchClauseComponent.

Search categories must be provided by the NAE_SEARCH_CATEGORIES injection token. Default factory methods for task and case search categories exist. See their documentation for more information.

The search component's visuals can be configured either by the NAE_SEARCH_COMPONENT_CONFIGURATION injection token, or by the appropriate component inputs. The injection token configuration takes precedence over the inputs if both are present.

Implements

SearchComponentConfiguration OnInit

Metadata

selector ncc-abstract-search

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

Protected constructor(_searchService: SearchService, _logger: LoggerService, _dialogService: DialogService, _translate: TranslateService, _userFilterService: UserFiltersService, _allowedNetsService: AllowedNetsService, _viewIdService: ViewIdService, _searchCategories: Array<Type<Category<any>>>, _configuration: SearchComponentConfiguration, _filtersFilter: Filter, _navigationItemTaskData: Array)
Parameters :
Name Type Optional
_searchService SearchService No
_logger LoggerService No
_dialogService DialogService No
_translate TranslateService No
_userFilterService UserFiltersService No
_allowedNetsService AllowedNetsService No
_viewIdService ViewIdService No
_searchCategories Array<Type<Category<any>>> No
_configuration SearchComponentConfiguration No
_filtersFilter Filter No
_navigationItemTaskData Array<DataGroup> No

Inputs

additionalFilterData
Type : TaskSetDataRequestFields
Default value : {}

Set data request body, that is sent to the filter in addition to the default body. The default body is applied first and can be overridden by this argument.

disabled
Type : boolean
initialSearchMode
showAdvancedSearchHelp
Type : boolean
showLoadFilterButton
Type : boolean
showSaveFilterButton
Type : boolean
showSearchIcon
Type : boolean
showSearchToggleButton
Type : boolean

Outputs

filterLoaded
Type : EventEmitter<SavedFilterMetadata>

The emitted data contains the filter case object

filterSaved
Type : EventEmitter<SavedFilterMetadata>

The emitted data contains only the saved case's ID

Methods

Public hasPredicates
hasPredicates()
Returns : boolean
Public loadFilter
loadFilter()

The loaded filter data are emitted into the filterLoaded EventEmitter

Returns : void
ngOnInit
ngOnInit()
Returns : void
Public saveFilter
saveFilter()

The saved filter data are emitted into the filterSaved EventEmitter

Returns : void
Public showHelp
showHelp()
Returns : void
Public toggleSearchMode
toggleSearchMode()
Returns : void

Properties

additionalFilterData
Type : TaskSetDataRequestFields
Default value : {}
Decorators :
@Input()

Set data request body, that is sent to the filter in addition to the default body. The default body is applied first and can be overridden by this argument.

Public advancedSearchDisplayed
Public disabled
Type : boolean
Decorators :
@Input()
filterLoaded
Type : EventEmitter<SavedFilterMetadata>
Default value : new EventEmitter()
Decorators :
@Output()

The emitted data contains the filter case object

filterSaved
Type : EventEmitter<SavedFilterMetadata>
Default value : new EventEmitter()
Decorators :
@Output()

The emitted data contains only the saved case's ID

Accessors

showSearchIcon
getshowSearchIcon()
setshowSearchIcon(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
showAdvancedSearchHelp
getshowAdvancedSearchHelp()
setshowAdvancedSearchHelp(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
showSaveFilterButton
getshowSaveFilterButton()
setshowSaveFilterButton(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
showLoadFilterButton
getshowLoadFilterButton()
setshowLoadFilterButton(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
initialSearchMode
getinitialSearchMode()
setinitialSearchMode(value: SearchMode)
Parameters :
Name Type Optional
value SearchMode No
Returns : void
showSearchToggleButton
getshowSearchToggleButton()
setshowSearchToggleButton(value: boolean)
Parameters :
Name Type Optional
value boolean No
Returns : void
import {SearchService} from '../search-service/search.service';
import {LoggerService} from '../../logger/services/logger.service';
import {DialogService} from '../../dialog/services/dialog.service';
import {TranslateService} from '@ngx-translate/core';
import {NAE_SEARCH_COMPONENT_CONFIGURATION} from '../models/component-configuration/search-component-configuration-injection-token';
import {Component, EventEmitter, Inject, Input, OnInit, Optional, Output, Type} from '@angular/core';
import {SearchComponentConfiguration} from '../models/component-configuration/search-component-configuration';
import {SearchMode} from '../models/component-configuration/search-mode';
import {UserFiltersService} from '../../filter/user-filters.service';
import {AllowedNetsService} from '../../allowed-nets/services/allowed-nets.service';
import {NAE_SEARCH_CATEGORIES} from '../category-factory/search-categories-injection-token';
import {Category} from '../models/category/category';
import {SavedFilterMetadata} from '../models/persistance/saved-filter-metadata';
import {ViewIdService} from '../../user/services/view-id.service';
import {NAE_FILTERS_FILTER} from '../../filter/models/filters-filter-injection-token';
import {Filter} from '../../filter/models/filter';
import {TaskSetDataRequestFields} from '../../resources/interface/task-set-data-request-body';
import {NAE_NAVIGATION_ITEM_TASK_DATA} from '../../navigation/model/filter-case-injection-token';
import {DataGroup} from '../../resources/interface/data-groups';

/**
 * A universal search component that can be used to interactively create search predicates for anything with supported categories.
 *
 * This component is responsible for the interactive creation of an AND {@link ClausePredicate} object instance.
 * The nested Predicates are OR {@link ClausePredicate} instances created by {@link AbstractSearchClauseComponent}.
 *
 * Search categories must be provided by the {@link NAE_SEARCH_CATEGORIES} injection token.
 * Default factory methods for [task]{@link defaultTaskSearchCategoriesFactory} and
 * [case]{@link defaultCaseSearchCategoriesFactory} search categories exist. See their documentation for more information.
 *
 * The search component's visuals can be configured either by the {@link NAE_SEARCH_COMPONENT_CONFIGURATION} injection token,
 * or by the appropriate component inputs. The injection token configuration takes precedence over the inputs if both are present.
 */
@Component({
    selector: 'ncc-abstract-search',
    template: ''
})
export abstract class AbstractSearchComponent implements SearchComponentConfiguration, OnInit {

    public advancedSearchDisplayed;

    private _showSearchIcon = true;
    private _showSearchToggleButton = true;
    private _showAdvancedSearchHelp = true;
    private _showSaveFilterButton = true;
    private _showLoadFilterButton = true;
    private _initialSearchMode = SearchMode.FULLTEXT;

    @Input() public disabled: boolean;
    /**
     * Set data request body, that is sent to the filter in addition to the default body.
     * The default body is applied first and can be overridden by this argument.
     */
    @Input() additionalFilterData: TaskSetDataRequestFields = {};

    /**
     * The emitted data contains the filter case object
     */
    @Output() filterLoaded: EventEmitter<SavedFilterMetadata> = new EventEmitter();
    /**
     * The emitted data contains only the saved case's ID
     */
    @Output() filterSaved: EventEmitter<SavedFilterMetadata> = new EventEmitter();

    protected constructor(protected _searchService: SearchService,
                          protected _logger: LoggerService,
                          protected _dialogService: DialogService,
                          protected _translate: TranslateService,
                          protected _userFilterService: UserFiltersService,
                          protected _allowedNetsService: AllowedNetsService,
                          protected _viewIdService: ViewIdService,
                          @Inject(NAE_SEARCH_CATEGORIES) protected _searchCategories: Array<Type<Category<any>>>,
                          @Optional() @Inject(NAE_SEARCH_COMPONENT_CONFIGURATION) protected _configuration: SearchComponentConfiguration,
                          @Optional() @Inject(NAE_FILTERS_FILTER) protected _filtersFilter: Filter = null,
                          @Optional() @Inject(NAE_NAVIGATION_ITEM_TASK_DATA) protected _navigationItemTaskData: Array<DataGroup> = null) {
        if (this._configuration === null) {
            this._configuration = {};
        }
    }

    ngOnInit(): void {
        this.advancedSearchDisplayed = this.initialSearchMode === SearchMode.ADVANCED;
    }

    get showSearchIcon(): boolean {
        return this._configuration.showSearchIcon ?? this._showSearchIcon;
    }

    @Input() set showSearchIcon(value: boolean) {
        this._showSearchIcon = value;
    }

    get showAdvancedSearchHelp(): boolean {
        return this._configuration.showAdvancedSearchHelp ?? this._showAdvancedSearchHelp;
    }

    @Input() set showAdvancedSearchHelp(value: boolean) {
        this._showAdvancedSearchHelp = value;
    }

    get showSaveFilterButton(): boolean {
        return this._configuration.showSaveFilterButton ?? this._showSaveFilterButton;
    }

    @Input() set showSaveFilterButton(value: boolean) {
        this._showSaveFilterButton = value;
    }

    get showLoadFilterButton(): boolean {
        return this._configuration.showLoadFilterButton ?? this._showLoadFilterButton;
    }

    @Input() set showLoadFilterButton(value: boolean) {
        this._showLoadFilterButton = value;
    }

    get initialSearchMode(): SearchMode {
        return this._configuration.initialSearchMode ?? this._initialSearchMode;
    }

    @Input() set initialSearchMode(value: SearchMode) {
        this._initialSearchMode = value;
    }

    get showSearchToggleButton(): boolean {
        return this._configuration.showSearchToggleButton ?? this._showSearchToggleButton;
    }

    @Input() set showSearchToggleButton(value: boolean) {
        this._showSearchToggleButton = value;
    }

    public hasPredicates(): boolean {
        return Array.from(this._searchService.rootPredicate.getPredicateMap().values()).some(value => value.isVisible);
    }

    public toggleSearchMode(): void {
        if (this.advancedSearchDisplayed) {
            this._searchService.clearPredicates();
        } else {
            this._searchService.clearFullTextFilter();
        }

        this.advancedSearchDisplayed = !this.advancedSearchDisplayed;
    }

    public showHelp(): void {
        this._dialogService.openAlertDialog(this._translate.instant('search.help.title'), this._translate.instant('search.help.text'));
    }

    /**
     * The saved filter data are emitted into the [filterSaved]{@link AbstractSearchComponent#filterSaved} `EventEmitter`
     */
    public saveFilter(): void {
        this._userFilterService.save(
            this._searchService,
            this._allowedNetsService.allowedNetsIdentifiers,
            this._searchCategories,
            this._viewIdService.viewId,
            this.additionalFilterData,
            this._configuration.saveFilterWithDefaultCategories ?? true,
            this._configuration.inheritAllowedNets ?? true,
            this._navigationItemTaskData).subscribe(savedFilterData => {
                if (savedFilterData) {
                    this.filterSaved.emit(savedFilterData);
                }
        });
    }

    /**
     * The loaded filter data are emitted into the [filterLoaded]{@link AbstractSearchComponent#filterLoaded} `EventEmitter`
     */
    public loadFilter(): void {
        this._userFilterService.load(this._searchService.filterType, this._filtersFilter ?? undefined).subscribe(savedFilterData => {
            if (savedFilterData) {
                this.filterLoaded.emit(savedFilterData);
            }
        });
    }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""