Commit 5826f8c9 by Nabiilah Putri Safa

edit lib

1 parent 3d03f305
Showing with 86 additions and 18 deletions
<script setup lang="ts"> <script setup lang="ts">
import { useKeycloakStore } from "@/@core/stores/keycloakStore"; import { useKeycloakStore } from "@/@core/stores/keycloakStore";
import { ref } from "vue"; import { ref, computed, onMounted } from "vue";
// Store Keycloak // Store Keycloak
const keycloakStore = useKeycloakStore(); const keycloakStore = useKeycloakStore();
...@@ -10,6 +11,7 @@ const items = ref<any[]>([]); ...@@ -10,6 +11,7 @@ const items = ref<any[]>([]);
const loading = ref(false); const loading = ref(false);
const searchQuery = ref(""); const searchQuery = ref("");
// Header tabel
const logHeaders = [ const logHeaders = [
{ title: "KOLEKSI", key: "koleksi" }, { title: "KOLEKSI", key: "koleksi" },
{ title: "TANGGAL PEMINJAMAN", key: "tglpinjam" }, { title: "TANGGAL PEMINJAMAN", key: "tglpinjam" },
...@@ -17,13 +19,12 @@ const logHeaders = [ ...@@ -17,13 +19,12 @@ const logHeaders = [
{ title: "DIPINJAM", key: "dipinjam" }, { title: "DIPINJAM", key: "dipinjam" },
{ title: "PERPANJANGAN", key: "perpanjangan" }, { title: "PERPANJANGAN", key: "perpanjangan" },
{ title: "DENDA", key: "denda" }, { title: "DENDA", key: "denda" },
{ title: "DENDA TOTAL", key: "dendatotoal" }, { title: "DENDA TOTAL", key: "dendatotal" },
]; ];
// Fungsi ambil data
async function getData() { async function getData() {
loading.value = true; loading.value = true;
items.value = [];
try { try {
const apiEndpoint = "https://api.ui.ac.id/my/lib"; const apiEndpoint = "https://api.ui.ac.id/my/lib";
const response = await fetch(apiEndpoint, { const response = await fetch(apiEndpoint, {
...@@ -31,16 +32,24 @@ async function getData() { ...@@ -31,16 +32,24 @@ async function getData() {
Authorization: `Bearer ${keycloakStore.accessToken}`, Authorization: `Bearer ${keycloakStore.accessToken}`,
}, },
}); });
if (!response.ok) throw new Error("Gagal mengambil data"); if (!response.ok) throw new Error("Gagal mengambil data");
const dataku = await response.json(); const dataku = await response.json();
// Tambahkan properti tanggal, namaHari, mulai aktual, dan selesai aktual ke setiap item // dataku adalah array, tiap elemen punya properti root-level
items.value = dataku.map((item: any) => { const requiredKeys = [
return { "denda",
...item, "dendatotal",
}; "dipinjam",
}); "koleksi",
"perpanjangan",
"tglkembali",
"tglpinjam",
"username",
];
// ambil hanya objek yang memiliki semua key di root
items.value = Array.isArray(dataku)
? dataku.filter((r: any) => requiredKeys.every(k => k in r))
: [];
} catch (err) { } catch (err) {
console.error("Gagal mengambil data:", err); console.error("Gagal mengambil data:", err);
} finally { } finally {
...@@ -48,21 +57,31 @@ async function getData() { ...@@ -48,21 +57,31 @@ async function getData() {
} }
} }
// Panggil saat komponen mount
onMounted(() => {
getData();
});
// Filter hasil pencarian
const filteredItems = computed(() => { const filteredItems = computed(() => {
if (!searchQuery.value) return items.value; if (!searchQuery.value) return items.value;
const q = searchQuery.value.toLowerCase();
const query = searchQuery.value.toLowerCase(); return items.value.filter(item =>
return items.value.filter((item) =>
logHeaders.some( logHeaders.some(
(header) => item[header.key] && String(item[header.key]).toLowerCase().includes(query) h => item[h.key] && String(item[h.key]).toLowerCase().includes(q)
) )
); );
}); });
</script> </script>
<template> <template>
<VCard title="Status Peminjaman Buku" class="recentnamaHariCard"> <AppCardActions
:title="`Status Peminjaman Buku`"
class="jadwalShift"
action-collapsed
action-remove
>
<!-- Search Input -->
<div class="search-container mb-4 pl-2 pr-2"> <div class="search-container mb-4 pl-2 pr-2">
<VTextField <VTextField
v-model="searchQuery" v-model="searchQuery"
...@@ -76,6 +95,7 @@ const filteredItems = computed(() => { ...@@ -76,6 +95,7 @@ const filteredItems = computed(() => {
outlined outlined
/> />
</div> </div>
<VDataTable <VDataTable
:headers="logHeaders" :headers="logHeaders"
:items="filteredItems" :items="filteredItems"
...@@ -85,5 +105,52 @@ const filteredItems = computed(() => { ...@@ -85,5 +105,52 @@ const filteredItems = computed(() => {
:sort-by="['tglpinjam']" :sort-by="['tglpinjam']"
:sort-asc="[true]" :sort-asc="[true]"
></VDataTable> ></VDataTable>
</VCard>
</AppCardActions>
</template> </template>
<style lang="scss">
.jadwalShift {
.v-table {
&--density-default {
.v-table__wrapper {
table {
thead {
th {
background-color: #f5f5f5;
border-block-end: 2px solid #ddd;
color: #2c2c2c;
font-weight: 600;
padding-block: 12px;
padding-inline: 1.5em;
}
}
tbody {
tr {
td {
border-block-end: 1px solid #eee;
min-block-size: auto;
padding-block: 8px;
padding-inline: 1em;
vertical-align: top;
&.vti-table__td--Jadwal {
color: #4a4a4a;
font-weight: 500;
}
}
}
}
}
}
}
}
}
.search-container {
display: flex;
justify-content: flex-end;
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!