mirror of
https://github.com/PhyreApps/PhyrePanel.git
synced 2024-11-25 09:00:27 +00:00
update
This commit is contained in:
parent
aab1b8128e
commit
ccbbdefda1
7 changed files with 166 additions and 2 deletions
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Filament\Resources;
|
||||
|
||||
use App\Models\CronJob;
|
||||
use App\Models\HostingSubscription;
|
||||
use Modules\Customer\App\Filament\Resources\CronJobResource\Pages;
|
||||
use Modules\Customer\App\Filament\Resources\CronJobResource\RelationManagers;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class CronJobResource extends Resource
|
||||
{
|
||||
protected static ?string $model = CronJob::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-clock';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
|
||||
Forms\Components\Select::make('hosting_subscription_id')
|
||||
->label('Hosting Subscription')
|
||||
->options(
|
||||
\App\Models\HostingSubscription::all()->pluck('domain', 'id')
|
||||
)
|
||||
->live()
|
||||
->disabled(function ($record) {
|
||||
return $record;
|
||||
})
|
||||
->columnSpanFull()
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('schedule')
|
||||
->autofocus()
|
||||
->required()
|
||||
->columnSpanFull()
|
||||
->helperText('The schedule to run the command. Example: * * * * *')
|
||||
->label('Schedule'),
|
||||
Forms\Components\TextInput::make('command')
|
||||
->required()
|
||||
->columnSpanFull()
|
||||
->helperText('The command to run. Example: ls -la')
|
||||
->label('Command'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('schedule')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('command')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('user')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCronJobs::route('/'),
|
||||
'create' => Pages\CreateCronJob::route('/create'),
|
||||
'edit' => Pages\EditCronJob::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Filament\Resources\CronJobResource\Pages;
|
||||
|
||||
use Modules\Customer\App\Filament\Resources\CronJobResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCronJob extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CronJobResource::class;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Filament\Resources\CronJobResource\Pages;
|
||||
|
||||
use Modules\Customer\App\Filament\Resources\CronJobResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCronJob extends EditRecord
|
||||
{
|
||||
protected static string $resource = CronJobResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Modules\Customer\App\Filament\Resources\CronJobResource\Pages;
|
||||
|
||||
use Modules\Customer\App\Filament\Resources\CronJobResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCronJobs extends ListRecords
|
||||
{
|
||||
protected static string $resource = CronJobResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
@ -13,6 +14,22 @@ class CronJob extends Model
|
|||
'user',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope('customer', function (Builder $query) {
|
||||
if (auth()->check() && auth()->guard()->name == 'web_customer') {
|
||||
$query->whereHas('hostingSubscription', function ($query) {
|
||||
$query->where('customer_id', auth()->user()->id);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function hostingSubscription()
|
||||
{
|
||||
return $this->belongsTo(HostingSubscription::class);
|
||||
}
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
|
|
@ -36,7 +36,6 @@ class HostingSubscription extends Model
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
|
|
@ -13,7 +13,7 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('cron_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('hosting_account_id')->nullable();
|
||||
$table->string('hosting_subscription_id')->nullable();
|
||||
$table->string('command');
|
||||
$table->string('schedule');
|
||||
$table->string('user');
|
||||
|
|
Loading…
Reference in a new issue