mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 09:54:44 +02:00
Add Egg
copy from
& ReplicateAction
(#1013)
* Add `Egg` `copy from` for Process & Install Script * Add builtin `ReplicateAction` * Use `CopyFrom` for less duplicated code * Hide label & add tooltip to `ReplicateAction` * use `iconButton()` instead of `hiddenLabel()` * use `iconButton()` for every Actions * Use our translation instead * Copy egg_variables aswell * remove `get()` Co-authored-by: Boy132 <Boy132@users.noreply.github.com> --------- Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
This commit is contained in:
parent
5be4e22a0c
commit
324fc4b7d5
@ -4,6 +4,7 @@ namespace App\Filament\Admin\Resources\EggResource\Pages;
|
|||||||
|
|
||||||
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
|
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
|
||||||
use App\Filament\Admin\Resources\EggResource;
|
use App\Filament\Admin\Resources\EggResource;
|
||||||
|
use App\Filament\Components\Forms\Fields\CopyFrom;
|
||||||
use App\Models\EggVariable;
|
use App\Models\EggVariable;
|
||||||
use Filament\Forms\Components\Checkbox;
|
use Filament\Forms\Components\Checkbox;
|
||||||
use Filament\Forms\Components\Fieldset;
|
use Filament\Forms\Components\Fieldset;
|
||||||
@ -117,12 +118,8 @@ class CreateEgg extends CreateRecord
|
|||||||
Tab::make(trans('admin/egg.tabs.process_management'))
|
Tab::make(trans('admin/egg.tabs.process_management'))
|
||||||
->columns()
|
->columns()
|
||||||
->schema([
|
->schema([
|
||||||
Hidden::make('config_from')
|
CopyFrom::make('copy_process_from')
|
||||||
->default(null)
|
->process(),
|
||||||
->label('Copy Settings From')
|
|
||||||
// ->placeholder('None')
|
|
||||||
// ->relationship('configFrom', 'name', ignoreRecord: true)
|
|
||||||
->helperText('If you would like to default to settings from another Egg select it from the menu above.'),
|
|
||||||
TextInput::make('config_stop')
|
TextInput::make('config_stop')
|
||||||
->label(trans('admin/egg.stop_command'))
|
->label(trans('admin/egg.stop_command'))
|
||||||
->required()
|
->required()
|
||||||
@ -237,10 +234,8 @@ class CreateEgg extends CreateRecord
|
|||||||
Tab::make(trans('admin/egg.tabs.install_script'))
|
Tab::make(trans('admin/egg.tabs.install_script'))
|
||||||
->columns(3)
|
->columns(3)
|
||||||
->schema([
|
->schema([
|
||||||
Hidden::make('copy_script_from'),
|
CopyFrom::make('copy_script_from')
|
||||||
//->placeholder('None')
|
->script(),
|
||||||
//->relationship('scriptFrom', 'name', ignoreRecord: true),
|
|
||||||
|
|
||||||
TextInput::make('script_container')
|
TextInput::make('script_container')
|
||||||
->label(trans('admin/egg.script_container'))
|
->label(trans('admin/egg.script_container'))
|
||||||
->required()
|
->required()
|
||||||
|
@ -7,6 +7,7 @@ use App\Filament\Admin\Resources\EggResource;
|
|||||||
use App\Filament\Admin\Resources\EggResource\RelationManagers\ServersRelationManager;
|
use App\Filament\Admin\Resources\EggResource\RelationManagers\ServersRelationManager;
|
||||||
use App\Filament\Components\Actions\ExportEggAction;
|
use App\Filament\Components\Actions\ExportEggAction;
|
||||||
use App\Filament\Components\Actions\ImportEggAction;
|
use App\Filament\Components\Actions\ImportEggAction;
|
||||||
|
use App\Filament\Components\Forms\Fields\CopyFrom;
|
||||||
use App\Models\Egg;
|
use App\Models\Egg;
|
||||||
use App\Models\EggVariable;
|
use App\Models\EggVariable;
|
||||||
use Filament\Actions\DeleteAction;
|
use Filament\Actions\DeleteAction;
|
||||||
@ -112,11 +113,8 @@ class EditEgg extends EditRecord
|
|||||||
->columns()
|
->columns()
|
||||||
->icon('tabler-server-cog')
|
->icon('tabler-server-cog')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('config_from')
|
CopyFrom::make('copy_process_from')
|
||||||
->label(trans('admin/egg.copy_from'))
|
->process(),
|
||||||
->placeholder(trans('admin/egg.none'))
|
|
||||||
->relationship('configFrom', 'name', ignoreRecord: true)
|
|
||||||
->helperText(trans('admin/egg.copy_from_help')),
|
|
||||||
TextInput::make('config_stop')
|
TextInput::make('config_stop')
|
||||||
->label(trans('admin/egg.stop_command'))
|
->label(trans('admin/egg.stop_command'))
|
||||||
->maxLength(255)
|
->maxLength(255)
|
||||||
@ -228,20 +226,18 @@ class EditEgg extends EditRecord
|
|||||||
->columns(3)
|
->columns(3)
|
||||||
->icon('tabler-file-download')
|
->icon('tabler-file-download')
|
||||||
->schema([
|
->schema([
|
||||||
Select::make('copy_script_from')
|
CopyFrom::make('copy_script_from')
|
||||||
->label(trans('admin/egg.script_from'))
|
->script(),
|
||||||
->placeholder(trans('admin/egg.none'))
|
|
||||||
->relationship('scriptFrom', 'name', ignoreRecord: true),
|
|
||||||
TextInput::make('script_container')
|
TextInput::make('script_container')
|
||||||
->label(trans('admin/egg.script_container'))
|
->label(trans('admin/egg.script_container'))
|
||||||
->required()
|
->required()
|
||||||
->maxLength(255)
|
->maxLength(255)
|
||||||
->default('alpine:3.4'),
|
->placeholder('ghcr.io/pelican-eggs/installers:debian'),
|
||||||
TextInput::make('script_entry')
|
Select::make('script_entry')
|
||||||
->label(trans('admin/egg.script_entry'))
|
->label(trans('admin/egg.script_entry'))
|
||||||
->required()
|
->selectablePlaceholder(false)
|
||||||
->maxLength(255)
|
->options(['bash', 'ash', '/bin/bash'])
|
||||||
->default('ash'),
|
->required(),
|
||||||
MonacoEditor::make('script_install')
|
MonacoEditor::make('script_install')
|
||||||
->label(trans('admin/egg.script_install'))
|
->label(trans('admin/egg.script_install'))
|
||||||
->placeholderText('')
|
->placeholderText('')
|
||||||
|
@ -14,8 +14,10 @@ use Filament\Tables\Actions\BulkActionGroup;
|
|||||||
use Filament\Tables\Actions\CreateAction;
|
use Filament\Tables\Actions\CreateAction;
|
||||||
use Filament\Tables\Actions\DeleteBulkAction;
|
use Filament\Tables\Actions\DeleteBulkAction;
|
||||||
use Filament\Tables\Actions\EditAction;
|
use Filament\Tables\Actions\EditAction;
|
||||||
|
use Filament\Tables\Actions\ReplicateAction;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
use Filament\Tables\Table;
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ListEggs extends ListRecords
|
class ListEggs extends ListRecords
|
||||||
{
|
{
|
||||||
@ -44,9 +46,28 @@ class ListEggs extends ListRecords
|
|||||||
->label(trans('admin/egg.servers')),
|
->label(trans('admin/egg.servers')),
|
||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
EditAction::make(),
|
EditAction::make()
|
||||||
ExportEggAction::make(),
|
->iconButton()
|
||||||
UpdateEggAction::make(),
|
->tooltip(trans('filament-actions::edit.single.label')),
|
||||||
|
ExportEggAction::make()
|
||||||
|
->iconButton()
|
||||||
|
->tooltip(trans('filament-actions::export.modal.actions.export.label')),
|
||||||
|
UpdateEggAction::make()
|
||||||
|
->iconButton()
|
||||||
|
->tooltip(trans('admin/egg.update')),
|
||||||
|
ReplicateAction::make()
|
||||||
|
->iconButton()
|
||||||
|
->tooltip(trans('filament-actions::replicate.single.label'))
|
||||||
|
->modal(false)
|
||||||
|
->excludeAttributes(['author', 'uuid', 'update_url', 'servers_count', 'created_at', 'updated_at'])
|
||||||
|
->beforeReplicaSaved(function (Egg $replica) {
|
||||||
|
$replica->author = auth()->user()->email;
|
||||||
|
$replica->name .= ' Copy';
|
||||||
|
$replica->uuid = Str::uuid()->toString();
|
||||||
|
})
|
||||||
|
->after(fn (Egg $record, Egg $replica) => $record->variables->each(fn ($variable) => $variable->replicate()->fill(['egg_id' => $replica->id])->save()))
|
||||||
|
->successRedirectUrl(fn (Egg $replica) => EditEgg::getUrl(['record' => $replica]))
|
||||||
|
->authorize(fn () => auth()->user()->can('create egg')),
|
||||||
])
|
])
|
||||||
->bulkActions([
|
->bulkActions([
|
||||||
BulkActionGroup::make([
|
BulkActionGroup::make([
|
||||||
|
69
app/Filament/Components/Forms/Fields/CopyFrom.php
Normal file
69
app/Filament/Components/Forms/Fields/CopyFrom.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Components\Forms\Fields;
|
||||||
|
|
||||||
|
use App\Models\Egg;
|
||||||
|
use Filament\Forms\Components\Select;
|
||||||
|
use Filament\Forms\Set;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class CopyFrom extends Select
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->label(trans('admin/egg.copy_from'));
|
||||||
|
|
||||||
|
$this->placeholder(trans('admin/egg.none'));
|
||||||
|
|
||||||
|
$this->live();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(): static
|
||||||
|
{
|
||||||
|
$this->helperText(trans('admin/egg.copy_from_help'));
|
||||||
|
|
||||||
|
$this->relationship('configFrom', 'name', ignoreRecord: true);
|
||||||
|
|
||||||
|
$this->afterStateUpdated(function ($state, Set $set) {
|
||||||
|
$set('copy_script_from', $state);
|
||||||
|
if ($state === null) {
|
||||||
|
$set('config_stop', '');
|
||||||
|
$set('config_startup', '{}');
|
||||||
|
$set('config_files', '{}');
|
||||||
|
$set('config_logs', '{}');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$egg = Egg::find($state);
|
||||||
|
$set('config_stop', $egg->config_stop);
|
||||||
|
$set('config_startup', $egg->config_startup);
|
||||||
|
$set('config_files', $egg->config_files);
|
||||||
|
$set('config_logs', $egg->config_logs);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function script(): static
|
||||||
|
{
|
||||||
|
$this->relationship('scriptFrom', 'name', ignoreRecord: true);
|
||||||
|
|
||||||
|
$this->afterStateUpdated(function ($state, Set $set, Component $livewire) {
|
||||||
|
if ($state === null) {
|
||||||
|
$set('script_container', 'ghcr.io/pelican-eggs/installers:debian');
|
||||||
|
$set('script_entry', 'bash');
|
||||||
|
$livewire->dispatch('setContent', content: '');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$egg = Egg::find($state);
|
||||||
|
$set('script_container', $egg->script_container);
|
||||||
|
$set('script_entry', $egg->script_entry);
|
||||||
|
$livewire->dispatch('setContent', content: $egg->script_install);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,9 @@
|
|||||||
@script
|
@script
|
||||||
<script>
|
<script>
|
||||||
|
$wire.on('setContent', ({ content }) => {
|
||||||
|
document.getElementById('{{ $getId() }}').editor.getModel().setValue(content);
|
||||||
|
});
|
||||||
|
|
||||||
$wire.on('setLanguage', ({ lang }) => {
|
$wire.on('setLanguage', ({ lang }) => {
|
||||||
monaco.editor.setModelLanguage(document.getElementById('{{ $getId() }}').editor.getModel(), lang);
|
monaco.editor.setModelLanguage(document.getElementById('{{ $getId() }}').editor.getModel(), lang);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user