Permalink
Browse files

Refactor db_tracking templates

Signed-off-by: Leonardo Strozzi <laps15@inf.ufpr.br>
  • Loading branch information...
laps15 committed Jun 26, 2018
1 parent f0eab56 commit 491ce9a6696d6a7675aa5900e8634c9c2a76acfd
View
@@ -107,46 +107,14 @@
}
// ---------------------------------------------------------------------------
$relation = new Relation();
$cfgRelation = $relation->getRelationsParam();
echo $tracking->getHtmlForDbTrackingTables(
$GLOBALS['db'],
$_REQUEST['db'],
$url_query,
$pmaThemeImage,
$text_dir
);
// Prepare statement to get HEAD version
$all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' .
Util::backquote($cfgRelation['db']) . '.' .
Util::backquote($cfgRelation['tracking']) .
' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($_REQUEST['db']) .
'\' ' .
' GROUP BY table_name' .
' ORDER BY table_name ASC';
$all_tables_result = $relation->queryAsControlUser($all_tables_query);
// If a HEAD version exists
if (is_object($all_tables_result)
&& $GLOBALS['dbi']->numRows($all_tables_result) > 0
) {
echo $tracking->getHtmlForTrackedTables(
$GLOBALS['db'],
$all_tables_result,
$url_query,
$pmaThemeImage,
$text_dir,
$cfgRelation
);
}
$untracked_tables = $tracking->getUntrackedTables($GLOBALS['db']);
// If untracked tables exist
if (count($untracked_tables) > 0) {
echo $tracking->getHtmlForUntrackedTables(
$GLOBALS['db'],
$untracked_tables,
$url_query,
$pmaThemeImage,
$text_dir
);
}
// If available print out database log
if (count($data['ddlog']) > 0) {
$log = '';
@@ -1264,30 +1264,76 @@ public function getVersionStatus(array $version)
}
/**
* Get HTML for untracked tables
* Get HTML for tracked and untracked tables
*
* @param string $db current database
* @param array $untrackedTables untracked tables
* @param string $urlQuery url query string
* @param string $pmaThemeImage path to theme's image folder
* @param string $textDir text direction
* @param string $db current database
* @param array $requestDb $_REQUEST['db']
* @param string $urlQuery url query string
* @param string $pmaThemeImage path to theme's image folder
* @param string $textDir text direction
*
* @return string HTML
*/
public function getHtmlForUntrackedTables(
$db,
array $untrackedTables,
$urlQuery,
$pmaThemeImage,
$textDir
public function getHtmlForDbTrackingTables(
string $db,
string $requestDb,
string $urlQuery,
string $pmaThemeImage,
string $textDir
) {
return $this->template->render('database/tracking/untracked_tables', [
$relation = new Relation();
$cfgRelation = $relation->getRelationsParam();
// Prepare statement to get HEAD version
$allTablesQuery = ' SELECT table_name, MAX(version) as version FROM ' .
Util::backquote($cfgRelation['db']) . '.' .
Util::backquote($cfgRelation['tracking']) .
' WHERE db_name = \'' . $GLOBALS['dbi']->escapeString($requestDb) .
'\' ' .
' GROUP BY table_name' .
' ORDER BY table_name ASC';
$allTablesResult = $relation->queryAsControlUser($allTablesQuery);
$untrackedTables = $this->getUntrackedTables($db);
// If a HEAD version exists
$versions = [];
$headVersionExists = is_object($allTablesResult)
&& $GLOBALS['dbi']->numRows($allTablesResult) > 0;
if ($headVersionExists) {
while ($oneResult = $GLOBALS['dbi']->fetchArray($allTablesResult)) {
list($tableName, $versionNumber) = $oneResult;
$tableQuery = ' SELECT * FROM ' .
Util::backquote($cfgRelation['db']) . '.' .
Util::backquote($cfgRelation['tracking']) .
' WHERE `db_name` = \''
. $GLOBALS['dbi']->escapeString($requestDb)
. '\' AND `table_name` = \''
. $GLOBALS['dbi']->escapeString($tableName)
. '\' AND `version` = \'' . $versionNumber . '\'';
$tableResult = $relation->queryAsControlUser($tableQuery);
$versionData = $GLOBALS['dbi']->fetchArray($tableResult);
$versionData['status_button'] = $this->getStatusButton(
$versionData,
$urlQuery
);
$versions[] = $versionData;
}
}
$html = $this->template->render('database/tracking/tables', [
'db' => $db,
'untracked_tables' => $untrackedTables,
'head_version_exists' => $headVersionExists,
'untracked_tables_exists' => count($untrackedTables) > 0,
'versions' => $versions,
'url_query' => $urlQuery,
'pma_theme_image' => $pmaThemeImage,
'text_dir' => $textDir,
'untracked_tables' => $untrackedTables,
'pma_theme_image' => $pmaThemeImage,
]);
return $html;
}
/**
@@ -1333,56 +1379,6 @@ public function getUntrackedTables($db)
return $untracked_tables;
}
/**
* Get tracked tables
*
* @param string $db current database
* @param object $allTablesResult result set of tracked tables
* @param string $urlQuery url query string
* @param string $pmaThemeImage path to theme's image folder
* @param string $textDir text direction
* @param array $cfgRelation configuration storage info
*
* @return string HTML
*/
public function getHtmlForTrackedTables(
$db,
$allTablesResult,
$urlQuery,
$pmaThemeImage,
$textDir,
array $cfgRelation
) {
$relation = new Relation();
$versions = [];
while ($oneResult = $GLOBALS['dbi']->fetchArray($allTablesResult)) {
list($tableName, $versionNumber) = $oneResult;
$tableQuery = ' SELECT * FROM ' .
Util::backquote($cfgRelation['db']) . '.' .
Util::backquote($cfgRelation['tracking']) .
' WHERE `db_name` = \''
. $GLOBALS['dbi']->escapeString($_REQUEST['db'])
. '\' AND `table_name` = \''
. $GLOBALS['dbi']->escapeString($tableName)
. '\' AND `version` = \'' . $versionNumber . '\'';
$tableResult = $relation->queryAsControlUser($tableQuery);
$versionData = $GLOBALS['dbi']->fetchArray($tableResult);
$versionData['status_button'] = $this->getStatusButton(
$versionData,
$urlQuery
);
$versions[] = $versionData;
}
return $this->template->render('database/tracking/tracked_tables', [
'db' => $db,
'versions' => $versions,
'url_query' => $urlQuery,
'text_dir' => $textDir,
'pma_theme_image' => $pmaThemeImage,
]);
}
/**
* Get tracking status button
*
@@ -0,0 +1,137 @@
{# Tracked tables exists#}
{% if head_version_exists %}
<div id="tracked_tables">
<h3>{% trans 'Tracked tables' %}</h3>
<form method="post" action="db_tracking.php" name="trackedForm"
id="trackedForm" class="ajax">
{{ Url_getHiddenInputs(db) }}
<table id="versions" class="data">
<thead>
<tr>
<th></th>
<th>{% trans 'Table' %}</th>
<th>{% trans 'Last version' %}</th>
<th>{% trans 'Created' %}</th>
<th>{% trans 'Updated' %}</th>
<th>{% trans 'Status' %}</th>
<th>{% trans 'Action' %}</th>
<th>{% trans 'Show' %}</th>
</tr>
</thead>
<tbody>
{% for version in versions %}
<tr>
<td class="center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="selected_tbl_{{ version.table_name }}"
value="{{ version.table_name }}"/>
</td>
<th>
<label for="selected_tbl_{{ version.table_name }}">
{{ version.table_name }}
</label>
</th>
<td class="right">
{{ version.version }}
</td>
<td>
{{ version.date_created }}
</td>
<td>
{{ version.date_updated }}
</td>
<td>
{{ version.status_button|raw }}
</td>
<td>
<a class="delete_tracking_anchor ajax"
href="db_tracking.php{{ url_query|raw }}&amp;table=
{{- version.table_name }}&amp;delete_tracking=true">
{{ Util_getIcon('b_drop', 'Delete tracking'|trans) }}
</a>
</td>
<td>
<a href="tbl_tracking.php{{ url_query|raw }}&amp;table=
{{- version.table_name }}">
{{ Util_getIcon('b_versions', 'Versions'|trans) }}
</a>
<a href="tbl_tracking.php{{ url_query|raw }}&amp;table=
{{- version.table_name }}&amp;report=true&amp;version=
{{- version.version }}">
{{ Util_getIcon('b_report', 'Tracking report'|trans) }}
</a>
<a href="tbl_tracking.php{{ url_query|raw }}&amp;table=
{{- version.table_name }}&amp;snapshot=true&amp;version=
{{- version.version }}">
{{ Util_getIcon('b_props', 'Structure snapshot'|trans) }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'select_all.twig' with {
'pma_theme_image': pma_theme_image,
'text_dir': text_dir,
'form_name': 'trackedForm'
} only %}
{{ Util_getButtonOrImage(
'submit_mult',
'mult_submit',
'Delete tracking'|trans,
'b_drop',
'delete_tracking'
) }}
</form>
</div>
{% endif %}
{% if untracked_tables_exists %}
<h3>{% trans 'Untracked tables' %}</h3>
<form method="post" action="db_tracking.php" name="untrackedForm"
id="untrackedForm" class="ajax">
{{ Url_getHiddenInputs(db) }}
<table id="noversions" class="data">
<thead>
<tr>
<th></th>
<th>{% trans 'Table' %}</th>
<th>{% trans 'Action' %}</th>
</tr>
</thead>
<tbody>
{% for table_name in untracked_tables if Tracker_getVersion(db, table_name) == -1 %}
<tr>
<td class="center">
<input type="checkbox" name="selected_tbl[]"
class="checkall" id="selected_tbl_{{ table_name }}"
value="{{ table_name }}"/>
</td>
<th>
<label for="selected_tbl_{{ table_name }}">
{{ table_name }}
</label>
</th>
<td>
<a href="tbl_tracking.php{{ url_query|raw }}&amp;table={{ table_name }}">
{{ Util_getIcon('eye', 'Track table'|trans) }}
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include 'select_all.twig' with {
'pma_theme_image': pma_theme_image,
'text_dir': text_dir,
'form_name': 'untrackedForm'
} only %}
{{ Util_getButtonOrImage(
'submit_mult',
'mult_submit',
'Track table'|trans,
'eye',
'track'
) }}
</form>
{% endif %}
Oops, something went wrong.

0 comments on commit 491ce9a

Please sign in to comment.