UNPKG

@adaptabletools/adaptable

Version:

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

88 lines (87 loc) 4.45 kB
import * as SystemStatusRedux from '../../Redux/ActionsReducers/SystemStatusRedux'; import * as InternalRedux from '../../Redux/ActionsReducers/InternalRedux'; import { ApiBase } from './ApiBase'; import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants'; import ObjectFactory from '../../Utilities/ObjectFactory'; import { createElement } from 'react'; import UIHelper from '../../View/UIHelper'; import StringExtensions from '../../Utilities/Extensions/StringExtensions'; import { SystemStatusInternalApi } from '../Internal/SystemStatusInternalApi'; import { resolveContainerElement } from '../../Utilities/resolveContainerElement'; export class SystemStatusApiImpl extends ApiBase { systemStatusDiv; internalApi; constructor(_adaptable) { super(_adaptable); this.internalApi = new SystemStatusInternalApi(_adaptable); } setSystemStatus(statusMessage, messageType, statusFurtherInformation) { let systemStatusMessageInfo = ObjectFactory.CreateSystemStatusMessageInfo(statusMessage, messageType, statusFurtherInformation ? statusFurtherInformation : ''); this.internalApi.addSystemStatusMessageInfo(systemStatusMessageInfo); this.getEventApi().internalApi.fireSystemStatusMessageDisplayedEvent(systemStatusMessageInfo); if (this.getNotificationsOptions().showSystemStatusMessageNotifications) { const alertApi = this.getAlertApi(); let fullMessage = statusMessage; if (StringExtensions.IsNotNullOrEmpty(statusFurtherInformation)) { fullMessage += '\n' + statusFurtherInformation; } switch (messageType) { case 'Success': alertApi.showAlertSuccess('System Status', fullMessage); return; case 'Info': alertApi.showAlertInfo('System Status', fullMessage); return; case 'Warning': alertApi.showAlertWarning('System Status', fullMessage); return; case 'Error': alertApi.showAlertError('System Status', fullMessage); return; } } if (this.getContainerOptions().systemStatusContainer != null) { this.displayMessageInDiv(statusMessage, statusFurtherInformation, messageType); } this.dispatchAction(SystemStatusRedux.SystemStatusSetMesage(systemStatusMessageInfo)); } displayMessageInDiv(statusMessage, statusFurtherInformation, messageType) { if (!this.systemStatusDiv) { this.systemStatusDiv = resolveContainerElement(this.getContainerOptions().systemStatusContainer, this.getAdaptableInternalApi().buildBaseContext()); } if (this.systemStatusDiv) { if (StringExtensions.IsNotNullOrEmpty(statusFurtherInformation)) { statusMessage += statusFurtherInformation; } const foreColor = messageType ? UIHelper.getColorByMessageType(messageType) : 'black'; this._adaptable.renderReactRoot(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(); } }