Skip to content

Commit 72fac8d

Browse files
committed
Time logged activities
1 parent c43f5d1 commit 72fac8d

File tree

13 files changed

+303
-2
lines changed

13 files changed

+303
-2
lines changed

app/Exports/ProjectHoursExport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function headings(): array
2525
'User',
2626
'Time',
2727
'Hours',
28+
'Activity',
2829
'Date',
2930
];
3031
}
@@ -45,6 +46,7 @@ public function collection()
4546
'user' => $item->user->name,
4647
'time' => $item->forHumans,
4748
'hours' => number_format($item->value, 2, ',', ' '),
49+
'activity' => $item->activity ? $item->activity->name : '-',
4850
'date' => $item->created_at->format(__('Y-m-d g:i A')),
4951
]))
5052
);

app/Exports/TicketHoursExport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function headings(): array
2424
'User',
2525
'Time',
2626
'Hours',
27+
'Activity',
2728
'Date',
2829
'Comment',
2930
];
@@ -41,6 +42,7 @@ public function collection()
4142
'user' => $item->user->name,
4243
'time' => $item->forHumans,
4344
'hours' => number_format($item->value, 2, ',', ' '),
45+
'activity' => $item->activity ? $item->activity->name : '-',
4446
'date' => $item->created_at->format(__('Y-m-d g:i A')),
4547
'comment' => $item->comment
4648
]);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace App\Filament\Resources;
4+
5+
use App\Filament\Resources\ActivityResource\Pages;
6+
use App\Filament\Resources\ActivityResource\RelationManagers;
7+
use App\Models\Activity;
8+
use Filament\Forms;
9+
use Filament\Resources\Form;
10+
use Filament\Resources\Resource;
11+
use Filament\Resources\Table;
12+
use Filament\Tables;
13+
14+
class ActivityResource extends Resource
15+
{
16+
protected static ?string $model = Activity::class;
17+
18+
protected static ?string $navigationIcon = 'heroicon-o-clipboard';
19+
20+
protected static ?int $navigationSort = 1;
21+
22+
protected static function getNavigationLabel(): string
23+
{
24+
return __('Activities');
25+
}
26+
27+
public static function getPluralLabel(): ?string
28+
{
29+
return static::getNavigationLabel();
30+
}
31+
32+
protected static function getNavigationGroup(): ?string
33+
{
34+
return __('Referential');
35+
}
36+
37+
public static function form(Form $form): Form
38+
{
39+
return $form
40+
->schema([
41+
Forms\Components\Card::make()
42+
->schema([
43+
Forms\Components\Grid::make()
44+
->schema([
45+
Forms\Components\TextInput::make('name')
46+
->label(__('Activity name'))
47+
->required()
48+
->maxLength(255),
49+
50+
Forms\Components\RichEditor::make('description')
51+
->label(__('Description'))
52+
->required()
53+
->columnSpan(2),
54+
55+
])
56+
])
57+
]);
58+
}
59+
60+
public static function table(Table $table): Table
61+
{
62+
return $table
63+
->columns([
64+
Tables\Columns\TextColumn::make('name')
65+
->label(__('Activity name'))
66+
->sortable()
67+
->searchable(),
68+
69+
Tables\Columns\TextColumn::make('created_at')
70+
->label(__('Created at'))
71+
->dateTime()
72+
->sortable()
73+
->searchable(),
74+
])
75+
->filters([
76+
//
77+
])
78+
->actions([
79+
Tables\Actions\ViewAction::make(),
80+
Tables\Actions\EditAction::make(),
81+
])
82+
->bulkActions([
83+
Tables\Actions\DeleteBulkAction::make(),
84+
])
85+
->defaultSort('id');
86+
}
87+
88+
public static function getRelations(): array
89+
{
90+
return [
91+
//
92+
];
93+
}
94+
95+
public static function getPages(): array
96+
{
97+
return [
98+
'index' => Pages\ListActivities::route('/'),
99+
'create' => Pages\CreateActivity::route('/create'),
100+
'view' => Pages\ViewActivity::route('/{record}'),
101+
'edit' => Pages\EditActivity::route('/{record}/edit'),
102+
];
103+
}
104+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\ActivityResource\Pages;
4+
5+
use App\Filament\Resources\ActivityResource;
6+
use App\Models\TicketType;
7+
use Filament\Resources\Pages\CreateRecord;
8+
9+
class CreateActivity extends CreateRecord
10+
{
11+
protected static string $resource = ActivityResource::class;
12+
13+
protected function afterCreate(): void
14+
{
15+
if ($this->record->is_default) {
16+
TicketType::where('id', '<>', $this->record->id)
17+
->where('is_default', true)
18+
->update(['is_default' => false]);
19+
}
20+
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\ActivityResource\Pages;
4+
5+
use App\Filament\Resources\ActivityResource;
6+
use App\Models\TicketStatus;
7+
use Filament\Pages\Actions;
8+
use Filament\Resources\Pages\EditRecord;
9+
10+
class EditActivity extends EditRecord
11+
{
12+
protected static string $resource = ActivityResource::class;
13+
14+
protected function getActions(): array
15+
{
16+
return [
17+
Actions\ViewAction::make(),
18+
Actions\DeleteAction::make(),
19+
];
20+
}
21+
22+
protected function afterSave(): void
23+
{
24+
if ($this->record->is_default) {
25+
TicketStatus::where('id', '<>', $this->record->id)
26+
->where('is_default', true)
27+
->update(['is_default' => false]);
28+
}
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\ActivityResource\Pages;
4+
5+
use App\Filament\Resources\ActivityResource;
6+
use Filament\Pages\Actions;
7+
use Filament\Resources\Pages\ListRecords;
8+
9+
class ListActivities extends ListRecords
10+
{
11+
protected static string $resource = ActivityResource::class;
12+
13+
protected function getActions(): array
14+
{
15+
return [
16+
Actions\CreateAction::make(),
17+
];
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Filament\Resources\ActivityResource\Pages;
4+
5+
use App\Filament\Resources\ActivityResource;
6+
use Filament\Pages\Actions;
7+
use Filament\Resources\Pages\ViewRecord;
8+
9+
class ViewActivity extends ViewRecord
10+
{
11+
protected static string $resource = ActivityResource::class;
12+
13+
protected function getActions(): array
14+
{
15+
return [
16+
Actions\EditAction::make(),
17+
];
18+
}
19+
}

app/Filament/Resources/TicketResource/Pages/ViewTicket.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use App\Exports\TicketHoursExport;
66
use App\Filament\Resources\TicketResource;
7+
use App\Models\Activity;
78
use App\Models\TicketComment;
89
use App\Models\TicketHour;
910
use App\Models\TicketSubscriber;
1011
use Filament\Forms\Components\RichEditor;
12+
use Filament\Forms\Components\Select;
1113
use Filament\Forms\Components\Textarea;
1214
use Filament\Forms\Components\TextInput;
1315
use Filament\Forms\Components\TimePicker;
@@ -99,7 +101,13 @@ protected function getActions(): array
99101
->label(__('Time to log'))
100102
->numeric()
101103
->required(),
102-
104+
Select::make('activity_id')
105+
->label(__('Activity'))
106+
->searchable()
107+
->reactive()
108+
->options(function ($get, $set) {
109+
return Activity::all()->pluck('name', 'id')->toArray();
110+
}),
103111
Textarea::make('comment')
104112
->label(__('Comment'))
105113
->rows(3),
@@ -109,6 +117,7 @@ protected function getActions(): array
109117
$comment = $data['comment'];
110118
TicketHour::create([
111119
'ticket_id' => $this->record->id,
120+
'activity_id' => $data['activity_id'],
112121
'user_id' => auth()->user()->id,
113122
'value' => $value,
114123
'comment' => $comment

app/Models/Activity.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Activity extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = [
13+
'name',
14+
'description'
15+
];
16+
}

app/Models/TicketHour.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TicketHour extends Model
1313
use HasFactory;
1414

1515
protected $fillable = [
16-
'user_id', 'ticket_id', 'value', 'comment'
16+
'user_id', 'ticket_id', 'value', 'comment', 'activity_id'
1717
];
1818

1919
public function user(): BelongsTo
@@ -26,6 +26,11 @@ public function ticket(): BelongsTo
2626
return $this->belongsTo(Ticket::class, 'ticket_id', 'id');
2727
}
2828

29+
public function activity(): BelongsTo
30+
{
31+
return $this->belongsTo(Activity::class, 'activity_id', 'id');
32+
}
33+
2934
public function forHumans(): Attribute
3035
{
3136
return new Attribute(

0 commit comments

Comments
 (0)