Skip to content

Commit 77150b2

Browse files
committed
Add increment id to mount, add basic mount view page
1 parent 976b669 commit 77150b2

File tree

8 files changed

+203
-12
lines changed

8 files changed

+203
-12
lines changed

app/Http/Controllers/Admin/MountController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public function index()
5454
]);
5555
}
5656

57+
/**
58+
* Return the mount view page.
59+
*
60+
* @param string $id
61+
* @return \Illuminate\View\View
62+
*
63+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
64+
*/
65+
public function view($id)
66+
{
67+
return view('admin.mounts.view', [
68+
'mount' => $this->repository->getWithRelations($id),
69+
]);
70+
}
71+
5772
/**
5873
* Handle request to create new mount.
5974
*

app/Models/Mount.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
namespace Pterodactyl\Models;
44

55
/**
6-
* @property string $id
6+
* @property int $id
7+
* @property string $uuid
78
* @property string $name
89
* @property string $description
910
* @property string $source
1011
* @property string $target
1112
* @property bool $read_only
1213
* @property bool $user_mountable
1314
*
14-
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
1515
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
16+
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
1617
*/
1718
class Mount extends Model
1819
{
@@ -34,14 +35,20 @@ class Mount extends Model
3435
*
3536
* @var array
3637
*/
37-
protected $guarded = ['id', 'name', 'description', 'source', 'target'];
38+
protected $guarded = ['id', 'uuid', 'name', 'description', 'source', 'target'];
3839

3940
/**
4041
* Default values for specific fields in the database.
4142
*
4243
* @var array
4344
*/
4445
protected $attributes = [
46+
'id' => 'int',
47+
'uuid' => 'string',
48+
'name' => 'string',
49+
'description' => 'string',
50+
'source' => 'string',
51+
'target' => 'string',
4552
'read_only' => 'bool',
4653
'user_mountable' => 'bool',
4754
];
@@ -52,7 +59,7 @@ class Mount extends Model
5259
* @var string
5360
*/
5461
public static $validationRules = [
55-
// 'id' => 'required|string|size:36|unique:mounts,id',
62+
// 'uuid' => 'required|string|size:36|unique:mounts,uuid',
5663
'name' => 'required|string|min:2|max:64|unique:mounts,name',
5764
'description' => 'nullable|string|max:255',
5865
'source' => 'required|string',

app/Repositories/Eloquent/MountRepository.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Pterodactyl\Models\Mount;
66
use Illuminate\Support\Collection;
77
use Pterodactyl\Repositories\Concerns\Searchable;
8+
use Illuminate\Database\Eloquent\ModelNotFoundException;
9+
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
810

911
class MountRepository extends EloquentRepository
1012
{
@@ -29,4 +31,21 @@ public function getAllWithDetails(): Collection
2931
{
3032
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
3133
}
34+
35+
/**
36+
* Return all of the mounts and their respective relations.
37+
*
38+
* @param string $id
39+
* @return mixed
40+
*
41+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
42+
*/
43+
public function getWithRelations(string $id): Mount
44+
{
45+
try {
46+
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
47+
} catch (ModelNotFoundException $exception) {
48+
throw new RecordNotFoundException;
49+
}
50+
}
3251
}

app/Services/Mounts/MountCreationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(MountRepository $repository)
3434
public function handle(array $data)
3535
{
3636
return $this->repository->create(array_merge($data, [
37-
'id' => Uuid::uuid4()->toString(),
37+
'uuid' => Uuid::uuid4()->toString(),
3838
]), true, true);
3939
}
4040
}

database/migrations/2020_05_20_234655_add_mounts_table.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class AddMountsTable extends Migration
1414
public function up()
1515
{
1616
Schema::create('mounts', function (Blueprint $table) {
17-
$table->char('id', 36)->unique();
18-
$table->string('name');
17+
$table->increments('id')->unique();
18+
$table->char('uuid', 36)->unique();
19+
$table->string('name')->unique();
1920
$table->text('description')->nullable();
2021
$table->string('source');
2122
$table->string('target');
@@ -24,13 +25,13 @@ public function up()
2425
});
2526

2627
Schema::create('egg_mount', function (Blueprint $table) {
27-
$table->increments('egg_id')->unique();
28-
$table->char('mount_id', 36)->unique();
28+
$table->integer('egg_id');
29+
$table->char('mount_id', 36);
2930
});
3031

3132
Schema::create('mount_node', function (Blueprint $table) {
32-
$table->increments('node_id')->unique();
33-
$table->char('mount_id', 36)->unique();
33+
$table->integer('node_id');
34+
$table->char('mount_id', 36);
3435
});
3536
}
3637

resources/views/admin/mounts/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
@foreach ($mounts as $mount)
4747
<tr>
4848
<td><code>{{ $mount->id }}</code></td>
49-
<td><a href="{{ route('admin.locations.view', $mount->id) }}">{{ $mount->name }}</a></td>
49+
<td><a href="{{ route('admin.mounts.view', $mount->id) }}">{{ $mount->name }}</a></td>
5050
<td>{{ $mount->source }}</td>
5151
<td>{{ $mount->target }}</td>
5252
<td class="text-center">{{ $mount->eggs_count }}</td>
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
{{-- Pterodactyl - Panel --}}
2+
{{-- Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com> --}}
3+
4+
{{-- This software is licensed under the terms of the MIT license. --}}
5+
{{-- https://opensource.org/licenses/MIT --}}
6+
7+
@extends('layouts.admin')
8+
9+
@section('title')
10+
Mounts &rarr; View &rarr; {{ $mount->id }}
11+
@endsection
12+
13+
@section('content-header')
14+
<h1>{{ $mount->name }}<small>{{ str_limit($mount->description, 75) }}</small></h1>
15+
<ol class="breadcrumb">
16+
<li><a href="{{ route('admin.index') }}">Admin</a></li>
17+
<li><a href="{{ route('admin.mounts') }}">Mounts</a></li>
18+
<li class="active">{{ $mount->name }}</li>
19+
</ol>
20+
@endsection
21+
22+
@section('content')
23+
<div class="row">
24+
<div class="col-sm-6">
25+
<div class="box box-primary">
26+
<div class="box-header with-border">
27+
<h3 class="box-title">Location Details</h3>
28+
</div>
29+
30+
<form action="{{ route('admin.mounts.view', $mount->id) }}" method="POST">
31+
<div class="box-body">
32+
<div class="form-group">
33+
<label for="pName" class="form-label">Name</label>
34+
<input type="text" id="pName" name="name" class="form-control" value="{{ $mount->name }}" />
35+
</div>
36+
37+
<div class="form-group">
38+
<label for="pDescription" class="form-label">Description</label>
39+
<textarea id="pDescription" name="description" class="form-control" rows="4">{{ $mount->description }}</textarea>
40+
</div>
41+
42+
<div class="row">
43+
<div class="form-group col-md-6">
44+
<label for="pSource" class="form-label">Source</label>
45+
<input type="text" id="pSource" name="source" class="form-control" value="{{ $mount->source }}" />
46+
</div>
47+
48+
<div class="form-group col-md-6">
49+
<label for="pTarget" class="form-label">Target</label>
50+
<input type="text" id="pTarget" name="target" class="form-control" value="{{ $mount->target }}" />
51+
</div>
52+
</div>
53+
54+
<div class="row">
55+
<div class="form-group col-md-6">
56+
<label class="form-label">Read Only</label>
57+
58+
<div>
59+
<div class="radio radio-success radio-inline">
60+
<input type="radio" id="pReadOnlyFalse" name="read_only" value="0" @if($mount->read_only) checked @endif>
61+
<label for="pReadOnlyFalse">False</label>
62+
</div>
63+
64+
<div class="radio radio-warning radio-inline">
65+
<input type="radio" id="pReadOnly" name="read_only" value="1" @if(!$mount->read_only) checked @endif>
66+
<label for="pReadOnly">True</label>
67+
</div>
68+
</div>
69+
</div>
70+
71+
<div class="form-group col-md-6">
72+
<label class="form-label">User Mountable</label>
73+
74+
<div>
75+
<div class="radio radio-success radio-inline">
76+
<input type="radio" id="pUserMountableFalse" name="user_mountable" value="0" @if($mount->user_mountable) checked @endif>
77+
<label for="pUserMountableFalse">False</label>
78+
</div>
79+
80+
<div class="radio radio-warning radio-inline">
81+
<input type="radio" id="pUserMountable" name="user_mountable" value="1" @if(!$mount->user_mountable) checked @endif>
82+
<label for="pUserMountable">True</label>
83+
</div>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
89+
<div class="box-footer">
90+
{!! csrf_field() !!}
91+
{!! method_field('PATCH') !!}
92+
93+
<button name="action" value="edit" class="btn btn-sm btn-primary pull-right">Save</button>
94+
<button name="action" value="delete" class="btn btn-sm btn-danger pull-left muted muted-hover"><i class="fa fa-trash-o"></i></button>
95+
</div>
96+
</form>
97+
</div>
98+
</div>
99+
100+
<div class="col-sm-6">
101+
<div class="box">
102+
<div class="box-header with-border">
103+
<h3 class="box-title">Eggs</h3>
104+
</div>
105+
106+
<div class="box-body table-responsive no-padding">
107+
<table class="table table-hover">
108+
<tr>
109+
<th>ID</th>
110+
<th>Name</th>
111+
</tr>
112+
113+
@foreach($mount->eggs as $egg)
114+
<tr>
115+
<td><code>{{ $egg->id }}</code></td>
116+
<td><a href="{{ route('admin.nests.egg.view', $egg->id) }}">{{ $egg->name }}</a></td>
117+
</tr>
118+
@endforeach
119+
</table>
120+
</div>
121+
</div>
122+
123+
<div class="box">
124+
<div class="box-header with-border">
125+
<h3 class="box-title">Nodes</h3>
126+
</div>
127+
128+
<div class="box-body table-responsive no-padding">
129+
<table class="table table-hover">
130+
<tr>
131+
<th>ID</th>
132+
<th>Name</th>
133+
<th>FQDN</th>
134+
</tr>
135+
136+
@foreach($mount->nodes as $node)
137+
<tr>
138+
<td><code>{{ $node->id }}</code></td>
139+
<td><a href="{{ route('admin.nodes.view', $node->id) }}">{{ $node->name }}</a></td>
140+
<td><code>{{ $node->fqdn }}</code></td>
141+
</tr>
142+
@endforeach
143+
</table>
144+
</div>
145+
</div>
146+
</div>
147+
</div>
148+
@endsection

routes/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
*/
176176
Route::group(['prefix' => 'mounts'], function () {
177177
Route::get('/', 'MountController@index')->name('admin.mounts');
178+
Route::get('/view/{mount}', 'MountController@view')->name('admin.mounts.view');
178179

179180
Route::post('/', 'MountController@create');
180181
});

0 commit comments

Comments
 (0)