refactored to make training reports linkable
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getTrainingReport, getTrainingReports } from '@/api/trainingReport';
|
import { getTrainingReport, getTrainingReports } from '@/api/trainingReport';
|
||||||
import { CourseAttendee, CourseEventDetails, CourseEventSummary } from '@shared/types/course';
|
import { CourseAttendee, CourseEventDetails, CourseEventSummary } from '@shared/types/course';
|
||||||
import { computed, onMounted, ref } from 'vue';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -14,12 +14,30 @@ import { Plus, X } from 'lucide-vue-next';
|
|||||||
import Button from '@/components/ui/button/Button.vue';
|
import Button from '@/components/ui/button/Button.vue';
|
||||||
import TrainingReportForm from '@/components/trainingReport/trainingReportForm.vue';
|
import TrainingReportForm from '@/components/trainingReport/trainingReportForm.vue';
|
||||||
import Checkbox from '@/components/ui/checkbox/Checkbox.vue';
|
import Checkbox from '@/components/ui/checkbox/Checkbox.vue';
|
||||||
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
enum sidePanelState { view, create, closed };
|
enum sidePanelState { view, create, closed };
|
||||||
|
|
||||||
const trainingReports = ref<CourseEventSummary[] | null>(null);
|
const trainingReports = ref<CourseEventSummary[] | null>(null);
|
||||||
const loaded = ref(false);
|
const loaded = ref(false);
|
||||||
|
|
||||||
|
const route = useRoute();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const sidePanel = computed<sidePanelState>(() => {
|
||||||
|
if (route.path.endsWith('/new')) return sidePanelState.create;
|
||||||
|
if (route.params.id) return sidePanelState.view;
|
||||||
|
return sidePanelState.closed;
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => route.params.id, async (newID) => {
|
||||||
|
if (!newID) {
|
||||||
|
focusedTrainingReport.value = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
viewTrainingReport(Number(route.params.id));
|
||||||
|
})
|
||||||
|
|
||||||
const focusedTrainingReport = ref<CourseEventDetails | null>(null);
|
const focusedTrainingReport = ref<CourseEventDetails | null>(null);
|
||||||
const focusedTrainingTrainees = computed<CourseAttendee[] | null>(() => {
|
const focusedTrainingTrainees = computed<CourseAttendee[] | null>(() => {
|
||||||
if (focusedTrainingReport == null) return null;
|
if (focusedTrainingReport == null) return null;
|
||||||
@@ -35,18 +53,11 @@ const focusedTrainingTrainers = computed<CourseAttendee[] | null>(() => {
|
|||||||
})
|
})
|
||||||
async function viewTrainingReport(id: number) {
|
async function viewTrainingReport(id: number) {
|
||||||
focusedTrainingReport.value = await getTrainingReport(id);
|
focusedTrainingReport.value = await getTrainingReport(id);
|
||||||
sidePanel.value = sidePanelState.view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function closeTrainingReport() {
|
async function closeTrainingReport() {
|
||||||
|
router.push(`/trainingReport`)
|
||||||
focusedTrainingReport.value = null;
|
focusedTrainingReport.value = null;
|
||||||
sidePanel.value = sidePanelState.closed;
|
|
||||||
}
|
|
||||||
|
|
||||||
const sidePanel = ref<sidePanelState>(sidePanelState.closed);
|
|
||||||
|
|
||||||
function createTrainingReport() {
|
|
||||||
sidePanel.value = sidePanelState.create;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadTrainingReports() {
|
async function loadTrainingReports() {
|
||||||
@@ -55,6 +66,8 @@ async function loadTrainingReports() {
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
loadTrainingReports();
|
loadTrainingReports();
|
||||||
|
if (route.params.id)
|
||||||
|
viewTrainingReport(Number(route.params.id))
|
||||||
loaded.value = true;
|
loaded.value = true;
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -65,7 +78,7 @@ onMounted(async () => {
|
|||||||
<div class="px-4 my-3" :class="sidePanel == sidePanelState.closed ? 'w-full' : 'w-2/5'">
|
<div class="px-4 my-3" :class="sidePanel == sidePanelState.closed ? 'w-full' : 'w-2/5'">
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Reports</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Reports</p>
|
||||||
<Button @click="createTrainingReport">
|
<Button @click="router.push('/trainingReport/new')">
|
||||||
<Plus></Plus> New Training Report
|
<Plus></Plus> New Training Report
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -84,12 +97,13 @@ onMounted(async () => {
|
|||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody v-if="loaded">
|
<TableBody v-if="loaded">
|
||||||
<TableRow class="cursor-pointer" v-for="report in trainingReports" :key="report.event_id"
|
<TableRow class="cursor-pointer" v-for="report in trainingReports" :key="report.event_id"
|
||||||
@click="viewTrainingReport(report.event_id);">
|
@click="router.push(`/trainingReport/${report.event_id}`)">
|
||||||
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname : report.course_name }}</TableCell>
|
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
||||||
|
report.course_name }}</TableCell>
|
||||||
<TableCell>{{ report.date }}</TableCell>
|
<TableCell>{{ report.date }}</TableCell>
|
||||||
<TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
<TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
||||||
report.created_by_name
|
report.created_by_name
|
||||||
}}</TableCell>
|
}}</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
@@ -109,7 +123,7 @@ onMounted(async () => {
|
|||||||
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date }}</p>
|
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date }}</p>
|
||||||
<p class="">Created by {{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
<p class="">Created by {{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
||||||
focusedTrainingReport.created_by_name
|
focusedTrainingReport.created_by_name
|
||||||
}}
|
}}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,7 +141,9 @@ onMounted(async () => {
|
|||||||
class="grid grid-cols-4 py-2 items-center border-b last:border-none">
|
class="grid grid-cols-4 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<p>{{ person.attendee_name }}</p>
|
||||||
<p class="">{{ person.role.name }}</p>
|
<p class="">{{ person.role.name }}</p>
|
||||||
<p class="col-span-2 text-right px-2" :class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--' : person.remarks }}</p>
|
<p class="col-span-2 text-right px-2"
|
||||||
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--'
|
||||||
|
: person.remarks }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- trainees -->
|
<!-- trainees -->
|
||||||
@@ -141,13 +157,18 @@ onMounted(async () => {
|
|||||||
<span class="text-right col-span-2">Remarks</span>
|
<span class="text-right col-span-2">Remarks</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedTrainingTrainees" class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
<div v-for="person in focusedTrainingTrainees"
|
||||||
|
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<p>{{ person.attendee_name }}</p>
|
||||||
<Checkbox :disabled="!focusedTrainingReport.course.hasQual" :default-value="person.passed_bookwork ? true : false" class="pointer-events-none ml-5">
|
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
||||||
|
:default-value="person.passed_bookwork ? true : false" class="pointer-events-none ml-5">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<Checkbox :disabled="!focusedTrainingReport.course.hasQual" :default-value="person.passed_qual ? true : false" class="pointer-events-none ml-1">
|
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
||||||
|
:default-value="person.passed_qual ? true : false" class="pointer-events-none ml-1">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<p class="col-span-2 text-right px-2" :class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--' : person.remarks }}</p>
|
<p class="col-span-2 text-right px-2"
|
||||||
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--'
|
||||||
|
: person.remarks }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- No Shows -->
|
<!-- No Shows -->
|
||||||
@@ -163,7 +184,8 @@ onMounted(async () => {
|
|||||||
<span class="text-right col-span-2">Remarks</span>
|
<span class="text-right col-span-2">Remarks</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedNoShows" class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
<div v-for="person in focusedNoShows"
|
||||||
|
class="grid grid-cols-5 py-2 items-center border-b last:border-none">
|
||||||
<p>{{ person.attendee_name }}</p>
|
<p>{{ person.attendee_name }}</p>
|
||||||
<!-- <Checkbox :default-value="person.passed_bookwork ? true : false" class="pointer-events-none">
|
<!-- <Checkbox :default-value="person.passed_bookwork ? true : false" class="pointer-events-none">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
@@ -171,12 +193,16 @@ onMounted(async () => {
|
|||||||
</Checkbox> -->
|
</Checkbox> -->
|
||||||
<div></div>
|
<div></div>
|
||||||
<div></div>
|
<div></div>
|
||||||
<p class="col-span-2 text-right px-2" :class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--' : person.remarks }}</p>
|
<p class="col-span-2 text-right px-2"
|
||||||
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">{{ person.remarks == "" ? '--'
|
||||||
|
: person.remarks }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Remarks</label>
|
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Remarks</label>
|
||||||
<p class="border bg-muted/50 px-3 py-2 rounded-lg min-h-24 my-2" :class="focusedTrainingReport.remarks == '' ? 'text-muted-foreground' : ''"> {{ focusedTrainingReport.remarks == "" ? 'None' : focusedTrainingReport.remarks }}</p>
|
<p class="border bg-muted/50 px-3 py-2 rounded-lg min-h-24 my-2"
|
||||||
|
:class="focusedTrainingReport.remarks == '' ? 'text-muted-foreground' : ''"> {{
|
||||||
|
focusedTrainingReport.remarks == "" ? 'None' : focusedTrainingReport.remarks }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -191,7 +217,7 @@ onMounted(async () => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
||||||
<TrainingReportForm class="w-full pl-2"
|
<TrainingReportForm class="w-full pl-2"
|
||||||
@submit="(newID) => { viewTrainingReport(newID); loadTrainingReports() }"></TrainingReportForm>
|
@submit="(newID) => { router.push(`/trainingReport/${newID}`); loadTrainingReports() }"></TrainingReportForm>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ const router = createRouter({
|
|||||||
{ path: '/transfer', component: () => import('@/pages/Transfer.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/transfer', component: () => import('@/pages/Transfer.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/calendar', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/calendar', component: () => import('@/pages/Calendar.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
{ path: '/trainingReport', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
{ path: '/trainingReport', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
{ path: '/trainingReport/new', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
{ path: '/trainingReport/:id', component: () => import('@/pages/TrainingReport.vue'), meta: { requiresAuth: true, memberOnly: true } },
|
||||||
|
|
||||||
// ADMIN / STAFF ROUTES
|
// ADMIN / STAFF ROUTES
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user