Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
🎨 [REFACTOR] Cleaning up.
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenJustus committed Jul 19, 2019
1 parent 27cfafd commit 0a5e0f4
Show file tree
Hide file tree
Showing 8 changed files with 109,237 additions and 67 deletions.
35,075 changes: 35,074 additions & 1 deletion public/app.css

Large diffs are not rendered by default.

74,118 changes: 74,117 additions & 1 deletion public/app.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
:value="app.serverInfo.QUERIES_PER_SECOND_AVG ? app.serverInfo.QUERIES_PER_SECOND_AVG : 'Could not retrieve'"
:unit="app.serverInfo.QUERIES_PER_SECOND_AVG ? 'queries per second' : '...'">
<slot ref="alert">
<Badge v-if="app.serverInfo.QUERIES_PER_SECOND_AVG && app.serverInfo.QUERIES_PER_SECOND_AVG === 0"
<Badge v-if="app.serverInfo.QUERIES_PER_SECOND_AVG === 0"
type="critical"/>
<Badge v-if="app.serverInfo.QUERIES_PER_SECOND_AVG && app.serverInfo.QUERIES_PER_SECOND_AVG >= 0.3"
type="average"/>
<Badge v-if="app.serverInfo.QUERIES_PER_SECOND_AVG && app.serverInfo.QUERIES_PER_SECOND_AVG >= 1"
<Badge v-else-if="app.serverInfo.QUERIES_PER_SECOND_AVG <= 0.3 && app.serverInfo.QUERIES_PER_SECOND_AVG <= 0.9"
type="neutral"/>
<Badge v-else-if="app.serverInfo.QUERIES_PER_SECOND_AVG > 0.9"
type="good"/>
</slot>
</StatusDisplay>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
methods: {
runMigrations: function() {
api.get('migrations/run').then(res => {
api.get('database/migrations/run').then(res => {
if (res) {
window.location.reload();
}
});
},
resetMigrations: function() {
api.get('migrations/reset').finally(() => {
api.get('database/migrations/reset').finally(() => {
window.location.reload();
});
},
Expand Down
15 changes: 1 addition & 14 deletions src/Classes/Database/DatabaseTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,6 @@ public function getTablesFromDB(string $database): array
{
$tables = $this->connection->select($this->databaseQueries->showTablesFrom($database));

// Collect differently if postgres. @TODO.
$tmp = [];

if ($this->databaseConn === 'pgsql') {
for ($i = 0; $i < count($tables); $i++) {
if ($tables[$i]->schemaname === $database) {
array_push($tmp, $tables[$i]);
}
}
unset($tables);
$tables = $tmp;
}

return $this->normalise($tables);
}

Expand Down Expand Up @@ -227,7 +214,7 @@ public function getAllDatabases(): array

/**
* Normalise query results; assumes a lot about the structure, which can
* potentially cause problems later on. @TODO
* potentially cause problems later on.
* Assumed structure:
* -----------------
* Array [
Expand Down
39 changes: 0 additions & 39 deletions src/Http/Controllers/DatabaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Protoqol\Prequel\Classes\App\Migrations;
use Protoqol\Prequel\Classes\Database\DatabaseConnector;
use Protoqol\Prequel\Classes\Database\DatabaseTraverser;
use Protoqol\Prequel\Http\Requests\PrequelDatabaseRequest;

/**
* Class DatabaseActionController
Expand Down Expand Up @@ -72,8 +70,6 @@ public function getTableData()
{
// If Model exists
if ($this->model && $this->databaseName === config('database.connections.mysql.database')) {
$hidden = $this->model->getHidden();
$visible = $this->model->getVisible();
$paginated = $this->model->paginate(config('prequel.pagination'));
$paginated->setCollection($paginated->getCollection()->each->setHidden([])->each->setVisible([]));

Expand All @@ -98,25 +94,8 @@ public function getTableData()
];
}

/**
* Get count of rows in table
* Not yet used.
* @return array
*/
public function countTableRecords(): array
{
$count = DB::table($this->qualifiedName)
->count('id');

return [
"table" => $this->qualifiedName,
"count" => $count,
];
}

/**
* Find given value in given column with given operator.
* @TODO Clean up.
* @return mixed
*/
public function findInTable()
Expand All @@ -131,22 +110,4 @@ public function findInTable()
->where($column, $queryType, $value)
->paginate(config('prequel.pagination'));
}

/**
* Run pending migrations.
* @return int
*/
public function runMigrations()
{
return (new Migrations())->run();
}

/**
* Reset latest migrations.
* @return int
*/
public function resetMigrations()
{
return (new Migrations())->reset();
}
}
21 changes: 19 additions & 2 deletions src/Http/Controllers/PrequelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use Illuminate\Routing\Controller;
use Protoqol\Prequel\Classes\App\AppStatus;
use Protoqol\Prequel\Classes\App\Migrations;
use Protoqol\Prequel\Classes\Database\DatabaseTraverser;

/**
* Class PrequelController
*
* @package Protoqol\Prequel\Http\Controllers
*/
class PrequelController extends Controller
Expand Down Expand Up @@ -40,11 +40,28 @@ public function index()

/**
* Get app status.
*
* @return array
*/
public function status()
{
return (new AppStatus())->getStatus();
}

/**
* Run pending migrations.
* @return int
*/
public function runMigrations()
{
return (new Migrations())->run();
}

/**
* Reset latest migrations.
* @return int
*/
public function resetMigrations()
{
return (new Migrations())->reset();
}
}
24 changes: 20 additions & 4 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

use Illuminate\Support\Facades\Route;


/**
|-----------------------------------------
| Prequel Web Routes /prequel or via config.
|-----------------------------------------
|
| Separate from web route to avoid user configured path messing up the Prequel-API.
|
*/
Route::namespace('Protoqol\Prequel\Http\Controllers')
->middleware(config('prequel.middleware'))
->prefix(config('prequel.path'))
Expand All @@ -12,9 +21,16 @@

});

// Separate from web route to avoid user configured path messing up the Prequel-API.
/**
|-----------------------------------------
| Prequel API Routes /prequel-api
|-----------------------------------------
|
| Separate from web route to avoid user configured path messing up the Prequel-API.
|
*/
Route::namespace('Protoqol\Prequel\Http\Controllers')
->middleware([Protoqol\Prequel\Http\Middleware\Authorised::class])
->middleware(config('prequel.middleware'))
->prefix('prequel-api')
->name('prequel.')
->group(function () {
Expand All @@ -26,8 +42,8 @@
Route::get('count/{database}/{table}', 'DatabaseController@countTableRecords');
Route::get('find/{database}/{table}/{column}/{type}/{value}', 'DatabaseController@findInTable');

Route::get('run', 'DatabaseController@runMigrations');
Route::get('reset', 'DatabaseController@resetMigrations');
Route::get('migrations/run', 'PrequelController@runMigrations');
Route::get('migrations/reset', 'PrequelController@resetMigrations');
});

});

0 comments on commit 0a5e0f4

Please sign in to comment.