@itwin/core-frontend
Version:
iTwin.js frontend components
316 lines • 16.4 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Notifications
*/
import { BeDuration } from "@itwin/core-bentley";
import { Point2d } from "@itwin/core-geometry";
import { DisplayMessageType, MessageSeverity, RelativePosition } from "@itwin/appui-abstract";
import { IModelApp } from "./IModelApp";
// cSpell:words messagebox
/** Describes the type and behavior of a [[NotifyMessageDetails]].
* @public
* @extensions
*/
export var OutputMessageType;
(function (OutputMessageType) {
/** Temporary message box displays at the top or bottom of the screen then disappears automatically. */
OutputMessageType[OutputMessageType["Toast"] = 0] = "Toast";
/** Message box displays near the cursor over a Viewport and is closed by calling `closePointerMessage`. */
OutputMessageType[OutputMessageType["Pointer"] = 1] = "Pointer";
/** Message box displays at the top or bottom of the screen and contains a Close button. */
OutputMessageType[OutputMessageType["Sticky"] = 2] = "Sticky";
/** Message box displays near an input field and contains a Close button. */
OutputMessageType[OutputMessageType["InputField"] = 3] = "InputField";
/** Modal message box. */
OutputMessageType[OutputMessageType["Alert"] = 4] = "Alert";
})(OutputMessageType || (OutputMessageType = {}));
/** Classifies a [[NotifyMessageDetails]] by its level of importance.
* @public
* @extensions
*/
export var OutputMessagePriority;
(function (OutputMessagePriority) {
OutputMessagePriority[OutputMessagePriority["None"] = 0] = "None";
OutputMessagePriority[OutputMessagePriority["Success"] = 1] = "Success";
OutputMessagePriority[OutputMessagePriority["Error"] = 10] = "Error";
OutputMessagePriority[OutputMessagePriority["Warning"] = 11] = "Warning";
OutputMessagePriority[OutputMessagePriority["Info"] = 12] = "Info";
OutputMessagePriority[OutputMessagePriority["Debug"] = 13] = "Debug";
OutputMessagePriority[OutputMessagePriority["Fatal"] = 17] = "Fatal";
})(OutputMessagePriority || (OutputMessagePriority = {}));
/** Describes the alert behavior of a [[NotifyMessageDetails]].
* @public
* @extensions
*/
export var OutputMessageAlert;
(function (OutputMessageAlert) {
OutputMessageAlert[OutputMessageAlert["None"] = 0] = "None";
OutputMessageAlert[OutputMessageAlert["Dialog"] = 1] = "Dialog";
OutputMessageAlert[OutputMessageAlert["Balloon"] = 2] = "Balloon";
})(OutputMessageAlert || (OutputMessageAlert = {}));
/** Reason for ending the activity message via endActivityMessage
* @public
* @extensions
*/
export var ActivityMessageEndReason;
(function (ActivityMessageEndReason) {
ActivityMessageEndReason[ActivityMessageEndReason["Completed"] = 0] = "Completed";
ActivityMessageEndReason[ActivityMessageEndReason["Cancelled"] = 1] = "Cancelled";
})(ActivityMessageEndReason || (ActivityMessageEndReason = {}));
/** Describes the set of buttons displayed in a message box opened using [[NotificationManager.openMessageBox]].
* @public
* @extensions
*/
export var MessageBoxType;
(function (MessageBoxType) {
MessageBoxType[MessageBoxType["OkCancel"] = 0] = "OkCancel";
MessageBoxType[MessageBoxType["Ok"] = 1] = "Ok";
MessageBoxType[MessageBoxType["LargeOk"] = 2] = "LargeOk";
MessageBoxType[MessageBoxType["MediumAlert"] = 3] = "MediumAlert";
MessageBoxType[MessageBoxType["YesNoCancel"] = 4] = "YesNoCancel";
MessageBoxType[MessageBoxType["YesNo"] = 5] = "YesNo";
})(MessageBoxType || (MessageBoxType = {}));
/** Describes the icon displayed in a messagebox opened using [[NotificationManager.openMessageBox]].
* @public
* @extensions
*/
export var MessageBoxIconType;
(function (MessageBoxIconType) {
MessageBoxIconType[MessageBoxIconType["NoSymbol"] = 0] = "NoSymbol";
MessageBoxIconType[MessageBoxIconType["Information"] = 1] = "Information";
MessageBoxIconType[MessageBoxIconType["Question"] = 2] = "Question";
MessageBoxIconType[MessageBoxIconType["Warning"] = 3] = "Warning";
MessageBoxIconType[MessageBoxIconType["Critical"] = 4] = "Critical";
MessageBoxIconType[MessageBoxIconType["Success"] = 5] = "Success";
})(MessageBoxIconType || (MessageBoxIconType = {}));
/** Describes the possible return values produced when the user clicks a button in a messagebox opened using [[NotificationManager.openMessageBox]].
* @public
* @extensions
*/
export var MessageBoxValue;
(function (MessageBoxValue) {
MessageBoxValue[MessageBoxValue["Apply"] = 1] = "Apply";
MessageBoxValue[MessageBoxValue["Reset"] = 2] = "Reset";
MessageBoxValue[MessageBoxValue["Ok"] = 3] = "Ok";
MessageBoxValue[MessageBoxValue["Cancel"] = 4] = "Cancel";
MessageBoxValue[MessageBoxValue["Default"] = 5] = "Default";
MessageBoxValue[MessageBoxValue["Yes"] = 6] = "Yes";
MessageBoxValue[MessageBoxValue["No"] = 7] = "No";
MessageBoxValue[MessageBoxValue["Retry"] = 8] = "Retry";
MessageBoxValue[MessageBoxValue["Stop"] = 9] = "Stop";
MessageBoxValue[MessageBoxValue["Help"] = 10] = "Help";
MessageBoxValue[MessageBoxValue["YesToAll"] = 11] = "YesToAll";
MessageBoxValue[MessageBoxValue["NoToAll"] = 12] = "NoToAll";
})(MessageBoxValue || (MessageBoxValue = {}));
/** Describes a message to be displayed to the user.
* @public
* @extensions
*/
export class NotifyMessageDetails {
priority;
briefMessage;
detailedMessage;
msgType;
openAlert;
displayTime = BeDuration.fromSeconds(5);
viewport;
inputField;
displayPoint;
relativePosition = RelativePosition.TopRight;
/** Constructor
* @param priority The priority this message should be accorded by the NotificationManager.
* @param briefMessage A short message that conveys the simplest explanation of the issue.
* @param detailedMessage An optional comprehensive message that explains the issue in detail and potentially offers a solution.
* @param msgType The type of message. Defaults to Toast.
* @param openAlert Whether an alert box should be displayed or not, and if so what kind.
*/
constructor(priority, briefMessage, detailedMessage, msgType = OutputMessageType.Toast, openAlert = OutputMessageAlert.None) {
this.priority = priority;
this.briefMessage = briefMessage;
this.detailedMessage = detailedMessage;
this.msgType = msgType;
this.openAlert = openAlert;
}
/** Set OutputMessageType.Pointer message details.
* @param viewport Viewport over which to display the Pointer type message.
* @param displayPoint Point at which to display the Pointer type message.
* @param relativePosition Position relative to displayPoint at which to display the Pointer type message.
*/
setPointerTypeDetails(viewport, displayPoint, relativePosition = RelativePosition.TopRight) {
this.viewport = viewport;
this.displayPoint = Point2d.fromJSON(displayPoint);
this.relativePosition = relativePosition;
this.msgType = OutputMessageType.Pointer;
}
/** Set OutputMessageType.InputField message details.
* @param inputField Input field to which the message pertains. The message will be shown just below this input field element.
*/
setInputFieldTypeDetails(inputField) {
this.inputField = inputField;
this.msgType = OutputMessageType.InputField;
}
}
/** Specifies the details of an activity message to be displayed to the user.
* @public
* @extensions
*/
export class ActivityMessageDetails {
showProgressBar;
showPercentInMessage;
supportsCancellation;
showDialogInitially;
wasCancelled = false;
/**
* @param showProgressBar Indicates whether to show the progress bar in the activity message dialog.
* @param showPercentInMessage Indicates whether to show the percentage complete in the activity message text.
* @param supportsCancellation Indicates whether to show the Cancel button, giving the user the ability to cancel the operation.
* @param showDialogInitially Indicates whether to show the activity message dialog initially. User can click status bar to open it.
*/
constructor(showProgressBar, showPercentInMessage, supportsCancellation, showDialogInitially = true) {
this.showProgressBar = showProgressBar;
this.showPercentInMessage = showPercentInMessage;
this.supportsCancellation = supportsCancellation;
this.showDialogInitially = showDialogInitially;
}
/** Called from NotificationAdmin when the user cancels the activity. */
onActivityCancelled() { this.wasCancelled = true; }
/** Called from NotificationAdmin when the activity completes successfully. */
onActivityCompleted() { this.wasCancelled = false; }
}
/** The NotificationManager controls the interaction with the user for prompts, error messages, and alert dialogs.
* Implementations of the NotificationManager may present the information in different ways. For example, in
* non-interactive sessions, these messages may be saved to a log file or simply discarded.
* @public
* @extensions
*/
export class NotificationManager {
toolTipLocation = new Point2d();
/** Output a prompt, given a localization key.
* @param key The key of the localized string with the prompt message.
*/
outputPromptByKey(key) { this.outputPrompt(IModelApp.localization.getLocalizedString(key)); }
/** Output a localized prompt to the user. A 'prompt' indicates an action the user should take to proceed.
* @param _prompt The localized string with the prompt message.
*/
outputPrompt(_prompt) { }
/** Output a message and/or alert to the user. */
outputMessage(_message) { }
/** Output a MessageBox and wait for response from the user.
* @param _mbType The MessageBox type.
* @param _message The message to display.
* @param _icon The MessageBox icon type.
* @return the response from the user.
*/
async openMessageBox(_mbType, _message, _icon) { return MessageBoxValue.Ok; }
/**
* Set up for activity messages.
* @param _details The activity message details.
* @return true if the message was displayed, false if an invalid priority is specified.
*/
setupActivityMessage(_details) { return true; }
/**
* Output an activity message to the user.
* @param _messageText The message text.
* @param _percentComplete The percentage of completion.
* @return true if the message was displayed, false if the message could not be displayed.
*/
outputActivityMessage(_messageText, _percentComplete) { return true; }
/**
* End an activity message.
* @param _reason The reason for the end of the Activity Message.
* @return true if the message was ended successfully, false if the activityMessage could not be ended.
*/
endActivityMessage(_reason) { return true; }
/** Return true if _showTooltip has an implementation and will display a tooltip. */
get isToolTipSupported() { return false; }
/** Return true if the tooltip is currently open. */
get isToolTipOpen() { return false; }
/** Implement to display a tooltip message at the specified location. */
_showToolTip(_htmlElement, _message, _location, _options) { }
/** Show a tooltip window. Saves tooltip location for AccuSnap to test if cursor has moved far enough away to close tooltip.
* @param htmlElement The HTMLElement that anchors the toolTip.
* @param message What to display inside the ToolTip. May be a string or an HTMLElement.
* @param location An optional location, relative to the origin of _htmlElement, for the ToolTip. If undefined, center of `htmlElement`
* @param options Options that supply additional information about how the ToolTip should function.
* @note If message is an HTMLElement, the notification manager will display the HTMLElement verbatim. This can represent a security
* risk if any part the element is created from user input. Applications should be careful to *sanitize* any such input before
* creating an HTMLElement to pass to this method.
*/
openToolTip(htmlElement, message, location, options) {
this.toolTipLocation.setFrom(location);
this._showToolTip(htmlElement, message, location, options);
}
/** Clear the tooltip if it is currently open. */
clearToolTip() { }
/** Update message position created with [[OutputMessageType.Pointer]].
* @param displayPoint Point at which to display the Pointer type message.
* @param relativePosition Position relative to displayPoint at which to display the Pointer type message.
*/
updatePointerMessage(_displayPoint, _relativePosition = RelativePosition.TopRight) { }
/** Close message created with [[OutputMessageType.Pointer]]. */
closePointerMessage() { }
/** Close message created with [[OutputMessageType.InputField]]. */
closeInputFieldMessage() { }
/** Setup tool assistance instructions for a tool. The instructions include the main instruction, which includes the current prompt.
* @param instructions The tool assistance instructions.
*/
setToolAssistance(instructions) {
this.outputPrompt(instructions ? instructions.mainInstruction.text : "");
}
/**
* Displays a notification message.
* @param severity The severity of the message.
* @param briefMessage A short message that conveys the simplest explanation of the issue.
* @param detailedMessage An optional comprehensive message that explains the issue in detail and potentially offers a solution.
* @param messageType The type of message. Defaults to Toast.
*/
displayMessage(severity, briefMessage, detailedMessage, messageType) {
const details = new NotifyMessageDetails(this.convertSeverityToPriority(severity), briefMessage, detailedMessage, this.convertMessageType(messageType));
this.outputMessage(details);
}
/**
* Displays an input field notification message.
* @param inputField Input field to which the message pertains. The message will be shown just below this input field element.
* @param severity The severity of the message.
* @param briefMessage A short message that conveys the simplest explanation of the issue.
* @param detailedMessage An optional comprehensive message that explains the issue in detail and potentially offers a solution.
*/
displayInputFieldMessage(inputField, severity, briefMessage, detailedMessage) {
const details = new NotifyMessageDetails(this.convertSeverityToPriority(severity), briefMessage, detailedMessage);
details.setInputFieldTypeDetails(inputField);
this.outputMessage(details);
}
convertSeverityToPriority(severity) {
switch (severity) {
case MessageSeverity.Information:
return OutputMessagePriority.Info;
case MessageSeverity.Warning:
return OutputMessagePriority.Warning;
case MessageSeverity.Error:
return OutputMessagePriority.Error;
case MessageSeverity.Fatal:
return OutputMessagePriority.Fatal;
case MessageSeverity.None:
default:
return OutputMessagePriority.None;
}
}
convertMessageType(inMessageType) {
switch (inMessageType) {
case DisplayMessageType.Alert:
return OutputMessageType.Alert;
case DisplayMessageType.InputField:
return OutputMessageType.InputField;
case DisplayMessageType.Sticky:
return OutputMessageType.Sticky;
case DisplayMessageType.Toast:
return OutputMessageType.Toast;
default:
return undefined;
}
}
}
//# sourceMappingURL=NotificationManager.js.map