UNPKG

@adaptabletools/adaptable-cjs

Version:

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

58 lines (57 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NamedQueryApiImpl = void 0; const tslib_1 = require("tslib"); const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants")); const StringExtensions_1 = require("../../Utilities/Extensions/StringExtensions"); const NamedQueryInternalApi_1 = require("../Internal/NamedQueryInternalApi"); const ApiBase_1 = require("./ApiBase"); const NamedQueryRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/NamedQueryRedux")); class NamedQueryApiImpl extends ApiBase_1.ApiBase { constructor(_adaptable) { super(_adaptable); this.internalApi = new NamedQueryInternalApi_1.NamedQueryInternalApi(_adaptable); } addNamedQuery(namedQuery) { this.dispatchAction(NamedQueryRedux.NamedQueryAdd(namedQuery)); } addNamedQueries(namedQueries) { this.dispatchAction(NamedQueryRedux.NamedQueriesAdd(namedQueries)); } getNamedQueryState() { return this.getAdaptableState().NamedQuery; } getNamedQueries() { return this.getNamedQueryState().NamedQueries || []; } getNamedQueryByName(namedQueryName) { return this.getNamedQueries().find((se) => se.Name == namedQueryName); } isValidNamedQuery(namedQuery) { if ((0, StringExtensions_1.IsNullOrEmptyOrWhiteSpace)(namedQuery?.Name)) { return { valid: false, message: 'Named Query name cannot be blank' }; } // check that there is no other existing named query with the same name const duplicate = this.getNamedQueries().find((q) => q.Name === namedQuery.Name && q.Uuid !== namedQuery.Uuid); if (duplicate) { return { valid: false, message: 'A Named Query already exists with that name', }; } return { valid: true, message: '' }; } openNamedQuerySettingsPanel() { this.showModulePopup(ModuleConstants.NamedQueryModuleId); } runNamedQuery(namedQuery) { this.getGridFilterApi().setGridFilterExpression(namedQuery.Name); } runQueryByName(queryName) { const namedQuery = this.getNamedQueryByName(queryName); if (namedQuery) { this.runNamedQuery(namedQuery); } } } exports.NamedQueryApiImpl = NamedQueryApiImpl;