UNPKG

@adaptabletools/adaptable

Version:

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

71 lines (70 loc) 2.85 kB
import ObjectFactory from '../../Utilities/ObjectFactory'; import { ApiBase } from '../Implementation/ApiBase'; export class NamedQueryInternalApi extends ApiBase { /** * Returns the name of all the referenced Named Queries as an array of strings * @param expression query string */ getReferencedNamedQueryNames(expression = '') { try { return this.getAdaptableInternalApi() .getQueryLanguageService() .getNamedQueryNamesFromExpression(expression); } catch (error) { // defensive programing, this should happen only if someone botched Initial Adaptable State this.logWarn(`QueryApi.getReferencedNamedQueryNames received an invalid expression: ${expression} Error: ${error}`); return []; } } /** * Returns all the references in the AdaptableState of the NamedQuery with the given name * @param namedQueryName namedQuery name */ getNamedQueryModuleReferences(namedQueryName) { const references = []; this.getAdaptableInternalApi() .getModules() .forEach((module) => { if (module .getModuleNamedQueryReferences() .some((moduleReference) => moduleReference === namedQueryName)) { references.push(module.moduleInfo.FriendlyName); } }); return references; } validateDeletedNamedQuery(namedQuery) { const namedQueryReferences = this.getNamedQueryModuleReferences(namedQuery); if (namedQueryReferences.length) { const alert = { alertType: 'generic', header: 'Named Query could not be deleted', message: `It is still referenced in the following modules: ${namedQueryReferences.join(', ')}`, alertDefinition: ObjectFactory.CreateInternalAlertDefinitionForMessages('Error'), }; this.getAlertApi().displayAdaptableAlertNotification(alert); return false; } else { return true; } } validateRenamedNamedQuery(namedQuery) { const namedQueryReferences = this.getNamedQueryModuleReferences(namedQuery); if (namedQueryReferences.length) { const alert = { alertType: 'generic', header: 'Named Query could not be renamed', message: `It is currently referenced in the following modules: ${namedQueryReferences.join(', ')}`, alertDefinition: ObjectFactory.CreateInternalAlertDefinitionForMessages('Error'), }; this.getAlertApi().displayAdaptableAlertNotification(alert); return false; } else { return true; } } }