Add increment id to mount, add basic mount view page

This commit is contained in:
Matthew Penner 2020-05-20 19:11:20 -06:00
parent 976b669059
commit 77150b2551
8 changed files with 203 additions and 12 deletions

View file

@ -54,6 +54,21 @@ class MountController extends Controller
]);
}
/**
* Return the mount view page.
*
* @param string $id
* @return \Illuminate\View\View
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function view($id)
{
return view('admin.mounts.view', [
'mount' => $this->repository->getWithRelations($id),
]);
}
/**
* Handle request to create new mount.
*

View file

@ -3,7 +3,8 @@
namespace Pterodactyl\Models;
/**
* @property string $id
* @property int $id
* @property string $uuid
* @property string $name
* @property string $description
* @property string $source
@ -11,8 +12,8 @@ namespace Pterodactyl\Models;
* @property bool $read_only
* @property bool $user_mountable
*
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
*/
class Mount extends Model
{
@ -34,7 +35,7 @@ class Mount extends Model
*
* @var array
*/
protected $guarded = ['id', 'name', 'description', 'source', 'target'];
protected $guarded = ['id', 'uuid', 'name', 'description', 'source', 'target'];
/**
* Default values for specific fields in the database.
@ -42,6 +43,12 @@ class Mount extends Model
* @var array
*/
protected $attributes = [
'id' => 'int',
'uuid' => 'string',
'name' => 'string',
'description' => 'string',
'source' => 'string',
'target' => 'string',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
@ -52,7 +59,7 @@ class Mount extends Model
* @var string
*/
public static $validationRules = [
// 'id' => 'required|string|size:36|unique:mounts,id',
// 'uuid' => 'required|string|size:36|unique:mounts,uuid',
'name' => 'required|string|min:2|max:64|unique:mounts,name',
'description' => 'nullable|string|max:255',
'source' => 'required|string',

View file

@ -5,6 +5,8 @@ namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Mount;
use Illuminate\Support\Collection;
use Pterodactyl\Repositories\Concerns\Searchable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class MountRepository extends EloquentRepository
{
@ -29,4 +31,21 @@ class MountRepository extends EloquentRepository
{
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
}
/**
* Return all of the mounts and their respective relations.
*
* @param string $id
* @return mixed
*
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function getWithRelations(string $id): Mount
{
try {
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException $exception) {
throw new RecordNotFoundException;
}
}
}

View file

@ -34,7 +34,7 @@ class MountCreationService
public function handle(array $data)
{
return $this->repository->create(array_merge($data, [
'id' => Uuid::uuid4()->toString(),
'uuid' => Uuid::uuid4()->toString(),
]), true, true);
}
}

View file

@ -14,8 +14,9 @@ class AddMountsTable extends Migration
public function up()
{
Schema::create('mounts', function (Blueprint $table) {
$table->char('id', 36)->unique();
$table->string('name');
$table->increments('id')->unique();
$table->char('uuid', 36)->unique();
$table->string('name')->unique();
$table->text('description')->nullable();
$table->string('source');
$table->string('target');
@ -24,13 +25,13 @@ class AddMountsTable extends Migration
});
Schema::create('egg_mount', function (Blueprint $table) {
$table->increments('egg_id')->unique();
$table->char('mount_id', 36)->unique();
$table->integer('egg_id');
$table->char('mount_id', 36);
});
Schema::create('mount_node', function (Blueprint $table) {
$table->increments('node_id')->unique();
$table->char('mount_id', 36)->unique();
$table->integer('node_id');
$table->char('mount_id', 36);
});
}

View file

@ -46,7 +46,7 @@
@foreach ($mounts as $mount)
<tr>
<td><code>{{ $mount->id }}</code></td>
<td><a href="{{ route('admin.locations.view', $mount->id) }}">{{ $mount->name }}</a></td>
<td><a href="{{ route('admin.mounts.view', $mount->id) }}">{{ $mount->name }}</a></td>
<td>{{ $mount->source }}</td>
<td>{{ $mount->target }}</td>
<td class="text-center">{{ $mount->eggs_count }}</td>

View file

@ -0,0 +1,148 @@
{{-- Pterodactyl - Panel --}}
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
{{-- This software is licensed under the terms of the MIT license. --}}
{{-- https://opensource.org/licenses/MIT --}}
@extends('layouts.admin')
@section('title')
Mounts &rarr; View &rarr; {{ $mount->id }}
@endsection
@section('content-header')
<h1>{{ $mount->name }}<small>{{ str_limit($mount->description, 75) }}</small></h1>
<ol class="breadcrumb">
<li><a href="{{ route('admin.index') }}">Admin</a></li>
<li><a href="{{ route('admin.mounts') }}">Mounts</a></li>
<li class="active">{{ $mount->name }}</li>
</ol>
@endsection
@section('content')
<div class="row">
<div class="col-sm-6">
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Location Details</h3>
</div>
<form action="{{ route('admin.mounts.view', $mount->id) }}" method="POST">
<div class="box-body">
<div class="form-group">
<label for="pName" class="form-label">Name</label>
<input type="text" id="pName" name="name" class="form-control" value="{{ $mount->name }}" />
</div>
<div class="form-group">
<label for="pDescription" class="form-label">Description</label>
<textarea id="pDescription" name="description" class="form-control" rows="4">{{ $mount->description }}</textarea>
</div>
<div class="row">
<div class="form-group col-md-6">
<label for="pSource" class="form-label">Source</label>
<input type="text" id="pSource" name="source" class="form-control" value="{{ $mount->source }}" />
</div>
<div class="form-group col-md-6">
<label for="pTarget" class="form-label">Target</label>
<input type="text" id="pTarget" name="target" class="form-control" value="{{ $mount->target }}" />
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="form-label">Read Only</label>
<div>
<div class="radio radio-success radio-inline">
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" @if($mount->read_only) checked @endif>
<label for="pReadOnlyFalse">False</label>
</div>
<div class="radio radio-warning radio-inline">
<input type="radio" id="pReadOnly" name="read_only" value="1" @if(!$mount->read_only) checked @endif>
<label for="pReadOnly">True</label>
</div>
</div>
</div>
<div class="form-group col-md-6">
<label class="form-label">User Mountable</label>
<div>
<div class="radio radio-success radio-inline">
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" @if($mount->user_mountable) checked @endif>
<label for="pUserMountableFalse">False</label>
</div>
<div class="radio radio-warning radio-inline">
<input type="radio" id="pUserMountable" name="user_mountable" value="1" @if(!$mount->user_mountable) checked @endif>
<label for="pUserMountable">True</label>
</div>
</div>
</div>
</div>
</div>
<div class="box-footer">
{!! csrf_field() !!}
{!! method_field('PATCH') !!}
<button name="action" value="edit" class="btn btn-sm btn-primary pull-right">Save</button>
<button name="action" value="delete" class="btn btn-sm btn-danger pull-left muted muted-hover"><i class="fa fa-trash-o"></i></button>
</div>
</form>
</div>
</div>
<div class="col-sm-6">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Eggs</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
@foreach($mount->eggs as $egg)
<tr>
<td><code>{{ $egg->id }}</code></td>
<td><a href="{{ route('admin.nests.egg.view', $egg->id) }}">{{ $egg->name }}</a></td>
</tr>
@endforeach
</table>
</div>
</div>
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Nodes</h3>
</div>
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Name</th>
<th>FQDN</th>
</tr>
@foreach($mount->nodes as $node)
<tr>
<td><code>{{ $node->id }}</code></td>
<td><a href="{{ route('admin.nodes.view', $node->id) }}">{{ $node->name }}</a></td>
<td><code>{{ $node->fqdn }}</code></td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
</div>
@endsection

View file

@ -175,6 +175,7 @@ Route::group(['prefix' => 'nodes'], function () {
*/
Route::group(['prefix' => 'mounts'], function () {
Route::get('/', 'MountController@index')->name('admin.mounts');
Route::get('/view/{mount}', 'MountController@view')->name('admin.mounts.view');
Route::post('/', 'MountController@create');
});