From 887ccf9f265c0f31fa6756f98de548ef03f7ca80 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 20 Mar 2025 18:12:10 -0400 Subject: [PATCH] [ROMM-1761] Show platform disk size in sidebar --- backend/endpoints/responses/platform.py | 1 + backend/handler/database/stats_handler.py | 13 +++++ backend/models/platform.py | 7 +++ .../__generated__/models/PlatformSchema.ts | 1 + .../AppBar/Platform/PlatformInfoDrawer.vue | 51 ++++++++++--------- frontend/src/locales/de_DE/common.json | 3 +- frontend/src/locales/de_DE/platform.json | 1 - frontend/src/locales/en_GB/common.json | 3 +- frontend/src/locales/en_GB/platform.json | 1 - frontend/src/locales/en_US/common.json | 3 +- frontend/src/locales/en_US/platform.json | 1 - frontend/src/locales/es_ES/common.json | 3 +- frontend/src/locales/es_ES/platform.json | 1 - frontend/src/locales/fr_FR/common.json | 3 +- frontend/src/locales/fr_FR/platform.json | 1 - frontend/src/locales/ja_JP/common.json | 3 +- frontend/src/locales/ja_JP/platform.json | 1 - frontend/src/locales/ko_KR/common.json | 3 +- frontend/src/locales/ko_KR/platform.json | 1 - frontend/src/locales/pt_BR/common.json | 3 +- frontend/src/locales/pt_BR/platform.json | 1 - frontend/src/locales/ru_RU/common.json | 3 +- frontend/src/locales/ru_RU/platform.json | 1 - frontend/src/locales/zh_CN/platform.json | 1 - 24 files changed, 67 insertions(+), 43 deletions(-) diff --git a/backend/endpoints/responses/platform.py b/backend/endpoints/responses/platform.py index 29e1362e7..cae9a9a22 100644 --- a/backend/endpoints/responses/platform.py +++ b/backend/endpoints/responses/platform.py @@ -29,6 +29,7 @@ class PlatformSchema(BaseModel): aspect_ratio: str = DEFAULT_COVER_ASPECT_RATIO created_at: datetime updated_at: datetime + filesystem_size_bytes: int class Config: from_attributes = True diff --git a/backend/handler/database/stats_handler.py b/backend/handler/database/stats_handler.py index 2bc0f3e56..ff5a6535e 100644 --- a/backend/handler/database/stats_handler.py +++ b/backend/handler/database/stats_handler.py @@ -43,3 +43,16 @@ class DBStatsHandler(DBBaseHandler): ) or 0 ) + + @begin_session + def get_platform_filesize(self, platform_id: int, session: Session = None) -> int: + """Get the total filesize of all roms in the database, in bytes.""" + return ( + session.scalar( + select(func.sum(RomFile.file_size_bytes)) + .select_from(RomFile) + .join(Rom) + .filter(Rom.platform_id == platform_id) + ) + or 0 + ) diff --git a/backend/models/platform.py b/backend/models/platform.py index 7c1087b5d..7e4de74df 100644 --- a/backend/models/platform.py +++ b/backend/models/platform.py @@ -1,5 +1,6 @@ from __future__ import annotations +from functools import cached_property from typing import TYPE_CHECKING from models.base import BaseModel @@ -50,3 +51,9 @@ class Platform(BaseModel): def __repr__(self) -> str: return self.name + + @cached_property + def filesystem_size_bytes(self) -> int: + from handler.database import db_stats_handler + + return db_stats_handler.get_platform_filesize(self.id) diff --git a/frontend/src/__generated__/models/PlatformSchema.ts b/frontend/src/__generated__/models/PlatformSchema.ts index 11fd8a0e0..4b6e820d1 100644 --- a/frontend/src/__generated__/models/PlatformSchema.ts +++ b/frontend/src/__generated__/models/PlatformSchema.ts @@ -25,6 +25,7 @@ export type PlatformSchema = { aspect_ratio?: string; created_at: string; updated_at: string; + filesystem_size_bytes: number; readonly display_name: string; }; diff --git a/frontend/src/components/Gallery/AppBar/Platform/PlatformInfoDrawer.vue b/frontend/src/components/Gallery/AppBar/Platform/PlatformInfoDrawer.vue index 4d67854ab..22be49b0f 100644 --- a/frontend/src/components/Gallery/AppBar/Platform/PlatformInfoDrawer.vue +++ b/frontend/src/components/Gallery/AppBar/Platform/PlatformInfoDrawer.vue @@ -12,11 +12,13 @@ import storePlatforms from "@/stores/platforms"; import storeRoms from "@/stores/roms"; import storeScanning from "@/stores/scanning"; import type { Events } from "@/types/emitter"; +import { formatBytes } from "@/utils"; import type { Emitter } from "mitt"; import { storeToRefs } from "pinia"; import { computed, inject, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; import { useDisplay } from "vuetify"; +import { identity } from "lodash"; // Props const { t } = useI18n(); @@ -28,7 +30,6 @@ const platformsStore = storePlatforms(); const scanningStore = storeScanning(); const { scanning } = storeToRefs(scanningStore); const { currentPlatform } = storeToRefs(romsStore); -const { allPlatforms } = storeToRefs(platformsStore); const auth = storeAuth(); const navigationStore = storeNavigation(); const { activePlatformInfoDrawer } = storeToRefs(navigationStore); @@ -55,14 +56,25 @@ const aspectRatioOptions = computed(() => [ source: t("platform.old-horizontal-cases"), }, ]); -const platformInfoFields = [ - { key: "name", label: t("common.name") }, - { key: "slug", label: "Slug" }, - { key: "fs_slug", label: t("platform.filesystem-folder-name") }, - { key: "category", label: t("platform.category") }, - { key: "generation", label: t("platform.generation") }, - { key: "family_name", label: t("platform.family") }, + +const PLATFORM_INFO_FIELDS: { + key: keyof Platform; + label: string; + format: (value: any) => string; +}[] = [ + { key: "name", label: t("common.name"), format: identity }, + { key: "slug", label: t("common.slug"), format: identity }, + { key: "fs_slug", label: t("settings.folder-name"), format: identity }, + { key: "category", label: t("platform.category"), format: identity }, + { key: "generation", label: t("platform.generation"), format: identity }, + { key: "family_name", label: t("platform.family"), format: identity }, + { + key: "filesystem_size_bytes", + label: t("common.size-on-disk"), + format: (fs: number) => formatBytes(fs, 2), + }, ]; + const updating = ref(false); const updatedPlatform = ref({ ...currentPlatform.value }); const isEditable = ref(false); @@ -334,22 +346,13 @@ watch( - -