Extract browse action from table structure index method
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
a6d9818b3a
commit
3bf3fd5c36
@ -420,7 +420,9 @@ AJAX.registerOnload('table/structure.js', function () {
|
||||
AJAX.source = $form;
|
||||
var url = $form.attr('action');
|
||||
|
||||
if (action === 'add_to_central_columns') {
|
||||
if (action === 'browse') {
|
||||
url = 'index.php?route=/table/structure/browse';
|
||||
} else if (action === 'add_to_central_columns') {
|
||||
url = 'index.php?route=/table/structure/central-columns-add';
|
||||
} else if (action === 'remove_from_central_columns') {
|
||||
url = 'index.php?route=/table/structure/central-columns-remove';
|
||||
|
||||
@ -113,10 +113,8 @@ class StructureController extends AbstractController
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
global $containerBuilder, $sql_query, $reread_info, $showtable;
|
||||
global $containerBuilder, $reread_info, $showtable, $url_params;
|
||||
global $tbl_is_view, $tbl_storage_engine, $tbl_collation, $table_info_num_rows;
|
||||
global $db, $table, $goto, $message, $mult_btn, $query_type;
|
||||
global $selected, $selected_fld, $submit_mult, $url_query, $url_params;
|
||||
|
||||
$this->dbi->selectDb($this->db);
|
||||
$reread_info = $this->table_obj->getStatusInfo(null, true);
|
||||
@ -124,6 +122,7 @@ class StructureController extends AbstractController
|
||||
null,
|
||||
(isset($reread_info) && $reread_info)
|
||||
);
|
||||
|
||||
if ($this->table_obj->isView()) {
|
||||
$tbl_is_view = true;
|
||||
$tbl_storage_engine = __('View');
|
||||
@ -131,6 +130,7 @@ class StructureController extends AbstractController
|
||||
$tbl_is_view = false;
|
||||
$tbl_storage_engine = $this->table_obj->getStorageEngine();
|
||||
}
|
||||
|
||||
$tbl_collation = $this->table_obj->getCollation();
|
||||
$table_info_num_rows = $this->table_obj->getNumRows();
|
||||
|
||||
@ -139,12 +139,10 @@ class StructureController extends AbstractController
|
||||
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
|
||||
$checkUserPrivileges->getPrivileges();
|
||||
|
||||
$this->response->getHeader()->getScripts()->addFiles(
|
||||
[
|
||||
'table/structure.js',
|
||||
'indexes.js',
|
||||
]
|
||||
);
|
||||
$this->response->getHeader()->getScripts()->addFiles([
|
||||
'table/structure.js',
|
||||
'indexes.js',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Handle column moving
|
||||
@ -193,6 +191,7 @@ class StructureController extends AbstractController
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* A click on Change has been made for one column
|
||||
*/
|
||||
@ -216,28 +215,6 @@ class StructureController extends AbstractController
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* handle multiple field commands if required
|
||||
*
|
||||
* submit_mult_*_x comes from IE if <input type="img" ...> is used
|
||||
*/
|
||||
$submit_mult = $this->getMultipleFieldCommandType();
|
||||
|
||||
if (! empty($submit_mult)) {
|
||||
if (isset($_POST['selected_fld'])) {
|
||||
if ($submit_mult == 'browse') {
|
||||
// browsing the table displaying only selected columns
|
||||
$this->displayTableBrowseForSelectedColumns(
|
||||
$GLOBALS['goto'],
|
||||
$GLOBALS['pmaThemeImage']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', __('No column selected.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifications have been submitted -> updates the table
|
||||
*/
|
||||
@ -269,34 +246,17 @@ class StructureController extends AbstractController
|
||||
$GLOBALS['reload'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relation settings
|
||||
*/
|
||||
$cfgRelation = $this->relation->getRelationsParam();
|
||||
|
||||
/**
|
||||
* Runs common work
|
||||
*/
|
||||
// set db, table references, for require_once that follows
|
||||
// got to be eliminated in long run
|
||||
$db = &$this->db;
|
||||
$table = &$this->table;
|
||||
$url_params = [];
|
||||
|
||||
Common::table();
|
||||
|
||||
$this->_url_query = Url::getCommonRaw([
|
||||
'db' => $db,
|
||||
'table' => $table,
|
||||
'goto' => Url::getFromRoute('/table/structure'),
|
||||
'back' => Url::getFromRoute('/table/structure'),
|
||||
]);
|
||||
/* The url_params array is initialized in above include */
|
||||
$url_params['goto'] = Url::getFromRoute('/table/structure');
|
||||
$url_params['back'] = Url::getFromRoute('/table/structure');
|
||||
|
||||
// 2. Gets table keys and retains them
|
||||
// @todo should be: $server->db($db)->table($table)->primary()
|
||||
$this->_url_query = Url::getCommonRaw($url_params);
|
||||
|
||||
$primary = Index::getPrimary($this->table, $this->db);
|
||||
$columns_with_index = $this->dbi
|
||||
->getTable($this->db, $this->table)
|
||||
@ -308,7 +268,6 @@ class StructureController extends AbstractController
|
||||
->getTable($this->db, $this->table)
|
||||
->getColumnsWithIndex(Index::UNIQUE);
|
||||
|
||||
// 3. Get fields
|
||||
$fields = (array) $this->dbi->getColumns(
|
||||
$this->db,
|
||||
$this->table,
|
||||
@ -316,16 +275,28 @@ class StructureController extends AbstractController
|
||||
true
|
||||
);
|
||||
|
||||
//display table structure
|
||||
$this->response->addHTML(
|
||||
$this->displayStructure(
|
||||
$cfgRelation,
|
||||
$columns_with_unique_index,
|
||||
$url_params,
|
||||
$primary,
|
||||
$fields,
|
||||
$columns_with_index
|
||||
)
|
||||
$this->response->addHTML($this->displayStructure(
|
||||
$cfgRelation,
|
||||
$columns_with_unique_index,
|
||||
$url_params,
|
||||
$primary,
|
||||
$fields,
|
||||
$columns_with_index
|
||||
));
|
||||
}
|
||||
|
||||
public function browse(): void
|
||||
{
|
||||
if (empty($_POST['selected_fld'])) {
|
||||
$this->response->setRequestStatus(false);
|
||||
$this->response->addJSON('message', __('No column selected.'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->displayTableBrowseForSelectedColumns(
|
||||
$GLOBALS['goto'],
|
||||
$GLOBALS['pmaThemeImage']
|
||||
);
|
||||
}
|
||||
|
||||
@ -1610,36 +1581,6 @@ class StructureController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the type of command for multiple field handling
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getMultipleFieldCommandType()
|
||||
{
|
||||
$types = ['browse'];
|
||||
|
||||
foreach ($types as $type) {
|
||||
if (isset($_POST['submit_mult_' . $type . '_x'])) {
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['submit_mult'])) {
|
||||
return $_POST['submit_mult'];
|
||||
} elseif (isset($_POST['mult_btn'])
|
||||
&& $_POST['mult_btn'] == __('Yes')
|
||||
) {
|
||||
if (isset($_POST['selected'])) {
|
||||
$_POST['selected_fld'] = $_POST['selected'];
|
||||
}
|
||||
|
||||
return 'row_delete';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to display table browse for selected columns
|
||||
*
|
||||
|
||||
@ -253,6 +253,7 @@ return function (RouteCollector $routes) {
|
||||
$routes->addRoute(['GET', 'POST'], '/sql', [TableSqlController::class, 'index']);
|
||||
$routes->addGroup('/structure', function (RouteCollector $routes) {
|
||||
$routes->addRoute(['GET', 'POST'], '', [TableStructureController::class, 'index']);
|
||||
$routes->post('/browse', [TableStructureController::class, 'browse']);
|
||||
$routes->post('/central-columns-add', [TableStructureController::class, 'addToCentralColumns']);
|
||||
$routes->post('/central-columns-remove', [TableStructureController::class, 'removeFromCentralColumns']);
|
||||
$routes->post('/change', [TableStructureController::class, 'change']);
|
||||
|
||||
@ -189,59 +189,4 @@ class StructureControllerTest extends AbstractTestCase
|
||||
$method->invokeArgs($ctrl, [[]])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for getMultipleFieldCommandType()
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
public function testGetMultipleFieldCommandType()
|
||||
{
|
||||
$class = new ReflectionClass(StructureController::class);
|
||||
$method = $class->getMethod('getMultipleFieldCommandType');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$relation = new Relation($GLOBALS['dbi'], $this->template);
|
||||
$ctrl = new StructureController(
|
||||
$this->_response,
|
||||
$GLOBALS['dbi'],
|
||||
$this->template,
|
||||
$GLOBALS['db'],
|
||||
$GLOBALS['table'],
|
||||
$relation,
|
||||
new Transformations(),
|
||||
new CreateAddField($GLOBALS['dbi']),
|
||||
new RelationCleanup($GLOBALS['dbi'], $relation)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
null,
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_POST['submit_mult'] = 'create';
|
||||
$this->assertEquals(
|
||||
'create',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
unset($_POST['submit_mult']);
|
||||
|
||||
$_POST['mult_btn'] = __('Yes');
|
||||
$this->assertEquals(
|
||||
'row_delete',
|
||||
$method->invoke($ctrl)
|
||||
);
|
||||
|
||||
$_POST['selected'] = [
|
||||
'a',
|
||||
'b',
|
||||
];
|
||||
$method->invoke($ctrl);
|
||||
$this->assertEquals(
|
||||
$_POST['selected'],
|
||||
$_POST['selected_fld']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user