|
|
|
|
@@ -1,138 +1,141 @@
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCaption,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table"
|
|
|
|
|
import { Badge } from '@/components/ui/badge'
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu"
|
|
|
|
|
import { ChevronDown, ChevronUp, Ellipsis, X } from "lucide-vue-next";
|
|
|
|
|
import { cancelLOA, extendLOA, getAllLOAs, getMyLOAs } from "@/api/loa";
|
|
|
|
|
import { onMounted, ref, computed } from "vue";
|
|
|
|
|
import { LOARequest } from "@shared/types/loa";
|
|
|
|
|
import Dialog from "../ui/dialog/Dialog.vue";
|
|
|
|
|
import DialogTrigger from "../ui/dialog/DialogTrigger.vue";
|
|
|
|
|
import DialogContent from "../ui/dialog/DialogContent.vue";
|
|
|
|
|
import DialogHeader from "../ui/dialog/DialogHeader.vue";
|
|
|
|
|
import DialogTitle from "../ui/dialog/DialogTitle.vue";
|
|
|
|
|
import DialogDescription from "../ui/dialog/DialogDescription.vue";
|
|
|
|
|
import Button from "../ui/button/Button.vue";
|
|
|
|
|
import Calendar from "../ui/calendar/Calendar.vue";
|
|
|
|
|
import {
|
|
|
|
|
CalendarDate,
|
|
|
|
|
getLocalTimeZone,
|
|
|
|
|
} from "@internationalized/date"
|
|
|
|
|
import { el } from "@fullcalendar/core/internal-common";
|
|
|
|
|
import MemberCard from "../members/MemberCard.vue";
|
|
|
|
|
import {
|
|
|
|
|
Pagination,
|
|
|
|
|
PaginationContent,
|
|
|
|
|
PaginationEllipsis,
|
|
|
|
|
PaginationItem,
|
|
|
|
|
PaginationNext,
|
|
|
|
|
PaginationPrevious,
|
|
|
|
|
} from '@/components/ui/pagination'
|
|
|
|
|
import { pagination } from "@shared/types/pagination";
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCaption,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table"
|
|
|
|
|
import { Badge } from '@/components/ui/badge'
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu"
|
|
|
|
|
import { ChevronDown, ChevronUp, Ellipsis, X } from "lucide-vue-next";
|
|
|
|
|
import { adminExtendLOA, cancelLOA, extendLOA, getAllLOAs, getMyLOAs } from "@/api/loa";
|
|
|
|
|
import { onMounted, ref, computed } from "vue";
|
|
|
|
|
import { LOARequest } from "@shared/types/loa";
|
|
|
|
|
import Dialog from "../ui/dialog/Dialog.vue";
|
|
|
|
|
import DialogTrigger from "../ui/dialog/DialogTrigger.vue";
|
|
|
|
|
import DialogContent from "../ui/dialog/DialogContent.vue";
|
|
|
|
|
import DialogHeader from "../ui/dialog/DialogHeader.vue";
|
|
|
|
|
import DialogTitle from "../ui/dialog/DialogTitle.vue";
|
|
|
|
|
import DialogDescription from "../ui/dialog/DialogDescription.vue";
|
|
|
|
|
import Button from "../ui/button/Button.vue";
|
|
|
|
|
import Calendar from "../ui/calendar/Calendar.vue";
|
|
|
|
|
import {
|
|
|
|
|
CalendarDate,
|
|
|
|
|
getLocalTimeZone,
|
|
|
|
|
} from "@internationalized/date"
|
|
|
|
|
import { el } from "@fullcalendar/core/internal-common";
|
|
|
|
|
import MemberCard from "../members/MemberCard.vue";
|
|
|
|
|
import {
|
|
|
|
|
Pagination,
|
|
|
|
|
PaginationContent,
|
|
|
|
|
PaginationEllipsis,
|
|
|
|
|
PaginationItem,
|
|
|
|
|
PaginationNext,
|
|
|
|
|
PaginationPrevious,
|
|
|
|
|
} from '@/components/ui/pagination'
|
|
|
|
|
import { pagination } from "@shared/types/pagination";
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
adminMode?: boolean
|
|
|
|
|
}>()
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
adminMode?: boolean
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const LOAList = ref<LOARequest[]>([]);
|
|
|
|
|
const LOAList = ref<LOARequest[]>([]);
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function loadLOAs() {
|
|
|
|
|
if (props.adminMode) {
|
|
|
|
|
let result = await getAllLOAs(pageNum.value, pageSize.value);
|
|
|
|
|
LOAList.value = result.data;
|
|
|
|
|
pageData.value = result.pagination;
|
|
|
|
|
} else {
|
|
|
|
|
let result = await getMyLOAs(pageNum.value, pageSize.value);
|
|
|
|
|
LOAList.value = result.data;
|
|
|
|
|
pageData.value = result.pagination;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatDate(date: Date): string {
|
|
|
|
|
if (!date) return "";
|
|
|
|
|
date = typeof date === 'string' ? new Date(date) : date;
|
|
|
|
|
return date.toLocaleDateString("en-US", {
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Extended" | "Overdue" | "Closed" {
|
|
|
|
|
if (loa.closed) return "Closed";
|
|
|
|
|
async function loadLOAs() {
|
|
|
|
|
if (props.adminMode) {
|
|
|
|
|
let result = await getAllLOAs(pageNum.value, pageSize.value);
|
|
|
|
|
LOAList.value = result.data;
|
|
|
|
|
pageData.value = result.pagination;
|
|
|
|
|
} else {
|
|
|
|
|
let result = await getMyLOAs(pageNum.value, pageSize.value);
|
|
|
|
|
LOAList.value = result.data;
|
|
|
|
|
pageData.value = result.pagination;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const start = new Date(loa.start_date);
|
|
|
|
|
const end = new Date(loa.end_date);
|
|
|
|
|
const extension = new Date(loa.extended_till);
|
|
|
|
|
function formatDate(date: Date): string {
|
|
|
|
|
if (!date) return "";
|
|
|
|
|
date = typeof date === 'string' ? new Date(date) : date;
|
|
|
|
|
return date.toLocaleDateString("en-US", {
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now < start) return "Upcoming";
|
|
|
|
|
if (now >= start && (now <= end)) return "Active";
|
|
|
|
|
if (now >= start && (now <= extension)) return "Extended";
|
|
|
|
|
if (now > loa.extended_till || end) return "Overdue";
|
|
|
|
|
function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Extended" | "Overdue" | "Closed" {
|
|
|
|
|
if (loa.closed) return "Closed";
|
|
|
|
|
|
|
|
|
|
return "Overdue"; // fallback
|
|
|
|
|
}
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const start = new Date(loa.start_date);
|
|
|
|
|
const end = new Date(loa.end_date);
|
|
|
|
|
const extension = new Date(loa.extended_till);
|
|
|
|
|
|
|
|
|
|
async function cancelAndReload(id: number) {
|
|
|
|
|
await cancelLOA(id, props.adminMode);
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
if (now < start) return "Upcoming";
|
|
|
|
|
if (now >= start && (now <= end)) return "Active";
|
|
|
|
|
if (now >= start && (now <= extension)) return "Extended";
|
|
|
|
|
if (now > loa.extended_till || end) return "Overdue";
|
|
|
|
|
|
|
|
|
|
const isExtending = ref(false);
|
|
|
|
|
const targetLOA = ref<LOARequest | null>(null);
|
|
|
|
|
const extendTo = ref<CalendarDate | null>(null);
|
|
|
|
|
return "Overdue"; // fallback
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const targetEnd = computed(() => { return targetLOA.value.extended_till ? targetLOA.value.extended_till : targetLOA.value.end_date })
|
|
|
|
|
async function cancelAndReload(id: number) {
|
|
|
|
|
await cancelLOA(id, props.adminMode);
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toCalendarDate(date: Date): CalendarDate {
|
|
|
|
|
if (typeof date === 'string')
|
|
|
|
|
date = new Date(date);
|
|
|
|
|
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate())
|
|
|
|
|
}
|
|
|
|
|
const isExtending = ref(false);
|
|
|
|
|
const targetLOA = ref<LOARequest | null>(null);
|
|
|
|
|
const extendTo = ref<CalendarDate | null>(null);
|
|
|
|
|
|
|
|
|
|
async function commitExtend() {
|
|
|
|
|
await extendLOA(targetLOA.value.id, extendTo.value.toDate(getLocalTimeZone()));
|
|
|
|
|
isExtending.value = false;
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
const targetEnd = computed(() => { return targetLOA.value.extended_till ? targetLOA.value.extended_till : targetLOA.value.end_date })
|
|
|
|
|
function toCalendarDate(date: Date): CalendarDate {
|
|
|
|
|
if (typeof date === 'string')
|
|
|
|
|
date = new Date(date);
|
|
|
|
|
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const expanded = ref<number | null>(null);
|
|
|
|
|
const hoverID = ref<number | null>(null);
|
|
|
|
|
async function commitExtend() {
|
|
|
|
|
if (props.adminMode) {
|
|
|
|
|
await adminExtendLOA(targetLOA.value.id, extendTo.value.toDate(getLocalTimeZone()));
|
|
|
|
|
} else {
|
|
|
|
|
await extendLOA(targetLOA.value.id, extendTo.value.toDate(getLocalTimeZone()));
|
|
|
|
|
}
|
|
|
|
|
isExtending.value = false;
|
|
|
|
|
await loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pageNum = ref<number>(1);
|
|
|
|
|
const pageData = ref<pagination>();
|
|
|
|
|
const expanded = ref<number | null>(null);
|
|
|
|
|
const hoverID = ref<number | null>(null);
|
|
|
|
|
|
|
|
|
|
const pageSize = ref<number>(15)
|
|
|
|
|
const pageSizeOptions = [10, 15, 30]
|
|
|
|
|
const pageNum = ref<number>(1);
|
|
|
|
|
const pageData = ref<pagination>();
|
|
|
|
|
|
|
|
|
|
function setPageSize(size: number) {
|
|
|
|
|
pageSize.value = size
|
|
|
|
|
pageNum.value = 1;
|
|
|
|
|
loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
const pageSize = ref<number>(15)
|
|
|
|
|
const pageSizeOptions = [10, 15, 30]
|
|
|
|
|
|
|
|
|
|
function setPage(pagenum: number) {
|
|
|
|
|
pageNum.value = pagenum;
|
|
|
|
|
loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
function setPageSize(size: number) {
|
|
|
|
|
pageSize.value = size
|
|
|
|
|
pageNum.value = 1;
|
|
|
|
|
loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setPage(pagenum: number) {
|
|
|
|
|
pageNum.value = pagenum;
|
|
|
|
|
loadLOAs();
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
@@ -145,7 +148,7 @@ function setPage(pagenum: number) {
|
|
|
|
|
<div class="flex gap-5">
|
|
|
|
|
<Calendar v-model="extendTo" class="rounded-md border shadow-sm w-min" layout="month-and-year"
|
|
|
|
|
:min-value="toCalendarDate(targetEnd)"
|
|
|
|
|
:max-value="toCalendarDate(targetEnd).add({ years: 1 })" />
|
|
|
|
|
:max-value="props.adminMode ? toCalendarDate(targetEnd).add({ years: 1 }) : toCalendarDate(targetEnd).add({ months: 1 })" />
|
|
|
|
|
<div class="flex flex-col w-full gap-3 px-2">
|
|
|
|
|
<p>Quick Options</p>
|
|
|
|
|
<Button variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ days: 7 })">1
|
|
|
|
|
@@ -205,9 +208,10 @@ function setPage(pagenum: number) {
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent>
|
|
|
|
|
<DropdownMenuItem v-if="!post.closed && props.adminMode"
|
|
|
|
|
<DropdownMenuItem v-if="!post.closed"
|
|
|
|
|
:disabled="post.extended_till !== null && !props.adminMode"
|
|
|
|
|
@click="isExtending = true; targetLOA = post">
|
|
|
|
|
Extend
|
|
|
|
|
{{ (post.extended_till !== null && !props.adminMode) ? 'Extend (Already Extended)' : 'Extend' }}
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem v-if="!post.closed" :variant="'destructive'"
|
|
|
|
|
@click="cancelAndReload(post.id)">{{ loaStatus(post) === 'Upcoming' ?
|
|
|
|
|
@@ -256,7 +260,7 @@ function setPage(pagenum: number) {
|
|
|
|
|
<div class="">
|
|
|
|
|
<p class="text-muted-foreground">Extended to</p>
|
|
|
|
|
<p class="font-medium text-foreground">
|
|
|
|
|
{{post.extended_till ? formatDate(post.extended_till) : 'N/A' }}
|
|
|
|
|
{{ post.extended_till ? formatDate(post.extended_till) : 'N/A' }}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|