UNPKG

@adaptabletools/adaptable

Version:

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

69 lines (68 loc) 2.92 kB
import { AdaptableModuleBase } from './AdaptableModuleBase'; import * as ModuleConstants from '../Utilities/Constants/ModuleConstants'; import { DataChangeHistoryStatusBarContent } from '../View/DataChangeHistory/DataChangeHistoryStatusBarContent'; export class DataChangeHistoryModule extends AdaptableModuleBase { constructor(api) { super(ModuleConstants.DataChangeHistoryModuleId, ModuleConstants.DataChangeHistoryFriendlyName, 'target', 'DataChangeHistoryPopup', 'Provides an overview of all previous changes, giving the possibility to undo specific changes', api); this.isListeningToCellDataChanges = false; } onAdaptableReady() { this.api.internalApi.initializeDataChangeHistory(); this.checkListenToCellDataChanged(); } shouldListenToDataChanges() { return this.api.dataChangeHistoryApi.getDataChangeHistoryMode() === 'ACTIVE'; } checkListenToCellDataChanged() { if (!this.isListeningToCellDataChanges) { if (this.shouldListenToDataChanges()) { this.setupCellDataChangeListener(); this.isListeningToCellDataChanges = true; } } } setupCellDataChangeListener() { this.api.internalApi .getDataService() .on('CellDataChanged', (cellDataChangedInfo) => { if (this.isListeningToCellDataChanges && this.isDataChangeLoggable(cellDataChangedInfo)) { this.api.dataChangeHistoryApi.addDataChangeHistoryEntry(cellDataChangedInfo); } }); } isModuleAvailable() { const isAdaptableModuleAvailable = super.isModuleAvailable(); const isAgGridModuleAvailable = this.api.internalApi .getAdaptableInstance() .agGridAdapter.isAgGridModuleRegistered('ClientSideRowModel'); if (isAdaptableModuleAvailable && !isAgGridModuleAvailable) { this.api.logWarn(`Data Change History is NOT available due to missing required AG Grid module: ClientSideRowModel`); } return isAdaptableModuleAvailable && isAgGridModuleAvailable; } getPopupMaxWidth() { return 1000; } hasNamedQueryReferences() { return false; } isDataChangeLoggable(cellDataChangedInfo) { if (cellDataChangedInfo.trigger === 'undo' || cellDataChangedInfo.trigger === 'aggChange') { return false; } if (this.api.optionsApi.getDataChangeHistoryOptions().showDataChange) { return this.api.optionsApi.getDataChangeHistoryOptions().showDataChange(cellDataChangedInfo); } return true; } getViewProperties() { return { getStatusBarPanelProps: () => { return { triggerActionOnWrapperClick: false, content: DataChangeHistoryStatusBarContent, }; }, }; } }