UNPKG

@adaptabletools/adaptable

Version:

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

124 lines (123 loc) 4.64 kB
import * as PopupRedux from '../../Redux/ActionsReducers/PopupRedux'; import { ArrayExtensions } from '../../Utilities/Extensions/ArrayExtensions'; import { CUSTOM_WINDOW_FACTORY_ID } from '../../View/Components/Popups/WindowPopups/WindowPopups'; import { UserInterfaceInternalApi } from '../Internal/UserInterfaceInternalApi'; import { ApiBase } from './ApiBase'; import { ProgressIndicatorHide, ProgressIndicatorShow, } from '../../Redux/ActionsReducers/PopupRedux'; export class UserInterfaceApiImpl extends ApiBase { constructor(_adaptable) { super(_adaptable); this.showProgressIndicatorTimeout = null; this.internalApi = new UserInterfaceInternalApi(_adaptable); } getColorPalette() { let colorPalette = this.getUserInterfaceOptions().colorPalette; // first do the function then get hardcoded items if (colorPalette != null && typeof colorPalette === 'function') { const currentTheme = this.getThemeApi().getCurrentTheme(); const colours = colorPalette(currentTheme); return colours; } else { let arr = colorPalette; if (arr && ArrayExtensions.IsNotNullOrEmpty(arr)) { return arr; } } return []; } getStyleClassNames() { return this.getUserInterfaceOptions().styleClassNames; } getEditableCellStyle() { return this.getUserInterfaceOptions().editableCellStyle; } getEditedCellStyle() { return this.getUserInterfaceOptions().editedCellStyle; } getReadOnlyCellStyle() { return this.getUserInterfaceOptions().readOnlyCellStyle; } getAdaptableObjectTags() { const objectTags = this.getUserInterfaceOptions().objectTags; if (objectTags != null && typeof objectTags === 'function') { return objectTags(this.getAdaptableInternalApi().buildBaseContext()); } else { let arr = objectTags; if (arr && ArrayExtensions.IsNotNullOrEmpty(arr)) { return arr; } } } getAdaptableObjectsWithTag(tag, adaptableModule) { if (adaptableModule) { const module = this.getAdaptableInternalApi() .getModuleService() .getModuleById(adaptableModule); if (!module) { return undefined; } return module .getModuleAdaptableObjects() ?.filter((ao) => ao.Tags?.includes(tag)); } else { const modules = this.getAdaptableInternalApi().getModules(); let returnObjects = []; modules.forEach((module) => { returnObjects.push(...module .getModuleAdaptableObjects() ?.filter((ao) => ao.Tags?.includes(tag))); }); return returnObjects; } } getCustomIconDefinition(iconName) { let customIcon = undefined; const customIcons = this.getUserInterfaceOptions().customIcons ?? []; customIcon = customIcons.find((icon) => icon.name === iconName); if (customIcon) { return customIcon.icon; } return customIcon; } showProgressIndicator(config) { if (config.delay) { this.showProgressIndicatorTimeout = setTimeout(() => { this.dispatchAction(ProgressIndicatorShow(config)); }, config.delay); } else { this.dispatchAction(ProgressIndicatorShow(config)); } } hideProgressIndicator() { if (this.showProgressIndicatorTimeout) { clearTimeout(this.showProgressIndicatorTimeout); this.showProgressIndicatorTimeout = null; } this.dispatchAction(ProgressIndicatorHide()); } openCustomWindowPopup(config) { const close = () => { this.dispatchAction(PopupRedux.PopupHideWindow(config.id)); }; const action = PopupRedux.PopupShowWindow({ Id: config.id, Title: config.title, FactoryId: CUSTOM_WINDOW_FACTORY_ID, PopupProps: { render: config.render, frameworkComponent: config.frameworkComponent, onFrameworkComponentDestroyed: config.onFrameworkComponentDestroyed, }, Icon: config.icon, }); this.dispatchAction(action); return { close }; } closeCustomWindowPopup(windowId) { this.dispatchAction(PopupRedux.PopupHideWindow(windowId)); } }