From f5a5983bc1a9752834dd8ad58ea1b52575c86196 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 5 Apr 2023 20:06:30 -0300 Subject: [PATCH] Declare some js globals as Window properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .eslintrc.json | 1 + js/global.d.ts | 8 ++++++++ js/src/chart.ts | 16 ++++++++++++---- js/src/designer/history.ts | 7 ++++++- js/src/designer/init.ts | 15 ++++++++++++++- js/src/error_report.ts | 7 +++++++ js/src/gis_data_editor.ts | 19 +++++++++++++------ js/src/modules/config.ts | 10 +++++++++- js/src/modules/console.ts | 6 ++++++ js/src/modules/functions.ts | 7 +++++++ js/src/modules/navigation.ts | 6 ++++++ js/src/sql.ts | 6 ++++++ js/src/table/change.ts | 13 ++++++++++--- js/src/table/gis_visualization.ts | 26 ++++++++++++++++---------- js/src/validator-messages.ts | 6 ++++++ 15 files changed, 127 insertions(+), 26 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c104018da7..79261d576c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -67,6 +67,7 @@ "wrap-iife": "error", "@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-this-alias": "off" } diff --git a/js/global.d.ts b/js/global.d.ts index 2f65f51d52..268bf50513 100644 --- a/js/global.d.ts +++ b/js/global.d.ts @@ -9,6 +9,12 @@ declare var maxInputVars: number; declare function sprintf(format: string, ...values: (string|number)[]): string; +interface Window { + ol: any; + + drawOpenLayers: () => any; +} + interface JQuery { getPostData: () => string; @@ -27,4 +33,6 @@ interface JQuery { interface JQueryStatic { timepicker: JQueryUI.Datepicker; + + jqplot: any; } diff --git a/js/src/chart.ts b/js/src/chart.ts index 7f6bb1493f..dbd122e172 100644 --- a/js/src/chart.ts +++ b/js/src/chart.ts @@ -13,7 +13,6 @@ var ChartType = { TIMELINE: 'timeline', SCATTER: 'scatter' }; -window.ChartType = ChartType; /** * Column type enumeration @@ -24,7 +23,6 @@ var ColumnType = { BOOLEAN: 'boolean', DATE: 'date' }; -window.ColumnType = ColumnType; /** * Abstract chart factory which defines the contract for chart factories @@ -211,8 +209,6 @@ var DataTable = function () { }; }; -window.DataTable = DataTable; - /** ***************************************************************************** * JQPlot specific code ******************************************************************************/ @@ -729,4 +725,16 @@ JQPlotChartFactory.prototype.createChart = function (type, elementId) { return chart; }; +declare global { + interface Window { + ChartType: typeof ChartType; + ColumnType: typeof ColumnType; + DataTable: typeof DataTable; + JQPlotChartFactory: typeof JQPlotChartFactory; + } +} + +window.ChartType = ChartType; +window.ColumnType = ColumnType; +window.DataTable = DataTable; window.JQPlotChartFactory = JQPlotChartFactory; diff --git a/js/src/designer/history.ts b/js/src/designer/history.ts index fac1844a14..1e33d9b4b0 100644 --- a/js/src/designer/history.ts +++ b/js/src/designer/history.ts @@ -887,7 +887,12 @@ DesignerHistory.buildQuery = function () { }); }; -// @ts-ignore +declare global { + interface Window { + DesignerHistory: typeof DesignerHistory; + } +} + window.DesignerHistory = DesignerHistory; export { DesignerHistory }; diff --git a/js/src/designer/init.ts b/js/src/designer/init.ts index c0ef8ea289..d5e88ac9a4 100644 --- a/js/src/designer/init.ts +++ b/js/src/designer/init.ts @@ -319,6 +319,20 @@ AJAX.registerTeardown('designer/init.js', function () { $('.trigger').off('click'); }); +declare global { + interface Window { + designerConfig: { + db: string; + scriptTables: { j_tabs: any[], h_tabs: any[] }; + scriptContr: any[]; + server: number; + scriptDisplayField: any[]; + displayPage: number; + tablesEnabled: boolean; + }; + } +} + AJAX.registerOnload('designer/init.js', function () { $('.trigger').on('click', function () { $('.panel').toggle('fast'); @@ -328,7 +342,6 @@ AJAX.registerOnload('designer/init.js', function () { return false; }); - // @ts-ignore const configValues = window.designerConfig; DesignerConfig.jTabs = configValues.scriptTables.j_tabs; diff --git a/js/src/error_report.ts b/js/src/error_report.ts index 39e3f0021c..9a428b9c61 100644 --- a/js/src/error_report.ts +++ b/js/src/error_report.ts @@ -3,6 +3,13 @@ import { AJAX } from './modules/ajax.ts'; import { CommonParams } from './modules/common.ts'; import { ajaxShowMessage } from './modules/ajax-message.ts'; import getImageTag from './modules/functions/getImageTag.ts'; +import type * as TraceKit from 'tracekit/tracekit.d.ts'; + +declare global { + interface Window { + TraceKit: typeof TraceKit; + } +} /** * general function, usually for data manipulation pages diff --git a/js/src/gis_data_editor.ts b/js/src/gis_data_editor.ts index 156df569c0..82b303fb06 100644 --- a/js/src/gis_data_editor.ts +++ b/js/src/gis_data_editor.ts @@ -126,8 +126,6 @@ function loadJSAndGISEditor (value, field, type, inputName) { window.gisEditorLoaded = true; } -window.loadJSAndGISEditor = loadJSAndGISEditor; - /** * Loads the GIS editor via AJAX * @@ -157,8 +155,6 @@ function loadGISEditor (value, field, type, inputName) { }, 'json'); } -window.loadGISEditor = loadGISEditor; - /** * Opens up the dialog for the GIS data editor. */ @@ -189,8 +185,6 @@ function openGISEditor () { $gisEditor.fadeIn('fast'); } -window.openGISEditor = openGISEditor; - /** * Prepare and insert the GIS data in Well Known Text format * to the input field. @@ -402,3 +396,16 @@ AJAX.registerOnload('gis_data_editor.js', function () { $noOfGeomsInput.val(noOfGeoms + 1); }); }); + +declare global { + interface Window { + gisEditorLoaded: boolean; + loadJSAndGISEditor: typeof loadJSAndGISEditor; + loadGISEditor: typeof loadGISEditor; + openGISEditor: typeof openGISEditor; + } +} + +window.loadJSAndGISEditor = loadJSAndGISEditor; +window.loadGISEditor = loadGISEditor; +window.openGISEditor = openGISEditor; diff --git a/js/src/modules/config.ts b/js/src/modules/config.ts index fe6e3a62a8..78a6feb398 100644 --- a/js/src/modules/config.ts +++ b/js/src/modules/config.ts @@ -213,7 +213,7 @@ function getIdPrefix (element) { let validate = {}; // form validator list -window.validators = { +const validators = { // regexp: numeric value regExpNumeric: /^[0-9]+$/, // regexp: extract parts from PCRE expression @@ -842,6 +842,14 @@ const Config = { on: on, }; +declare global { + interface Window { + validators: typeof validators; + Config: typeof Config; + } +} + +window.validators = validators; window.Config = Config; export { Config }; diff --git a/js/src/modules/console.ts b/js/src/modules/console.ts index 822484a5eb..62341f9b52 100644 --- a/js/src/modules/console.ts +++ b/js/src/modules/console.ts @@ -1565,4 +1565,10 @@ var ConsoleDebug = { } }; +declare global { + interface Window { + Console: typeof Console; + } +} + export { Console }; diff --git a/js/src/modules/functions.ts b/js/src/modules/functions.ts index 0b204ae37f..4585e46a5f 100644 --- a/js/src/modules/functions.ts +++ b/js/src/modules/functions.ts @@ -3853,6 +3853,13 @@ $.fn.confirm = Functions.confirm; $.fn.sortTable = Functions.sortTable; $.fn.getPostData = Functions.getPostData; +declare global { + interface Window { + codeMirrorEditor: CodeMirror.EditorFromTextArea | boolean | null; + Functions: typeof Functions; + } +} + window.Functions = Functions; export { Functions }; diff --git a/js/src/modules/navigation.ts b/js/src/modules/navigation.ts index 5be4858143..039d1888f3 100644 --- a/js/src/modules/navigation.ts +++ b/js/src/modules/navigation.ts @@ -1414,6 +1414,12 @@ const Navigation = { update: update, }; +declare global { + interface Window { + Navigation: typeof Navigation; + } +} + window.Navigation = Navigation; export { Navigation }; diff --git a/js/src/sql.ts b/js/src/sql.ts index 7845b10742..e679b0bc09 100644 --- a/js/src/sql.ts +++ b/js/src/sql.ts @@ -1391,4 +1391,10 @@ const Sql = { initProfilingTables: initProfilingTables, }; +declare global { + interface Window { + Sql: typeof Sql; + } +} + window.Sql = Sql; diff --git a/js/src/table/change.ts b/js/src/table/change.ts index f6c04cd6dd..de98b4eef0 100644 --- a/js/src/table/change.ts +++ b/js/src/table/change.ts @@ -224,8 +224,6 @@ function verifyAfterSearchFieldChange (index, searchFormId) { } } -window.verifyAfterSearchFieldChange = verifyAfterSearchFieldChange; - /** * Validate the an input contains multiple int values * @param {jQuery} jqueryInput the Jquery object @@ -462,7 +460,6 @@ function verificationsAfterFieldChange (urlField, multiEdit, theType) { } } -window.verificationsAfterFieldChange = verificationsAfterFieldChange; /* End of fields validation*/ /** @@ -941,4 +938,14 @@ function changeValueFieldType (elem, searchIndex) { } } +declare global { + interface Window { + verifyAfterSearchFieldChange: typeof verifyAfterSearchFieldChange; + verificationsAfterFieldChange: typeof verificationsAfterFieldChange; + changeValueFieldType: typeof changeValueFieldType; + } +} + +window.verifyAfterSearchFieldChange = verifyAfterSearchFieldChange; +window.verificationsAfterFieldChange = verificationsAfterFieldChange; window.changeValueFieldType = changeValueFieldType; diff --git a/js/src/table/gis_visualization.ts b/js/src/table/gis_visualization.ts index 72d752be8d..4d9d83a8e4 100644 --- a/js/src/table/gis_visualization.ts +++ b/js/src/table/gis_visualization.ts @@ -40,8 +40,6 @@ function zoomAndPan () { $('path.vector', gisSvg).attr('stroke-width', 0.5 / scale); } -window.zoomAndPan = zoomAndPan; - /** * Initially loads either SVG or OSM visualization based on the choice. */ @@ -53,8 +51,6 @@ function selectVisualization () { } } -window.selectVisualization = selectVisualization; - /** * Adds necessary styles to the div that contains the openStreetMap. */ @@ -69,8 +65,6 @@ function styleOSM () { $('#openlayersmap').css(cssObj); } -window.styleOSM = styleOSM; - /** * Store a reference to the gis svg element. */ @@ -78,8 +72,6 @@ function storeGisSvgRef () { gisSvg = $('#placeholder').find('svg').get(0); } -window.storeGisSvgRef = storeGisSvgRef; - /** * Adds controls for zooming and panning. */ @@ -102,8 +94,6 @@ function addZoomPanControllers () { ); } -window.addZoomPanControllers = addZoomPanControllers; - /** * Resizes the GIS visualization to fit into the space available. */ @@ -370,3 +360,19 @@ AJAX.registerOnload('table/gis_visualization.js', function () { $('#tooltip').remove(); }); }); + +declare global { + interface Window { + zoomAndPan: typeof zoomAndPan; + selectVisualization: typeof selectVisualization; + styleOSM: typeof styleOSM; + storeGisSvgRef: typeof storeGisSvgRef; + addZoomPanControllers: typeof addZoomPanControllers; + } +} + +window.zoomAndPan = zoomAndPan; +window.selectVisualization = selectVisualization; +window.styleOSM = styleOSM; +window.storeGisSvgRef = storeGisSvgRef; +window.addZoomPanControllers = addZoomPanControllers; diff --git a/js/src/validator-messages.ts b/js/src/validator-messages.ts index 3dc11669ca..c14e71724b 100644 --- a/js/src/validator-messages.ts +++ b/js/src/validator-messages.ts @@ -25,4 +25,10 @@ function extendingValidatorMessages () { }); } +declare global { + interface Window { + extendingValidatorMessages: typeof extendingValidatorMessages; + } +} + window.extendingValidatorMessages = extendingValidatorMessages;