Skip to content

Commit c5a82dd

Browse files
committed
Tickets attachments
1 parent 81f5fdc commit c5a82dd

7 files changed

Lines changed: 119 additions & 2 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace App\Http\Livewire\Ticket;
4+
5+
use App\Models\Ticket;
6+
use Filament\Facades\Filament;
7+
use Filament\Forms\Components\FileUpload;
8+
use Filament\Forms\Concerns\InteractsWithForms;
9+
use Filament\Forms\Contracts\HasForms;
10+
use Illuminate\Database\Eloquent\Model;
11+
use Livewire\Component;
12+
13+
class Attachments extends Component implements HasForms
14+
{
15+
use InteractsWithForms;
16+
17+
public Ticket $ticket;
18+
19+
public function mount(): void
20+
{
21+
$this->form->fill([
22+
'attachments' => $this->ticket->attachments
23+
]);
24+
}
25+
26+
public function render()
27+
{
28+
return view('livewire.ticket.attachments');
29+
}
30+
31+
protected function getFormModel(): Model|string|null
32+
{
33+
return $this->ticket;
34+
}
35+
36+
protected function getFormSchema(): array
37+
{
38+
return [
39+
FileUpload::make('attachments')
40+
->label(__('Attachments'))
41+
->hint(__('Important: If a file has the same name, it will be replaced'))
42+
->helperText(__('Here you can attach all files needed for this ticket'))
43+
->multiple()
44+
->disablePreview()
45+
->enableReordering()
46+
->enableOpen()
47+
->preserveFilenames()
48+
->enableDownload()
49+
->directory(fn() => 'tickets/' . $this->ticket->code)
50+
];
51+
}
52+
53+
public function perform(): void
54+
{
55+
$data = $this->form->getState();
56+
$this->ticket->attachments = $data['attachments'];
57+
$this->ticket->save();
58+
$this->ticket->refresh();
59+
Filament::notify('success', __('Ticket attachments saved'));
60+
}
61+
}

app/Models/Ticket.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ class Ticket extends Model
2020
protected $fillable = [
2121
'name', 'content', 'owner_id', 'responsible_id',
2222
'status_id', 'project_id', 'code', 'order', 'type_id',
23-
'priority_id', 'estimation', 'epic_id'
23+
'priority_id', 'estimation', 'epic_id', 'attachments',
24+
];
25+
26+
protected $casts = [
27+
'attachments' => 'array',
2428
];
2529

2630
public static function boot()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('tickets', function (Blueprint $table) {
16+
$table->longText('attachments')->nullable();
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
Schema::table('tickets', function (Blueprint $table) {
28+
$table->dropColumn('attachments');
29+
});
30+
}
31+
};

lang/fr.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,9 @@
189189
"Ticket successfully saved": "Ticket enregistré avec succès",
190190
"Parent epic": "Epic parent",
191191
"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"
192+
"Comment": "Commentaire",
193+
"Attachments": "Pièces jointes",
194+
"Here you can attach all files needed for this ticket": "Ici vous pouvez joindre tous les fichiers nécessaires pour ce ticket",
195+
"Submit": "Soumettre",
196+
"Ticket attachments saved": "Pièces jointes au ticket enregistrées"
193197
}

resources/views/filament/resources/tickets/view.blade.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ class="md:text-xl text-sm p-3 border-b-2 border-transparent hover:border-primary
219219
@if($tab === 'time') border-primary-500 text-primary-500 @else text-gray-700 @endif">
220220
{{ __('Time logged') }}
221221
</button>
222+
<button wire:click="selectTab('attachments')"
223+
class="md:text-xl text-sm p-3 border-b-2 border-transparent hover:border-primary-500
224+
@if($tab === 'attachments') border-primary-500 text-primary-500 @else text-gray-700 @endif">
225+
{{ __('Attachments') }}
226+
</button>
222227
</div>
223228
@if($tab === 'comments')
224229
<form wire:submit.prevent="submitComment" class="pb-5">
@@ -333,6 +338,9 @@ class="text-danger-500 text-xs hover:text-danger-600 hover:underline">
333338
@endif
334339
</div>
335340
@endif
341+
@if($tab === 'attachments')
342+
<livewire:ticket.attachments :ticket="$record" />
343+
@endif
336344
</x-filament::card>
337345

338346
<div class="md:w-1/3 w-full flex flex-col"></div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<form wire:submit.prevent="perform" class="w-full">
2+
{{ $this->form }}
3+
4+
<button type="submit" wire:loading.prop="disabled"
5+
class="px-3 py-2 bg-primary-500 disabled:bg-gray-300 hover:bg-primary-600 text-white rounded mt-3">
6+
{{ __('Submit') }}
7+
</button>
8+
</form>

tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
content: [
66
'./resources/**/*.blade.php',
77
'./app/Filament/**/*.php',
8+
'./app/Http/Livewire/**/*.php',
89
'./vendor/filament/**/*.blade.php',
910
'./node_modules/flowbite/**/*.js'
1011
],

0 commit comments

Comments
 (0)