Extract drop confirmation action from index action
Extracts the /table/structure/drop-confirm route from the /table/structure route. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
73290bcdcf
commit
ff86a0b6d6
@ -412,12 +412,19 @@ AJAX.registerOnload('table/structure.js', function () {
|
||||
$('body').on('click', '#fieldsForm.ajax button[name="submit_mult"], #fieldsForm.ajax input[name="submit_mult"]', function (e) {
|
||||
e.preventDefault();
|
||||
var $button = $(this);
|
||||
var action = $button.val();
|
||||
var $form = $button.parents('form');
|
||||
var argsep = CommonParams.get('arg_separator');
|
||||
var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep + 'submit_mult=' + $button.val();
|
||||
var submitData = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true' + argsep + 'submit_mult=' + action;
|
||||
Functions.ajaxShowMessage();
|
||||
AJAX.source = $form;
|
||||
$.post($form.attr('action'), submitData, AJAX.responseHandler);
|
||||
var url = $form.attr('action');
|
||||
|
||||
if (action === 'drop') {
|
||||
url = 'index.php?route=/table/structure/drop-confirm';
|
||||
}
|
||||
|
||||
$.post(url, submitData, AJAX.responseHandler);
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -315,18 +315,6 @@ class StructureController extends AbstractController
|
||||
$full_query = preg_replace('@,$@', ');<br>', $full_query);
|
||||
}
|
||||
break;
|
||||
case 'drop_fld':
|
||||
if ($full_query == '') {
|
||||
$full_query .= 'ALTER TABLE '
|
||||
. Util::backquote(htmlspecialchars($table));
|
||||
}
|
||||
$full_query .= '<br> DROP '
|
||||
. Util::backquote(htmlspecialchars($selectedValue))
|
||||
. ',';
|
||||
if ($i == $selectedCount - 1) {
|
||||
$full_query = preg_replace('@,$@', ';<br>', $full_query);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@ -551,6 +539,49 @@ class StructureController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
public function dropConfirm(): void
|
||||
{
|
||||
global $db, $table;
|
||||
|
||||
$selected = $_POST['selected_fld'] ?? null;
|
||||
|
||||
if (empty($selected)) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', __('No column selected.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dbi->selectDb($this->db);
|
||||
|
||||
PageSettings::showGroup('TableStructure');
|
||||
|
||||
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
|
||||
$checkUserPrivileges->getPrivileges();
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles([
|
||||
'table/structure.js',
|
||||
'indexes.js',
|
||||
]);
|
||||
|
||||
Common::table();
|
||||
|
||||
$urlParams = [
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'query_type' => 'drop_fld',
|
||||
];
|
||||
foreach ($selected as $selectedValue) {
|
||||
$urlParams['selected'][] = $selectedValue;
|
||||
}
|
||||
|
||||
$this->render('table/structure/drop_confirm', [
|
||||
'url_params' => $urlParams,
|
||||
'table' => $table,
|
||||
'fields' => $selected,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves columns in the table's structure based on $_REQUEST
|
||||
*
|
||||
@ -966,7 +997,6 @@ class StructureController extends AbstractController
|
||||
{
|
||||
$types = [
|
||||
'change',
|
||||
'drop',
|
||||
'primary',
|
||||
'index',
|
||||
'unique',
|
||||
@ -1748,9 +1778,6 @@ class StructureController extends AbstractController
|
||||
$mult_btn = null;
|
||||
$centralColsError = null;
|
||||
switch ($submit_mult) {
|
||||
case 'drop':
|
||||
$what = 'drop_fld';
|
||||
break;
|
||||
case 'primary':
|
||||
// Gets table primary key
|
||||
$primary = $this->getKeyForTablePrimary();
|
||||
|
||||
@ -251,7 +251,10 @@ return function (RouteCollector $routes) {
|
||||
$routes->addRoute(['GET', 'POST'], '/replace', [ReplaceController::class, 'index']);
|
||||
$routes->addRoute(['GET', 'POST'], '/search', [TableSearchController::class, 'index']);
|
||||
$routes->addRoute(['GET', 'POST'], '/sql', [TableSqlController::class, 'index']);
|
||||
$routes->addRoute(['GET', 'POST'], '/structure', [TableStructureController::class, 'index']);
|
||||
$routes->addGroup('/structure', function (RouteCollector $routes) {
|
||||
$routes->addRoute(['GET', 'POST'], '', [TableStructureController::class, 'index']);
|
||||
$routes->post('/drop-confirm', [TableStructureController::class, 'dropConfirm']);
|
||||
});
|
||||
$routes->addRoute(['GET', 'POST'], '/tracking', [TableTrackingController::class, 'index']);
|
||||
$routes->addRoute(['GET', 'POST'], '/triggers', [TableTriggersController::class, 'index']);
|
||||
$routes->addRoute(['GET', 'POST'], '/zoom-search', [ZoomSearchController::class, 'index']);
|
||||
|
||||
22
templates/table/structure/drop_confirm.twig
Normal file
22
templates/table/structure/drop_confirm.twig
Normal file
@ -0,0 +1,22 @@
|
||||
<form action="{{ url('/table/structure') }}" method="post">
|
||||
{{ get_hidden_inputs(url_params) }}
|
||||
|
||||
<fieldset class="confirmation">
|
||||
<legend>
|
||||
{% trans 'Do you really want to execute the following query?' %}
|
||||
</legend>
|
||||
|
||||
<code>
|
||||
ALTER TABLE {{ backquote(table) }}<br>
|
||||
{% for field in fields %}
|
||||
DROP {{ backquote(field) }}
|
||||
{%- if loop.last %};{% else %},<br>{% endif %}
|
||||
{% endfor %}
|
||||
</code>
|
||||
</fieldset>
|
||||
|
||||
<fieldset class="tblFooters">
|
||||
<input id="buttonYes" class="btn btn-secondary" type="submit" name="mult_btn" value="{% trans 'Yes' %}">
|
||||
<input id="buttonNo" class="btn btn-secondary" type="submit" name="mult_btn" value="{% trans 'No' %}">
|
||||
</fieldset>
|
||||
</form>
|
||||
@ -215,12 +215,12 @@ class StructureControllerTest extends PmaTestCase
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_POST['submit_mult_drop_x'] = true;
|
||||
$_POST['submit_mult_unique_x'] = true;
|
||||
$this->assertEquals(
|
||||
'drop',
|
||||
'unique',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
unset($_POST['submit_mult_drop_x']);
|
||||
unset($_POST['submit_mult_unique_x']);
|
||||
|
||||
$_POST['submit_mult'] = 'create';
|
||||
$this->assertEquals(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user