autocomplete for tables

This commit is contained in:
Marcin Łojewski
2018-06-28 20:16:43 +02:00
parent ffb28c62be
commit ecb04a331b
3 changed files with 12 additions and 5 deletions

View File

@@ -41,6 +41,7 @@ user_sql.adminSettingsUI = function () {
$(ids).autocomplete({
source: function (request, response) {
var post = $(form_id).serializeArray();
post.push({name: "input", value: request["term"]});
$.post(OC.generateUrl(path), post, response, "json");
},
minLength: 0,

View File

@@ -266,7 +266,8 @@ class SettingsController extends Controller
try {
$connection = $this->getConnection();
$platform = PlatformFactory::getPlatform($connection);
$tables = $platform->getTables();
$input = $this->request->getParam("input");
$tables = $platform->getTables($input);
$this->logger->debug(
"Returning tableAutocomplete(): count(" . count($tables) . ")",

View File

@@ -49,12 +49,13 @@ abstract class AbstractPlatform
/**
* Get all the tables defined in the database.
*
* @param string $phrase Show only tables containing given phrase.
* @param bool $schemaPrefix Show schema name in the results.
*
* @return array Array with table names.
* @throws DBALException On a database exception.
*/
public function getTables($schemaPrefix = false)
public function getTables($phrase = "", $schemaPrefix = false)
{
$platform = $this->connection->getDatabasePlatform();
@@ -68,14 +69,18 @@ abstract class AbstractPlatform
$result = $this->connection->executeQuery($queryTables);
while ($row = $result->fetch()) {
$name = $this->getTableName($row, $schemaPrefix);
if (preg_match("/.*$phrase.*/i", $name)) {
$tables[] = $name;
}
}
$result = $this->connection->executeQuery($queryViews);
while ($row = $result->fetch()) {
$name = $this->getViewName($row, $schemaPrefix);
if (preg_match("/.*$phrase.*/i", $name)) {
$tables[] = $name;
}
}
return $tables;
}