upd: home

Deskripsi:
- chart jumlah dokumen di halaman home

No Issues"
This commit is contained in:
amel
2024-09-03 10:46:11 +08:00
parent 21cfa509f4
commit 309f0f17e0
2 changed files with 44 additions and 31 deletions

View File

@@ -150,7 +150,7 @@ export async function GET(request: Request) {
for (let index = 0; index < dataStatus.length; index++) { for (let index = 0; index < dataStatus.length; index++) {
const cek = data.some((i: any) => i.status == dataStatus[index].status) const cek = data.some((i: any) => i.status == dataStatus[index].status)
if (cek) { if (cek) {
const find = ((Number(data.find((i: any) => i.status == dataStatus[index].status)?._count) * 100)/ data.reduce((n, {_count}) => n + _count, 0)).toFixed(2) const find = ((Number(data.find((i: any) => i.status == dataStatus[index].status)?._count) * 100) / data.reduce((n, { _count }) => n + _count, 0)).toFixed(2)
input = { input = {
name: dataStatus[index].name, name: dataStatus[index].name,
value: find value: find
@@ -195,14 +195,39 @@ export async function GET(request: Request) {
where: kondisi, where: kondisi,
}) })
allData = _.map(_.groupBy(data, "extension"), (v: any) => ({ const groupData = _.map(_.groupBy(data, "extension"), (v: any) => ({
file: v[0].extension, file: v[0].extension,
jumlah: v.length, jumlah: v.length,
})) }))
// console.log(allData) const image = ['jpg', 'jpeg', 'png', 'heic']
let hasilImage = {
name: 'Gambar',
value: 0
}
let hasilFile = {
name: 'Dokumen',
value: 0
}
groupData.map((v: any) => {
if (image.some((i: any) => i == v.file)) {
hasilImage = {
name: 'Gambar',
value: hasilImage.value + v.jumlah
}
} else {
hasilFile = {
name: 'Dokumen',
value: hasilFile.value + v.jumlah
}
}
})
allData = [hasilImage, hasilFile]
} else if (kategori == "event") { } else if (kategori == "event") {
let kondisi let kondisi

View File

@@ -9,12 +9,13 @@ import toast from "react-hot-toast";
import { funGetHome } from "../lib/api_home"; import { funGetHome } from "../lib/api_home";
export default function ChartDocumentHome() { export default function ChartDocumentHome() {
const [options, setOptions] = useState<EChartsOption>({}); const [options, setOptions] = useState<EChartsOption>({})
const [isData, setData] = useState<any[]>([]) const [isData, setData] = useState<any[]>([])
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true)
const color = ["#F3C96B", "#9EC97F", "#5971C0"]
useShallowEffect(() => { useShallowEffect(() => {
loadData() // loadData()
fetchData() fetchData()
}, []) }, [])
@@ -28,6 +29,7 @@ export default function ChartDocumentHome() {
if (response.success) { if (response.success) {
setData(response.data) setData(response.data)
loadData(response.data)
} else { } else {
toast.error(response.message); toast.error(response.message);
} }
@@ -40,7 +42,7 @@ export default function ChartDocumentHome() {
} }
}; };
const loadData = () => { const loadData = (value: any) => {
const option: EChartsOption = { const option: EChartsOption = {
title: { title: {
text: "DOKUMEN", text: "DOKUMEN",
@@ -65,7 +67,7 @@ export default function ChartDocumentHome() {
xAxis: [ xAxis: [
{ {
type: 'category', type: 'category',
data: ['File', 'Folder', 'Documen'], data: value.map(({ name }: any) => name),
axisLabel: { axisLabel: {
fontSize: 14 fontSize: 14
}, },
@@ -94,30 +96,16 @@ export default function ChartDocumentHome() {
name: 'Direct', name: 'Direct',
type: 'bar', type: 'bar',
barWidth: '70%', barWidth: '70%',
data: [ data: value.map(
{ (v: any, i: any) =>
value: 78, ({
name: 'File', name: v.name,
value: v.value,
itemStyle: { itemStyle: {
color: "#F3C96B" color: color[i]
}
}, },
{ })
value: 35, ),
name: 'Folder',
itemStyle: {
color: "#9EC97F"
}
},
{
value: 58,
name: 'Documen',
itemStyle: {
color: "#5971C0"
}
},
],
} }
] ]
}; };