Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Apr 26, 2024
1 parent aab1b81 commit ccbbdef
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
98 changes: 98 additions & 0 deletions web/Modules/Customer/App/Filament/Resources/CronJobResource.php
Original file line number Diff line number Diff line change
@@ -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'),
];
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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(),
];
}
}
Original file line number Diff line number Diff line change
@@ -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(),
];
}
}
17 changes: 17 additions & 0 deletions web/app/Models/CronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

Expand All @@ -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();
Expand Down
1 change: 0 additions & 1 deletion web/app/Models/HostingSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ protected static function booted(): void
});
}


public static function boot()
{
parent::boot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function up(): void
{
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');
Expand Down

0 comments on commit ccbbdef

Please sign in to comment.