UNPKG

@adaptabletools/adaptable-cjs

Version:

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

80 lines (79 loc) 3.3 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); } 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;