mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
add ui option to fetch/show virtual platforms
This commit is contained in:
@@ -117,6 +117,8 @@ def get_collections(
|
||||
@protected_route(router.get, "/collections/virtual", [Scope.COLLECTIONS_READ])
|
||||
def get_virtual_collections(
|
||||
request: Request,
|
||||
type: str,
|
||||
limit: int | None = None,
|
||||
) -> list[VirtualCollectionSchema]:
|
||||
"""Get virtual collections endpoint
|
||||
|
||||
@@ -127,7 +129,7 @@ def get_virtual_collections(
|
||||
list[VirtualCollectionSchema]: List of virtual collections
|
||||
"""
|
||||
|
||||
virtual_collections = db_collection_handler.get_virtual_collections()
|
||||
virtual_collections = db_collection_handler.get_virtual_collections(type, limit)
|
||||
|
||||
return [VirtualCollectionSchema.model_validate(vc) for vc in virtual_collections]
|
||||
|
||||
|
||||
@@ -51,12 +51,13 @@ class DBCollectionsHandler(DBBaseHandler):
|
||||
|
||||
@begin_session
|
||||
def get_virtual_collections(
|
||||
self, session: Session = None
|
||||
self, type: str, limit: int | None = None, session: Session = None
|
||||
) -> Sequence[VirtualCollection]:
|
||||
return (
|
||||
session.scalars(
|
||||
select(VirtualCollection)
|
||||
.filter(VirtualCollection.type.in_(["collection"]))
|
||||
.filter(VirtualCollection.type.in_([type]))
|
||||
.limit(limit)
|
||||
.order_by(VirtualCollection.name.asc())
|
||||
)
|
||||
.unique()
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import InterfaceOption from "@/components/Settings/UserInterface/InterfaceOption.vue";
|
||||
import RSection from "@/components/common/RSection.vue";
|
||||
import collectionApi from "@/services/api/collection";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import { computed, ref } from "vue";
|
||||
import { isNull } from "lodash";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
// Props
|
||||
const { t } = useI18n();
|
||||
const collectionsStore = storeCollections();
|
||||
|
||||
// Initializing refs from localStorage
|
||||
const storedShowRecentRoms = localStorage.getItem("settings.showRecentRoms");
|
||||
const showRecentRomsRef = ref(
|
||||
@@ -48,6 +52,22 @@ const storedGridCollections = localStorage.getItem("settings.gridCollections");
|
||||
const gridCollectionsRef = ref(
|
||||
isNull(storedGridCollections) ? true : storedGridCollections === "true",
|
||||
);
|
||||
const storedShowVirtualCollections = localStorage.getItem(
|
||||
"settings.showVirtualCollections",
|
||||
);
|
||||
const showVirtualCollectionsRef = ref(
|
||||
isNull(storedShowVirtualCollections)
|
||||
? true
|
||||
: storedShowVirtualCollections === "true",
|
||||
);
|
||||
const storedVirtualCollectionType = localStorage.getItem(
|
||||
"settings.virtualCollectionType",
|
||||
);
|
||||
const virtualCollectionTypeRef = ref(
|
||||
isNull(storedVirtualCollectionType)
|
||||
? "collection"
|
||||
: storedVirtualCollectionType,
|
||||
);
|
||||
|
||||
const storedGroupRoms = localStorage.getItem("settings.groupRoms");
|
||||
const groupRomsRef = ref(
|
||||
@@ -214,6 +234,20 @@ const toggleGridCollections = (value: boolean) => {
|
||||
gridCollectionsRef.value = value;
|
||||
localStorage.setItem("settings.gridCollections", value.toString());
|
||||
};
|
||||
const toggleShowVirtualCollections = (value: boolean) => {
|
||||
showVirtualCollectionsRef.value = value;
|
||||
localStorage.setItem("settings.showVirtualCollections", value.toString());
|
||||
};
|
||||
const setVirtualCollectionType = async (value: string) => {
|
||||
virtualCollectionTypeRef.value = value;
|
||||
localStorage.setItem("settings.virtualCollectionType", value);
|
||||
|
||||
await collectionApi
|
||||
.getVirtualCollections({ type: value })
|
||||
.then(({ data: virtualCollections }) => {
|
||||
collectionsStore.setVirtual(virtualCollections);
|
||||
});
|
||||
};
|
||||
|
||||
const toggleGroupRoms = (value: boolean) => {
|
||||
groupRomsRef.value = value;
|
||||
@@ -295,6 +329,43 @@ const toggleStatus = (value: boolean) => {
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-chip
|
||||
label
|
||||
variant="text"
|
||||
prepend-icon="mdi-view-grid"
|
||||
class="ml-2 mt-4"
|
||||
>{{ t("settings.virtual-collections") }}</v-chip
|
||||
>
|
||||
<v-divider class="border-opacity-25 mx-2 mb-2" />
|
||||
<v-row class="py-1" no-gutters>
|
||||
<v-col cols="12" md="6">
|
||||
<interface-option
|
||||
class="mx-2"
|
||||
:title="t('settings.show-virtual-collections')"
|
||||
:description="t('settings.show-virtual-collections-desc')"
|
||||
:icon="
|
||||
showVirtualCollectionsRef
|
||||
? 'mdi-bookmark-box-multiple'
|
||||
: 'mdi-bookmark-box-multiple'
|
||||
"
|
||||
v-model="showVirtualCollectionsRef"
|
||||
@update:model-value="toggleShowVirtualCollections"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col cols="12" md="6">
|
||||
<v-select
|
||||
v-model="virtualCollectionTypeRef"
|
||||
:items="['collection', 'franchise', 'genre', 'mode', 'company']"
|
||||
:label="t('settings.virtual-collection-type')"
|
||||
class="mx-2"
|
||||
dense
|
||||
outlined
|
||||
hide-details
|
||||
:disabled="!showVirtualCollectionsRef"
|
||||
@update:model-value="setVirtualCollectionType"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</template>
|
||||
</r-section>
|
||||
</template>
|
||||
|
||||
@@ -34,7 +34,7 @@ withDefaults(
|
||||
class="py-1 pl-1"
|
||||
>
|
||||
<template #prepend>
|
||||
<r-avatar :size="75" :collection="collection" />
|
||||
<r-avatar :size="48" :collection="collection" />
|
||||
</template>
|
||||
<v-row v-if="withTitle" no-gutters
|
||||
><v-col
|
||||
|
||||
@@ -34,7 +34,7 @@ withDefaults(
|
||||
class="py-1 pl-1"
|
||||
>
|
||||
<template #prepend>
|
||||
<r-avatar :size="75" :collection="collection" />
|
||||
<r-avatar :size="48" :collection="collection" />
|
||||
</template>
|
||||
<v-row v-if="withTitle" no-gutters
|
||||
><v-col
|
||||
|
||||
@@ -10,6 +10,7 @@ import { storeToRefs } from "pinia";
|
||||
import { inject } from "vue";
|
||||
import { useDisplay } from "vuetify";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { isNull } from "lodash";
|
||||
|
||||
// Props
|
||||
const { t } = useI18n();
|
||||
@@ -21,6 +22,12 @@ const { filteredCollections, filteredVirtualCollections, searchText } =
|
||||
const { activeCollectionsDrawer } = storeToRefs(navigationStore);
|
||||
const emitter = inject<Emitter<Events>>("emitter");
|
||||
|
||||
const showVirtualCollections = isNull(
|
||||
localStorage.getItem("settings.showVirtualCollections"),
|
||||
)
|
||||
? true
|
||||
: localStorage.getItem("settings.showVirtualCollections") === "true";
|
||||
|
||||
async function addCollection() {
|
||||
emitter?.emit("showCreateCollectionDialog", null);
|
||||
}
|
||||
@@ -57,14 +64,16 @@ function clear() {
|
||||
:collection="collection"
|
||||
with-link
|
||||
/>
|
||||
<v-list-subheader class="uppercase">{{
|
||||
t("common.virtual-collections").toUpperCase()
|
||||
}}</v-list-subheader>
|
||||
<virtual-collection-list-item
|
||||
v-for="collection in filteredVirtualCollections"
|
||||
:collection="collection"
|
||||
with-link
|
||||
/>
|
||||
<template v-if="showVirtualCollections">
|
||||
<v-list-subheader class="uppercase">{{
|
||||
t("common.virtual-collections").toUpperCase()
|
||||
}}</v-list-subheader>
|
||||
<virtual-collection-list-item
|
||||
v-for="collection in filteredVirtualCollections"
|
||||
:collection="collection"
|
||||
with-link
|
||||
/>
|
||||
</template>
|
||||
</v-list>
|
||||
<template #append>
|
||||
<v-btn
|
||||
|
||||
@@ -18,7 +18,8 @@ import storeNavigation from "@/stores/navigation";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import type { Emitter } from "mitt";
|
||||
import { inject, onBeforeMount } from "vue";
|
||||
import { inject, onBeforeMount, ref } from "vue";
|
||||
import { isNull } from "lodash";
|
||||
|
||||
// Props
|
||||
const navigationStore = storeNavigation();
|
||||
@@ -30,6 +31,21 @@ emitter?.on("refreshDrawer", async () => {
|
||||
platformsStore.set(platformData);
|
||||
});
|
||||
|
||||
const showVirtualCollections = isNull(
|
||||
localStorage.getItem("settings.showVirtualCollections"),
|
||||
)
|
||||
? true
|
||||
: localStorage.getItem("settings.showVirtualCollections") === "true";
|
||||
|
||||
const storedVirtualCollectionType = localStorage.getItem(
|
||||
"settings.virtualCollectionType",
|
||||
);
|
||||
const virtualCollectionTypeRef = ref(
|
||||
isNull(storedVirtualCollectionType)
|
||||
? "collection"
|
||||
: storedVirtualCollectionType,
|
||||
);
|
||||
|
||||
// Functions
|
||||
onBeforeMount(async () => {
|
||||
await platformApi
|
||||
@@ -40,6 +56,7 @@ onBeforeMount(async () => {
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
await collectionApi
|
||||
.getCollections()
|
||||
.then(({ data: collections }) => {
|
||||
@@ -53,11 +70,15 @@ onBeforeMount(async () => {
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
await collectionApi
|
||||
.getVirtualCollections()
|
||||
.then(({ data: virtualCollections }) => {
|
||||
collectionsStore.setVirtual(virtualCollections);
|
||||
});
|
||||
|
||||
if (showVirtualCollections) {
|
||||
await collectionApi
|
||||
.getVirtualCollections({ type: virtualCollectionTypeRef.value })
|
||||
.then(({ data: virtualCollections }) => {
|
||||
collectionsStore.setVirtual(virtualCollections);
|
||||
});
|
||||
}
|
||||
|
||||
navigationStore.resetDrawers();
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -27,8 +27,14 @@ async function getCollections(): Promise<{ data: Collection[] }> {
|
||||
return api.get("/collections");
|
||||
}
|
||||
|
||||
async function getVirtualCollections(): Promise<{ data: VirtualCollection[] }> {
|
||||
return api.get("/collections/virtual");
|
||||
async function getVirtualCollections({
|
||||
type = "collection",
|
||||
limit = 100,
|
||||
}: {
|
||||
type?: string;
|
||||
limit?: number;
|
||||
}): Promise<{ data: VirtualCollection[] }> {
|
||||
return api.get("/collections/virtual", { params: { type, limit } });
|
||||
}
|
||||
|
||||
async function getCollection(id: number): Promise<{ data: Collection }> {
|
||||
|
||||
@@ -38,6 +38,11 @@ const showPlatforms = isNull(localStorage.getItem("settings.showPlatforms"))
|
||||
const showCollections = isNull(localStorage.getItem("settings.showCollections"))
|
||||
? true
|
||||
: localStorage.getItem("settings.showCollections") === "true";
|
||||
const showVirtualCollections = isNull(
|
||||
localStorage.getItem("settings.showVirtualCollections"),
|
||||
)
|
||||
? true
|
||||
: localStorage.getItem("settings.showVirtualCollections") === "true";
|
||||
const fetchingRecentAdded = ref(false);
|
||||
const fetchingContinuePlaying = ref(false);
|
||||
|
||||
@@ -95,6 +100,6 @@ onMounted(async () => {
|
||||
<platforms v-if="filledPlatforms.length > 0 && showPlatforms" />
|
||||
<collections v-if="allCollections.length > 0 && showCollections" />
|
||||
<virtual-collections
|
||||
v-if="virtualCollections.length > 0 && showCollections"
|
||||
v-if="virtualCollections.length > 0 && showVirtualCollections"
|
||||
/>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user