From 59a150148aaf67291267a6c8efffb714df3d016c Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 20 May 2020 17:29:03 -0600 Subject: [PATCH 01/14] feature/server-mounts initial commit --- .../Admin/Mounts/MountController.php | 37 ++++++++ app/Models/Mount.php | 29 ++++++ resources/views/admin/mounts/index.blade.php | 93 +++++++++++++++++++ resources/views/layouts/admin.blade.php | 5 + routes/admin.php | 12 +++ 5 files changed, 176 insertions(+) create mode 100644 app/Http/Controllers/Admin/Mounts/MountController.php create mode 100644 app/Models/Mount.php create mode 100644 resources/views/admin/mounts/index.blade.php diff --git a/app/Http/Controllers/Admin/Mounts/MountController.php b/app/Http/Controllers/Admin/Mounts/MountController.php new file mode 100644 index 000000000..898293bbd --- /dev/null +++ b/app/Http/Controllers/Admin/Mounts/MountController.php @@ -0,0 +1,37 @@ +repository = $repository; + } + + /** + * Return the mount overview page. + * + * @return \Illuminate\View\View + */ + public function index() + { + return view('admin.mounts.index', [ + 'locations' => $this->repository->getAllWithDetails(), + ]); + } +} diff --git a/app/Models/Mount.php b/app/Models/Mount.php new file mode 100644 index 000000000..426c32bc4 --- /dev/null +++ b/app/Models/Mount.php @@ -0,0 +1,29 @@ + --}} + +{{-- This software is licensed under the terms of the MIT license. --}} +{{-- https://opensource.org/licenses/MIT --}} +@extends('layouts.admin') + +@section('title') + Mounts +@endsection + +@section('content-header') +

MountsSoonTM

+ +@endsection + +@section('content') +
+
+
+
+

Mount List

+ +
+ +
+
+ +
+ + + + + + + + + + + @foreach ($locations as $location) + + + + + + + + @endforeach + +
IDShort CodeDescriptionNodesServers
{{ $location->id }}{{ $location->short }}{{ $location->long }}{{ $location->nodes_count }}{{ $location->servers_count }}
+
+
+
+
+ + +@endsection diff --git a/resources/views/layouts/admin.blade.php b/resources/views/layouts/admin.blade.php index 373515e84..42a2bc434 100644 --- a/resources/views/layouts/admin.blade.php +++ b/resources/views/layouts/admin.blade.php @@ -117,6 +117,11 @@
  • SERVICE MANAGEMENT
  • +
  • + + Mounts + +
  • Nests diff --git a/routes/admin.php b/routes/admin.php index 7a1c9fa75..4e5ac8bb2 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -165,6 +165,18 @@ Route::group(['prefix' => 'nodes'], function () { Route::delete('/view/{node}/allocations', 'NodesController@allocationRemoveMultiple')->name('admin.nodes.view.allocation.removeMultiple'); }); +/* +|-------------------------------------------------------------------------- +| Mount Controller Routes +|-------------------------------------------------------------------------- +| +| Endpoint: /admin/mounts +| +*/ +Route::group(['prefix' => 'mounts'], function () { + Route::get('/', 'Mounts\MountController@index')->name('admin.mounts'); +}); + /* |-------------------------------------------------------------------------- | Nest Controller Routes From 00d1b5861ae03d26af624ee3076ae8cad4c2143a Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Wed, 20 May 2020 18:00:53 -0600 Subject: [PATCH 02/14] Properly setup Mount model, add database migration, get mount admin page added --- .../Admin/Mounts/MountController.php | 12 ++-- app/Models/Mount.php | 58 ++++++++++++++++++- app/Repositories/Eloquent/MountRepository.php | 32 ++++++++++ .../2020_05_20_234655_add_mounts_table.php | 48 +++++++++++++++ resources/views/admin/mounts/index.blade.php | 46 +++++++++------ 5 files changed, 169 insertions(+), 27 deletions(-) create mode 100644 app/Repositories/Eloquent/MountRepository.php create mode 100644 database/migrations/2020_05_20_234655_add_mounts_table.php diff --git a/app/Http/Controllers/Admin/Mounts/MountController.php b/app/Http/Controllers/Admin/Mounts/MountController.php index 898293bbd..977dd558c 100644 --- a/app/Http/Controllers/Admin/Mounts/MountController.php +++ b/app/Http/Controllers/Admin/Mounts/MountController.php @@ -2,23 +2,23 @@ namespace Pterodactyl\Http\Controllers\Admin\Mounts; -use Pterodactyl\Contracts\Repository\LocationRepositoryInterface; use Pterodactyl\Http\Controllers\Controller; +use Pterodactyl\Repositories\Eloquent\MountRepository; class MountController extends Controller { /** - * @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface + * @var \Pterodactyl\Repositories\Eloquent\MountRepository */ protected $repository; /** - * LocationController constructor. + * MountController constructor. * - * @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository + * @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository */ public function __construct( - LocationRepositoryInterface $repository + MountRepository $repository ) { $this->repository = $repository; } @@ -31,7 +31,7 @@ class MountController extends Controller public function index() { return view('admin.mounts.index', [ - 'locations' => $this->repository->getAllWithDetails(), + 'mounts' => $this->repository->getAllWithDetails(), ]); } } diff --git a/app/Models/Mount.php b/app/Models/Mount.php index 426c32bc4..6c3e699fe 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -3,7 +3,16 @@ namespace Pterodactyl\Models; /** - * @property int $id + * @property string $id + * @property string $name + * @property string $description + * @property string $source + * @property string $target + * @property bool $read_only + * @property bool $user_mountable + * + * @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes + * @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs */ class Mount extends Model { @@ -25,5 +34,50 @@ class Mount extends Model * * @var array */ - protected $guarded = ['id']; + protected $guarded = ['id', 'name', 'description', 'source', 'target']; + + /** + * Default values for specific fields in the database. + * + * @var array + */ + protected $attributes = [ + 'read_only' => 'bool', + 'user_mountable' => 'bool', + ]; + + /** + * Rules verifying that the data being stored matches the expectations of the database. + * + * @var string + */ + public static $validationRules = [ + 'id' => 'required|string|size:36|unique:mounts,id', + 'name' => 'required|string|min:2|max:64|unique:mounts,name', + 'description' => 'nullable|string|max:255', + 'source' => 'required|string', + 'target' => 'required|string', + 'read_only' => 'sometimes|boolean', + 'user_mountable' => 'sometimes|boolean', + ]; + + /** + * Returns all eggs that have this mount assigned. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function eggs() + { + return $this->belongsToMany(Egg::class); + } + + /** + * Returns all nodes that have this mount assigned. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function nodes() + { + return $this->belongsToMany(Node::class); + } } diff --git a/app/Repositories/Eloquent/MountRepository.php b/app/Repositories/Eloquent/MountRepository.php new file mode 100644 index 000000000..2bf953566 --- /dev/null +++ b/app/Repositories/Eloquent/MountRepository.php @@ -0,0 +1,32 @@ +getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns()); + } +} diff --git a/database/migrations/2020_05_20_234655_add_mounts_table.php b/database/migrations/2020_05_20_234655_add_mounts_table.php new file mode 100644 index 000000000..308ed685b --- /dev/null +++ b/database/migrations/2020_05_20_234655_add_mounts_table.php @@ -0,0 +1,48 @@ +char('id', 36)->unique(); + $table->string('name'); + $table->text('description')->nullable(); + $table->string('source'); + $table->string('target'); + $table->tinyInteger('read_only')->unsigned(); + $table->tinyInteger('user_mountable')->unsigned(); + }); + + Schema::create('egg_mount', function (Blueprint $table) { + $table->increments('egg_id')->unique(); + $table->char('mount_id', 36)->unique(); + }); + + Schema::create('mount_node', function (Blueprint $table) { + $table->increments('node_id')->unique(); + $table->char('mount_id', 36)->unique(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('mount_node'); + Schema::dropIfExists('egg_mount'); + Schema::dropIfExists('mounts'); + } +} diff --git a/resources/views/admin/mounts/index.blade.php b/resources/views/admin/mounts/index.blade.php index ba6701eac..6b9364b91 100644 --- a/resources/views/admin/mounts/index.blade.php +++ b/resources/views/admin/mounts/index.blade.php @@ -3,6 +3,7 @@ {{-- This software is licensed under the terms of the MIT license. --}} {{-- https://opensource.org/licenses/MIT --}} + @extends('layouts.admin') @section('title') @@ -25,7 +26,7 @@

    Mount List

    - +
    @@ -34,19 +35,23 @@ ID - Short Code - Description + Name + Source + Target + Eggs Nodes Servers - @foreach ($locations as $location) + @foreach ($mounts as $mount) - {{ $location->id }} -
    {{ $location->short }} - {{ $location->long }} - {{ $location->nodes_count }} - {{ $location->servers_count }} + {{ $mount->id }} + {{ $mount->name }} + {{ $mount->source }} + {{ $mount->target }} + {{ $mount->eggs_count }} + {{ $mount->nodes_count }} + {{ $mount->servers_count }} @endforeach @@ -56,27 +61,30 @@ -