turbogui-angular
Version:
A library that tries to help with the most common user interface elements on several frameworks and platforms
260 lines • 14 kB
TypeScript
import { Type, Injector, ApplicationRef, RendererFactory2, ViewContainerRef, EnvironmentInjector } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { BusyStateBaseComponent } from '../view/components/busy-state-base/busy-state-base.component';
import { DialogBaseComponent } from '../view/components/dialog-base/dialog-base.component';
import { SingletoneStrictClass } from '../model/classes/SingletoneStrictClass';
import * as i0 from "@angular/core";
/**
* Manages the application modal and non modal floating elements
*/
export declare class DialogService extends SingletoneStrictClass {
private readonly matSnackBar;
private readonly matDialog;
private readonly injector;
private readonly applicationRef;
private readonly environmentInjector;
/**
* Used to modify the busy state component that is shown by default by the addModalBusyState() method.
*
* @see this.addModalBusyState()
*/
customBusyStateComponentClass: Type<BusyStateBaseComponent>;
/**
* Check public getter for docs
*/
private _isEnabled;
/**
* Tells if the main application is currently showing a busy state that blocks all user interaction
*/
private _isShowingBusyState;
/**
* A reference to the modal busy state component that is initialized only the first time it is called.
*
* (To append the busy state dynamically, we use the Portal concept from the angular material library)
*/
private _componentPortal;
/**
* A reference to the modal busy state container where the component will be added
*/
private _modalBusyStateHost;
/**
* Tells if the manager is currently showing a snackbar element or not
*/
private _isShowingSnackBar;
/**
* Contains a list of the dialogs (MODAL AND NON MODAL) that are currently visible to the user.
* Each item in this list is a hash that is computed when dialog is created to uniquely identify it.
*
* Empty list means no dialogs are currently visible
*/
private _activeDialogs;
/**
* Contains a list with all the MatDialog instances that are currently visible to the user.
* The list uses the same order as the list of _activeDialogs hash values
*/
private _activeDialogInstances;
/**
* Counts the number of dialogs that are currently open and that can be closed by the user by navigating with the browser
*/
private _activeCloseableDialogs;
/**
* Used to store the initialized Renderer 2 instance that is used by this class
*/
private readonly _renderer;
/**
* Method that is used to delete the window beforeunload event listener once not used anymore
*/
private _windowBeforeUnloadUnListen;
/**
* Method that is used to delete the document keydown event listener once not used anymore
*/
private _documentKeydownUnlisten;
/**
* Method that is used to delete the document mousedown event listener once not used anymore
*/
private _documentMousedownUnlisten;
/**
* Method that is used to delete the document pointerdown event listener once not used anymore
*/
private _documentPointerdownUnlisten;
constructor(rendererFactory: RendererFactory2, matSnackBar: MatSnackBar, matDialog: MatDialog, injector: Injector, applicationRef: ApplicationRef, environmentInjector: EnvironmentInjector);
/**
* Tells if this dialog service is enabled or not. If dialog service is disabled, none of it's features will work
* This is used to block all dialog features normally when shutting down the application
*
* Use with caution. When this is set to false, dialog service stops working.
*/
set isEnabled(v: boolean);
/**
* Enables a warning that will be shown to the user when he/she tries to close the application.
* This warning will prompt the user to continue with the exit process or cancel it.
* The specific texts of this message are a generic ones and cannot be changed.
*
* IMPORTANT: This method must be called after the main application has been initialized in order to work,
* otherwise it will do nothing.
*/
addCloseApplicationWarning(): void;
/**
* Remove the close application warning message if previously assigned
*/
removeCloseApplicationWarning(): void;
/**
* Change the application visual appearance so the user perceives that the application is
* currently busy. While modal busy state is enabled, no user input is possible neither via
* keyboard, mouse or touch. Use this state when performing server requests or operations that
* must block the user interaction with the application. To allow user interaction again, you must
* call removeModalBusyState()
*
* Notice: We can modify the busy state visual component that is shown by this method. To do it, we must
* set this.customBusyStateComponentClass property with our own custom busy state component class. (We can do it at
* our main application component constructor for example). Our custom component must extend the
* BusyStateBaseComponent one to add its own visual appearance.
*
* @see this.customBusyStateComponentClass
*/
addModalBusyState(): void;
/**
* Tells if the application is currently locked in a modal busy state (caused by an addModalBusyState() call)
*/
get isShowingBusyState(): boolean;
/**
* Cancel the application busy state and restore it back to normal so user interaction is allowed again
*/
removeModalBusyState(): void;
/**
* TODO - adapt from TS version
*/
addToolTip(): void;
/**
* Show a non modal snackbar notification to the user (Only one snack-bar can ever be opened at the same time).
*
* Snackbars inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom or top of the screen.
* They shouldn’t interrupt the user experience, and they don’t require user input to disappear.
*
* @param config A MatSnackBarConfig instance with the customizations we want for this snackbar
* @param message The message to show on the snackbar
* @param action If not empty, the text to place on the snackbar confirmation button
* @param actionCallback A method to execute once the user clicks into the action button.
*
* @return A promise that will be resolved once the snackbar is closed.
*/
addSnackBar(config: MatSnackBarConfig, message: string, action?: string): Promise<unknown>;
/**
* Tells if the application is currently showing a snackbar or not
*/
get isShowingSnackBar(): boolean;
/**
* Force the removal of the snack bar dialog if it exists.
*
* If no snackbar is currently visible, this method will do nothing
*/
removeSnackBar(): void;
/**
* Show a dialog with one or more options that can be used to close it. We can use any of the predefined dialog types that are bundled with
* this library or extend DialogBaseComponent to create our own custom ones.
*
* @param dialogComponentClass A class for a component that extends DialogBaseComponent, which will be the dialog that is shown to the user.
* @param properties An object containing the different visual and textual options that this dialog allows.
* IMPORTANT: texts, options and data values need to be read at the dialog component by declaring "@Inject(MAT_DIALOG_DATA) public data: any"
* at the dialog component constructor. This data object will contain the texts, options and data properties
*
* - id: The html unique identifier that the dialog will have once created. If not specified, no id will be explicitly set
* - width: 50% by default. Specify the css value for the default dialog width. As the dialog is responsive, the value will be automatically
* reduced if the available screen is not enough, and will reach the desired value otherwise. We can set any css unit like pixels,
* %, vh, vw, or any other. For example: '400px', '50%', etc.
* - maxWidth: Defines the maximum width that the dialog will have. We can specify it in % or vw, just like is done in
* css. By default it is defined as 96vw, which will fit 96% of the viewport on small devices
* - height: Unset by default. Specify the css value for the dialog height.
* - maxHeight: Defines the maximum height that the dialog will have. We can specify it in % or vh, just like is done in
* css. By default it is defined as 96vh, which will fit 96% of the viewport
* - modal: True (default) if selecting an option is mandatory to close the dialog, false if the dialog can be closed
* by the user clicking outside it
* - closeOnNavigation: Tells if the dialog should be closed when the user navigates with the browser. By default is true for non modal and false for modal dialogs.
* - texts: A list with strings containing the dialog texts, sorted by importance. When dialog has a title, this should
* be placed first, subtitle second and so (Each dialog may accept a different custom number of texts).
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.texts)
* - options: A list of strings that will be used as button captions for each one of the accepted dialog options
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.options)
* - data: An object to pass any extra data we want to the dialog.
* (add "@Inject(MAT_DIALOG_DATA) public data: any" to dialog constructor and read it with data.data)
* - viewContainerRef: This is important if we want to propagate providers from a parent component to this dialog. We must specify
* this reference to make sure the same services injected on the parent are available too at the child dialog
*
* @return A promise that will be resolved once the dialog is closed.
* The promise will receive a selection object with two properties which will correspond to the index and value from the options
* array that's selected by the user. If no option selected, index will be -1 and value null
*/
addDialog(dialogComponentClass: Type<DialogBaseComponent>, properties: {
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
modal?: boolean;
closeOnNavigation?: boolean;
texts?: string[];
options?: string[];
data?: any;
viewContainerRef?: ViewContainerRef;
}): Promise<{
index: number;
value?: any;
}>;
/**
* Show a dialog with a calendar to let the user pick a date.
*
* @param properties An object containing the different visual and textual options that this dialog allows:
* - id: The html unique identifier that the dialog will have once created. If not specified, no id will be explicitly set
* - width: Specify the css value for the default dialog width. As the dialog is responsive, the value will be automatically
* reduced if the available screen is not enough, and will reach the desired value otherwise. We can set any css unit like pixels,
* %, vh, vw, or any other. For example: '400px', '50%', etc.
* - maxWidth: Defines the maximum width that the dialog will have regarding the viewport. We can specify it in % or vw, just like is done in
* css. By default it is defined as 96vw, which will fit 96% of the viewport on small devices
* - height: TODO docs
* - maxHeight: TODO docs
* - modal: True (default) if selecting an option is mandatory to close the dialog, false if the dialog can be closed
* by the user clicking outside it
* - title: An optional dialog title
* - viewContainerRef: This is important to propagate providers from a parent component to this dialog. We must specify
* this reference to make sure the same services injected on the parent are available too at the child dialog
*
* @returns A Promise that resolves to a Date() object selected by the user or null if no selection was made
*/
addDateSelectionDialog(properties: {
id?: string;
width?: string;
maxWidth?: string;
height?: string;
maxHeight?: string;
modal?: boolean;
title?: string;
viewContainerRef: ViewContainerRef;
}): Promise<Date | null>;
/**
* Force the removal of all the dialogs that are currently visible.
*
* If no dialogs are currently visible, this method will do nothing
*/
removeAllDialogs(): void;
/**
* TODO - translate from TS version
*/
/**
* TODO - translate from TS version
*/
/**
* TODO - translate from TS version
*/
/**
* Block all the user interactions with the application (keyboard, touch, mouse, ...)
*/
private _disableUserInteraction;
/**
* Restore the user interactions that were previously disabled with _disableUserInteraction method
*/
private _enableUserInteraction;
static ɵfac: i0.ɵɵFactoryDeclaration<DialogService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<DialogService>;
}
//# sourceMappingURL=dialog.service.d.ts.map