Feat: Reusable download Proof Button
This commit is contained in:
@@ -114,25 +114,6 @@ class ActivitiesAttendedController extends Controller
|
||||
return response()->json(['success' => 'Record deleted successfully']);
|
||||
}
|
||||
|
||||
public function downloadProofs(Request $request, ProofDownloadService $proofDownloadService)
|
||||
{
|
||||
// Validate the request
|
||||
$request->validate([
|
||||
'ids' => 'required|string',
|
||||
]);
|
||||
|
||||
$ids = json_decode($request->input('ids'));
|
||||
|
||||
$result = $proofDownloadService->downloadProofs(ActivitiesAttended::class, $ids);
|
||||
|
||||
if (isset($result['error'])) {
|
||||
return back()->with('error', $result['error']);
|
||||
}
|
||||
|
||||
// Return the zip file as a download
|
||||
return response()->download($result['filePath'], $result['fileName'])->deleteFileAfterSend(true);
|
||||
}
|
||||
|
||||
public function getActivitiesAttendedResponses(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Models\IvOrganised;
|
||||
use App\Models\OnlineCourse;
|
||||
use App\Models\Patent;
|
||||
use App\Models\Publication;
|
||||
use App\Services\ProofDownloadService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AdminController extends Controller
|
||||
@@ -69,6 +70,43 @@ class AdminController extends Controller
|
||||
{
|
||||
return view('pages.patents.index');
|
||||
}
|
||||
|
||||
public function downloadProofs(Request $request, ProofDownloadService $proofDownloadService)
|
||||
{
|
||||
// Validate the request
|
||||
$request->validate([
|
||||
'ids' => 'required|string',
|
||||
'model' => 'sometimes|string',
|
||||
]);
|
||||
|
||||
$ids = json_decode($request->input('ids'));
|
||||
$modelName = $request->input('model', 'ActivitiesAttended');
|
||||
|
||||
// Model mapping
|
||||
$modelMap = [
|
||||
'ActivitiesAttended' => ActivitiesAttended::class,
|
||||
'ActivitiesOrganised' => ActivitiesOrganised::class,
|
||||
'IvOrganised' => IvOrganised::class,
|
||||
'Publication' => Publication::class,
|
||||
'BooksPublished' => BooksPublished::class,
|
||||
'ExternalEngagement' => ExternalEngagement::class,
|
||||
'OnlineCourse' => OnlineCourse::class,
|
||||
'Patent' => Patent::class,
|
||||
];
|
||||
|
||||
// Get the model class from the map or default to ActivitiesAttended
|
||||
$modelClass = $modelMap[$modelName] ?? ActivitiesAttended::class;
|
||||
|
||||
$result = $proofDownloadService->downloadProofs($modelClass, $ids);
|
||||
|
||||
if (isset($result['error'])) {
|
||||
return back()->with('error', $result['error']);
|
||||
}
|
||||
|
||||
// Return the zip file as a download
|
||||
return response()->download($result['filePath'], $result['fileName'])->deleteFileAfterSend(true);
|
||||
}
|
||||
|
||||
public function analyticsActivitiesAttended()
|
||||
{
|
||||
$data = ActivitiesAttended::selectRaw('departments.name as department, COUNT(*) as count')
|
||||
|
||||
@@ -33,6 +33,12 @@
|
||||
idsInput.value = JSON.stringify(selectedIds);
|
||||
form.appendChild(idsInput);
|
||||
|
||||
const modelInput = document.createElement('input');
|
||||
modelInput.type = 'hidden';
|
||||
modelInput.name = 'model';
|
||||
modelInput.value = "{{ $model ?? 'ActivitiesAttended' }}";
|
||||
form.appendChild(modelInput);
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
} else {
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<!-- Column Selector -->
|
||||
<div class="flex justify-between col-md-12 mt-3 mb-4">
|
||||
<!-- Include the reusable download-proofs component -->
|
||||
<x-download-proofs :route="route('activitiesAttended.downloadProofs')" />
|
||||
<x-download-proofs :route="route('admin.downloadProofs')" :model="'ActivitiesAttended'" />
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-danger dropdown-toggle" type="button" id="columnSelectorDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="fas fa-columns me-1"></i> Customize Columns
|
||||
@@ -268,7 +268,8 @@
|
||||
@section('scripts')
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js" integrity="sha512-Tn2m0TIpgVyTzzvmxLNuqbSJH3JP8jm+Cy3hvHrW7ndTDcJ1w5mBiksqDBb8GpE2ksktFvDB/ykZ0mDpsZj20w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||||
<script>
|
||||
const downloadProofsRoute = "{{ route('activitiesAttended.downloadProofs') }}";
|
||||
const downloadProofsRoute = "{{ route('admin.downloadProofs') }}";
|
||||
const currentModel = "{{ isset($model) ? $model : 'ActivitiesAttended' }}";
|
||||
const csrf_token = "{{ csrf_token() }}";
|
||||
$(document).ready(function() {
|
||||
// Handle "Select All" checkbox
|
||||
@@ -583,6 +584,13 @@
|
||||
.attr('value', JSON.stringify(selectedIds))
|
||||
.appendTo(form);
|
||||
|
||||
// Add model name
|
||||
$('<input>')
|
||||
.attr('type', 'hidden')
|
||||
.attr('name', 'model')
|
||||
.attr('value', currentModel)
|
||||
.appendTo(form);
|
||||
|
||||
$('body').append(form);
|
||||
form.submit();
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ Route::prefix('admin')->name('admin.')->group(function () {
|
||||
Route::get('analytics/contribution', [AdminController::class, 'analyticsContribution'])->name('analytics.contribution');
|
||||
});
|
||||
|
||||
Route::post('/activities-attended/download-proofs', [ActivitiesAttendedController::class, 'downloadProofs'])->name('activitiesAttended.downloadProofs');
|
||||
Route::post('/admin/download-proofs', [AdminController::class, 'downloadProofs'])->name('admin.downloadProofs');
|
||||
|
||||
// Google Login Route
|
||||
Route::get('/auth/google', [App\Http\Controllers\Auth\GoogleController::class, 'redirectToGoogle'])->name('google.login');
|
||||
|
||||
Reference in New Issue
Block a user