Skip to content

Commit

Permalink
Extract export action from db structure index method
Browse files Browse the repository at this point in the history
Related to #16173

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jun 12, 2020
1 parent 1b80220 commit 4e84842
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
39 changes: 33 additions & 6 deletions js/database/structure.js
Expand Up @@ -216,7 +216,9 @@ AJAX.registerOnload('database/structure.js', function () {
* Event handler on select of "Make consistent with central list"
*/
$('select[name=submit_mult]').on('change', function (event) {
if ($(this).val() === 'make_consistent_with_central_list') {
var action = $(this).val();

if (action === 'make_consistent_with_central_list') {
event.preventDefault();
event.stopPropagation();
jqConfirm(
Expand All @@ -225,21 +227,27 @@ AJAX.registerOnload('database/structure.js', function () {
}
);
return false;
} else if ($(this).val() === 'copy_tbl' || $(this).val() === 'add_prefix_tbl' || $(this).val() === 'replace_prefix_tbl' || $(this).val() === 'copy_tbl_change_prefix') {
}

if (action === 'copy_tbl' ||
action === 'add_prefix_tbl' ||
action === 'replace_prefix_tbl' ||
action === 'copy_tbl_change_prefix'
) {
event.preventDefault();
event.stopPropagation();
if ($('input[name="selected_tbl[]"]:checked').length === 0) {
return false;
}
var formData = $('#tablesForm').serialize();
var modalTitle = '';
if ($(this).val() === 'copy_tbl') {
if (action === 'copy_tbl') {
modalTitle = Messages.strCopyTablesTo;
} else if ($(this).val() === 'add_prefix_tbl') {
} else if (action === 'add_prefix_tbl') {
modalTitle = Messages.strAddPrefix;
} else if ($(this).val() === 'replace_prefix_tbl') {
} else if (action === 'replace_prefix_tbl') {
modalTitle = Messages.strReplacePrefix;
} else if ($(this).val() === 'copy_tbl_change_prefix') {
} else if (action === 'copy_tbl_change_prefix') {
modalTitle = Messages.strCopyPrefix;
}
$.ajax({
Expand Down Expand Up @@ -268,9 +276,28 @@ AJAX.registerOnload('database/structure.js', function () {
buttons: buttonOptions
});
});

return;
}

var url = '';

if (action === 'export') {
url = 'index.php?route=/database/structure/export';
} else {
$('#tablesForm').trigger('submit');

return;
}

var $form = $(this).parents('form');
var argsep = CommonParams.get('arg_separator');
var data = $form.serialize() + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true';

Functions.ajaxShowMessage();
AJAX.source = $form;

$.post(url, data, AJAX.responseHandler);
});

/**
Expand Down
22 changes: 16 additions & 6 deletions libraries/classes/Controllers/Database/StructureController.php
Expand Up @@ -420,12 +420,6 @@ public function multiSubmitAction(): void
unset($submit_mult);
$mult_btn = __('Yes');
break;
case 'export':
unset($submit_mult);
/** @var ExportController $controller */
$controller = $containerBuilder->get(ExportController::class);
$controller->index();
exit;
case 'copy_tbl':
$_url_params = [
'query_type' => 'copy_tbl',
Expand Down Expand Up @@ -1613,4 +1607,20 @@ protected function getValuesForInnodbTable(
$sum_size,
];
}

public function export(): void
{
global $containerBuilder;

if (empty($_POST['selected_tbl'])) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', __('No table selected.'));

return;
}

/** @var ExportController $controller */
$controller = $containerBuilder->get(ExportController::class);
$controller->index();
}
}
1 change: 1 addition & 0 deletions libraries/routes.php
Expand Up @@ -138,6 +138,7 @@
});
$routes->addGroup('/structure', static function (RouteCollector $routes) {
$routes->addRoute(['GET', 'POST'], '', [StructureController::class, 'index']);
$routes->post('/export', [StructureController::class, 'export']);
$routes->addRoute(['GET', 'POST'], '/favorite-table', [
StructureController::class,
'addRemoveFavoriteTablesAction',
Expand Down

0 comments on commit 4e84842

Please sign in to comment.