Skip to content

Commit 0eb29da

Browse files
committed
Add mount_server table, fix wrong field type on other many to many tables, add routes for mounting and unmounting mounts on a server, finish server admin mounts page
1 parent a0900b8 commit 0eb29da

File tree

8 files changed

+117
-20
lines changed

8 files changed

+117
-20
lines changed

app/Http/Controllers/Admin/Servers/ServerViewController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public function database(Request $request, Server $server)
178178
*/
179179
public function mounts(Request $request, Server $server)
180180
{
181+
$server->load('mounts');
182+
181183
return $this->view->make('admin.servers.view.mounts', [
182184
'mounts' => $this->mountRepository->getMountListForServer($server),
183185
'server' => $server,

app/Http/Controllers/Admin/ServersController.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,34 @@ public function deleteDatabase($server, $database)
378378

379379
return response('', 204);
380380
}
381+
382+
/**
383+
* Add a mount to a server.
384+
*
385+
* @param Server $server
386+
* @param int $mount_id
387+
* @return \Illuminate\Http\RedirectResponse
388+
*/
389+
public function addMount(Server $server, int $mount_id)
390+
{
391+
$server->mounts()->attach($mount_id);
392+
393+
$this->alert->success('Mount was added successfully.')->flash();
394+
return redirect()->route('admin.servers.view.mounts', $server->id);
395+
}
396+
397+
/**
398+
* Remove a mount from a server.
399+
*
400+
* @param Server $server
401+
* @param int $mount_id
402+
* @return \Illuminate\Http\RedirectResponse
403+
*/
404+
public function deleteMount(Server $server, int $mount_id)
405+
{
406+
$server->mounts()->detach($mount_id);
407+
408+
$this->alert->success('Mount was removed successfully.')->flash();
409+
return redirect()->route('admin.servers.view.mounts', $server->id);
410+
}
381411
}

app/Models/Mount.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
* @property bool $read_only
1313
* @property bool $user_mountable
1414
*
15-
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $eggs
16-
* @property \Illuminate\Database\Eloquent\Relations\BelongsToMany $nodes
15+
* @property \Pterodactyl\Models\Egg[]|\Illuminate\Database\Eloquent\Collection $eggs
16+
* @property \Pterodactyl\Models\Node[]|\Illuminate\Database\Eloquent\Collection $nodes
17+
* @property \Pterodactyl\Models\Server[]|\Illuminate\Database\Eloquent\Collection $servers
1718
*/
1819
class Mount extends Model
1920
{
@@ -94,4 +95,14 @@ public function nodes()
9495
{
9596
return $this->belongsToMany(Node::class);
9697
}
98+
99+
/**
100+
* Returns all servers that have this mount assigned.
101+
*
102+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
103+
*/
104+
public function servers()
105+
{
106+
return $this->belongsToMany(Server::class);
107+
}
97108
}

app/Models/Server.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
* @property \Pterodactyl\Models\DaemonKey[]|\Illuminate\Database\Eloquent\Collection $keys
5454
* @property \Pterodactyl\Models\ServerTransfer $transfer
5555
* @property \Pterodactyl\Models\Backup[]|\Illuminate\Database\Eloquent\Collection $backups
56+
* @property \Pterodactyl\Models\Mount[]|\Illuminate\Database\Eloquent\Collection $mounts
5657
*/
5758
class Server extends Model
5859
{
@@ -351,4 +352,14 @@ public function backups()
351352
{
352353
return $this->hasMany(Backup::class);
353354
}
355+
356+
/**
357+
* Returns all mounts that have this server has mounted.
358+
*
359+
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
360+
*/
361+
public function mounts()
362+
{
363+
return $this->belongsToMany(Mount::class);
364+
}
354365
}

database/migrations/2020_05_20_234655_add_mounts_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function up()
2626

2727
Schema::create('egg_mount', function (Blueprint $table) {
2828
$table->integer('egg_id');
29-
$table->char('mount_id', 36);
29+
$table->integer('mount_id');
3030

3131
$table->unique(['egg_id', 'mount_id']);
3232
});
3333

3434
Schema::create('mount_node', function (Blueprint $table) {
3535
$table->integer('node_id');
36-
$table->char('mount_id', 36);
36+
$table->integer('mount_id');
3737

3838
$table->unique(['node_id', 'mount_id']);
3939
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddMountServerTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('mount_server', function (Blueprint $table) {
17+
$table->integer('server_id');
18+
$table->integer('mount_id');
19+
20+
$table->unique(['server_id', 'mount_id']);
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*
27+
* @return void
28+
*/
29+
public function down()
30+
{
31+
Schema::dropIfExists('mount_server');
32+
}
33+
}

resources/views/admin/servers/view/mounts.blade.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,33 @@
4141
<td class="middle"><a href="{{ route('admin.mounts.view', $mount->id) }}">{{ $mount->name }}</a></td>
4242
<td class="middle"><code>{{ $mount->source }}</code></td>
4343
<td class="col-sm-2 middle"><code>{{ $mount->target }}</code></td>
44-
<td class="col-sm-2 middle">
45-
@if ($mount->id == 2)
44+
45+
@if (! in_array($mount->id, $server->mounts->pluck('id')->toArray()))
46+
<td class="col-sm-2 middle">
4647
<span class="label label-primary">Unmounted</span>
47-
@else
48+
</td>
49+
50+
<td class="col-sm-1 middle">
51+
<form action="{{ route('admin.servers.view.mounts.toggle', [ 'server' => $server->id, 'mount' => $mount->id ]) }}" method="POST">
52+
{!! csrf_field() !!}
53+
54+
<button type="submit" class="btn btn-xs btn-success"><i class="fa fa-plus"></i></button>
55+
</form>
56+
</td>
57+
@else
58+
<td class="col-sm-2 middle">
4859
<span class="label label-success">Mounted</span>
49-
@endif
50-
</td>
60+
</td>
5161

52-
<td class="col-sm-1 middle">
53-
@if ($mount->id == 2)
54-
<button data-action="mount" data-id="{{ $mount->id }}" class="btn btn-xs btn-success"><i class="fa fa-plus"></i></button>
55-
@else
56-
<button data-action="unmount" data-id="{{ $mount->id }}" class="btn btn-xs btn-danger"><i class="fa fa-times"></i></button>
57-
@endif
58-
</td>
62+
<td class="col-sm-1 middle">
63+
<form action="{{ route('admin.servers.view.mounts.toggle', [ 'server' => $server->id, 'mount' => $mount->id ]) }}" method="POST">
64+
@method('DELETE')
65+
{!! csrf_field() !!}
66+
67+
<button type="submit" class="btn btn-xs btn-danger"><i class="fa fa-times"></i></button>
68+
</form>
69+
</td>
70+
@endif
5971
</tr>
6072
@endforeach
6173
</table>
@@ -64,7 +76,3 @@
6476
</div>
6577
</div>
6678
@endsection
67-
68-
@section('footer-scripts')
69-
@parent
70-
@endsection

routes/admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
Route::post('/view/{server}/build', 'ServersController@updateBuild');
124124
Route::post('/view/{server}/startup', 'ServersController@saveStartup');
125125
Route::post('/view/{server}/database', 'ServersController@newDatabase');
126+
Route::post('/view/{server}/mounts/{mount}', 'ServersController@addMount')->name('admin.servers.view.mounts.toggle');
126127
Route::post('/view/{server}/manage/toggle', 'ServersController@toggleInstall')->name('admin.servers.view.manage.toggle');
127128
Route::post('/view/{server}/manage/suspension', 'ServersController@manageSuspension')->name('admin.servers.view.manage.suspension');
128129
Route::post('/view/{server}/manage/reinstall', 'ServersController@reinstallServer')->name('admin.servers.view.manage.reinstall');
@@ -133,6 +134,7 @@
133134
Route::patch('/view/{server}/database', 'ServersController@resetDatabasePassword');
134135

135136
Route::delete('/view/{server}/database/{database}/delete', 'ServersController@deleteDatabase')->name('admin.servers.view.database.delete');
137+
Route::delete('/view/{server}/mounts/{mount}', 'ServersController@deleteMount');
136138
});
137139

138140
/*

0 commit comments

Comments
 (0)