-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c43f5d1
commit 72fac8d
Showing
13 changed files
with
303 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ActivityResource\Pages; | ||
use App\Filament\Resources\ActivityResource\RelationManagers; | ||
use App\Models\Activity; | ||
use Filament\Forms; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
|
||
class ActivityResource extends Resource | ||
{ | ||
protected static ?string $model = Activity::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-clipboard'; | ||
|
||
protected static ?int $navigationSort = 1; | ||
|
||
protected static function getNavigationLabel(): string | ||
{ | ||
return __('Activities'); | ||
} | ||
|
||
public static function getPluralLabel(): ?string | ||
{ | ||
return static::getNavigationLabel(); | ||
} | ||
|
||
protected static function getNavigationGroup(): ?string | ||
{ | ||
return __('Referential'); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\Card::make() | ||
->schema([ | ||
Forms\Components\Grid::make() | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->label(__('Activity name')) | ||
->required() | ||
->maxLength(255), | ||
|
||
Forms\Components\RichEditor::make('description') | ||
->label(__('Description')) | ||
->required() | ||
->columnSpan(2), | ||
|
||
]) | ||
]) | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->label(__('Activity name')) | ||
->sortable() | ||
->searchable(), | ||
|
||
Tables\Columns\TextColumn::make('created_at') | ||
->label(__('Created at')) | ||
->dateTime() | ||
->sortable() | ||
->searchable(), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
Tables\Actions\EditAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]) | ||
->defaultSort('id'); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListActivities::route('/'), | ||
'create' => Pages\CreateActivity::route('/create'), | ||
'view' => Pages\ViewActivity::route('/{record}'), | ||
'edit' => Pages\EditActivity::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/Filament/Resources/ActivityResource/Pages/CreateActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ActivityResource\Pages; | ||
|
||
use App\Filament\Resources\ActivityResource; | ||
use App\Models\TicketType; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateActivity extends CreateRecord | ||
{ | ||
protected static string $resource = ActivityResource::class; | ||
|
||
protected function afterCreate(): void | ||
{ | ||
if ($this->record->is_default) { | ||
TicketType::where('id', '<>', $this->record->id) | ||
->where('is_default', true) | ||
->update(['is_default' => false]); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/Filament/Resources/ActivityResource/Pages/EditActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ActivityResource\Pages; | ||
|
||
use App\Filament\Resources\ActivityResource; | ||
use App\Models\TicketStatus; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditActivity extends EditRecord | ||
{ | ||
protected static string $resource = ActivityResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\ViewAction::make(), | ||
Actions\DeleteAction::make(), | ||
]; | ||
} | ||
|
||
protected function afterSave(): void | ||
{ | ||
if ($this->record->is_default) { | ||
TicketStatus::where('id', '<>', $this->record->id) | ||
->where('is_default', true) | ||
->update(['is_default' => false]); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/ActivityResource/Pages/ListActivities.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ActivityResource\Pages; | ||
|
||
use App\Filament\Resources\ActivityResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListActivities extends ListRecords | ||
{ | ||
protected static string $resource = ActivityResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/ActivityResource/Pages/ViewActivity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\ActivityResource\Pages; | ||
|
||
use App\Filament\Resources\ActivityResource; | ||
use Filament\Pages\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewActivity extends ViewRecord | ||
{ | ||
protected static string $resource = ActivityResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Activity extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'description' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
database/migrations/2023_01_09_113159_create_activities_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('activities', function (Blueprint $table) { | ||
$table->id(); | ||
|
||
$table->string('name'); | ||
$table->mediumText('description'); | ||
|
||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('activities'); | ||
} | ||
}; |
33 changes: 33 additions & 0 deletions
33
database/migrations/2023_01_09_113847_add_activity_to_ticket_hours_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('ticket_hours', function (Blueprint $table) { | ||
$table->foreignId('activity_id')->nullable()->constrained('activities'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('ticket_hours', function (Blueprint $table) { | ||
$table->dropForeign(['activity_id']); | ||
$table->dropColumn('activity_id'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters