Skip to content

Commit

Permalink
Remove Indexes object from the Window global object
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Nov 29, 2022
1 parent b7a710e commit 49865fe
Show file tree
Hide file tree
Showing 16 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion js/src/functions.js
Expand Up @@ -3,10 +3,10 @@ import { AJAX } from './ajax.js';
import { Navigation } from './navigation.js';
import { CommonActions, CommonParams } from './common.js';
import { mysqlDocKeyword, mysqlDocBuiltin } from './modules/doc-links.js';
import { Indexes } from './indexes.js';

/* global ChartType, ColumnType, DataTable, JQPlotChartFactory */ // js/chart.js
/* global DatabaseStructure */ // js/database/structure.js
/* global Indexes */ // js/indexes.js
/* global firstDayOfCalendar, maxInputVars, mysqlDocTemplate, themeImagePath */ // templates/javascript/variables.twig

/**
Expand Down
6 changes: 3 additions & 3 deletions js/src/indexes.js
Expand Up @@ -10,9 +10,7 @@ import { CommonActions, CommonParams } from './common.js';
*
* @requires jQueryUI
*/

var Indexes = {};
window.Indexes = Indexes;
const Indexes = {};

/**
* Returns the array of indexes based on the index choice
Expand Down Expand Up @@ -803,3 +801,5 @@ Indexes.on = () => function () {
}
});
};

export { Indexes };
7 changes: 3 additions & 4 deletions js/src/main.js
Expand Up @@ -5,8 +5,7 @@ import { KeyHandlerEvents } from './keyhandler.js';
import { Navigation } from './navigation.js';
import { PageSettings } from './page_settings.js';
import { crossFramingProtection } from './cross_framing_protection.js';

/* global Indexes */
import { Indexes } from './indexes.js';

AJAX.registerOnload('main.js', () => AJAX.removeSubmitEvents());
$(AJAX.loadEventHandler());
Expand Down Expand Up @@ -39,8 +38,8 @@ $(Functions.breadcrumbScrollToTop());

$(Navigation.onload());

AJAX.registerTeardown('indexes.js', Indexes.off());
AJAX.registerOnload('indexes.js', Indexes.on());
AJAX.registerTeardown('main.js', Indexes.off());
AJAX.registerOnload('main.js', Indexes.on());

$(() => Functions.checkNumberOfFields());

Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Controllers/Sql/SqlController.php
Expand Up @@ -77,7 +77,6 @@ public function __invoke(ServerRequest $request): void
$this->addScriptFiles([
'vendor/jquery/jquery.uitablefilter.js',
'table/change.js',
'indexes.js',
'gis_data_editor.js',
'multi_column_sort.js',
]);
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/Table/AddFieldController.php
Expand Up @@ -188,7 +188,7 @@ public function __invoke(ServerRequest $request): void

$GLOBALS['active_page'] = Url::getFromRoute('/table/structure');

$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']);

$this->checkParameters(['server', 'db', 'table', 'num_fields']);

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/Table/CreateController.php
Expand Up @@ -153,7 +153,7 @@ public function __invoke(ServerRequest $request): void
// Do not display the table in the header since it hasn't been created yet
$this->response->getHeader()->getMenu()->setTable('');

$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']);

$this->checkParameters(['server', 'db']);

Expand Down
2 changes: 0 additions & 2 deletions libraries/classes/Controllers/Table/IndexRenameController.php
Expand Up @@ -91,8 +91,6 @@ private function displayRenameForm(Index $index): void
$formParams['old_index'] = $_POST['index'];
}

$this->addScriptFiles(['indexes.js']);

$this->render('table/index_rename_form', [
'index' => $index,
'form_params' => $formParams,
Expand Down
2 changes: 0 additions & 2 deletions libraries/classes/Controllers/Table/IndexesController.php
Expand Up @@ -139,8 +139,6 @@ private function displayForm(Index $index): void
$form_params['old_index'] = $_POST['index'];
}

$this->addScriptFiles(['indexes.js']);

$this->render('table/index_form', [
'fields' => $fields,
'index' => $index,
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/Table/RelationController.php
Expand Up @@ -93,7 +93,7 @@ public function __invoke(ServerRequest $request): void
return;
}

$this->addScriptFiles(['table/relation.js', 'indexes.js']);
$this->addScriptFiles(['table/relation.js']);

// Set the database
$this->dbi->selectDb($GLOBALS['db']);
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Controllers/Table/ReplaceController.php
Expand Up @@ -83,7 +83,7 @@ public function __invoke(ServerRequest $request): void

$this->dbi->selectDb($GLOBALS['db']);

$this->addScriptFiles(['makegrid.js', 'sql.js', 'indexes.js', 'gis_data_editor.js']);
$this->addScriptFiles(['makegrid.js', 'sql.js', 'gis_data_editor.js']);

$insertRows = $_POST['insert_rows'] ?? null;
if (is_numeric($insertRows) && $insertRows != $GLOBALS['cfg']['InsertRows']) {
Expand Down
Expand Up @@ -90,7 +90,7 @@ private function displayHtmlForColumnChange(array $selected): void
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
$checkUserPrivileges->getPrivileges();

$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']);

$this->checkParameters(['server', 'db', 'table', 'num_fields']);

Expand Down
Expand Up @@ -66,7 +66,7 @@ public function __invoke(ServerRequest $request): void
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$this->addScriptFiles(['table/structure.js', 'indexes.js']);
$this->addScriptFiles(['table/structure.js']);

$partitionDetails = null;
if (! isset($_POST['partition_by'])) {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public function __invoke(ServerRequest $request): void
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
$checkUserPrivileges->getPrivileges();

$this->addScriptFiles(['table/structure.js', 'indexes.js']);
$this->addScriptFiles(['table/structure.js']);

$relationParameters = $this->relation->getRelationParameters();

Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Header.php
Expand Up @@ -142,7 +142,6 @@ private function addDefaultScripts(): void
$this->scripts->addFile('shared.js');
$this->scripts->addFile('menu_resizer.js');
$this->scripts->addFile('config.js');
$this->scripts->addFile('indexes.js');
$this->scripts->addFile('main.js');

$this->scripts->addCode($this->getJsParamsCode());
Expand Down
1 change: 0 additions & 1 deletion test/classes/HeaderTest.php
Expand Up @@ -264,7 +264,6 @@ public function testAddedDefaultScripts(): void
['name' => 'shared.js', 'fire' => 0],
['name' => 'menu_resizer.js', 'fire' => 1],
['name' => 'config.js', 'fire' => 1],
['name' => 'indexes.js', 'fire' => 1],
['name' => 'main.js', 'fire' => 1],
];
$this->assertSame($expected, $scripts->getFiles());
Expand Down
1 change: 0 additions & 1 deletion webpack.config.cjs
Expand Up @@ -40,7 +40,6 @@ module.exports = [
'gis_data_editor': './js/src/gis_data_editor.js',
'home': './js/src/home.js',
'import': './js/src/import.js',
'indexes': './js/src/indexes.js',
'jqplot/plugins/jqplot.byteFormatter': './js/src/jqplot/plugins/jqplot.byteFormatter.js',
'jquery.sortable-table': './js/src/jquery.sortable-table.js',
'main': './js/src/main.js',
Expand Down

0 comments on commit 49865fe

Please sign in to comment.