Skip to content

Commit 4c908fb

Browse files
author
EL OUFIR
committed
Add comment to log time
1 parent 752f31c commit 4c908fb

5 files changed

Lines changed: 71 additions & 30 deletions

File tree

app/Exports/TicketHoursExport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function headings(): array
2525
'Time',
2626
'Hours',
2727
'Date',
28+
'Comment',
2829
];
2930
}
3031

@@ -41,6 +42,7 @@ public function collection()
4142
'time' => $item->forHumans,
4243
'hours' => number_format($item->value, 2, ',', ' '),
4344
'date' => $item->created_at->format(__('Y-m-d g:i A')),
45+
'comment' => $item->comment
4446
]);
4547
}
4648
}

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

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\TicketHour;
99
use App\Models\TicketSubscriber;
1010
use Filament\Forms\Components\RichEditor;
11+
use Filament\Forms\Components\Textarea;
1112
use Filament\Forms\Components\TextInput;
1213
use Filament\Forms\Components\TimePicker;
1314
use Filament\Forms\Concerns\InteractsWithForms;
@@ -81,35 +82,40 @@ protected function getActions(): array
8182
'url' => route('filament.resources.tickets.share', $this->record->code)
8283
])),
8384
Actions\EditAction::make(),
85+
Actions\Action::make('logHours')
86+
->label(__('Log time'))
87+
->icon('heroicon-o-clock')
88+
->color('warning')
89+
->modalWidth('sm')
90+
->modalHeading(__('Log worked time'))
91+
->modalSubheading(__('Use the following form to add your worked time in this ticket.'))
92+
->modalButton(__('Log'))
93+
->visible(fn() => in_array(
94+
auth()->user()->id,
95+
[$this->record->owner_id, $this->record->responsible_id]
96+
))
97+
->form([
98+
TextInput::make('time')
99+
->label(__('Time to log'))
100+
->numeric()
101+
->required(),
102+
103+
Textarea::make('comment')
104+
->label(__('Comment')),
105+
])
106+
->action(function (Collection $records, array $data): void {
107+
$value = $data['time'];
108+
$comment = $data['comment'];
109+
TicketHour::create([
110+
'ticket_id' => $this->record->id,
111+
'user_id' => auth()->user()->id,
112+
'value' => $value,
113+
'comment' => $comment
114+
]);
115+
$this->record->refresh();
116+
$this->notify('success', __('Time logged into ticket'));
117+
}),
84118
Actions\ActionGroup::make([
85-
Actions\Action::make('logHours')
86-
->label(__('Log time'))
87-
->icon('heroicon-o-clock')
88-
->color('warning')
89-
->modalWidth('sm')
90-
->modalHeading(__('Log worked time'))
91-
->modalSubheading(__('Use the following form to add your worked time in this ticket.'))
92-
->modalButton(__('Log'))
93-
->visible(fn() => in_array(
94-
auth()->user()->id,
95-
[$this->record->owner_id, $this->record->responsible_id]
96-
))
97-
->form([
98-
TextInput::make('time')
99-
->label(__('Time to log'))
100-
->numeric()
101-
->required()
102-
])
103-
->action(function (Collection $records, array $data): void {
104-
$value = $data['time'];
105-
TicketHour::create([
106-
'ticket_id' => $this->record->id,
107-
'user_id' => auth()->user()->id,
108-
'value' => $value
109-
]);
110-
$this->record->refresh();
111-
$this->notify('success', __('Time logged into ticket'));
112-
}),
113119
Actions\Action::make('exportLogHours')
114120
->label(__('Export time logged'))
115121
->icon('heroicon-o-document-download')

app/Models/TicketHour.php

Lines changed: 1 addition & 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'
16+
'user_id', 'ticket_id', 'value', 'comment'
1717
];
1818

1919
public function user(): BelongsTo
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('ticket_hours', function (Blueprint $table) {
17+
$table->longText('comment')->nullable();
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('ticket_hours', function (Blueprint $table) {
29+
$table->dropColumn('comment');
30+
});
31+
}
32+
};

lang/fr.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,6 @@
188188
"Epic successfully saved": "Epic enregistré avec succès",
189189
"Ticket successfully saved": "Ticket enregistré avec succès",
190190
"Parent epic": "Epic parent",
191-
"Road Map chart is only available on large screen": "Le graphique de la feuille de route n'est disponible que sur grand écran"
191+
"Road Map chart is only available on large screen": "Le graphique de la feuille de route n'est disponible que sur grand écran",
192+
"Comment": "Commentaire"
192193
}

0 commit comments

Comments
 (0)