mirror of
https://github.com/pelican-dev/panel.git
synced 2025-09-08 23:08:37 +02:00
wip
This commit is contained in:
parent
dd2fdd15a1
commit
c948314e21
@ -4,6 +4,7 @@ namespace App\Filament\Admin\Resources;
|
|||||||
|
|
||||||
use App\Filament\Admin\Resources\WebhookResource\Pages;
|
use App\Filament\Admin\Resources\WebhookResource\Pages;
|
||||||
use App\Filament\Admin\Resources\WebhookResource\Pages\EditWebhookConfiguration;
|
use App\Filament\Admin\Resources\WebhookResource\Pages\EditWebhookConfiguration;
|
||||||
|
use App\Filament\Admin\Resources\WebhookResource\RelationManagers\EventsRelationManager;
|
||||||
use App\Livewire\AlertBanner;
|
use App\Livewire\AlertBanner;
|
||||||
use App\Models\WebhookConfiguration;
|
use App\Models\WebhookConfiguration;
|
||||||
use App\Traits\Filament\CanCustomizePages;
|
use App\Traits\Filament\CanCustomizePages;
|
||||||
@ -23,6 +24,7 @@ use Filament\Forms\Components\Actions\Action;
|
|||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Resources\Pages\PageRegistration;
|
use Filament\Resources\Pages\PageRegistration;
|
||||||
use Filament\Forms\Get;
|
use Filament\Forms\Get;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Forms\Set;
|
use Filament\Forms\Set;
|
||||||
use Filament\Tables\Actions\DeleteBulkAction;
|
use Filament\Tables\Actions\DeleteBulkAction;
|
||||||
@ -161,17 +163,21 @@ class WebhookResource extends Resource
|
|||||||
->view('filament.components.webhooksection')
|
->view('filament.components.webhooksection')
|
||||||
->aside()
|
->aside()
|
||||||
->formBefore(),
|
->formBefore(),
|
||||||
Section::make(trans('admin/webhook.events'))
|
/*Section::make(trans('admin/webhook.events'))
|
||||||
->schema([
|
->schema([
|
||||||
CheckboxList::make('events')
|
CheckboxList::make('webhookEvents')
|
||||||
->live()
|
->relationship('webhookEvents')
|
||||||
->options(fn () => WebhookConfiguration::filamentCheckboxList())
|
->live()
|
||||||
->searchable()
|
->options(fn () => WebhookConfiguration::filamentCheckboxList())
|
||||||
->bulkToggleable()
|
->searchable()
|
||||||
->columns(3)
|
->bulkToggleable()
|
||||||
->columnSpanFull()
|
->columns(3)
|
||||||
->required(),
|
->columnSpanFull()
|
||||||
]),
|
->required()
|
||||||
|
->before(function (array $state) {
|
||||||
|
dd($state);
|
||||||
|
}),
|
||||||
|
]),*/
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,4 +349,12 @@ class WebhookResource extends Resource
|
|||||||
'edit' => Pages\EditWebhookConfiguration::route('/{record}/edit'),
|
'edit' => Pages\EditWebhookConfiguration::route('/{record}/edit'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return class-string<RelationManager>[] */
|
||||||
|
public static function getDefaultRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
EventsRelationManager::class,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Admin\Resources\WebhookResource\RelationManagers;
|
||||||
|
|
||||||
|
use App\Models\WebhookConfiguration;
|
||||||
|
use App\Models\WebhookEvent;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Tables\Actions\Action;
|
||||||
|
use Filament\Tables\Actions\DeleteAction;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method WebhookConfiguration getOwnerRecord()
|
||||||
|
*/
|
||||||
|
class EventsRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'webhookEvents';
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->heading('')
|
||||||
|
->columns([
|
||||||
|
TextColumn::make('id'),
|
||||||
|
TextColumn::make('name'),
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
Action::make('create')
|
||||||
|
->form(fn () => [
|
||||||
|
TextInput::make('name')
|
||||||
|
->inlineLabel()
|
||||||
|
->live()
|
||||||
|
->required(),
|
||||||
|
])
|
||||||
|
->action(function (array $data) {
|
||||||
|
$id = WebhookEvent::firstOrCreate([
|
||||||
|
'name' => $data['name'],
|
||||||
|
]);
|
||||||
|
$this->getOwnerRecord()->webhookEvents()->sync([$id]);
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
DeleteAction::make()
|
||||||
|
->authorize(fn (WebhookConfiguration $config) => auth()->user()->can('delete', $config)),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||||||
use App\Jobs\ProcessWebhook;
|
use App\Jobs\ProcessWebhook;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
@ -231,4 +232,9 @@ class WebhookConfiguration extends Model
|
|||||||
'id' => 2,
|
'id' => 2,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function webhookEvents(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(WebhookEvent::class, 'webhook_configurations_events', 'configuration_id', 'event_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
23
app/Models/WebhookEvent.php
Normal file
23
app/Models/WebhookEvent.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property string $name
|
||||||
|
*/
|
||||||
|
class WebhookEvent extends Model
|
||||||
|
{
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function webhookConfigurationEvent(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(WebhookConfiguration::class, 'webhook_configurations_events', 'event_id', 'configuration_id');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
/*Schema::table('webhook_configurations', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('events');
|
||||||
|
});*/ // TODO: convert old format
|
||||||
|
|
||||||
|
Schema::create('webhook_events', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
});
|
||||||
|
Schema::create('webhook_configurations_events', function (Blueprint $table) {
|
||||||
|
$table->foreignId('event_id')->references('id')->on('webhook_events')->onDelete('cascade');
|
||||||
|
$table->foreignId('configuration_id')->references('id')->on('webhook_configurations')->onDelete('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('webhook_events');
|
||||||
|
Schema::dropIfExists('webhook_configurations_events');
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user