Allow deleting individual versions of tracking data
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
parent
805352c1fd
commit
80c0ba810a
@ -39,6 +39,8 @@ $js_messages['strDropTableStrongWarning'] = __('You are about to DESTROY a compl
|
||||
$js_messages['strTruncateTableStrongWarning'] = __('You are about to TRUNCATE a complete table!');
|
||||
$js_messages['strDeleteTrackingData'] = __('Delete tracking data for this table?');
|
||||
$js_messages['strDeleteTrackingDataMultiple'] = __('Delete tracking data for these tables?');
|
||||
$js_messages['strDeleteTrackingVersion'] = __('Delete tracking data for this version?');
|
||||
$js_messages['strDeleteTrackingVersionMultiple'] = __('Delete tracking data for these versions?');
|
||||
$js_messages['strDeletingTrackingData'] = __('Deleting tracking data');
|
||||
$js_messages['strDroppingPrimaryKeyIndex'] = __('Dropping Primary Key/Index');
|
||||
$js_messages['strDroppingForeignKey'] = __('Dropping Foreign key.');
|
||||
|
||||
47
js/tbl_tracking.js
Normal file
47
js/tbl_tracking.js
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Unbind all event handlers before tearing down the page
|
||||
*/
|
||||
AJAX.registerTeardown('tbl_tracking.js', function () {
|
||||
$('body').off('click', '#versionsForm.ajax button[name="submit_mult"], #versionsForm.ajax input[name="submit_mult"]');
|
||||
$('body').off('click', 'a.delete_version_anchor.ajax');
|
||||
});
|
||||
|
||||
/**
|
||||
* Bind event handlers
|
||||
*/
|
||||
AJAX.registerOnload('tbl_tracking.js', function () {
|
||||
|
||||
/**
|
||||
* Handles multi submit for tracking versions
|
||||
*/
|
||||
$('body').on('click', '#versionsForm.ajax button[name="submit_mult"], #versionsForm.ajax input[name="submit_mult"]', function (e) {
|
||||
e.preventDefault();
|
||||
var $button = $(this);
|
||||
var $form = $button.parent('form');
|
||||
var submitData = $form.serialize() + '&ajax_request=true&ajax_page_request=true&submit_mult=' + $button.val();
|
||||
|
||||
if ($button.val() == 'delete_version') {
|
||||
var question = PMA_messages.strDeleteTrackingVersionMultiple;
|
||||
$button.PMA_confirm(question, $form.attr('action'), function (url) {
|
||||
PMA_ajaxShowMessage();
|
||||
$.get(url, submitData, AJAX.responseHandler);
|
||||
});
|
||||
} else {
|
||||
PMA_ajaxShowMessage();
|
||||
$.get($form.attr('action'), submitData, AJAX.responseHandler);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Ajax Event handler for 'Delete version'
|
||||
*/
|
||||
$('body').on('click', 'a.delete_version_anchor.ajax', function (e) {
|
||||
e.preventDefault();
|
||||
var $anchor = $(this);
|
||||
var question = PMA_messages.strDeleteTrackingVersion;
|
||||
$anchor.PMA_confirm(question, $anchor.attr('href'), function (url) {
|
||||
PMA_ajaxShowMessage();
|
||||
$.get(url, {'ajax_page_request': true, 'ajax_request': true}, AJAX.responseHandler);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -347,16 +347,17 @@ class PMA_Tracker
|
||||
|
||||
|
||||
/**
|
||||
* Removes all tracking data for a table
|
||||
* Removes all tracking data for a table or a version of a table
|
||||
*
|
||||
* @param string $dbname name of database
|
||||
* @param string $tablename name of table
|
||||
* @param string $version version
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @return int result of version insertion
|
||||
*/
|
||||
static public function deleteTracking($dbname, $tablename)
|
||||
static public function deleteTracking($dbname, $tablename, $version = '')
|
||||
{
|
||||
$sql_query = "/*NOTRACK*/\n"
|
||||
. "DELETE FROM " . self::$pma_table
|
||||
@ -364,6 +365,10 @@ class PMA_Tracker
|
||||
. PMA_Util::sqlAddSlashes($dbname) . "'"
|
||||
. " AND `table_name` = '"
|
||||
. PMA_Util::sqlAddSlashes($tablename) . "'";
|
||||
if ($version) {
|
||||
$sql_query .= " AND `version` = '"
|
||||
. PMA_Util::sqlAddSlashes($version) . "'";
|
||||
}
|
||||
$result = PMA_queryAsControlUser($sql_query);
|
||||
|
||||
return $result;
|
||||
|
||||
@ -221,26 +221,33 @@ function PMA_getListOfVersionsOfTable()
|
||||
/**
|
||||
* Function to get html for displaying last version number
|
||||
*
|
||||
* @param array $sql_result sql result
|
||||
* @param int $last_version last version
|
||||
* @param array $url_params url parameters
|
||||
* @param string $url_query url query
|
||||
* @param array $sql_result sql result
|
||||
* @param int $last_version last version
|
||||
* @param array $url_params url parameters
|
||||
* @param string $url_query url query
|
||||
* @param string $pmaThemeImage path to theme's image folder
|
||||
* @param string $text_dir text direction
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_params,
|
||||
$url_query
|
||||
function PMA_getHtmlForTableVersionDetails(
|
||||
$sql_result, $last_version, $url_params,
|
||||
$url_query, $pmaThemeImage, $text_dir
|
||||
) {
|
||||
$tracking_active = false;
|
||||
|
||||
$html = '<table id="versions" class="data">';
|
||||
$html = '<form method="post" action="tbl_tracking.php" name="versionsForm"'
|
||||
. ' id="versionsForm" class="ajax">';
|
||||
$html .= PMA_URL_getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
|
||||
$html .= '<table id="versions" class="data">';
|
||||
$html .= '<thead>';
|
||||
$html .= '<tr>';
|
||||
$html .= '<th>' . __('Table') . '</th>';
|
||||
$html .= '<th></th>';
|
||||
$html .= '<th>' . __('Version') . '</th>';
|
||||
$html .= '<th>' . __('Created') . '</th>';
|
||||
$html .= '<th>' . __('Updated') . '</th>';
|
||||
$html .= '<th>' . __('Status') . '</th>';
|
||||
$html .= '<th>' . __('Action') . '</th>';
|
||||
$html .= '<th>' . __('Show') . '</th>';
|
||||
$html .= '</tr>';
|
||||
$html .= '</thead>';
|
||||
@ -248,6 +255,7 @@ function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_para
|
||||
|
||||
$style = 'odd';
|
||||
$GLOBALS['dbi']->dataSeek($sql_result, 0);
|
||||
$delete = PMA_Util::getIcon('b_drop.png', __('Delete version'));
|
||||
while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) {
|
||||
if ($version['version'] == $last_version) {
|
||||
if ($version['tracking_active'] == 1) {
|
||||
@ -256,12 +264,20 @@ function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_para
|
||||
$tracking_active = false;
|
||||
}
|
||||
}
|
||||
$delete_link = 'tbl_tracking.php' . $url_query . '&version='
|
||||
. htmlspecialchars($version['version'])
|
||||
. '&submit_delete_version=true';
|
||||
$html .= '<tr class="noclick ' . $style . '">';
|
||||
$html .= '<td>' . htmlspecialchars($version['table_name']) . '</td>';
|
||||
$html .= '<td class="center">';
|
||||
$html .= '<input type="checkbox" name="selected_versions[]" class="checkall"'
|
||||
. 'value="' . htmlspecialchars($version['version']) . '"/>';
|
||||
$html .= '</td>';
|
||||
$html .= '<td>' . htmlspecialchars($version['version']) . '</td>';
|
||||
$html .= '<td>' . htmlspecialchars($version['date_created']) . '</td>';
|
||||
$html .= '<td>' . htmlspecialchars($version['date_updated']) . '</td>';
|
||||
$html .= '<td>' . PMA_getVersionStatus($version) . '</td>';
|
||||
$html .= '<td><a class="delete_version_anchor ajax"'
|
||||
. ' href="' . $delete_link . '" >' . $delete . '</a></td>';
|
||||
$html .= '<td><a href="tbl_tracking.php';
|
||||
$html .= PMA_URL_getCommon(
|
||||
$url_params + array(
|
||||
@ -290,6 +306,24 @@ function PMA_getHtmlForTableVersionDetails($sql_result, $last_version, $url_para
|
||||
$html .= '</tbody>';
|
||||
$html .= '</table>';
|
||||
|
||||
$html .= '<img class="selectallarrow" '
|
||||
. 'src="' . $pmaThemeImage . 'arrow_' . $text_dir . '.png" '
|
||||
. 'width="38" height="22" alt="' . __('With selected:') . '" />';
|
||||
|
||||
$html .= '<input type="checkbox" id="versionsForm_checkall" '
|
||||
. 'class="checkall_box" title="' . __('Check All') . '" />'
|
||||
. '<label for="versionsForm_checkall">' . __('Check All') . '</label>';
|
||||
|
||||
$html .= '<i style="margin-left: 2em">'
|
||||
. __('With selected:') . '</i>';
|
||||
|
||||
$html .= PMA_Util::getButtonOrImage(
|
||||
'submit_mult', 'mult_submit', 'submit_mult_delete_version',
|
||||
__('Delete version'), 'b_drop.png', 'delete_version'
|
||||
);
|
||||
|
||||
$html .= '</form>';
|
||||
|
||||
if ($tracking_active) {
|
||||
$html .= PMA_getHtmlForActivateDeactivateTracking(
|
||||
'deactivate', $url_query, $last_version
|
||||
@ -1213,6 +1247,35 @@ function PMA_getTrackingSet()
|
||||
return $tracking_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a tracking version
|
||||
*
|
||||
* @param string $version tracking version
|
||||
*
|
||||
* @return string HTML of the success message
|
||||
*/
|
||||
function PMA_deleteTrackingVersion($version)
|
||||
{
|
||||
$html = '';
|
||||
$versionDeleted = PMA_Tracker::deleteTracking(
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$version
|
||||
);
|
||||
if ($versionDeleted) {
|
||||
$msg = PMA_Message::success(
|
||||
sprintf(
|
||||
__('Version %1$s of %2$s was deleted.'),
|
||||
htmlspecialchars($version),
|
||||
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
|
||||
)
|
||||
);
|
||||
$html .= $msg->getDisplay();
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to create the tracking version
|
||||
*
|
||||
|
||||
@ -11,6 +11,12 @@ require_once './libraries/common.inc.php';
|
||||
|
||||
require_once './libraries/tracking.lib.php';
|
||||
|
||||
//Get some js files needed for Ajax requests
|
||||
$response = PMA_Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('tbl_tracking.js');
|
||||
|
||||
define('TABLE_MAY_BE_ABSENT', true);
|
||||
require './libraries/tbl_common.inc.php';
|
||||
|
||||
@ -84,6 +90,26 @@ $html = '<br />';
|
||||
/**
|
||||
* Actions
|
||||
*/
|
||||
if (isset($_REQUEST['submit_mult'])) {
|
||||
if (! empty($_REQUEST['selected_versions'])) {
|
||||
if ($_REQUEST['submit_mult'] == 'delete_version') {
|
||||
foreach ($_REQUEST['selected_versions'] as $version) {
|
||||
PMA_deleteTrackingVersion($version);
|
||||
}
|
||||
$html .= PMA_Message::success(
|
||||
__('Tracking versions deleted successfully.')
|
||||
)->getDisplay();
|
||||
}
|
||||
} else {
|
||||
$html .= PMA_Message::notice(
|
||||
__('No versions selected.')
|
||||
)->getDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit_delete_version'])) {
|
||||
$html .= PMA_deleteTrackingVersion($_REQUEST['version']);
|
||||
}
|
||||
|
||||
// Create tracking version
|
||||
if (isset($_REQUEST['submit_create_version'])) {
|
||||
@ -155,7 +181,8 @@ $sql_result = PMA_getListOfVersionsOfTable();
|
||||
$last_version = PMA_getTableLastVersionNumber($sql_result);
|
||||
if ($last_version > 0) {
|
||||
$html .= PMA_getHtmlForTableVersionDetails(
|
||||
$sql_result, $last_version, $url_params, $url_query
|
||||
$sql_result, $last_version, $url_params,
|
||||
$url_query, $pmaThemeImage, $text_dir
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user