Skip to content

Commit

Permalink
Extract method for adding script files
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 Jul 12, 2020
1 parent f832095 commit 1dccc10
Show file tree
Hide file tree
Showing 53 changed files with 138 additions and 252 deletions.
8 changes: 8 additions & 0 deletions libraries/classes/Controllers/AbstractController.php
Expand Up @@ -45,4 +45,12 @@ protected function render(string $template, array $data = []): void
{
$this->response->addHTML($this->template->render($template, $data));
}

/** @param string[] $files */
protected function addScriptFiles(array $files): void
{
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFiles($files);
}
}
Expand Up @@ -90,11 +90,11 @@ public function index(): void
]);
}

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
$scripts->addFile('database/central_columns.js');
$this->addScriptFiles([
'vendor/jquery/jquery.uitablefilter.js',
'vendor/jquery/jquery.tablesorter.js',
'database/central_columns.js',
]);

if (isset($_POST['edit_central_columns_page'])) {
$this->response->addHTML($this->editPage([
Expand Down
17 changes: 9 additions & 8 deletions libraries/classes/Controllers/Database/DesignerController.php
Expand Up @@ -210,14 +210,15 @@ public function index(): void
$header = $this->response->getHeader();
$header->setBodyId('designer_body');

$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.fullscreen.js');
$scripts->addFile('designer/database.js');
$scripts->addFile('designer/objects.js');
$scripts->addFile('designer/page.js');
$scripts->addFile('designer/history.js');
$scripts->addFile('designer/move.js');
$scripts->addFile('designer/init.js');
$this->addScriptFiles([
'vendor/jquery/jquery.fullscreen.js',
'designer/database.js',
'designer/objects.js',
'designer/page.js',
'designer/history.js',
'designer/move.js',
'designer/init.js',
]);

[
$tables,
Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/Database/ExportController.php
Expand Up @@ -46,9 +46,7 @@ public function index(): void
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('export.js');
$this->addScriptFiles(['export.js']);

// $sub_part is used in Util::getDbInfo() to see if we are coming from
// /database/export, in which case we don't obey $cfg['MaxTableList']
Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/Database/ImportController.php
Expand Up @@ -20,9 +20,7 @@ public function index(): void
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('import.js');
$this->addScriptFiles(['import.js']);

/**
* Gets tables information and displays top links
Expand Down
Expand Up @@ -16,11 +16,11 @@ class MultiTableQueryController extends AbstractController
{
public function index(): void
{
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.md5.js');
$scripts->addFile('database/multi_table_query.js');
$scripts->addFile('database/query_generator.js');
$this->addScriptFiles([
'vendor/jquery/jquery.md5.js',
'database/multi_table_query.js',
'database/query_generator.js',
]);

$queryInstance = new MultiTableQuery($this->dbi, $this->template, $this->db);

Expand Down
Expand Up @@ -77,9 +77,7 @@ public function index(): void

$this->checkUserPrivileges->getPrivileges();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('database/operations.js');
$this->addScriptFiles(['database/operations.js']);

$sql_query = '';

Expand Down
Expand Up @@ -47,9 +47,7 @@ public function index(): void
$savedSearch = null;
$currentSearchId = null;
if ($cfgRelation['savedsearcheswork']) {
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('database/qbe.js');
$this->addScriptFiles(['database/qbe.js']);

//Get saved search list.
$savedSearch = new SavedSearches($GLOBALS, $this->relation);
Expand Down
6 changes: 1 addition & 5 deletions libraries/classes/Controllers/Database/SearchController.php
Expand Up @@ -17,11 +17,7 @@ public function index(): void
global $cfg, $db, $err_url, $url_query, $url_params, $tables, $num_tables, $total_num_tables, $sub_part;
global $is_show_stats, $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos;

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('database/search.js');
$scripts->addFile('sql.js');
$scripts->addFile('makegrid.js');
$this->addScriptFiles(['database/search.js', 'sql.js', 'makegrid.js']);

Common::database();

Expand Down
6 changes: 1 addition & 5 deletions libraries/classes/Controllers/Database/SqlController.php
Expand Up @@ -38,11 +38,7 @@ public function index(): void
{
global $goto, $back;

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('makegrid.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('sql.js');
$this->addScriptFiles(['makegrid.js', 'vendor/jquery/jquery.uitablefilter.js', 'sql.js']);

$pageSettings = new PageSettings('Sql');
$this->response->addHTML($pageSettings->getErrorHTML());
Expand Down
Expand Up @@ -140,10 +140,7 @@ public function index(): void

Common::database();

$this->response->getHeader()->getScripts()->addFiles([
'database/structure.js',
'table/change.js',
]);
$this->addScriptFiles(['database/structure.js', 'table/change.js']);

// Gets the database structure
$this->getDatabaseInfo('_structure');
Expand Down
Expand Up @@ -46,11 +46,7 @@ public function index(): void
global $total_num_tables, $sub_part, $is_show_stats, $pos, $data, $cfg;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname;

//Get some js files needed for Ajax requests
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
$scripts->addFile('database/tracking.js');
$this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'database/tracking.js']);

/**
* If we are not in an Ajax request, then do the common work and show the links etc.
Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/ExportController.php
Expand Up @@ -67,9 +67,7 @@ public function index(): void
global $active_page, $do_relation, $do_comments, $do_mime, $do_dates, $whatStrucOrData, $db_select;
global $table_structure, $table_data, $lock_tables, $allrows, $limit_to, $limit_from;

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('export_output.js');
$this->addScriptFiles(['export_output.js']);

//check if it's the GET request to check export time out
if (isset($_GET['check_time_out'])) {
Expand Down
6 changes: 2 additions & 4 deletions libraries/classes/Controllers/NormalizationController.php
Expand Up @@ -103,10 +103,8 @@ public function index(): void
return;
}

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('normalization.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$this->addScriptFiles(['normalization.js', 'vendor/jquery/jquery.uitablefilter.js']);

$normalForm = '1nf';
if (Core::isValid($_POST['normalizeTo'], ['1nf', '2nf', '3nf'])) {
$normalForm = $_POST['normalizeTo'];
Expand Down
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
Expand Up @@ -239,9 +239,7 @@ public function index(): void
return;
}

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
5 changes: 1 addition & 4 deletions libraries/classes/Controllers/Preferences/SqlController.php
Expand Up @@ -88,10 +88,7 @@ public function index(): void
$error = $result;
}

// display forms
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('config.js');
$this->addScriptFiles(['config.js']);

$cfgRelation = $this->relation->getRelationsParam();

Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/Server/DatabasesController.php
Expand Up @@ -98,9 +98,7 @@ public function index(): void
'sort_order' => $_REQUEST['sort_order'] ?? null,
];

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server/databases.js');
$this->addScriptFiles(['server/databases.js']);

Common::server();
ReplicationInfo::load();
Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/Server/ExportController.php
Expand Up @@ -40,9 +40,7 @@ public function index(): void
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('export.js');
$this->addScriptFiles(['export.js']);

$export_page_title = __('View dump (schema) of databases') . "\n";

Expand Down
4 changes: 1 addition & 3 deletions libraries/classes/Controllers/Server/ImportController.php
Expand Up @@ -19,9 +19,7 @@ public function index(): void
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('import.js');
$this->addScriptFiles(['import.js']);

Common::server();

Expand Down
5 changes: 1 addition & 4 deletions libraries/classes/Controllers/Server/PluginsController.php
Expand Up @@ -43,10 +43,7 @@ public function index(): void
{
Common::server();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
$scripts->addFile('server/plugins.js');
$this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'server/plugins.js']);

$plugins = [];
$serverPlugins = $this->plugins->getAll();
Expand Down
Expand Up @@ -71,13 +71,7 @@ public function index(): void

$cfgRelation = $this->relation->getRelationsParam();

/**
* Does the common work
*/
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server/privileges.js');
$scripts->addFile('vendor/zxcvbn.js');
$this->addScriptFiles(['server/privileges.js', 'vendor/zxcvbn.js']);

$relationCleanup = new RelationCleanup($this->dbi, $this->relation);
$serverPrivileges = new Privileges($this->template, $this->dbi, $this->relation, $relationCleanup);
Expand Down
Expand Up @@ -50,11 +50,7 @@ public function index(): void
Common::server();
ReplicationInfo::load();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server/privileges.js');
$scripts->addFile('replication.js');
$scripts->addFile('vendor/zxcvbn.js');
$this->addScriptFiles(['server/privileges.js', 'replication.js', 'vendor/zxcvbn.js']);

if (isset($params['url_params']) && is_array($params['url_params'])) {
$url_params = $params['url_params'];
Expand Down
6 changes: 1 addition & 5 deletions libraries/classes/Controllers/Server/SqlController.php
Expand Up @@ -37,11 +37,7 @@ public function __construct($response, $dbi, Template $template, SqlQueryForm $s

public function index(): void
{
$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('makegrid.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('sql.js');
$this->addScriptFiles(['makegrid.js', 'vendor/jquery/jquery.uitablefilter.js', 'sql.js']);

$pageSettings = new PageSettings('Sql');
$this->response->addHTML($pageSettings->getErrorHTML());
Expand Down
30 changes: 15 additions & 15 deletions libraries/classes/Controllers/Server/Status/MonitorController.php
Expand Up @@ -39,21 +39,21 @@ public function index(): void
{
Common::server();

$header = $this->response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('vendor/jquery/jquery.tablesorter.js');
$scripts->addFile('vendor/jquery/jquery.sortableTable.js');
$scripts->addFile('vendor/jqplot/jquery.jqplot.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.pieRenderer.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.canvasTextRenderer.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.dateAxisRenderer.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.highlighter.js');
$scripts->addFile('vendor/jqplot/plugins/jqplot.cursor.js');
$scripts->addFile('jqplot/plugins/jqplot.byteFormatter.js');
$scripts->addFile('server/status/monitor.js');
$scripts->addFile('server/status/sorter.js');
$this->addScriptFiles([
'vendor/jquery/jquery.tablesorter.js',
'vendor/jquery/jquery.sortableTable.js',
'vendor/jqplot/jquery.jqplot.js',
'vendor/jqplot/plugins/jqplot.pieRenderer.js',
'vendor/jqplot/plugins/jqplot.enhancedPieLegendRenderer.js',
'vendor/jqplot/plugins/jqplot.canvasTextRenderer.js',
'vendor/jqplot/plugins/jqplot.canvasAxisLabelRenderer.js',
'vendor/jqplot/plugins/jqplot.dateAxisRenderer.js',
'vendor/jqplot/plugins/jqplot.highlighter.js',
'vendor/jqplot/plugins/jqplot.cursor.js',
'jqplot/plugins/jqplot.byteFormatter.js',
'server/status/monitor.js',
'server/status/sorter.js',
]);

$form = [
'server_time' => (int) (microtime(true) * 1000),
Expand Down

0 comments on commit 1dccc10

Please sign in to comment.