You've already forked isop-mirror
feat: add agreement and report download functionality to InternshipController and related components
This commit is contained in:
@@ -135,6 +135,56 @@ class InternshipController extends Controller
|
||||
return response()->json($internship);
|
||||
}
|
||||
|
||||
public function get_agreement(int $id) {
|
||||
$user = auth()->user();
|
||||
$internship = Internship::find($id);
|
||||
|
||||
if(!$internship) {
|
||||
return response()->json([
|
||||
'message' => 'No such internship exists.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if(!$internship->agreement) {
|
||||
return response()->json([
|
||||
'message' => 'No agreement file exists for this internship.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
if($user->role !== 'ADMIN' && $internship->user_id !== $user->id && $user->id !== $internship->company->contact) {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
|
||||
return response($internship->agreement, 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'attachment; filename="agreement_' . $id . '.pdf"');
|
||||
}
|
||||
|
||||
public function get_report(int $id) {
|
||||
$user = auth()->user();
|
||||
$internship = Internship::find($id);
|
||||
|
||||
if(!$internship) {
|
||||
return response()->json([
|
||||
'message' => 'No such internship exists.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if(!$internship->report) {
|
||||
return response()->json([
|
||||
'message' => 'No report file exists for this internship.'
|
||||
], 404);
|
||||
}
|
||||
|
||||
if($user->role !== 'ADMIN' && $internship->user_id !== $user->id && $user->id !== $internship->company->contact) {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
|
||||
return response($internship->report, 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'attachment; filename="report_' . $id . '.pdf"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,8 @@ Route::prefix('/internships')->group(function () {
|
||||
Route::put("/status", [InternshipStatusController::class, 'update'])->name("api.internships.status.update");
|
||||
Route::get("/statuses", [InternshipStatusController::class, 'get'])->name("api.internships.get");
|
||||
Route::get("/next-statuses", [InternshipStatusController::class, 'get_next_states'])->name("api.internships.status.next.get");
|
||||
Route::get("/agreement", [InternshipController::class, 'get_agreement'])->name("api.internships.agreement.get");
|
||||
Route::get("/report", [InternshipController::class, 'get_report'])->name("api.internships.report.get");
|
||||
Route::post("/documents", [InternshipController::class, 'update_documents'])->name("api.internships.documents.set");
|
||||
Route::post("/basic", [InternshipController::class, 'update_basic'])->name("api.internships.update.basic");
|
||||
});
|
||||
|
||||
@@ -25,6 +25,26 @@ const report_confirmed = ref(props.internship.report_confirmed);
|
||||
const client = useSanctumClient();
|
||||
const user = useSanctumUser<User>();
|
||||
|
||||
function triggerDownload(file: Blob, file_name: string) {
|
||||
const url = window.URL.createObjectURL(file);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `${file_name}.pdf`;
|
||||
link.target = "_blank";
|
||||
link.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function downloadAgreement() {
|
||||
const agreement: Blob = await client(`/api/internships/${props.internship.id}/agreement`);
|
||||
triggerDownload(agreement, `agreement-${props.internship.id}`);
|
||||
}
|
||||
|
||||
async function downloadReport() {
|
||||
const report: Blob = await client(`/api/internships/${props.internship.id}/report`);
|
||||
triggerDownload(report, `report-${props.internship.id}`);
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
error.value = null;
|
||||
loading.value = true;
|
||||
@@ -72,7 +92,14 @@ async function onSubmit() {
|
||||
|
||||
<v-alert v-if="props.internship.agreement" class="mb-2" type="warning" variant="tonal"
|
||||
title="Existujúci dokument"
|
||||
text="V systéme je už nahratá zmluva/dohoda. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené." />
|
||||
text="V systéme je už nahratá zmluva/dohoda. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené.">
|
||||
|
||||
<br />
|
||||
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" @click="downloadAgreement">
|
||||
Stiahnuť
|
||||
</v-btn>
|
||||
</v-alert>
|
||||
|
||||
<v-file-input v-model="agreement" :rules="[rules.isPdf, rules.maxSize]" accept=".pdf,application/pdf"
|
||||
prepend-icon="mdi-handshake" label="Nahrať PDF zmluvu" variant="outlined" show-size clearable
|
||||
@@ -86,18 +113,28 @@ async function onSubmit() {
|
||||
|
||||
<v-alert v-if="props.internship.report" class="mb-2" type="warning" variant="tonal"
|
||||
title="Existujúci dokument"
|
||||
text="V systéme je už nahratý výkaz. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené." />
|
||||
text="V systéme je už nahratý výkaz. Ak chcete nahradiť existujúcu verziu, vyberte súbor, alebo v opačnom prípade nechajte toto pole nevyplnené.">
|
||||
|
||||
<br />
|
||||
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" @click="downloadReport">
|
||||
Stiahnuť
|
||||
</v-btn>
|
||||
</v-alert>
|
||||
|
||||
<v-file-input v-model="report" :rules="[rules.isPdf, rules.maxSize]" accept=".pdf,application/pdf"
|
||||
prepend-icon="mdi-chart-box-outline" label="Nahrať PDF výkaz" variant="outlined" show-size clearable
|
||||
hint="Povolené: PDF, max 10 MB" persistent-hint />
|
||||
|
||||
<v-checkbox v-if="user?.role === Role.EMPLOYER" :disabled="!props.internship.agreement || !props.internship.report" v-model="report_confirmed" label="Výkaz je správny"></v-checkbox>
|
||||
|
||||
<v-checkbox v-if="user?.role === Role.EMPLOYER"
|
||||
:disabled="!props.internship.agreement || !props.internship.report" v-model="report_confirmed"
|
||||
label="Výkaz je správny"></v-checkbox>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
||||
<v-btn type="submit" color="success" size="large" block :disabled="!agreement && !report && (!props.internship.agreement || !props.internship.report)">
|
||||
<v-btn type="submit" color="success" size="large" block
|
||||
:disabled="!agreement && !report && (!props.internship.agreement || !props.internship.report)">
|
||||
Uloziť
|
||||
</v-btn>
|
||||
</v-form>
|
||||
|
||||
@@ -4,6 +4,28 @@ import type { Internship } from '~/types/internships';
|
||||
const props = defineProps<{
|
||||
internship: Internship
|
||||
}>();
|
||||
|
||||
const client = useSanctumClient();
|
||||
|
||||
function triggerDownload(file: Blob, file_name: string) {
|
||||
const url = window.URL.createObjectURL(file);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `${file_name}.pdf`;
|
||||
link.target = "_blank";
|
||||
link.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async function downloadAgreement() {
|
||||
const agreement: Blob = await client(`/api/internships/${props.internship.id}/agreement`);
|
||||
triggerDownload(agreement, `agreement-${props.internship.id}`);
|
||||
}
|
||||
|
||||
async function downloadReport() {
|
||||
const report: Blob = await client(`/api/internships/${props.internship.id}/report`);
|
||||
triggerDownload(report, `report-${props.internship.id}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -23,7 +45,8 @@ const props = defineProps<{
|
||||
<div v-else>
|
||||
<v-alert type="success" variant="tonal" title="Odovzdané" text="Zmluva bola nahratá." />
|
||||
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" to="/" block>
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" block
|
||||
@click="downloadAgreement">
|
||||
Stiahnuť
|
||||
</v-btn>
|
||||
</div>
|
||||
@@ -49,7 +72,8 @@ const props = defineProps<{
|
||||
<v-alert v-else type="success" variant="tonal" title="Potvrdené"
|
||||
text="Výkaz bol nahratý, aj potvrdený firmou." />
|
||||
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" to="/" block>
|
||||
<v-btn prepend-icon="mdi-download" color="blue" class="mr-2 mt-2" block
|
||||
@click="downloadReport">
|
||||
Stiahnuť
|
||||
</v-btn>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user