Merge branch 'issue-23' into 'develop'

add last_activity field on ticket - issue #23

See merge request ldc-web/projets/support-web!55
This commit is contained in:
Vincent BRIDIER 2023-08-14 14:15:14 +00:00
commit 773a4b6cb2
6 changed files with 53 additions and 6 deletions

View file

@ -541,7 +541,7 @@ class TicketController extends Controller
Session::get('tickets.sort_way')
);
} else {
$tickets->orderBy('id', 'DESC');
$tickets->orderBy('last_activity', 'DESC');
}
return $tickets;
}

View file

@ -51,7 +51,9 @@ class Message extends Model
$q->withTrashed();
}]);
/** @var \App\Models\Ticket $ticket */
$ticket = $message->ticket;
$ticket = $message->ticket;
$ticket->last_activity = $message->updated_at;
$ticket->saveQuietly();
if ($message->user) {
$ticket->load(['user' => function ($q) {
$q->withTrashed();

View file

@ -33,7 +33,8 @@ class Ticket extends Model
'type',
'status',
'text',
'is_internal'
'is_internal',
'last_activity',
];
/**
@ -44,7 +45,8 @@ class Ticket extends Model
protected $casts = [
'is_internal' => 'bool',
'type' => TicketTypeEnum::class,
'status' => TicketStatusEnum::class
'status' => TicketStatusEnum::class,
'last_activity' => 'timestamp',
];
/**

View file

@ -0,0 +1,43 @@
<?php
use App\Models\Ticket;
use Carbon\Carbon;
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(): void
{
Schema::table('tickets', function (Blueprint $table) {
$table->timestamp('last_activity')
->default(Carbon::now())
->comment('Last activity on the ticket.')
->after('is_internal');
});
Ticket::get()->map(function (object $ticket) {
$lastMessage = $ticket->messages->whereNotNull('user_id')->sortByDesc('updated_at')->first();
$ticket->last_activity =
$lastMessage->updated_at ?? $ticket->updated_at;
$ticket->saveQuietly();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('tickets', function (Blueprint $table) {
$table->dropColumn('last_activity');
});
}
};

View file

@ -31,7 +31,7 @@
@foreach (\App\Enums\ItemsPerPaginationEnum::toArray() as $itemsPerPaginationEnum)
<li>
<a class="dropdown-item text-center user-select-none @if($pagination === $itemsPerPaginationEnum->value) active @endif"
href="{{ request()->fullUrlWithQuery(['pagination' => $itemsPerPaginationEnum->value]) . $queryString }}"
href="{{ request()->fullUrlWithQuery(['page' => 1, 'pagination' => $itemsPerPaginationEnum->value]) . $queryString }}"
role="button">
{{ $itemsPerPaginationEnum->value }}
</a>

View file

@ -172,7 +172,7 @@ $userPr = Auth::user()->sites ?? collect([]);
<td>
<span class="ticket-index-labels">
@foreach ($ticket->labels as $label)
<span class="badge label colorize" data-color="{{ $label->color }}">{{ $label->name }}</span>
<span class="badge label colorize" data-color="{{ $label->color }}">{{ $label->name }}</span>
@endforeach
</span>
</td>