2022-10-23 16:54:54 -05:00
|
|
|
<script lang="ts">
|
2023-01-09 22:40:54 +02:00
|
|
|
import { api, ServerStatsResponseDto, UserResponseDto } from '@api';
|
2022-10-25 21:41:46 -05:00
|
|
|
import CameraIris from 'svelte-material-icons/CameraIris.svelte';
|
|
|
|
|
import PlayCircle from 'svelte-material-icons/PlayCircle.svelte';
|
|
|
|
|
import Memory from 'svelte-material-icons/Memory.svelte';
|
|
|
|
|
import StatsCard from './stats-card.svelte';
|
2022-12-05 04:35:20 +13:00
|
|
|
import { getBytesWithUnit, asByteUnitString } from '../../../utils/byte-units';
|
2023-01-09 22:40:54 +02:00
|
|
|
import { onMount, onDestroy } from 'svelte';
|
|
|
|
|
import LoadingSpinner from '$lib/components/shared-components/loading-spinner.svelte';
|
2023-02-22 18:53:08 +01:00
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2023-01-09 22:40:54 +02:00
|
|
|
|
2022-10-23 16:54:54 -05:00
|
|
|
export let allUsers: Array<UserResponseDto>;
|
|
|
|
|
|
2023-01-09 22:40:54 +02:00
|
|
|
let stats: ServerStatsResponseDto;
|
|
|
|
|
let setIntervalHandler: NodeJS.Timer;
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
const { data } = await api.serverInfoApi.getStats();
|
|
|
|
|
stats = data;
|
|
|
|
|
|
|
|
|
|
setIntervalHandler = setInterval(async () => {
|
|
|
|
|
const { data } = await api.serverInfoApi.getStats();
|
|
|
|
|
stats = data;
|
|
|
|
|
}, 5000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
onDestroy(() => {
|
|
|
|
|
clearInterval(setIntervalHandler);
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-23 16:54:54 -05:00
|
|
|
const getFullName = (userId: string) => {
|
|
|
|
|
let name = 'Admin'; // since we do not have admin user in allUsers
|
|
|
|
|
allUsers.forEach((user) => {
|
|
|
|
|
if (user.id === userId) name = `${user.firstName} ${user.lastName}`;
|
|
|
|
|
});
|
|
|
|
|
return name;
|
|
|
|
|
};
|
2022-10-25 21:41:46 -05:00
|
|
|
|
2023-01-09 22:40:54 +02:00
|
|
|
// Stats are unavailable if data is not loaded yet
|
|
|
|
|
$: [spaceUsage, spaceUnit] = getBytesWithUnit(stats ? stats.usageRaw : 0);
|
2022-10-23 16:54:54 -05:00
|
|
|
</script>
|
|
|
|
|
|
2022-10-25 21:41:46 -05:00
|
|
|
<div class="flex flex-col gap-5">
|
|
|
|
|
<div>
|
2022-10-26 11:10:48 -05:00
|
|
|
<p class="text-sm dark:text-immich-dark-fg">TOTAL USAGE</p>
|
2022-10-25 21:41:46 -05:00
|
|
|
|
|
|
|
|
<div class="flex mt-5 justify-between">
|
2023-01-09 22:40:54 +02:00
|
|
|
<StatsCard logo={CameraIris} title={'PHOTOS'} value={stats && stats.photos.toString()} />
|
|
|
|
|
<StatsCard logo={PlayCircle} title={'VIDEOS'} value={stats && stats.videos.toString()} />
|
|
|
|
|
<StatsCard
|
|
|
|
|
logo={Memory}
|
|
|
|
|
title={'STORAGE'}
|
|
|
|
|
value={stats && spaceUsage.toString()}
|
|
|
|
|
unit={spaceUnit}
|
|
|
|
|
/>
|
2022-10-23 16:54:54 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2022-10-25 21:41:46 -05:00
|
|
|
<div>
|
2022-10-26 11:10:48 -05:00
|
|
|
<p class="text-sm dark:text-immich-dark-fg">USER USAGE DETAIL</p>
|
2022-10-25 21:41:46 -05:00
|
|
|
<table class="text-left w-full mt-5">
|
2022-10-26 11:10:48 -05:00
|
|
|
<thead
|
|
|
|
|
class="border rounded-md mb-4 bg-gray-50 dark:bg-immich-dark-gray dark:border-immich-dark-gray flex text-immich-primary dark:text-immich-dark-primary w-full h-12"
|
|
|
|
|
>
|
2022-10-23 16:54:54 -05:00
|
|
|
<tr class="flex w-full place-items-center">
|
2022-11-20 13:09:31 -06:00
|
|
|
<th class="text-center w-1/4 font-medium text-sm">User</th>
|
|
|
|
|
<th class="text-center w-1/4 font-medium text-sm">Photos</th>
|
|
|
|
|
<th class="text-center w-1/4 font-medium text-sm">Videos</th>
|
|
|
|
|
<th class="text-center w-1/4 font-medium text-sm">Size</th>
|
2022-10-23 16:54:54 -05:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
2022-10-26 11:10:48 -05:00
|
|
|
<tbody
|
2022-11-09 05:41:45 -06:00
|
|
|
class="overflow-y-auto rounded-md w-full max-h-[320px] block border dark:border-immich-dark-gray dark:text-immich-dark-fg"
|
2022-10-26 11:10:48 -05:00
|
|
|
>
|
2023-01-09 22:40:54 +02:00
|
|
|
{#if stats}
|
|
|
|
|
{#each stats.usageByUser as user, i}
|
|
|
|
|
<tr
|
|
|
|
|
class={`text-center flex place-items-center w-full h-[50px] ${
|
|
|
|
|
i % 2 == 0
|
|
|
|
|
? 'bg-immich-gray dark:bg-immich-dark-gray/75'
|
|
|
|
|
: 'bg-immich-bg dark:bg-immich-dark-gray/50'
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
<td class="text-sm px-2 w-1/4 text-ellipsis">{getFullName(user.userId)}</td>
|
2023-02-22 18:53:08 +01:00
|
|
|
<td class="text-sm px-2 w-1/4 text-ellipsis">{user.photos.toLocaleString($locale)}</td
|
|
|
|
|
>
|
|
|
|
|
<td class="text-sm px-2 w-1/4 text-ellipsis">{user.videos.toLocaleString($locale)}</td
|
|
|
|
|
>
|
2023-01-09 22:40:54 +02:00
|
|
|
<td class="text-sm px-2 w-1/4 text-ellipsis">{asByteUnitString(user.usageRaw)}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{/each}
|
|
|
|
|
{:else}
|
2022-10-25 21:41:46 -05:00
|
|
|
<tr
|
2023-01-09 22:40:54 +02:00
|
|
|
class="text-center flex place-items-center w-full h-[50px] bg-immich-gray dark:bg-immich-dark-gray/75"
|
2022-10-25 21:41:46 -05:00
|
|
|
>
|
2023-01-09 22:40:54 +02:00
|
|
|
<td class="w-full flex justify-center">
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
</td>
|
2022-10-23 16:54:54 -05:00
|
|
|
</tr>
|
2023-01-09 22:40:54 +02:00
|
|
|
{/if}
|
2022-10-23 16:54:54 -05:00
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|