Feat: Responses table for coordinator
This commit is contained in:
@@ -3,6 +3,9 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use App\Models\Response;
|
||||||
|
|
||||||
class CoordinatorController extends Controller
|
class CoordinatorController extends Controller
|
||||||
{
|
{
|
||||||
@@ -15,10 +18,49 @@ class CoordinatorController extends Controller
|
|||||||
// View responses submitted by users
|
// View responses submitted by users
|
||||||
public function viewResponses()
|
public function viewResponses()
|
||||||
{
|
{
|
||||||
// Logic to fetch responses for Coordinator
|
|
||||||
// $responses = Response::where('department_id', auth()->user()->department_id)->get(); // Example query
|
|
||||||
|
|
||||||
// return view('coordinator.responses', compact('responses'));
|
|
||||||
return view('coordinator.responses');
|
return view('coordinator.responses');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getResponses()
|
||||||
|
{
|
||||||
|
// Get the current logged-in user
|
||||||
|
$currentUser = Auth::user();
|
||||||
|
|
||||||
|
// Get the department ID of the current user
|
||||||
|
$userDepartmentId = $currentUser->department->id ?? null;
|
||||||
|
|
||||||
|
// Fetch the responses and filter by department_id
|
||||||
|
$responses = Response::with('user', 'department')
|
||||||
|
->where('department_id', $userDepartmentId); // Filter by current user's department_id
|
||||||
|
|
||||||
|
return DataTables::of($responses)
|
||||||
|
->addColumn('user_name', function ($response) {
|
||||||
|
return $response->user->name ?? 'Unknown';
|
||||||
|
})
|
||||||
|
->addColumn('department_name', function ($response) {
|
||||||
|
return $response->department->name ?? 'Unknown';
|
||||||
|
})
|
||||||
|
->addColumn('start_date', function ($response) {
|
||||||
|
return \Carbon\Carbon::parse($response->start_date)->format('d-m-Y');
|
||||||
|
})
|
||||||
|
->addColumn('start_time', function ($response) {
|
||||||
|
return \Carbon\Carbon::parse($response->start_date)->format('h:i A');
|
||||||
|
})
|
||||||
|
->addColumn('end_date', function ($response) {
|
||||||
|
return \Carbon\Carbon::parse($response->end_date)->format('d-m-Y');
|
||||||
|
})
|
||||||
|
->addColumn('end_time', function ($response) {
|
||||||
|
return \Carbon\Carbon::parse($response->end_date)->format('h:i A');
|
||||||
|
})
|
||||||
|
->addColumn('action', function ($response) {
|
||||||
|
$viewButton = $response->proof
|
||||||
|
? '<a href="' . asset('storage/' . $response->proof) . '" target="_blank" class="btn btn-sm btn-primary">View</a>'
|
||||||
|
: 'No Proof';
|
||||||
|
return $viewButton;
|
||||||
|
})
|
||||||
|
->rawColumns(['action'])
|
||||||
|
->make(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="max-w-full mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
<div class="bg-white overflow-hidden shadow sm:rounded-lg">
|
||||||
|
<div class="px-4 py-5 sm:px-6">
|
||||||
|
<h3 class="text-xl leading-6 font-semibold text-gray-900">
|
||||||
|
All Responses
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="px-4 py-5 sm:px-6">
|
||||||
|
<!-- <div class="overflow-x-auto w-full"> -->
|
||||||
|
<div class="overflow-x-auto w-full max-w-screen-lg mx-auto">
|
||||||
|
<table id="responses-table" class="table-auto w-full table-striped border-collapse border border-gray-200 rounded-lg">
|
||||||
|
<thead class="bg-gray-100">
|
||||||
|
<tr>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">ID</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Title</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Organising Institute</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Address</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Department</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Faculty</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Start Date</th>
|
||||||
|
<!-- <th class="px-4 py-2 border border-gray-200">Start Time</th> -->
|
||||||
|
<th class="px-4 py-2 border border-gray-200">End Date</th>
|
||||||
|
<!-- <th class="px-4 py-2 border border-gray-200">End Time</th> -->
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Num Days</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Activity Type</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Category</th>
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Level</th>
|
||||||
|
<!-- <th class="px-4 py-2 border border-gray-200">Faculty</th> -->
|
||||||
|
<th class="px-4 py-2 border border-gray-200">Proof</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@section('scripts')
|
||||||
|
<!-- DataTables JS -->
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.1/css/dataTables.bootstrap5.min.css">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.13.1/js/dataTables.bootstrap5.min.js"></script>
|
||||||
|
|
||||||
|
<!-- <link rel="stylesheet" href="https://cdn.datatables.net/1.12.1/css/dataTables.bootstrap5.min.css">
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js"></script> -->
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var initAjaxRoute = function(route) {
|
||||||
|
table = $("#responses-table").DataTable({
|
||||||
|
fnDestroy: true,
|
||||||
|
processing: true,
|
||||||
|
serverSide: true,
|
||||||
|
responsive: true,
|
||||||
|
ajax: {
|
||||||
|
url: route,
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{ data: 'id', name: 'id', },
|
||||||
|
{ data: 'title', name: 'title', orderable: false},
|
||||||
|
{ data: 'organising_institute', name: 'organising_institute', orderable: false },
|
||||||
|
{ data: 'address', name: 'address' , orderable: false},
|
||||||
|
{ data: 'department_name', name: 'department' , orderable: false},
|
||||||
|
{ data: 'user_name', name: 'user_name', orderable: false },
|
||||||
|
{ data: 'start_date', name: 'start_date', orderable: false },
|
||||||
|
// { data: 'start_time', name: 'start_time', orderable: false },
|
||||||
|
{ data: 'end_date', name: 'end_date', orderable: false },
|
||||||
|
// { data: 'end_time', name: 'end_time', orderable: false },
|
||||||
|
{ data: 'num_days', name: 'num_days', orderable: false },
|
||||||
|
{ data: 'activity_type', name: 'activity_type', orderable: false },
|
||||||
|
{ data: 'category', name: 'category', orderable: false },
|
||||||
|
{ data: 'level', name: 'level', orderable: false },
|
||||||
|
{ data: 'action', name: 'proof', orderable: false, searchable: false }, // View button for proof
|
||||||
|
],
|
||||||
|
columnDefs: [
|
||||||
|
{
|
||||||
|
targets: 0,
|
||||||
|
// width: '170px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 1,
|
||||||
|
// width: '150px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 2,
|
||||||
|
// maxWidth: '150px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 3,
|
||||||
|
// maxWidth: '100px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 4,
|
||||||
|
// maxWidth: '300px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 5,
|
||||||
|
// maxWidth: '150px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 6,
|
||||||
|
// maxWidth: '100px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 7,
|
||||||
|
// maxWidth: '100px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 8,
|
||||||
|
// width: '100px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 9,
|
||||||
|
// width: '50px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 10,
|
||||||
|
// width: '120px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: 11,
|
||||||
|
// width: '120px',
|
||||||
|
className: 'text-center wrap-text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// order: [[4, 'asc']],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
initAjaxRoute("{{ route('coordinator.responses.data') }}");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
@endsection
|
||||||
@@ -47,6 +47,7 @@ Route::middleware(['auth', CheckRole::class . ':Admin'])->group(function () {
|
|||||||
Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function () {
|
Route::middleware(['auth', CheckRole::class . ':Coordinator'])->group(function () {
|
||||||
Route::get('/coordinator', [CoordinatorController::class, 'index'])->name('coordinator.dashboard');
|
Route::get('/coordinator', [CoordinatorController::class, 'index'])->name('coordinator.dashboard');
|
||||||
Route::get('/coordinator/responses', [CoordinatorController::class, 'viewResponses'])->name('coordinator.responses');
|
Route::get('/coordinator/responses', [CoordinatorController::class, 'viewResponses'])->name('coordinator.responses');
|
||||||
|
Route::get('/coordinator/responses/data', [CoordinatorController::class, 'getResponses'])->name('coordinator.responses.data');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user