mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
refactor: enhance PlatformsStats component with sorting functionality and clean up SummaryStats template
This commit is contained in:
@@ -3,6 +3,7 @@ import { formatBytes } from "@/utils";
|
||||
import PlatformListItem from "@/components/common/Platform/ListItem.vue";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { ref, computed } from "vue";
|
||||
|
||||
// Props
|
||||
const props = defineProps<{
|
||||
@@ -11,62 +12,89 @@ const props = defineProps<{
|
||||
|
||||
const platformsStore = storePlatforms();
|
||||
const { filteredPlatforms } = storeToRefs(platformsStore);
|
||||
const orderBy = ref("name");
|
||||
|
||||
// Functions
|
||||
function getPercentage(filesize: number | string, total: number): number {
|
||||
const sortedPlatforms = computed(() => {
|
||||
const platforms = [...filteredPlatforms.value];
|
||||
if (orderBy.value === "size") {
|
||||
return platforms.sort(
|
||||
(a, b) => Number(b.fs_size_bytes) - Number(a.fs_size_bytes),
|
||||
);
|
||||
}
|
||||
// Default to name
|
||||
return platforms.sort((a, b) =>
|
||||
a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
|
||||
);
|
||||
});
|
||||
|
||||
function getPlatformPercentage(
|
||||
filesize: number | string,
|
||||
total: number,
|
||||
): number {
|
||||
const size = typeof filesize === "string" ? parseInt(filesize, 10) : filesize;
|
||||
if (!total || isNaN(size)) return 0;
|
||||
return (size / total) * 100;
|
||||
}
|
||||
|
||||
function idToHexColor(id: number): string {
|
||||
const knuthHash = 2654435761;
|
||||
const hex = ((id * knuthHash) >>> 0).toString(16).padStart(6, "0");
|
||||
return `#${hex.slice(0, 6)}`;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-text>
|
||||
<div
|
||||
v-for="(platform, idx) in filteredPlatforms"
|
||||
:class="{ 'mb-8': idx !== filteredPlatforms.length - 1 }"
|
||||
>
|
||||
<v-row no-gutters class="d-flex justify-space-between align-center">
|
||||
<v-col cols="6">
|
||||
<platform-list-item
|
||||
:platform="platform"
|
||||
:key="platform.slug"
|
||||
:showRomCount="false"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="6" class="text-right">
|
||||
<v-list-item>
|
||||
<v-list-item-title class="text-body-2">
|
||||
{{ formatBytes(Number(platform.fs_size_bytes)) }}
|
||||
({{
|
||||
getPercentage(
|
||||
platform.fs_size_bytes,
|
||||
props.total_filesize,
|
||||
).toFixed(1)
|
||||
}}%)
|
||||
</v-list-item-title>
|
||||
<v-list-item-subtitle class="text-right mt-1">
|
||||
{{ platform.rom_count }} roms
|
||||
</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-progress-linear
|
||||
:model-value="
|
||||
getPercentage(platform.fs_size_bytes, props.total_filesize)
|
||||
"
|
||||
rounded
|
||||
color="primary"
|
||||
height="8"
|
||||
/>
|
||||
</div>
|
||||
<v-card-text class="pa-0">
|
||||
<v-row no-gutters>
|
||||
<v-col class="pa-4" cols="12">
|
||||
<v-select
|
||||
v-model="orderBy"
|
||||
:items="[
|
||||
{ title: 'Name', value: 'name' },
|
||||
{ title: 'Size', value: 'size' },
|
||||
]"
|
||||
label="Order by"
|
||||
variant="outlined"
|
||||
hide-details
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row no-gutters>
|
||||
<v-col v-for="platform in sortedPlatforms" cols="12" class="pa-4">
|
||||
<v-row no-gutters class="d-flex justify-space-between align-center">
|
||||
<v-col cols="6">
|
||||
<platform-list-item
|
||||
:platform="platform"
|
||||
:key="platform.slug"
|
||||
:showRomCount="false"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="6" class="text-right">
|
||||
<v-list-item>
|
||||
<v-list-item-title class="text-body-2">
|
||||
{{ formatBytes(Number(platform.fs_size_bytes)) }}
|
||||
({{
|
||||
getPlatformPercentage(
|
||||
platform.fs_size_bytes,
|
||||
props.total_filesize,
|
||||
).toFixed(1)
|
||||
}}%)
|
||||
</v-list-item-title>
|
||||
<v-list-item-subtitle class="text-right mt-1">
|
||||
{{ platform.rom_count }} roms
|
||||
</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-progress-linear
|
||||
:model-value="
|
||||
getPlatformPercentage(
|
||||
platform.fs_size_bytes,
|
||||
props.total_filesize,
|
||||
)
|
||||
"
|
||||
rounded
|
||||
color="primary"
|
||||
height="8"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
@@ -17,11 +17,6 @@ const { t } = useI18n();
|
||||
|
||||
<template>
|
||||
<v-card class="pa-4">
|
||||
<v-card-title class="text-h6 text-truncate mb-2">
|
||||
<v-icon class="mr-2">mdi-server</v-icon>
|
||||
{{ t("rom.summary") }}
|
||||
</v-card-title>
|
||||
<v-divider class="mb-3"></v-divider>
|
||||
<v-row dense>
|
||||
<v-col cols="6" md="4" lg="2">
|
||||
<v-sheet class="pa-3 text-center" color="toplayer" rounded>
|
||||
|
||||
Reference in New Issue
Block a user