@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
74 lines (73 loc) • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataChangeHistoryModule = void 0;
const tslib_1 = require("tslib");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
const DataChangeHistoryStatusBarContent_1 = require("../View/DataChangeHistory/DataChangeHistoryStatusBarContent");
class DataChangeHistoryModule extends AdaptableModuleBase_1.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_1.DataChangeHistoryStatusBarContent,
};
},
};
}
}
exports.DataChangeHistoryModule = DataChangeHistoryModule;