From 9675c1bb3a196a4b49b4aa4bf6ea3f136600a7b5 Mon Sep 17 00:00:00 2001 From: "nicolas.demangeat" Date: Fri, 2 Feb 2024 10:34:06 +0000 Subject: [PATCH] add field for the title of a ticket, make the migration and the request --- app/Http/Controllers/Bo/TicketController.php | 2 +- app/Http/Requests/Bo/StoreTicket.php | 1 + app/Models/Ticket.php | 1 + ...1_13_144755_add_title_to_tickets_table.php | 44 ++ package-lock.json | 2 +- .../views/bo/pages/tickets/edit.blade.php | 46 +- .../bo/pages/tickets/form-inputs.blade.php | 184 +++--- .../views/bo/pages/tickets/index.blade.php | 539 ++++++++++-------- .../views/bo/pages/tickets/show.blade.php | 469 ++++++++------- 9 files changed, 726 insertions(+), 562 deletions(-) create mode 100644 database/migrations/2023_11_13_144755_add_title_to_tickets_table.php diff --git a/app/Http/Controllers/Bo/TicketController.php b/app/Http/Controllers/Bo/TicketController.php index 6d88359..26ee400 100644 --- a/app/Http/Controllers/Bo/TicketController.php +++ b/app/Http/Controllers/Bo/TicketController.php @@ -595,7 +595,7 @@ class TicketController extends Controller }); } //end foreach } //end if - }, 'text', 'file', 'file2'); + }, 'text', 'title', 'file', 'file2'); } /** diff --git a/app/Http/Requests/Bo/StoreTicket.php b/app/Http/Requests/Bo/StoreTicket.php index 1368c89..e010179 100644 --- a/app/Http/Requests/Bo/StoreTicket.php +++ b/app/Http/Requests/Bo/StoreTicket.php @@ -97,6 +97,7 @@ class StoreTicket extends FormRequest } ], 'text' => 'required|string|min:40', + 'title' => 'required|string|between:3,255', 'file_ticket' => 'mimes:jpeg,jpg,png,pdf|max:2048', 'file_ticket2' => 'mimes:jpeg,jpg,png,pdf|max:2048', 'is_internal' => 'required|boolean', diff --git a/app/Models/Ticket.php b/app/Models/Ticket.php index dda89c0..136672f 100644 --- a/app/Models/Ticket.php +++ b/app/Models/Ticket.php @@ -33,6 +33,7 @@ class Ticket extends Model 'type', 'status', 'text', + 'title', 'is_internal', 'last_activity', ]; diff --git a/database/migrations/2023_11_13_144755_add_title_to_tickets_table.php b/database/migrations/2023_11_13_144755_add_title_to_tickets_table.php new file mode 100644 index 0000000..548d20d --- /dev/null +++ b/database/migrations/2023_11_13_144755_add_title_to_tickets_table.php @@ -0,0 +1,44 @@ +string('title') + ->after('type') + ->comment('Titre du ticket'); + }); + + DB::transaction(function () { + $tickets = Ticket::all(); + foreach ($tickets as $ticket) { + $ticket->title = 'ts-' . $ticket->id; + $ticket->saveQuietly(); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('tickets', function (Blueprint $table) { + $table->dropColumn('title'); + }); + } +}; diff --git a/package-lock.json b/package-lock.json index 98e39da..572ab94 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "supportweb", + "name": "srcs", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/views/bo/pages/tickets/edit.blade.php b/resources/views/bo/pages/tickets/edit.blade.php index bc7e00c..357fb92 100644 --- a/resources/views/bo/pages/tickets/edit.blade.php +++ b/resources/views/bo/pages/tickets/edit.blade.php @@ -5,25 +5,31 @@ @section('bodyClass', 'col-md-8') @section('content') -
-
-

- -  {{ __('Modifier un ticket') }} - - {{ $ticket->full_name }} - @if ($ticket->is_internal)@endif - {{ $ticket->type->label() }} -

+
+
+

+ +  {{ __('Modifier un ticket') }} - + {{ $ticket->full_name }} + @if ($ticket->is_internal) + + @endif + {{ $ticket->type->label() }} +

+

+ {{ $ticket->title }} +

+
+
+
+ @csrf + @method('PUT') + @include('bo.pages.tickets.form-inputs') +
+ +
+
+
-
-
- @csrf - @method('PUT') - @include('bo.pages.tickets.form-inputs') -
- -
-
-
-
@endsection diff --git a/resources/views/bo/pages/tickets/form-inputs.blade.php b/resources/views/bo/pages/tickets/form-inputs.blade.php index 2438da3..0abe56d 100644 --- a/resources/views/bo/pages/tickets/form-inputs.blade.php +++ b/resources/views/bo/pages/tickets/form-inputs.blade.php @@ -1,125 +1,133 @@ @php -$userPr = Auth::user()->sites ?? collect([]); + $userPr = Auth::user()->sites ?? collect([]); @endphp
- - + @foreach ($sites as $site) + @if (Auth::user()->isAdmin()) + + @elseif ( + $userPr->filter(function ($pr) use ($site) { + return $pr->id === $site->id; + })->count()) + + @endif @endforeach
- - + @foreach (\App\Enums\Tickets\TicketTypeEnum::cases() as $ticketType) + @endforeach
@can('changeStatus', App\Model\Ticket::class) -
- - -
- @push('scripts') - - @endpush + }; + + const changeTextValue = () => { + switch (typeSwitch.value) { + @foreach (\App\Models\Ticket\TicketType::query()->get() as $ticketTypeModel) + case "{{ $ticketTypeModel->type->value }}": + // * Ignore if template already changed. + if (textArea.value !== (templates[textArea.template] ?? null) && textArea.value.length) { + return; + } + // Save actual template + textArea.template = typeSwitch.value; + // apply template + textArea.value = templates[typeSwitch.value]; + break; + @endforeach + default: + console.error(`Unkown value ${typeSwitch.value}`); + } + }; + typeSwitch.addEventListener('change', changeTextValue); + changeTextValue(); + }); + + @endpush @else - + @endcan @can('assignLabels', App\Model\Ticket::class) -
- -
- @php - $dataVue = [ - 'name' => 'labels', - 'value' => optional($ticket ?? null)->labels, - 'labels' => \App\Models\Label::all() - ]; - @endphp -
+
+ +
+ @php + $dataVue = [ + 'name' => 'labels', + 'value' => optional($ticket ?? null)->labels, + 'labels' => \App\Models\Label::all(), + ]; + @endphp +
+
+
- -
@endcan
+
+ + +
+
- - + +

Fichier joint 1

- + @if (isset($ticket) and $ticket->file !== null) -
-
- -
+
+
+ +
@endif

Fichier joint 2

- + @if (isset($ticket) and $ticket->file2 !== null) -
-
- -
+
+
+ +
@endif
@can('changeInternalStatus', App\Model\Ticket::class) -
- is_internal)) checked @endif> - -
+
+ is_internal)) checked @endif> + +
@endcan diff --git a/resources/views/bo/pages/tickets/index.blade.php b/resources/views/bo/pages/tickets/index.blade.php index 172473f..9d73db6 100644 --- a/resources/views/bo/pages/tickets/index.blade.php +++ b/resources/views/bo/pages/tickets/index.blade.php @@ -5,267 +5,320 @@ @section('bodyClass', 'content ticketsIndex') @section('content') -@php -$userPr = Auth::user()->sites ?? collect([]); -@endphp -
-
-
-
-
-

{{ __('Gestion des tickets') }} @if(Session::get('tickets.st') == \App\Enums\Tickets\TicketStatusEnum::archived->value) (Archivés) @endif

-
-
-
-
- @can('isAdmin') - - @endcan -   {{ __('ticket') }} - @if(session('tickets.st') == \App\Enums\Tickets\TicketStatusEnum::archived->value) - - @else - - @endif -  {{ __(' le tri') }} -
-
-
- - - @push('scripts') - - @endpush + @php + $userPr = Auth::user()->sites ?? collect([]); + @endphp +
+
+
+
+
+

{{ __('Gestion des tickets') }} @if (Session::get('tickets.st') == \App\Enums\Tickets\TicketStatusEnum::archived->value) + (Archivés) + @endif +

+
+
+
+
+ @can('isAdmin') + + @endcan +   {{ __('ticket') }} + @if (session('tickets.st') == \App\Enums\Tickets\TicketStatusEnum::archived->value) + + @else + + @endif +  {{ __(' le tri') }}
-
-
-
- - - @push('scripts') - - @endpush +
+
+ + + @push('scripts') + + @endpush +
+
+
+
+ + + @push('scripts') + + @endpush +
-
-
- @can('assignTickets', App\Models\Ticket::class) -
-
-
- - +
+ @can('assignTickets', App\Models\Ticket::class) +
+
+
+ + + @push('scripts') + + @endpush +
+
+
+ @endcan +
+
+
+ + + +
@push('scripts') - + @endpush -
+
- @endcan -
-
-
- - - -
- @push('scripts') - - @endpush -
-
-
-
- - - - - - @can('assignLabels', App\Models\Ticket::class) - - @endcan - @if(Auth::user()->isAdmin()) - +
+
- #  - @include('modules.sorter', ['colname' => 'id']) - - {{__('Type') }}  - @include('modules.sorter', ['colname' => 'type']) - {{ __('Étiquettes') }} - {{__('Assigné à') }}  - @include('modules.sorter', ['colname' => 'assigned_to']) -
+ + + + + + @can('assignLabels', App\Models\Ticket::class) + + @endcan + @if (Auth::user()->isAdmin()) + + @endif + + + + + + @if (!count($tickets)) + + + @endif - - - - - - - @if(!count($tickets)) - - - - @endif - @foreach ($tickets as $ticket) - - - - @can('assignLabels', App\Models\Ticket::class) - - @endcan - @if(Auth::user()->isAdmin()) - - @endif - - - + + + + @can('assignLabels', App\Models\Ticket::class) + + @endcan + @if (Auth::user()->isAdmin()) + + @endif + + - - @endforeach - -
+ #  + @include('modules.sorter', ['colname' => 'id']) + + {{ __('Titre') }}  + @include('modules.sorter', ['colname' => 'title']) + + {{ __('Type') }}  + @include('modules.sorter', ['colname' => 'type']) + {{ __('Étiquettes') }} + {{ __('Assigné à') }}  + @include('modules.sorter', ['colname' => 'assigned_to']) + + {{ __('Le') }}  + @include('modules.sorter', ['colname' => 'created_at']) +
+

{{ __('Aucun ticket') }}

+
- {{__('Créé par') }}  - @include('modules.sorter', ['colname' => 'created_by']) - - {{__('Le') }}  - @include('modules.sorter', ['colname' => 'created_at']) -
-

{{ __('Aucun ticket') }}

-
-
- {{ $ticket->id }}  @if($ticket->is_internal)@endif - - @if (Auth::user()->isAdmin()) - {{ $ticket->site->name }} - @else - {{ $ticket->site->name }} - @endif - {{ $ticket->status->label() }} - -
-
- {{ $ticket->type->label() }} - - - @foreach ($ticket->labels as $label) - {{ $label->name }} - @endforeach - - {{ $ticket->assignedUser ? $ticket->assignedUser->name : __('Personne') }}{{ $ticket->user ? $ticket->user->name : __('Utilisateur supprimé') }}{{ Carbon\Carbon::parse($ticket->created_at)->format('d/m/Y à H:i') }} -
-
-
- @if ($ticket->file !== null) - - @endif - @if ($ticket->file2 !== null) - - @endif - {{-- Modal du ticket --}} - - - - @if(auth()->user()->isAdmin()) - - @endif - @can('changeStatus', $ticket) - @if(!$ticket->status->equals(\App\Enums\Tickets\TicketStatusEnum::archived)) -
- @method('PUT') - @csrf - -
- @endif - @endcan + @foreach ($tickets as $ticket) +
+
+ {{ $ticket->id }}  @if ($ticket->is_internal) + + @endif + + + @if (Auth::user()->isAdmin()) + {{ $ticket->site->name }} + @else + {{ $ticket->site->name }} + @endif + {{ $ticket->status->label() }} +
- - - -
+ {{ $ticket->title }} + + {{ $ticket->type->label() }} + + + @foreach ($ticket->labels as $label) + {{ $label->name }} + @endforeach + + {{ $ticket->assignedUser ? $ticket->assignedUser->name : __('Personne') }}{{ Carbon\Carbon::parse($ticket->created_at)->format('d/m/Y à H:i') }} +
+
+
+ @if ($ticket->file !== null) + + @endif + @if ($ticket->file2 !== null) + + @endif + {{-- Modal du ticket --}} + + + + @if (auth()->user()->isAdmin()) + + @endif + @can('changeStatus', $ticket) + @if (!$ticket->status->equals(\App\Enums\Tickets\TicketStatusEnum::archived)) +
+ @method('PUT') + @csrf + +
@endif -  -  - - {{$ticket->type->label()}} - - - -
- -
-
- -
- {{ $tickets->withQueryString()->links() }} + + + + + @endforeach + + + {{ $tickets->withQueryString()->links() }} +
-
@endsection diff --git a/resources/views/bo/pages/tickets/show.blade.php b/resources/views/bo/pages/tickets/show.blade.php index a54c92c..99618a6 100644 --- a/resources/views/bo/pages/tickets/show.blade.php +++ b/resources/views/bo/pages/tickets/show.blade.php @@ -5,167 +5,253 @@ @section('bodyClass', 'content ticketsShow') @section('content') -
-

- - {{ $ticket->full_name }} - @if ($ticket->is_internal)@endif - {{ $ticket->type->label() }} -

-
- @can('suscribeToTicket', $ticket) -
- @csrf -
- - -
- @push('scripts') - - @endpush -
- @endcan - @can('assignTo', $ticket) -
- @csrf -
- - - @push('scripts') - - @endpush -
-
- @endcan - @can('changeStatus', $ticket) -
- @csrf -
- - - @push('scripts') - - @endpush -
-
- @endcan - @if($ticket->status->equals(\App\Enums\Tickets\TicketStatusEnum::archived)) - @can('reopen', $ticket) -
- @csrf - -
- @endcan - @endif -
-
-@can('assignLabels', App\Models\Ticket::class) -
-
- @foreach ($ticket->labels as $label) - {{ $label->name }} - @endforeach -
-
-@endcan -
-@if($ticket->estimation) -@include('estimations.pendingCard', ['ticket' => $ticket, 'estimation' => $ticket->estimation]) -
-@endif -
-

- {{ __('Suivi') }} - @can('createMessage', $ticket) - -

- @foreach ($messages as $message) - @if ( - $message->type->equals(\App\Enums\MessageTypeEnum::public) || - (Auth::user()->can('createPrivateMessage', $ticket)) - ) - @if ($message->user_id === null) -
- {!! nl2br(clean($message->message)) !!} - Le {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i')}} - ({{ __('Message système') }}) + @endcan +
+ @if ($ticket->estimation) + @include('estimations.pendingCard', ['ticket' => $ticket, 'estimation' => $ticket->estimation]) +
+ @endif +
+

+ {{ __('Suivi') }} + @can('createMessage', $ticket) + + + @endcan + @can('estimate', $ticket) + {{ __('Estimation') }} + @endcan +

+ @foreach ($messages as $message) + @if ($message->type->equals(\App\Enums\MessageTypeEnum::public) || Auth::user()->can('createPrivateMessage', $ticket)) + @if ($message->user_id === null) +
+ {!! nl2br(clean($message->message)) !!} - Le + {{ \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i') }} + ({{ __('Message système') }}) +
+ @else +
+ @if ($message->type->equals(\App\Enums\MessageTypeEnum::private)) +    + @endif + {!! \App\Lib\Helpers\ToolboxHelper::plainToHtml($message->message) !!} + @if ($message->file !== null) +
file)) data-fslightbox="gallery" @endif + target="_blank">Ouvrir la pièce jointe
+ @endif +

+ + {!! __('Créé le :date par :userName', [ + 'date' => \Carbon\Carbon::parse($message->created_at)->format('d/m/Y à H:i'), + 'userName' => $message->user ? $message->user->name : __('Utilisateur supprimé'), + ]) !!} + + @if ($message->user_id === Auth::user()->id) + @can('updateMessage', $ticket, $message) + + + @endcan + @endif +
+ @endif + @endif + @endforeach +
+
+
+

{{ __('Description') }}

+

{!! clean(\App\Lib\Helpers\ToolboxHelper::plainToHtml($ticket->text)) !!}

+ {!! __('Créé le :date par :userName', [ + 'date' => \Carbon\Carbon::parse($ticket->created_at)->format('d/m/Y à H:i'), + 'userName' => $ticket->user ? $ticket->user->name : __('Utilisateur supprimé'), + ]) !!}
@else
@@ -220,56 +306,21 @@
+ @endif + @can('createGitlabIssue', $ticket) +
+ @csrf + +
+ @else + @can('isAdmin') + @if (!\is_null($ticket->gitlab_issue)) +
+

+ {{ __("Lien vers l'issue Gitlab : ") }} + {{ __('Ouvrir') }} +

+ @endif @endcan - @endif -
- @endif - @endif - @endforeach -
-
-
-

{{__('Description') }}

-

{!! clean(\App\Lib\Helpers\ToolboxHelper::plainToHtml($ticket->text)) !!}

- {!! __('Créé le :date par :userName', [ - 'date' => \Carbon\Carbon::parse($ticket->created_at)->format('d/m/Y à H:i'), - 'userName' => $ticket->user ? $ticket->user->name : __('Utilisateur supprimé') - ]) !!} -
-@if (!is_null($ticket->file) or !is_null($ticket->file2)) -
-
-

{{ __('Pièces jointes') }}

- -
-@endif -@can('createGitlabIssue', $ticket) -
- @csrf - -
-@else - @can('isAdmin') - @if (!\is_null($ticket->gitlab_issue)) -
-

- {{ __("Lien vers l'issue Gitlab : ")}} - {{ __("Ouvrir") }} -

- @endif - @endcan -@endcan -@endsection + @endcan + @endsection