Skip to content

Commit

Permalink
Add visualize page
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelTallet committed Aug 21, 2020
1 parent ae23e79 commit 050c1bf
Show file tree
Hide file tree
Showing 21 changed files with 399 additions and 4 deletions.
8 changes: 5 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ Additional features: Export documents to JSON. Import documents from JSON. ISODa
Screenshots
-----------

![MongoDB PHP GUI](https://raw.githubusercontent.com/SamuelTS/MongoDB-PHP-GUI/master/docs/screenshots/new-mpg-database-query.png)
![MongoDB PHP GUI - Visualize Database](https://raw.githubusercontent.com/SamuelTS/MongoDB-PHP-GUI/master/docs/screenshots/newest-mpg-database-visualize.png)

![MongoDB PHP GUI](https://raw.githubusercontent.com/SamuelTS/MongoDB-PHP-GUI/master/docs/screenshots/new-mpg-collection-indexes.png)
![MongoDB PHP GUI - Query Database](https://raw.githubusercontent.com/SamuelTS/MongoDB-PHP-GUI/master/docs/screenshots/newest-mpg-database-query.png)

![MongoDB PHP GUI - Manage Indexes](https://raw.githubusercontent.com/SamuelTS/MongoDB-PHP-GUI/master/docs/screenshots/newest-mpg-collection-indexes.png)

Installation
------------
Expand All @@ -24,7 +26,7 @@ Thanks
------

❤️ Thanks to [Limber](https://github.com/nimbly/Limber), [Capsule](https://github.com/nimbly/Capsule), [Font Awesome](https://fontawesome.com/), [Bootstrap](https://getbootstrap.com/), [CodeMirror](https://github.com/codemirror/codemirror) and [JsonView](https://github.com/pgrabovets/json-view).<br>
Special thanks to [MongoDB PHP library](https://github.com/mongodb/mongo-php-library) and [SQL to MongoDB Query Converter](https://github.com/vincentrussell/sql-to-mongo-db-query-converter). ❤️
Thanks also to [MongoDB PHP lib](https://github.com/mongodb/mongo-php-library), [vis.js](https://github.com/visjs) and [SQL to MongoDB Query Converter](https://github.com/vincentrussell/sql-to-mongo-db-query-converter). ❤️

Copyright
---------
Expand Down
Binary file removed docs/screenshots/new-mpg-collection-indexes.png
Binary file not shown.
Binary file removed docs/screenshots/new-mpg-database-query.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/screenshots/newest-mpg-database-query.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @var string
*/
define('MPG_APP_VERSION', '1.0.5');
define('MPG_APP_VERSION', '1.0.6');

/**
* Development mode?
Expand Down
10 changes: 10 additions & 0 deletions routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
CollectionController::class . '@renderImportViewAction'
);

$router->get(
MPG_SERVER_PATH . '/visualizeDatabase',
DatabaseController::class . '@renderVisualizeViewAction'
);

$router->get(
MPG_SERVER_PATH . '/ajaxDatabaseGetNetworkGraph',
DatabaseController::class . '@getNetworkGraphAction'
);

$router->get(
MPG_SERVER_PATH . '/queryDatabase',
DatabaseController::class . '@renderQueryViewAction'
Expand Down
101 changes: 101 additions & 0 deletions src/Controllers/DatabaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,107 @@ public static function getDatabaseNames() : array {

}

public function renderVisualizeViewAction() : Response {

LoginController::ensureUserIsLogged();

return new Response(200, $this->renderView('database.visualize'));

}

public function getNetworkGraphAction() : Response {

$networkGraph = [
'visData' => [
'nodes' => [
[
'id' => 1,
'label' => 'MongoDB server',
'shape' => 'image',
'image' => MPG_BASE_URL . '/static/images/leaf-icon.svg',
'size' => 32
]
],
'edges' => []
],
'mapping' => [

1 => [
'databaseName' => null,
'collectionName' => null
]

]
];

$nodeCounter = 1;

try {

foreach (MongoDBHelper::getClient()->listDatabases() as $databaseInfo) {

$nodeCounter++;

$databaseNode = [
'id' => $nodeCounter,
'label' => 'DB: ' . $databaseInfo['name'],
'shape' => 'image',
'image' => MPG_BASE_URL . '/static/images/database-icon.svg',
'size' => 24
];

$database = MongoDBHelper::getClient()->selectDatabase(
$databaseInfo['name']
);

foreach ($database->listCollections() as $collectionInfo) {

$nodeCounter++;

$collectionNode = [
'id' => $nodeCounter,
'label' => 'Coll: ' . $collectionInfo['name'],
'shape' => 'image',
'image' => MPG_BASE_URL . '/static/images/document-icon.svg',
'size' => 24
];

array_push($networkGraph['visData']['nodes'], $collectionNode);

array_push($networkGraph['visData']['edges'], [
'from' => $databaseNode['id'],
'to' => $collectionNode['id']
]);

$networkGraph['mapping'][ $collectionNode['id'] ] = [
'databaseName' => $databaseInfo['name'],
'collectionName' => $collectionInfo['name']
];

}

array_push($networkGraph['visData']['nodes'], $databaseNode);

array_push($networkGraph['visData']['edges'], [
'from' => 1, // MongoDB server
'to' => $databaseNode['id']
]);

$networkGraph['mapping'][ $databaseNode['id'] ] = [
'databaseName' => $databaseInfo['name'],
'collectionName' => null
];

}

} catch (\Throwable $th) {
return new JsonResponse(500, ErrorNormalizer::normalize($th, __METHOD__));
}

return new JsonResponse(200, $networkGraph);

}

public function renderQueryViewAction() : Response {

LoginController::ensureUserIsLogged();
Expand Down
6 changes: 6 additions & 0 deletions static/css/mpg.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@

}

.vis-network:focus {

outline: none;

}

code {

font-size: 100%;
Expand Down
1 change: 1 addition & 0 deletions static/images/database-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions static/images/document-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/images/leaf-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions static/js/mpg.database.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ MPG.eventListeners.addCollections = function() {

document.querySelector('#mpg-output-code').innerHTML = '';

document.querySelector('#mpg-find-button').click();

},
JSON.stringify(requestBody)
);
Expand Down
Loading

0 comments on commit 050c1bf

Please sign in to comment.