forked from Inist-CNRS/tdm-factory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finish the basic version of the admin panel
- Loading branch information
1 parent
3b5b1f9
commit ab5def4
Showing
11 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { dashboard } from '~/app/services/admin/dashboard'; | ||
import { getDatabaseStatus } from '~/app/util/utils'; | ||
|
||
import Alert from '@mui/material/Alert'; | ||
import Box from '@mui/material/Box'; | ||
import Paper from '@mui/material/Paper'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useMemo } from 'react'; | ||
import { | ||
Area, | ||
AreaChart, | ||
PolarAngleAxis, | ||
PolarGrid, | ||
PolarRadiusAxis, | ||
Radar, | ||
RadarChart, | ||
ResponsiveContainer, | ||
Tooltip, | ||
XAxis, | ||
YAxis, | ||
} from 'recharts'; | ||
|
||
import type { StorageDashboard } from '~/app/util/type'; | ||
|
||
const Dashboard = () => { | ||
const { data, isFetching, isLoading } = useQuery({ | ||
queryKey: ['dashboard'], | ||
queryFn: () => { | ||
return dashboard(); | ||
}, | ||
}); | ||
|
||
const statusData = useMemo(() => { | ||
if (!data) { | ||
return []; | ||
} | ||
const output = []; | ||
for (const datum of Object.entries(data.status)) { | ||
output.push({ | ||
name: getDatabaseStatus(Number(datum[0])).toLowerCase().replace('_', ' '), | ||
count: datum[1], | ||
}); | ||
} | ||
return output; | ||
}, [data]); | ||
|
||
if (isFetching || isLoading) { | ||
return <p>Is Loading</p>; | ||
} | ||
|
||
if (!data) { | ||
return <Alert color="error">No database found.</Alert>; | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Paper sx={{ width: '500px', height: '300px', padding: '12px' }}> | ||
<Typography sx={{ textAlign: 'center' }} variant="h5"> | ||
Résumé des Status | ||
</Typography> | ||
<ResponsiveContainer width="100%" height="100%"> | ||
<RadarChart cx="50%" cy="50%" outerRadius="60%" data={statusData}> | ||
<PolarGrid /> | ||
<PolarAngleAxis dataKey="name" /> | ||
<PolarRadiusAxis /> | ||
<Tooltip /> | ||
<Radar dataKey="count" stroke="#8884d8" fill="#8884d8" fillOpacity={0.6} /> | ||
</RadarChart> | ||
</ResponsiveContainer> | ||
</Paper> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default Dashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createQuery, environment, getAuthHeader, json } from '~/app/services/Environment'; | ||
|
||
import type { Dashboard } from '~/app/util/type'; | ||
|
||
export const dashboard = async (): Promise<Dashboard> => { | ||
const response = await fetch(createQuery(environment.get.dashboard), { | ||
headers: { | ||
Authorization: getAuthHeader(), | ||
}, | ||
}); | ||
if (response.status !== 200) { | ||
return { status: {}, storage: { download: [], tmp: [], upload: [] } }; | ||
} | ||
return await json<Dashboard>(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { filesLocation, readDir } from '~/lib/files'; | ||
import { findAllStatus } from '~/model/ProcessingModel'; | ||
|
||
import { statfs } from 'node:fs/promises'; | ||
|
||
import type { Stats } from 'node:fs'; | ||
|
||
const createStorage = async () => { | ||
const files = await Promise.all([ | ||
readDir(filesLocation.upload), | ||
readDir(filesLocation.tmp), | ||
readDir(filesLocation.download), | ||
]).then(); | ||
|
||
let used = 0; | ||
const convertFile = ({ stats }: { file: string; stats: Stats }) => { | ||
used += stats.size; | ||
return { | ||
date: stats.ctime, | ||
size: stats.size, | ||
}; | ||
}; | ||
|
||
const upload = files[0].map(convertFile); | ||
const tmp = files[1].map(convertFile); | ||
const download = files[2].map(convertFile); | ||
|
||
const fsStats = await statfs(filesLocation.app); | ||
|
||
return { | ||
free: fsStats.bfree * fsStats.bsize, | ||
used, | ||
files: { | ||
upload, | ||
tmp, | ||
download, | ||
}, | ||
}; | ||
}; | ||
|
||
const createStatus = () => { | ||
const status: Record<number, number> = {}; | ||
for (const datum of findAllStatus()) { | ||
const previousStatus = status[datum.status]; | ||
if (previousStatus === undefined) { | ||
status[datum.status] = 1; | ||
continue; | ||
} | ||
status[datum.status] = previousStatus + 1; | ||
} | ||
|
||
return status; | ||
}; | ||
|
||
const createDashboard = async () => { | ||
return { | ||
status: createStatus(), | ||
storage: await createStorage(), | ||
}; | ||
}; | ||
|
||
export default createDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters