mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 14:24:46 +02:00
Merge pull request #307 from pelican-dev/issue/287
Allow Servers to have Mounts
This commit is contained in:
commit
88f910f3e7
@ -23,6 +23,8 @@ class CreateServer extends CreateRecord
|
|||||||
protected static string $resource = ServerResource::class;
|
protected static string $resource = ServerResource::class;
|
||||||
protected static bool $canCreateAnother = false;
|
protected static bool $canCreateAnother = false;
|
||||||
|
|
||||||
|
public ?Node $node = null;
|
||||||
|
|
||||||
public function form(Form $form): Form
|
public function form(Form $form): Form
|
||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
@ -77,13 +79,16 @@ class CreateServer extends CreateRecord
|
|||||||
Forms\Components\Select::make('node_id')
|
Forms\Components\Select::make('node_id')
|
||||||
->disabledOn('edit')
|
->disabledOn('edit')
|
||||||
->prefixIcon('tabler-server-2')
|
->prefixIcon('tabler-server-2')
|
||||||
->default(fn () => Node::query()->latest()->first()?->id)
|
->default(fn () => ($this->node = Node::query()->latest()->first())?->id)
|
||||||
->columnSpan(2)
|
->columnSpan(2)
|
||||||
->live()
|
->live()
|
||||||
->relationship('node', 'name')
|
->relationship('node', 'name')
|
||||||
->searchable()
|
->searchable()
|
||||||
->preload()
|
->preload()
|
||||||
->afterStateUpdated(fn (Forms\Set $set) => $set('allocation_id', null))
|
->afterStateUpdated(function (Forms\Set $set, $state) {
|
||||||
|
$set('allocation_id', null);
|
||||||
|
$this->node = Node::find($state);
|
||||||
|
})
|
||||||
->required(),
|
->required(),
|
||||||
|
|
||||||
Forms\Components\Select::make('allocation_id')
|
Forms\Components\Select::make('allocation_id')
|
||||||
@ -688,6 +693,15 @@ class CreateServer extends CreateRecord
|
|||||||
->keyLabel('Title')
|
->keyLabel('Title')
|
||||||
->valueLabel('Description')
|
->valueLabel('Description')
|
||||||
->columnSpan(3),
|
->columnSpan(3),
|
||||||
|
|
||||||
|
Forms\Components\CheckboxList::make('mounts')
|
||||||
|
->live()
|
||||||
|
->relationship('mounts')
|
||||||
|
->options(fn () => $this->node?->mounts->mapWithKeys(fn ($mount) => [$mount->id => $mount->name]) ?? [])
|
||||||
|
->descriptions(fn () => $this->node?->mounts->mapWithKeys(fn ($mount) => [$mount->id => "$mount->source -> $mount->target"]) ?? [])
|
||||||
|
->label('Mounts')
|
||||||
|
->helperText(fn () => $this->node?->mounts->isNotEmpty() ? '' : 'No Mounts exist for this Node')
|
||||||
|
->columnSpanFull(),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
@ -516,6 +516,13 @@ class EditServer extends EditRecord
|
|||||||
->keyLabel('Label Name')
|
->keyLabel('Label Name')
|
||||||
->valueLabel('Label Description')
|
->valueLabel('Label Description')
|
||||||
->columnSpanFull(),
|
->columnSpanFull(),
|
||||||
|
|
||||||
|
Forms\Components\CheckboxList::make('mounts')
|
||||||
|
->relationship('mounts')
|
||||||
|
->options(fn (Server $server) => $server->node->mounts->mapWithKeys(fn ($mount) => [$mount->id => $mount->name]))
|
||||||
|
->descriptions(fn (Server $server) => $server->node->mounts->mapWithKeys(fn ($mount) => [$mount->id => "$mount->source -> $mount->target"]))
|
||||||
|
->label('Mounts')
|
||||||
|
->columnSpanFull(),
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
@ -9,7 +9,6 @@ use Illuminate\Http\Response;
|
|||||||
use App\Models\Mount;
|
use App\Models\Mount;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\MountServer;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Prologue\Alerts\AlertsMessageBag;
|
use Prologue\Alerts\AlertsMessageBag;
|
||||||
use App\Exceptions\DisplayException;
|
use App\Exceptions\DisplayException;
|
||||||
@ -228,12 +227,7 @@ class ServersController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function addMount(Request $request, Server $server): RedirectResponse
|
public function addMount(Request $request, Server $server): RedirectResponse
|
||||||
{
|
{
|
||||||
$mountServer = (new MountServer())->forceFill([
|
$server->mounts()->attach($request->input('mount_id'));
|
||||||
'mount_id' => $request->input('mount_id'),
|
|
||||||
'server_id' => $server->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$mountServer->saveOrFail();
|
|
||||||
|
|
||||||
$this->alert->success('Mount was added successfully.')->flash();
|
$this->alert->success('Mount was added successfully.')->flash();
|
||||||
|
|
||||||
@ -245,7 +239,7 @@ class ServersController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function deleteMount(Server $server, Mount $mount): RedirectResponse
|
public function deleteMount(Server $server, Mount $mount): RedirectResponse
|
||||||
{
|
{
|
||||||
MountServer::where('mount_id', $mount->id)->where('server_id', $server->id)->delete();
|
$server->mounts()->detach($mount);
|
||||||
|
|
||||||
$this->alert->success('Mount was removed successfully.')->flash();
|
$this->alert->success('Mount was removed successfully.')->flash();
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class MountServer extends Model
|
|
||||||
{
|
|
||||||
protected $table = 'mount_server';
|
|
||||||
|
|
||||||
public $timestamps = false;
|
|
||||||
|
|
||||||
protected $primaryKey = null;
|
|
||||||
|
|
||||||
public $incrementing = false;
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use App\Enums\ServerState;
|
use App\Enums\ServerState;
|
||||||
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Illuminate\Database\Query\JoinClause;
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
@ -13,7 +14,6 @@ use Illuminate\Database\Eloquent\Relations\HasOne;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
||||||
use App\Exceptions\Http\Server\ServerStateConflictException;
|
use App\Exceptions\Http\Server\ServerStateConflictException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -311,12 +311,9 @@ class Server extends Model
|
|||||||
return $this->hasMany(Backup::class);
|
return $this->hasMany(Backup::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function mounts(): BelongsToMany
|
||||||
* Returns all mounts that have this server has mounted.
|
|
||||||
*/
|
|
||||||
public function mounts(): HasManyThrough
|
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Mount::class, MountServer::class, 'server_id', 'id', 'id', 'mount_id');
|
return $this->belongsToMany(Mount::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user