Skip to content

Commit 00d1b58

Browse files
committed
Properly setup Mount model, add database migration, get mount admin page added
1 parent 59a1501 commit 00d1b58

File tree

5 files changed

+169
-27
lines changed

5 files changed

+169
-27
lines changed

app/Http/Controllers/Admin/Mounts/MountController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
namespace Pterodactyl\Http\Controllers\Admin\Mounts;
44

5-
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
65
use Pterodactyl\Http\Controllers\Controller;
6+
use Pterodactyl\Repositories\Eloquent\MountRepository;
77

88
class MountController extends Controller
99
{
1010
/**
11-
* @var \Pterodactyl\Contracts\Repository\LocationRepositoryInterface
11+
* @var \Pterodactyl\Repositories\Eloquent\MountRepository
1212
*/
1313
protected $repository;
1414

1515
/**
16-
* LocationController constructor.
16+
* MountController constructor.
1717
*
18-
* @param \Pterodactyl\Contracts\Repository\LocationRepositoryInterface $repository
18+
* @param \Pterodactyl\Repositories\Eloquent\MountRepository $repository
1919
*/
2020
public function __construct(
21-
LocationRepositoryInterface $repository
21+
MountRepository $repository
2222
) {
2323
$this->repository = $repository;
2424
}
@@ -31,7 +31,7 @@ public function __construct(
3131
public function index()
3232
{
3333
return view('admin.mounts.index', [
34-
'locations' => $this->repository->getAllWithDetails(),
34+
'mounts' => $this->repository->getAllWithDetails(),
3535
]);
3636
}
3737
}

app/Models/Mount.php

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

55
/**
6-
* @property int $id
6+
* @property string $id
7+
* @property string $name
8+
* @property string $description
9+
* @property string $source
10+
* @property string $target
11+
* @property bool $read_only
12+
* @property bool $user_mountable
13+
*
14+
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
15+
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
716
*/
817
class Mount extends Model
918
{
@@ -25,5 +34,50 @@ class Mount extends Model
2534
*
2635
* @var array
2736
*/
28-
protected $guarded = ['id'];
37+
protected $guarded = ['id', 'name', 'description', 'source', 'target'];
38+
39+
/**
40+
* Default values for specific fields in the database.
41+
*
42+
* @var array
43+
*/
44+
protected $attributes = [
45+
'read_only' => 'bool',
46+
'user_mountable' => 'bool',
47+
];
48+
49+
/**
50+
* Rules verifying that the data being stored matches the expectations of the database.
51+
*
52+
* @var string
53+
*/
54+
public static $validationRules = [
55+
'id' => 'required|string|size:36|unique:mounts,id',
56+
'name' => 'required|string|min:2|max:64|unique:mounts,name',
57+
'description' => 'nullable|string|max:255',
58+
'source' => 'required|string',
59+
'target' => 'required|string',
60+
'read_only' => 'sometimes|boolean',
61+
'user_mountable' => 'sometimes|boolean',
62+
];
63+
64+
/**
65+
* Returns all eggs that have this mount assigned.
66+
*
67+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
68+
*/
69+
public function eggs()
70+
{
71+
return $this->belongsToMany(Egg::class);
72+
}
73+
74+
/**
75+
* Returns all nodes that have this mount assigned.
76+
*
77+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
78+
*/
79+
public function nodes()
80+
{
81+
return $this->belongsToMany(Node::class);
82+
}
2983
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Pterodactyl\Repositories\Eloquent;
4+
5+
use Pterodactyl\Models\Mount;
6+
use Illuminate\Support\Collection;
7+
use Pterodactyl\Repositories\Concerns\Searchable;
8+
9+
class MountRepository extends EloquentRepository
10+
{
11+
use Searchable;
12+
13+
/**
14+
* Return the model backing this repository.
15+
*
16+
* @return string
17+
*/
18+
public function model()
19+
{
20+
return Mount::class;
21+
}
22+
23+
/**
24+
* Return mounts with a count of eggs, nodes, and servers attached to it.
25+
*
26+
* @return \Illuminate\Support\Collection
27+
*/
28+
public function getAllWithDetails(): Collection
29+
{
30+
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
31+
}
32+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddMountsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('mounts', function (Blueprint $table) {
17+
$table->char('id', 36)->unique();
18+
$table->string('name');
19+
$table->text('description')->nullable();
20+
$table->string('source');
21+
$table->string('target');
22+
$table->tinyInteger('read_only')->unsigned();
23+
$table->tinyInteger('user_mountable')->unsigned();
24+
});
25+
26+
Schema::create('egg_mount', function (Blueprint $table) {
27+
$table->increments('egg_id')->unique();
28+
$table->char('mount_id', 36)->unique();
29+
});
30+
31+
Schema::create('mount_node', function (Blueprint $table) {
32+
$table->increments('node_id')->unique();
33+
$table->char('mount_id', 36)->unique();
34+
});
35+
}
36+
37+
/**
38+
* Reverse the migrations.
39+
*
40+
* @return void
41+
*/
42+
public function down()
43+
{
44+
Schema::dropIfExists('mount_node');
45+
Schema::dropIfExists('egg_mount');
46+
Schema::dropIfExists('mounts');
47+
}
48+
}

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

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
{{-- This software is licensed under the terms of the MIT license. --}}
55
{{-- https://opensource.org/licenses/MIT --}}
6+
67
@extends('layouts.admin')
78

89
@section('title')
@@ -25,7 +26,7 @@
2526
<h3 class="box-title">Mount List</h3>
2627

2728
<div class="box-tools">
28-
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#newLocationModal">Create New</button>
29+
<button class="btn btn-sm btn-primary" data-toggle="modal" data-target="#newMountModal">Create New</button>
2930
</div>
3031
</div>
3132

@@ -34,19 +35,23 @@
3435
<tbody>
3536
<tr>
3637
<th>ID</th>
37-
<th>Short Code</th>
38-
<th>Description</th>
38+
<th>Name</th>
39+
<th>Source</th>
40+
<th>Target</th>
41+
<th class="text-center">Eggs</th>
3942
<th class="text-center">Nodes</th>
4043
<th class="text-center">Servers</th>
4144
</tr>
4245

43-
@foreach ($locations as $location)
46+
@foreach ($mounts as $mount)
4447
<tr>
45-
<td><code>{{ $location->id }}</code></td>
46-
<td><a href="{{ route('admin.locations.view', $location->id) }}">{{ $location->short }}</a></td>
47-
<td>{{ $location->long }}</td>
48-
<td class="text-center">{{ $location->nodes_count }}</td>
49-
<td class="text-center">{{ $location->servers_count }}</td>
48+
<td><code>{{ $mount->id }}</code></td>
49+
<td><a href="{{ route('admin.locations.view', $mount->id) }}">{{ $mount->name }}</a></td>
50+
<td>{{ $mount->source }}</td>
51+
<td>{{ $mount->target }}</td>
52+
<td class="text-center">{{ $mount->eggs_count }}</td>
53+
<td class="text-center">{{ $mount->nodes_count }}</td>
54+
<td class="text-center">{{ $mount->servers_count }}</td>
5055
</tr>
5156
@endforeach
5257
</tbody>
@@ -56,27 +61,30 @@
5661
</div>
5762
</div>
5863

59-
<div class="modal fade" id="newLocationModal" tabindex="-1" role="dialog">
64+
<div class="modal fade" id="newMountModal" tabindex="-1" role="dialog">
6065
<div class="modal-dialog" role="document">
6166
<div class="modal-content">
62-
<form action="{{ route('admin.locations') }}" method="POST">
67+
<form action="{{ route('admin.mounts') }}" method="POST">
6368
<div class="modal-header">
64-
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
65-
<h4 class="modal-title">Create Location</h4>
69+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
70+
<span aria-hidden="true" style="color: #FFFFFF">&times;</span>
71+
</button>
72+
73+
<h4 class="modal-title">Create Mount</h4>
6674
</div>
6775

6876
<div class="modal-body">
6977
<div class="row">
7078
<div class="col-md-12">
71-
<label for="pShortModal" class="form-label">Short Code</label>
72-
<input type="text" name="short" id="pShortModal" class="form-control" />
73-
<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>
79+
<label for="pName" class="form-label">Name</label>
80+
<input type="text" id="pName" name="name" class="form-control" />
81+
<p class="text-muted small">Thiccc boi name used to separate this mount from another!</p>
7482
</div>
7583

7684
<div class="col-md-12">
77-
<label for="pLongModal" class="form-label">Description</label>
78-
<textarea name="long" id="pLongModal" class="form-control" rows="4"></textarea>
79-
<p class="text-muted small">A longer description of this location. Must be less than 255 characters.</p>
85+
<label for="pDescription" class="form-label">Description</label>
86+
<textarea id="pDescription" name="description" class="form-control" rows="4"></textarea>
87+
<p class="text-muted small">A longer description of this mount. Must be less than 255 characters.</p>
8088
</div>
8189
</div>
8290
</div>

0 commit comments

Comments
 (0)