UNPKG

@adaptabletools/adaptable-cjs

Version:

Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

96 lines (95 loc) 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemStatusApiImpl = void 0; const tslib_1 = require("tslib"); const SystemStatusRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/SystemStatusRedux")); const InternalRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/InternalRedux")); const ApiBase_1 = require("./ApiBase"); const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants")); const ObjectFactory_1 = tslib_1.__importDefault(require("../../Utilities/ObjectFactory")); const react_1 = require("react"); const UIHelper_1 = tslib_1.__importDefault(require("../../View/UIHelper")); const StringExtensions_1 = tslib_1.__importDefault(require("../../Utilities/Extensions/StringExtensions")); const SystemStatusInternalApi_1 = require("../Internal/SystemStatusInternalApi"); class SystemStatusApiImpl extends ApiBase_1.ApiBase { constructor(_adaptable) { super(_adaptable); this.internalApi = new SystemStatusInternalApi_1.SystemStatusInternalApi(_adaptable); } setSystemStatus(statusMessage, messageType, statusFurtherInformation) { let systemStatusMessageInfo = ObjectFactory_1.default.CreateSystemStatusMessageInfo(statusMessage, messageType, statusFurtherInformation ? statusFurtherInformation : ''); this.internalApi.addSystemStatusMessageInfo(systemStatusMessageInfo); // publish the event this.getEventApi().internalApi.fireSystemStatusMessageDisplayedEvent(systemStatusMessageInfo); if (this.getNotificationsOptions().showSystemStatusMessageNotifications) { const alertApi = this.getAlertApi(); let fullMessage = statusMessage; if (StringExtensions_1.default.IsNotNullOrEmpty(statusFurtherInformation)) { fullMessage += '\n' + statusFurtherInformation; } switch (messageType) { case 'Success': alertApi.showAlertSuccess('System Status Success', fullMessage); return; case 'Info': alertApi.showAlertInfo('System Status Info', fullMessage); return; case 'Warning': alertApi.showAlertWarning('System Status Warning', fullMessage); return; case 'Error': alertApi.showAlertError('System Status Error', fullMessage); return; } } if (this.getContainerOptions().systemStatusContainer != null) { this.displayMessageInDiv(statusMessage, statusFurtherInformation, messageType); } // doesnt do anything but useful for Audit this.dispatchAction(SystemStatusRedux.SystemStatusSetMesage(systemStatusMessageInfo)); } displayMessageInDiv(statusMessage, statusFurtherInformation, messageType) { if (!this.systemStatusDiv) { let optionsDiv = this.getContainerOptions().systemStatusContainer; if (optionsDiv) { this.systemStatusDiv = typeof optionsDiv === 'string' ? document.getElementById(optionsDiv) : optionsDiv; } } if (this.systemStatusDiv) { if (StringExtensions_1.default.IsNotNullOrEmpty(statusFurtherInformation)) { statusMessage += statusFurtherInformation; } const foreColor = messageType ? UIHelper_1.default.getColorByMessageType(messageType) : 'black'; this._adaptable.renderReactRoot((0, react_1.createElement)('span', { style: { color: foreColor } }, statusMessage), this.systemStatusDiv); } } setErrorSystemStatus(statusMessage, statusFurtherInformation) { this.setSystemStatus(statusMessage, 'Error', statusFurtherInformation); } setWarningSystemStatus(statusMessage, statusFurtherInformation) { this.setSystemStatus(statusMessage, 'Warning', statusFurtherInformation); } setSuccessSystemStatus(statusMessage, statusFurtherInformation) { this.setSystemStatus(statusMessage, 'Success', statusFurtherInformation); } setInfoSystemStatus(statusMessage, statusFurtherInformation) { this.setSystemStatus(statusMessage, 'Info', statusFurtherInformation); } openSystemStatusSettingsPanel() { this.showModulePopup(ModuleConstants.SystemStatusModuleId); } getCurrentSystemStatusMessageInfo() { const messageInfos = this.internalApi.getSystemStatusMessageInfos() || []; const orderedArray = messageInfos.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime()); return orderedArray[0]; } deleteAllSystemStatusMessages() { this.dispatchAction(InternalRedux.SystemStatusMessageInfoDeleteAll()); } destroy() { this.systemStatusDiv = null; super.destroy(); } } exports.SystemStatusApiImpl = SystemStatusApiImpl;