UNPKG

@netgrif/components-core

Version:

Netgrif Application engine frontend core Angular library

126 lines (125 loc) 5.59 kB
import { TabContent, TabViewInterface } from '../interfaces'; import { OpenedTab } from './opened-tab'; import { Injector } from '@angular/core'; import { ViewService } from '../../routing/view-service/view.service'; import { LoggerService } from '../../logger/services/logger.service'; import { MatTabChangeEvent } from '@angular/material/tabs'; import { FormControl } from '@angular/forms'; /** * Holds the logic for tab management in {@link AbstractTabViewComponent}. * If you want to implement your own TabViewComponent, you might want to extend this class to hold your logic. */ export declare class TabView implements TabViewInterface { private _viewService; private _logger; private _initialTabs; private _parentInjector; static readonly DYNAMIC_TAB_VIEW_ID_SEGMENT = "dynamic"; /** * Holds the tabs that are opened in the tab view, and allows them to be bound to HTML. */ openedTabs: Array<OpenedTab>; /** * Holds the index of the currently selected tab. * * Selected index initializes to `0`. */ selectedIndex: FormControl<number>; private uniqueIdCounter; /** * @ignore * Holds a reference to an object that hides some public attributes and methods from tabs. */ private tabViewInterface; /** * @param _viewService [ViewService]{@link ViewService} reference * @param _logger [Logger]{@link LoggerService} reference * @param _initialTabs Tabs that should be initially opened in the tab view * @param _parentInjector `Injector` instance of the [TabViewComponent]{@link AbstractTabViewComponent}, * to be passed onto each tab, so that the dependency injection tree is not broken */ constructor(_viewService: ViewService, _logger: LoggerService, _initialTabs: Array<TabContent>, _parentInjector: Injector); /** * @returns the index of the currently selected tab */ currentlySelectedTab(): number; /** * Opens a new tab with the provided content. * @param tabContent - content of the new tab * @param autoswitch - whether the newly opened tab should be switched to. Defaults to `false`. * @param openExisting - whether the opened tab already existing should be switched to existing one. Defaults to `true`. * @returns the `tabUniqueId` of the newly opened tab */ openTab(tabContent: TabContent, autoswitch?: boolean, openExisting?: boolean): string; protected findIndexExistingTab(newTab: OpenedTab): number; private searchesForOneCaseId; private getSearchedCaseId; private getSearchedCase; private hasCaseFilterParamSet; private hasBaseFilter; private hasInjectedObject; /** * Adds a new tab into the correct position based on its `order` property. * @param newTab the tab that should be opened * @param autoswitch whether the new tab should be switched to after it is created * @returns the `uniqueId` of the opened tab */ protected openNewTab(newTab: OpenedTab, autoswitch: boolean): string; /** * Switches to a tab with the given `index`. * * Throws an error if the `index` is invalid. * @param index - index of the tab that should be switched to */ switchToTabIndex(index: number): void; /** * Switches to a tab with the given `uniqueId`. * * Throws an error if the `uniqueId` is invalid. * @param uniqueId - id of the tab that should be switched to */ switchToTabUniqueId(uniqueId: string): void; private setTabIndexWithNotification; /** * Closes the tab with the given `index`. * * Throws an error if the `index` is invalid. * * Throws an error if the tab has it's `canBeClosed` property set to `false`. * @param index index of the tab that should be closed * @param force when `true` closes a tab even if it's `cantBeClosed` attribute is set to `true` */ closeTabIndex(index: number, force?: boolean): void; /** * Closes the tab with the given `uniqueId`. Throws an error if the `uniqueId` is invalid. * Throws an error if the tab has it's `canBeClosed` property set to `false`. * @param uniqueId - id of the tab that should be closed * @param force when `true` closes a tab even if it's `cantBeClosed` attribute is set to `true` */ closeTabUniqueId(uniqueId: string, force?: boolean): void; /** * Closes the tab at the given index. * * If the conditions for closing a tab are not met throws an `Error` with the given message. * @param index index of the tab that should be closed * @param force when `true` closes a tab even if it's `cantBeClosed` attribute is set to `true` * @param error the message that should be displayed if the conditions for closing a tab are not met */ protected closeTab(index: number, force: boolean, error: string): void; /** * Initializes the tab if it wasn't initialized yet. * Creates a new {@link ComponentPortal} for the tab and provides the data for the tab under the `NAE_TAB_DATA` injection token. * @param index - index of the tab that should be initialized */ initializeTab(index: number): void; tabChange(event: MatTabChangeEvent): void; /** * Transforms a tab `uniqueId` into it's index. * * Throws an error if no tab with the given `uniqueId` exists. * @param uniqueId - id of the tab that we want to find index for * @returns index of the tab with the given id */ private getTabIndex; private checkIndexRange; }