Refactor Tracking::displayTrackedTables
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
c930c7a030
commit
261c39c815
@ -128,7 +128,7 @@ $all_tables_result = Relation::queryAsControlUser($all_tables_query);
|
||||
if (is_object($all_tables_result)
|
||||
&& $GLOBALS['dbi']->numRows($all_tables_result) > 0
|
||||
) {
|
||||
Tracking::displayTrackedTables(
|
||||
echo Tracking::getHtmlForTrackedTables(
|
||||
$GLOBALS['db'], $all_tables_result, $url_query, $pmaThemeImage,
|
||||
$text_dir, $cfgRelation
|
||||
);
|
||||
|
||||
@ -1573,143 +1573,65 @@ class Tracking
|
||||
}
|
||||
|
||||
/**
|
||||
* Display tracked tables
|
||||
* Get tracked tables
|
||||
*
|
||||
* @param string $db current database
|
||||
* @param object $all_tables_result result set of tracked tables
|
||||
* @param string $url_query url query string
|
||||
* @param string $pmaThemeImage path to theme's image folder
|
||||
* @param string $text_dir text direction
|
||||
* @param array $cfgRelation configuration storage info
|
||||
* @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 void
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function displayTrackedTables(
|
||||
$db, $all_tables_result, $url_query, $pmaThemeImage, $text_dir, array $cfgRelation
|
||||
public static function getHtmlForTrackedTables(
|
||||
$db,
|
||||
$allTablesResult,
|
||||
$urlQuery,
|
||||
$pmaThemeImage,
|
||||
$textDir,
|
||||
array $cfgRelation
|
||||
) {
|
||||
?>
|
||||
<div id="tracked_tables">
|
||||
<h3><?php echo __('Tracked tables');?></h3>
|
||||
|
||||
<form method="post" action="db_tracking.php" name="trackedForm"
|
||||
id="trackedForm" class="ajax">
|
||||
<?php
|
||||
echo Url::getHiddenInputs($db)
|
||||
?>
|
||||
<table id="versions" class="data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th><?php echo __('Table');?></th>
|
||||
<th><?php echo __('Last version');?></th>
|
||||
<th><?php echo __('Created');?></th>
|
||||
<th><?php echo __('Updated');?></th>
|
||||
<th><?php echo __('Status');?></th>
|
||||
<th><?php echo __('Action');?></th>
|
||||
<th><?php echo __('Show');?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
// Print out information about versions
|
||||
|
||||
$delete = Util::getIcon('b_drop', __('Delete tracking'));
|
||||
$versions = Util::getIcon('b_versions', __('Versions'));
|
||||
$report = Util::getIcon('b_report', __('Tracking report'));
|
||||
$structure = Util::getIcon('b_props', __('Structure snapshot'));
|
||||
|
||||
while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) {
|
||||
list($table_name, $version_number) = $one_result;
|
||||
$table_query = ' SELECT * FROM ' .
|
||||
$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($table_name)
|
||||
. '\' AND `version` = \'' . $version_number . '\'';
|
||||
. $GLOBALS['dbi']->escapeString($tableName)
|
||||
. '\' AND `version` = \'' . $versionNumber . '\'';
|
||||
|
||||
$table_result = Relation::queryAsControlUser($table_query);
|
||||
$version_data = $GLOBALS['dbi']->fetchArray($table_result);
|
||||
|
||||
$tbl_link = 'tbl_tracking.php' . $url_query . '&table='
|
||||
. htmlspecialchars($version_data['table_name']);
|
||||
$delete_link = 'db_tracking.php' . $url_query . '&table='
|
||||
. htmlspecialchars($version_data['table_name'])
|
||||
. '&delete_tracking=true&';
|
||||
$checkbox_id = "selected_tbl_"
|
||||
. htmlspecialchars($version_data['table_name']);
|
||||
?>
|
||||
<tr>
|
||||
<td class="center">
|
||||
<input type="checkbox" name="selected_tbl[]"
|
||||
class="checkall" id="<?php echo $checkbox_id;?>"
|
||||
value="<?php echo htmlspecialchars($version_data['table_name']);?>"/>
|
||||
</td>
|
||||
<th>
|
||||
<label for="<?php echo $checkbox_id;?>">
|
||||
<?php echo htmlspecialchars($version_data['table_name']);?>
|
||||
</label>
|
||||
</th>
|
||||
<td class="right"><?php echo $version_data['version'];?></td>
|
||||
<td><?php echo $version_data['date_created'];?></td>
|
||||
<td><?php echo $version_data['date_updated'];?></td>
|
||||
<td>
|
||||
<?php
|
||||
self::displayStatusButton($version_data, $tbl_link);
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<a class="delete_tracking_anchor ajax"
|
||||
href="<?php echo $delete_link;?>" >
|
||||
<?php echo $delete; ?></a>
|
||||
<?php
|
||||
echo '</td>'
|
||||
, '<td>'
|
||||
, '<a href="' , $tbl_link , '">' , $versions , '</a>'
|
||||
, ' '
|
||||
, '<a href="' , $tbl_link , '&report=true&version='
|
||||
, $version_data['version'] , '">' , $report , '</a>'
|
||||
, ' '
|
||||
, '<a href="' . $tbl_link , '&snapshot=true&version='
|
||||
, $version_data['version'] , '">' , $structure , '</a>'
|
||||
, '</td>'
|
||||
, '</tr>';
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
echo Template::get('select_all')
|
||||
->render(
|
||||
array(
|
||||
'pma_theme_image' => $pmaThemeImage,
|
||||
'text_dir' => $text_dir,
|
||||
'form_name' => 'trackedForm',
|
||||
)
|
||||
$tableResult = Relation::queryAsControlUser($tableQuery);
|
||||
$versionData = $GLOBALS['dbi']->fetchArray($tableResult);
|
||||
$versionData['status_button'] = self::getStatusButton(
|
||||
$versionData,
|
||||
$urlQuery
|
||||
);
|
||||
echo Util::getButtonOrImage(
|
||||
'submit_mult', 'mult_submit',
|
||||
__('Delete tracking'), 'b_drop', 'delete_tracking'
|
||||
);
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
$versions[] = $versionData;
|
||||
}
|
||||
return Template::get('database/tracking/tracked_tables')->render([
|
||||
'db' => $db,
|
||||
'versions' => $versions,
|
||||
'url_query' => $urlQuery,
|
||||
'text_dir' => $textDir,
|
||||
'pma_theme_image' => $pmaThemeImage,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display tracking status button
|
||||
* Get tracking status button
|
||||
*
|
||||
* @param array $version_data data about tracking versions
|
||||
* @param string $tbl_link link for tbl_tracking.php
|
||||
* @param array $versionData data about tracking versions
|
||||
* @param string $urlQuery url query string
|
||||
*
|
||||
* @return void
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function displayStatusButton(array $version_data, $tbl_link)
|
||||
private static function getStatusButton(array $versionData, $urlQuery)
|
||||
{
|
||||
$state = self::getVersionStatus($version_data);
|
||||
$state = self::getVersionStatus($versionData);
|
||||
$options = array(
|
||||
0 => array(
|
||||
'label' => __('not active'),
|
||||
@ -1722,8 +1644,12 @@ class Tracking
|
||||
'selected' => ($state == 'active')
|
||||
)
|
||||
);
|
||||
echo Util::toggleButton(
|
||||
$tbl_link . '&version=' . $version_data['version'],
|
||||
$link = 'tbl_tracking.php' . $urlQuery . '&table='
|
||||
. htmlspecialchars($versionData['table_name'])
|
||||
. '&version=' . $versionData['version'];
|
||||
|
||||
return Util::toggleButton(
|
||||
$link,
|
||||
'toggle_activation',
|
||||
$options,
|
||||
null
|
||||
|
||||
85
templates/database/tracking/tracked_tables.twig
Normal file
85
templates/database/tracking/tracked_tables.twig
Normal file
@ -0,0 +1,85 @@
|
||||
<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 }}&table=
|
||||
{{- version.table_name }}&delete_tracking=true">
|
||||
{{ Util_getIcon('b_drop', 'Delete tracking'|trans) }}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="tbl_tracking.php{{ url_query|raw }}&table=
|
||||
{{- version.table_name }}">
|
||||
{{ Util_getIcon('b_versions', 'Versions'|trans) }}
|
||||
</a>
|
||||
<a href="tbl_tracking.php{{ url_query|raw }}&table=
|
||||
{{- version.table_name }}&report=true&version=
|
||||
{{- version.version }}">
|
||||
{{ Util_getIcon('b_report', 'Tracking report'|trans) }}
|
||||
</a>
|
||||
<a href="tbl_tracking.php{{ url_query|raw }}&table=
|
||||
{{- version.table_name }}&snapshot=true&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>
|
||||
Loading…
Reference in New Issue
Block a user