Properly setup Mount model, add database migration, get mount admin page added
This commit is contained in:
parent
59a150148a
commit
00d1b5861a
5 changed files with 169 additions and 27 deletions
|
@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
32
app/Repositories/Eloquent/MountRepository.php
Normal file
32
app/Repositories/Eloquent/MountRepository.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Repositories\Eloquent;
|
||||
|
||||
use Pterodactyl\Models\Mount;
|
||||
use Illuminate\Support\Collection;
|
||||
use Pterodactyl\Repositories\Concerns\Searchable;
|
||||
|
||||
class MountRepository extends EloquentRepository
|
||||
{
|
||||
use Searchable;
|
||||
|
||||
/**
|
||||
* Return the model backing this repository.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function model()
|
||||
{
|
||||
return Mount::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return mounts with a count of eggs, nodes, and servers attached to it.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getAllWithDetails(): Collection
|
||||
{
|
||||
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
|
||||
}
|
||||
}
|
48
database/migrations/2020_05_20_234655_add_mounts_table.php
Normal file
48
database/migrations/2020_05_20_234655_add_mounts_table.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddMountsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('mounts', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
|
@ -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 @@
|
|||
<h3 class="box-title">Mount List</h3>
|
||||
|
||||
<div class="box-tools">
|
||||
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#newLocationModal">Create New</button>
|
||||
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#newMountModal">Create New</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -34,19 +35,23 @@
|
|||
<tbody>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Short Code</th>
|
||||
<th>Description</th>
|
||||
<th>Name</th>
|
||||
<th>Source</th>
|
||||
<th>Target</th>
|
||||
<th class="text-center">Eggs</th>
|
||||
<th class="text-center">Nodes</th>
|
||||
<th class="text-center">Servers</th>
|
||||
</tr>
|
||||
|
||||
@foreach ($locations as $location)
|
||||
@foreach ($mounts as $mount)
|
||||
<tr>
|
||||
<td><code>{{ $location->id }}</code></td>
|
||||
<td><a href="{{ route('admin.locations.view', $location->id) }}">{{ $location->short }}</a></td>
|
||||
<td>{{ $location->long }}</td>
|
||||
<td class="text-center">{{ $location->nodes_count }}</td>
|
||||
<td class="text-center">{{ $location->servers_count }}</td>
|
||||
<td><code>{{ $mount->id }}</code></td>
|
||||
<td><a href="{{ route('admin.locations.view', $mount->id) }}">{{ $mount->name }}</a></td>
|
||||
<td>{{ $mount->source }}</td>
|
||||
<td>{{ $mount->target }}</td>
|
||||
<td class="text-center">{{ $mount->eggs_count }}</td>
|
||||
<td class="text-center">{{ $mount->nodes_count }}</td>
|
||||
<td class="text-center">{{ $mount->servers_count }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
@ -56,27 +61,30 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="newLocationModal" tabindex="-1" role="dialog">
|
||||
<div class="modal fade" id="newMountModal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<form action="{{ route('admin.locations') }}" method="POST">
|
||||
<form action="{{ route('admin.mounts') }}" method="POST">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Create Location</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true" style="color: #FFFFFF">×</span>
|
||||
</button>
|
||||
|
||||
<h4 class="modal-title">Create Mount</h4>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<label for="pShortModal" class="form-label">Short Code</label>
|
||||
<input type="text" name="short" id="pShortModal" class="form-control" />
|
||||
<p class="text-muted small">A short identifier used to distinguish this location from others. Must be between 1 and 60 characters, for example, <code>us.nyc.lvl3</code>.</p>
|
||||
<label for="pName" class="form-label">Name</label>
|
||||
<input type="text" id="pName" name="name" class="form-control" />
|
||||
<p class="text-muted small">Thiccc boi name used to separate this mount from another!</p>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<label for="pLongModal" class="form-label">Description</label>
|
||||
<textarea name="long" id="pLongModal" class="form-control" rows="4"></textarea>
|
||||
<p class="text-muted small">A longer description of this location. Must be less than 255 characters.</p>
|
||||
<label for="pDescription" class="form-label">Description</label>
|
||||
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
|
||||
<p class="text-muted small">A longer description of this mount. Must be less than 255 characters.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue