mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-07 21:33:18 +01:00
147 lines
5.1 KiB
PHP
147 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\ReportResource\Pages\EditReport;
|
|
use App\Filament\Resources\ReportResource\Pages\ListReports;
|
|
use App\Filament\Resources\ReportResource\Pages\ViewReport;
|
|
use App\Models\Report;
|
|
use App\Service\Dto\ReportPropertiesDto;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Columns\ToggleColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Novadaemon\FilamentPrettyJson\Form\PrettyJsonField;
|
|
|
|
class ReportResource extends Resource
|
|
{
|
|
protected static ?string $model = Report::class;
|
|
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-document-chart-bar';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Timetracking';
|
|
|
|
protected static ?int $navigationSort = 7;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->columns(1)
|
|
->components([
|
|
TextInput::make('name')
|
|
->label('Name')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('description')
|
|
->label('Description')
|
|
->nullable()
|
|
->maxLength(255),
|
|
Toggle::make('is_public')
|
|
->label('Is public?')
|
|
->required(),
|
|
DateTimePicker::make('public_until')
|
|
->label('Public until')
|
|
->nullable(),
|
|
Select::make('organization_id')
|
|
->label('Organization')
|
|
->relationship(name: 'organization', titleAttribute: 'name')
|
|
->searchable(['name'])
|
|
->disabled()
|
|
->required(),
|
|
TextInput::make('share_secret')
|
|
->label('Share Secret')
|
|
->nullable(),
|
|
PrettyJsonField::make('properties')
|
|
->formatStateUsing(function (ReportPropertiesDto $state, Report $record): string {
|
|
return $record->getRawOriginal('properties');
|
|
})
|
|
->disabled(),
|
|
DateTimePicker::make('created_at')
|
|
->label('Created At')
|
|
->hiddenOn(['create'])
|
|
->disabled(),
|
|
DateTimePicker::make('updated_at')
|
|
->label('Updated At')
|
|
->hiddenOn(['create'])
|
|
->disabled(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('name')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('description')
|
|
->searchable()
|
|
->sortable(),
|
|
ToggleColumn::make('is_public')
|
|
->label('Is public?')
|
|
->sortable(),
|
|
TextColumn::make('organization.name')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable(),
|
|
TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
SelectFilter::make('organization')
|
|
->label('Organization')
|
|
->relationship('organization', 'name')
|
|
->searchable(),
|
|
SelectFilter::make('organization_id')
|
|
->label('Organization ID')
|
|
->relationship('organization', 'id')
|
|
->searchable(),
|
|
])
|
|
->recordActions([
|
|
Action::make('public-view')
|
|
->label('Public')
|
|
->icon('heroicon-o-eye')
|
|
->color('gray')
|
|
->hidden(fn (Report $record): bool => $record->getShareableLink() === null)
|
|
->url(fn (Report $record): string => $record->getShareableLink(), true),
|
|
ViewAction::make(),
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListReports::route('/'),
|
|
'edit' => EditReport::route('/{record}/edit'),
|
|
'view' => ViewReport::route('/{record}'),
|
|
];
|
|
}
|
|
}
|