implemented pagination, header polish, and new display fixes
This commit is contained in:
@@ -66,9 +66,11 @@ router.get("/history", async (req: Request, res: Response) => {
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/all', [requireRole("17th Administrator")], async (req, res) => {
|
||||
router.get('/all', [requireRole("17th Administrator")], async (req: Request, res: Response) => {
|
||||
try {
|
||||
const result = await getAllLOA();
|
||||
const page = Number(req.query.page) || undefined;
|
||||
const pageSize = Number(req.query.pageSize) || undefined;
|
||||
const result = await getAllLOA(page, pageSize);
|
||||
res.status(200).json(result)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { toDateTime } from "@app/shared/utils/time";
|
||||
import pool from "../db";
|
||||
import { LOARequest, LOAType } from '@app/shared/types/loa'
|
||||
import { PagedData } from '@app/shared/types/pagination'
|
||||
|
||||
export async function getLoaTypes(): Promise<LOAType[]> {
|
||||
return await pool.query('SELECT * FROM leave_of_absences_types;');
|
||||
}
|
||||
|
||||
export async function getAllLOA(page = 1, pageSize = 10): Promise<LOARequest[]> {
|
||||
export async function getAllLOA(page = 1, pageSize = 10): Promise<PagedData<LOARequest>> {
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
const sql = `
|
||||
@@ -26,9 +27,13 @@ export async function getAllLOA(page = 1, pageSize = 10): Promise<LOARequest[]>
|
||||
loa.start_date DESC
|
||||
LIMIT ? OFFSET ?;
|
||||
`;
|
||||
let loaList: LOARequest[] = await pool.query(sql, [pageSize, offset]) as LOARequest[];
|
||||
|
||||
let res: LOARequest[] = await pool.query(sql, [pageSize, offset]) as LOARequest[];
|
||||
return res;
|
||||
let loaCount = Number((await pool.query(`SELECT COUNT(*) as count FROM leave_of_absences;`))[0].count);
|
||||
let pageCount = loaCount / pageSize;
|
||||
|
||||
let output: PagedData<LOARequest> = { data: loaList, pagination: { page: page, pageSize: pageSize, total: loaCount, totalPages: pageCount } }
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function getUserLOA(userId: number): Promise<LOARequest[]> {
|
||||
|
||||
11
shared/types/pagination.ts
Normal file
11
shared/types/pagination.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface PagedData<T> {
|
||||
data: T[]
|
||||
pagination: pagination
|
||||
}
|
||||
|
||||
export interface pagination {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
totalPages: number
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { LOARequest, LOAType } from '@shared/types/loa'
|
||||
import { PagedData } from '@shared/types/pagination'
|
||||
// @ts-ignore
|
||||
const addr = import.meta.env.VITE_APIHOST;
|
||||
|
||||
@@ -58,8 +59,18 @@ export async function getMyLOA(): Promise<LOARequest | null> {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllLOAs(): Promise<LOARequest[]> {
|
||||
return fetch(`${addr}/loa/all`, {
|
||||
export async function getAllLOAs(page?: number, pageSize?: number): Promise<PagedData<LOARequest>> {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (page !== undefined) {
|
||||
params.set("page", page.toString());
|
||||
}
|
||||
|
||||
if (pageSize !== undefined) {
|
||||
params.set("pageSize", pageSize.toString());
|
||||
}
|
||||
|
||||
return fetch(`${addr}/loa/all?${params}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -33,6 +33,15 @@ import {
|
||||
} 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
|
||||
@@ -46,7 +55,9 @@ onMounted(async () => {
|
||||
|
||||
async function loadLOAs() {
|
||||
if (props.adminMode) {
|
||||
LOAList.value = await getAllLOAs();
|
||||
let result = await getAllLOAs(pageNum.value, pageSize.value);
|
||||
LOAList.value = result.data;
|
||||
pageData.value = result.pagination;
|
||||
} else {
|
||||
LOAList.value = await getMyLOAs();
|
||||
}
|
||||
@@ -76,12 +87,6 @@ function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Overdue" | "Closed
|
||||
return "Overdue"; // fallback
|
||||
}
|
||||
|
||||
function sortByStartDate(loas: LOARequest[]): LOARequest[] {
|
||||
return [...loas].sort(
|
||||
(a, b) => new Date(b.start_date).getTime() - new Date(a.start_date).getTime()
|
||||
);
|
||||
}
|
||||
|
||||
async function cancelAndReload(id: number) {
|
||||
await cancelLOA(id, props.adminMode);
|
||||
await loadLOAs();
|
||||
@@ -107,6 +112,23 @@ async function commitExtend() {
|
||||
|
||||
const expanded = ref<number | null>(null);
|
||||
const hoverID = ref<number | null>(null);
|
||||
|
||||
const pageNum = ref<number>(1);
|
||||
const pageData = ref<pagination>();
|
||||
|
||||
const pageSize = ref<number>(15)
|
||||
const pageSizeOptions = [10, 15, 30]
|
||||
|
||||
function setPageSize(size: number) {
|
||||
pageSize.value = size
|
||||
pageNum.value = 1;
|
||||
loadLOAs();
|
||||
}
|
||||
|
||||
function setPage(pagenum: number) {
|
||||
pageNum.value = pagenum;
|
||||
loadLOAs();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -229,6 +251,34 @@ const hoverID = ref<number | null>(null);
|
||||
</template>
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div class="mt-5 flex justify-between">
|
||||
<div></div>
|
||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
||||
<PaginationContent v-slot="{ items }">
|
||||
<PaginationPrevious />
|
||||
<template v-for="(item, index) in items" :key="index">
|
||||
<PaginationItem v-if="item.type === 'page'" :value="item.value"
|
||||
:is-active="item.value === page">
|
||||
{{ item.value }}
|
||||
</PaginationItem>
|
||||
</template>
|
||||
<PaginationEllipsis :index="4" />
|
||||
<PaginationNext />
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
<div class="flex items-center gap-3 text-sm">
|
||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
||||
|
||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
||||
class="px-2 py-1 rounded transition-colors" :class="{
|
||||
'bg-muted font-semibold': pageSize === size,
|
||||
'hover:bg-muted/50': pageSize !== size
|
||||
}">
|
||||
{{ size }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
33
ui/src/components/ui/pagination/Pagination.vue
Normal file
33
ui/src/components/ui/pagination/Pagination.vue
Normal file
@@ -0,0 +1,33 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationRoot, useForwardPropsEmits } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
page: { type: Number, required: false },
|
||||
defaultPage: { type: Number, required: false },
|
||||
itemsPerPage: { type: Number, required: true },
|
||||
total: { type: Number, required: false },
|
||||
siblingCount: { type: Number, required: false },
|
||||
disabled: { type: Boolean, required: false },
|
||||
showEdges: { type: Boolean, required: false },
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
const emits = defineEmits(["update:page"]);
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationRoot
|
||||
v-slot="slotProps"
|
||||
data-slot="pagination"
|
||||
v-bind="forwarded"
|
||||
:class="cn('mx-auto flex w-full justify-center', props.class)"
|
||||
>
|
||||
<slot v-bind="slotProps" />
|
||||
</PaginationRoot>
|
||||
</template>
|
||||
24
ui/src/components/ui/pagination/PaginationContent.vue
Normal file
24
ui/src/components/ui/pagination/PaginationContent.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationList } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationList
|
||||
v-slot="slotProps"
|
||||
data-slot="pagination-content"
|
||||
v-bind="delegatedProps"
|
||||
:class="cn('flex flex-row items-center gap-1', props.class)"
|
||||
>
|
||||
<slot v-bind="slotProps" />
|
||||
</PaginationList>
|
||||
</template>
|
||||
27
ui/src/components/ui/pagination/PaginationEllipsis.vue
Normal file
27
ui/src/components/ui/pagination/PaginationEllipsis.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { MoreHorizontal } from "lucide-vue-next";
|
||||
import { PaginationEllipsis } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationEllipsis
|
||||
data-slot="pagination-ellipsis"
|
||||
v-bind="delegatedProps"
|
||||
:class="cn('flex size-9 items-center justify-center', props.class)"
|
||||
>
|
||||
<slot>
|
||||
<MoreHorizontal class="size-4" />
|
||||
<span class="sr-only">More pages</span>
|
||||
</slot>
|
||||
</PaginationEllipsis>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationFirst.vue
Normal file
36
ui/src/components/ui/pagination/PaginationFirst.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronLeftIcon } from "lucide-vue-next";
|
||||
import { PaginationFirst, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationFirst
|
||||
data-slot="pagination-first"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<ChevronLeftIcon />
|
||||
<span class="hidden sm:block">First</span>
|
||||
</slot>
|
||||
</PaginationFirst>
|
||||
</template>
|
||||
35
ui/src/components/ui/pagination/PaginationItem.vue
Normal file
35
ui/src/components/ui/pagination/PaginationItem.vue
Normal file
@@ -0,0 +1,35 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { PaginationListItem } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
value: { type: Number, required: true },
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "icon" },
|
||||
class: { type: null, required: false },
|
||||
isActive: { type: Boolean, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size", "isActive");
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationListItem
|
||||
data-slot="pagination-item"
|
||||
v-bind="delegatedProps"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({
|
||||
variant: isActive ? 'outline' : 'ghost',
|
||||
size,
|
||||
}),
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
>
|
||||
<slot />
|
||||
</PaginationListItem>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationLast.vue
Normal file
36
ui/src/components/ui/pagination/PaginationLast.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronRightIcon } from "lucide-vue-next";
|
||||
import { PaginationLast, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationLast
|
||||
data-slot="pagination-last"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<span class="hidden sm:block">Last</span>
|
||||
<ChevronRightIcon />
|
||||
</slot>
|
||||
</PaginationLast>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationNext.vue
Normal file
36
ui/src/components/ui/pagination/PaginationNext.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronRightIcon } from "lucide-vue-next";
|
||||
import { PaginationNext, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationNext
|
||||
data-slot="pagination-next"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<span class="hidden sm:block">Next</span>
|
||||
<ChevronRightIcon />
|
||||
</slot>
|
||||
</PaginationNext>
|
||||
</template>
|
||||
36
ui/src/components/ui/pagination/PaginationPrevious.vue
Normal file
36
ui/src/components/ui/pagination/PaginationPrevious.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<script setup>
|
||||
import { reactiveOmit } from "@vueuse/core";
|
||||
import { ChevronLeftIcon } from "lucide-vue-next";
|
||||
import { PaginationPrev, useForwardProps } from "reka-ui";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { buttonVariants } from '@/components/ui/button';
|
||||
|
||||
const props = defineProps({
|
||||
asChild: { type: Boolean, required: false },
|
||||
as: { type: null, required: false },
|
||||
size: { type: null, required: false, default: "default" },
|
||||
class: { type: null, required: false },
|
||||
});
|
||||
|
||||
const delegatedProps = reactiveOmit(props, "class", "size");
|
||||
const forwarded = useForwardProps(delegatedProps);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PaginationPrev
|
||||
data-slot="pagination-previous"
|
||||
:class="
|
||||
cn(
|
||||
buttonVariants({ variant: 'ghost', size }),
|
||||
'gap-1 px-2.5 sm:pr-2.5',
|
||||
props.class,
|
||||
)
|
||||
"
|
||||
v-bind="forwarded"
|
||||
>
|
||||
<slot>
|
||||
<ChevronLeftIcon />
|
||||
<span class="hidden sm:block">Previous</span>
|
||||
</slot>
|
||||
</PaginationPrev>
|
||||
</template>
|
||||
8
ui/src/components/ui/pagination/index.js
Normal file
8
ui/src/components/ui/pagination/index.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export { default as Pagination } from "./Pagination.vue";
|
||||
export { default as PaginationContent } from "./PaginationContent.vue";
|
||||
export { default as PaginationEllipsis } from "./PaginationEllipsis.vue";
|
||||
export { default as PaginationFirst } from "./PaginationFirst.vue";
|
||||
export { default as PaginationItem } from "./PaginationItem.vue";
|
||||
export { default as PaginationLast } from "./PaginationLast.vue";
|
||||
export { default as PaginationNext } from "./PaginationNext.vue";
|
||||
export { default as PaginationPrevious } from "./PaginationPrevious.vue";
|
||||
@@ -30,10 +30,12 @@ const showLOADialog = ref(false);
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<div class="max-w-5xl mx-auto pt-10">
|
||||
<div class="flex justify-end mb-4">
|
||||
<div class="flex justify-between mb-4">
|
||||
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Log</h1>
|
||||
<div>
|
||||
<Button @click="showLOADialog = true">Post LOA</Button>
|
||||
</div>
|
||||
<h1>LOA Log</h1>
|
||||
</div>
|
||||
<LoaList :admin-mode="true"></LoaList>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user