Properly setup Mount model, add database migration, get mount admin page added
This commit is contained in:
parent
59a150148a
commit
00d1b5861a
|
@ -2,23 +2,23 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Http\Controllers\Admin\Mounts;
|
namespace Pterodactyl\Http\Controllers\Admin\Mounts;
|
||||||
|
|
||||||
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
|
|
||||||
use Pterodactyl\Http\Controllers\Controller;
|
use Pterodactyl\Http\Controllers\Controller;
|
||||||
|
use Pterodactyl\Repositories\Eloquent\MountRepository;
|
||||||
|
|
||||||
class MountController extends Controller
|
class MountController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
|
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
|
||||||
*/
|
*/
|
||||||
protected $repository;
|
protected $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LocationController constructor.
|
* MountController constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
|
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
LocationRepositoryInterface $repository
|
MountRepository $repository
|
||||||
) {
|
) {
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class MountController extends Controller
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('admin.mounts.index', [
|
return view('admin.mounts.index', [
|
||||||
'locations' => $this->repository->getAllWithDetails(),
|
'mounts' => $this->repository->getAllWithDetails(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,16 @@
|
||||||
namespace Pterodactyl\Models;
|
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
|
class Mount extends Model
|
||||||
{
|
{
|
||||||
|
@ -25,5 +34,50 @@ class Mount extends Model
|
||||||
*
|
*
|
||||||
* @var array
|
* @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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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. --}}
|
{{-- This software is licensed under the terms of the MIT license. --}}
|
||||||
{{-- https://opensource.org/licenses/MIT --}}
|
{{-- https://opensource.org/licenses/MIT --}}
|
||||||
|
|
||||||
@extends('layouts.admin')
|
@extends('layouts.admin')
|
||||||
|
|
||||||
@section('title')
|
@section('title')
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
<h3 class="box-title">Mount List</h3>
|
<h3 class="box-title">Mount List</h3>
|
||||||
|
|
||||||
<div class="box-tools">
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -34,19 +35,23 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>Short Code</th>
|
<th>Name</th>
|
||||||
<th>Description</th>
|
<th>Source</th>
|
||||||
|
<th>Target</th>
|
||||||
|
<th class="text-center">Eggs</th>
|
||||||
<th class="text-center">Nodes</th>
|
<th class="text-center">Nodes</th>
|
||||||
<th class="text-center">Servers</th>
|
<th class="text-center">Servers</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@foreach ($locations as $location)
|
@foreach ($mounts as $mount)
|
||||||
<tr>
|
<tr>
|
||||||
<td><code>{{ $location->id }}</code></td>
|
<td><code>{{ $mount->id }}</code></td>
|
||||||
<td><a href="{{ route('admin.locations.view', $location->id) }}">{{ $location->short }}</a></td>
|
<td><a href="{{ route('admin.locations.view', $mount->id) }}">{{ $mount->name }}</a></td>
|
||||||
<td>{{ $location->long }}</td>
|
<td>{{ $mount->source }}</td>
|
||||||
<td class="text-center">{{ $location->nodes_count }}</td>
|
<td>{{ $mount->target }}</td>
|
||||||
<td class="text-center">{{ $location->servers_count }}</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>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -56,27 +61,30 @@
|
||||||
</div>
|
</div>
|
||||||
</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-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<form action="{{ route('admin.locations') }}" method="POST">
|
<form action="{{ route('admin.mounts') }}" method="POST">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
<h4 class="modal-title">Create Location</h4>
|
<span aria-hidden="true" style="color: #FFFFFF">×</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<h4 class="modal-title">Create Mount</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label for="pShortModal" class="form-label">Short Code</label>
|
<label for="pName" class="form-label">Name</label>
|
||||||
<input type="text" name="short" id="pShortModal" class="form-control" />
|
<input type="text" id="pName" name="name" 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>
|
<p class="text-muted small">Thiccc boi name used to separate this mount from another!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<label for="pLongModal" class="form-label">Description</label>
|
<label for="pDescription" class="form-label">Description</label>
|
||||||
<textarea name="long" id="pLongModal" class="form-control" rows="4"></textarea>
|
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
|
||||||
<p class="text-muted small">A longer description of this location. Must be less than 255 characters.</p>
|
<p class="text-muted small">A longer description of this mount. Must be less than 255 characters.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue