Browse Source

Added latest tickets to admin overview

ok236449 2 năm trước cách đây
mục cha
commit
4871272670

+ 31 - 1
app/Http/Controllers/Admin/OverViewController.php

@@ -13,6 +13,7 @@ use App\Models\User;
 use Illuminate\Support\Facades\Cache;
 use App\Classes\Pterodactyl;
 use App\Models\Product;
+use App\Models\Ticket;
 use Carbon\Carbon;
 
 class OverViewController extends Controller
@@ -117,12 +118,41 @@ class OverViewController extends Controller
             }
             return $output;
         });
+
+        $tickets = Cache::remember('tickets', self::TTL, function(){
+            $output = collect();
+            foreach(Ticket::query()->latest()->take(3)->get() as $ticket){
+                $output->put($ticket->ticket_id, collect());
+                $output[$ticket->ticket_id]->title = $ticket->title;
+                $user = User::query()->where('id', $ticket->user_id)->first();
+                $output[$ticket->ticket_id]->user_id = $user->id;
+                $output[$ticket->ticket_id]->user = $user->name;
+                $output[$ticket->ticket_id]->status = $ticket->status;
+                $output[$ticket->ticket_id]->last_updated = $ticket->updated_at->diffForHumans();
+                switch ($ticket->status) {
+                    case 'Open':
+                        $output[$ticket->ticket_id]->statusBadgeColor = 'badge-success';
+                        break;
+                    case 'Closed':
+                        $output[$ticket->ticket_id]->statusBadgeColor = 'badge-danger';
+                        break;
+                    case 'Answered':
+                        $output[$ticket->ticket_id]->statusBadgeColor = 'badge-info';
+                        break;
+                    default:
+                        $output[$ticket->ticket_id]->statusBadgeColor = 'badge-warning';
+                        break;
+                }
+            }
+            return $output;
+        });
         //dd($counters);
         return view('admin.overview.index', [
             'counters'       => $counters,
             'nodes'          => $nodes,
             'syncLastUpdate' => $syncLastUpdate,
-            'perPageLimit'   => ($counters['servers']->total != Server::query()->count())?true:false
+            'perPageLimit'   => ($counters['servers']->total != Server::query()->count())?true:false,
+            'tickets'        => $tickets
         ]);
     }   
 

+ 36 - 0
resources/views/admin/overview/index.blade.php

@@ -142,6 +142,42 @@
                             <span><i class="fas fa-sync mr-2"></i>{{__('Last updated :date', ['date' => $syncLastUpdate])}}</span>
                         </div>
                     </div>
+                    <div class="card">
+                        <div class="card-header">
+                            <div class="d-flex justify-content-between">
+                                <div class="card-title ">
+                                    <span><i class="fas fa-ticket-alt mr-2"></i>{{__('Latest tickets')}}</span>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="card-body py-1">
+                            @if(!$tickets->count())<span style="font-size: 16px; font-weight:700">{{__('There are no tickets')}}.</span>
+                            @else
+                                <table class="table">
+                                    <thead>
+                                    <tr>
+                                        <th>{{__('Title')}}</th>
+                                        <th>{{__('User')}}</th>
+                                        <th>{{__('Status')}}</th>
+                                        <th>{{__('Last updated')}}</th>
+                                    </tr>
+                                    </thead>
+                                    <tbody>
+                                        
+                                        @foreach($tickets as $ticket_id => $ticket)
+                                            <tr>
+                                                <td><a class="text-info"  href="{{route('moderator.ticket.show', ['ticket_id' => $ticket_id])}}">#{{$ticket_id}} - {{$ticket->title}}</td>
+                                                <td><a href="{{route('admin.users.show', $ticket->user_id)}}">{{$ticket->user}}</a></td>
+                                                <td><span class="badge {{$ticket->statusBadgeColor}}">{{$ticket->status}}</span></td>
+                                                <td>{{$ticket->last_updated}}</td>
+                                            </tr>
+                                        @endforeach
+                                        
+                                    </tbody>
+                                </table>
+                            @endif
+                        </div>
+                    </div>
                     <div class="card">
                         <div class="card-header">
                             <div class="d-flex justify-content-between">