UNPKG

@adaptabletools/adaptable-cjs

Version:

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

116 lines (115 loc) 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomSortApiImpl = void 0; const tslib_1 = require("tslib"); const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants")); const CustomSortRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/CustomSortRedux")); const ApiBase_1 = require("./ApiBase"); const CustomSortInternalApi_1 = require("../Internal/CustomSortInternalApi"); class CustomSortApiImpl extends ApiBase_1.ApiBase { constructor(_adaptable) { super(_adaptable); this.internalApi = new CustomSortInternalApi_1.CustomSortInternalApi(_adaptable); } getCustomSortState() { return this.getAdaptableState().CustomSort; } getCustomSorts(config) { return (this.handleLayoutAssociatedObjects(this.getCustomSortState().CustomSorts, 'CustomSort', config) ?? []); } getCustomSortById(id) { return this.getCustomSorts().find((customSort) => customSort.Uuid === id); } getLiveCustomSorts() { let returnVals = []; const sortedColIds = this.getGridApi() .getColumnSorts() .map((c) => c.ColumnId); const activeCustomSorts = this.getActiveCustomSorts(); if (sortedColIds == undefined || activeCustomSorts == undefined) { return returnVals; } sortedColIds.forEach((columnId) => { const customSort = activeCustomSorts.find((c) => c.ColumnId == columnId); if (customSort) { returnVals.push(customSort); } }); return returnVals; } getLiveCustomSortComparers() { let returnComparers = []; const sortedColIds = this.getGridApi() .getColumnSorts() .map((c) => c.ColumnId); const sortedCols = this.getColumnApi().getColumnsWithColumnIds(sortedColIds); const customSortComparers = this.getCustomSortOptions().customSortComparers; if (sortedColIds == undefined || customSortComparers == undefined) { return returnComparers; } const scopeApi = this.getColumnScopeApi(); sortedCols.forEach((column) => { const comparer = customSortComparers.find((acs) => scopeApi.isColumnInScope(column, acs.scope)); if (comparer && !returnComparers.includes(comparer)) { returnComparers.push(comparer); } }); return returnComparers; } getActiveCustomSorts(config) { return this.getCustomSorts(config).filter((customSort) => !customSort.IsSuspended); } getSuspendedCustomSorts(config) { return this.getCustomSorts(config).filter((customSort) => customSort.IsSuspended); } getCustomSortByColumn(column) { return this.getCustomSorts().find((cs) => cs.ColumnId == column); } getCustomSortForColumn(columnId) { return this.getCustomSorts().find((cs) => cs.ColumnId == columnId); } addCustomSort(customSort) { this.addUidToAdaptableObject(customSort); this.dispatchAction(CustomSortRedux.CustomSortAdd(customSort)); return this.getCustomSortById(customSort.Uuid); } createCustomSort(columnId, values) { let customSort = { ColumnId: columnId, SortedValues: values }; return this.addCustomSort(customSort); } editCustomSort(columnId, values) { const previousCustomSort = this.getCustomSortForColumn(columnId); if (!previousCustomSort) { this.logWarn(`No custom sort defined for ${columnId}`); return; } const newCustomSort = { ...previousCustomSort, SortedValues: values, }; this.dispatchAction(CustomSortRedux.CustomSortEdit(newCustomSort)); return this.getCustomSortByColumn(columnId); } deleteCustomSort(column) { let customSort = this.getCustomSortForColumn(column); this.dispatchAction(CustomSortRedux.CustomSortDelete(customSort)); } suspendCustomSort(customSort) { this.dispatchAction(CustomSortRedux.CustomSortSuspend(customSort)); return this.getCustomSortById(customSort.Uuid); } unSuspendCustomSort(customSort) { this.dispatchAction(CustomSortRedux.CustomSortUnSuspend(customSort)); return this.getCustomSortById(customSort.Uuid); } suspendAllCustomSort() { this.dispatchAction(CustomSortRedux.CustomSortSuspendAll()); } unSuspendAllCustomSort() { this.dispatchAction(CustomSortRedux.CustomSortUnSuspendAll()); } openCustomSortSettingsPanel() { this.showModulePopup(ModuleConstants.CustomSortModuleId); } } exports.CustomSortApiImpl = CustomSortApiImpl;