diff --git a/backend/endpoints/rom.py b/backend/endpoints/rom.py index 4f6143d50..6808b6de8 100644 --- a/backend/endpoints/rom.py +++ b/backend/endpoints/rom.py @@ -181,6 +181,10 @@ def get_roms( str | None, Query(description="Virtual collection internal id."), ] = None, + smart_collection_id: Annotated[ + int | None, + Query(description="Smart collection internal id.", ge=1), + ] = None, matched: Annotated[ bool | None, Query(description="Whether the rom matched a metadata source."), @@ -274,6 +278,7 @@ def get_roms( platform_id=platform_id, collection_id=collection_id, virtual_collection_id=virtual_collection_id, + smart_collection_id=smart_collection_id, search_term=search_term, matched=matched, favourite=favourite, diff --git a/backend/handler/database/roms_handler.py b/backend/handler/database/roms_handler.py index 2dfd0743f..1d055e7f6 100644 --- a/backend/handler/database/roms_handler.py +++ b/backend/handler/database/roms_handler.py @@ -178,6 +178,18 @@ class DBRomsHandler(DBBaseHandler): return query.filter(Rom.id.in_(v_collection.rom_ids)) return query + def filter_by_smart_collection_id( + self, query: Query, session: Session, smart_collection_id: int + ): + smart_collection = ( + session.query(Collection) + .filter(Collection.id == smart_collection_id) + .one_or_none() + ) + if smart_collection: + return query.filter(Rom.id.in_(smart_collection.rom_ids)) + return query + def filter_by_search_term(self, query: Query, search_term: str): return query.filter( or_( @@ -390,6 +402,7 @@ class DBRomsHandler(DBBaseHandler): platform_id: int | None = None, collection_id: int | None = None, virtual_collection_id: str | None = None, + smart_collection_id: int | None = None, search_term: str | None = None, matched: bool | None = None, favourite: bool | None = None, @@ -421,6 +434,11 @@ class DBRomsHandler(DBBaseHandler): query, session, virtual_collection_id ) + if smart_collection_id: + query = self.filter_by_smart_collection_id( + query, session, smart_collection_id + ) + if search_term: query = self.filter_by_search_term(query, search_term) diff --git a/frontend/package.json b/frontend/package.json index 802bec82a..ba2c28bfd 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "build": "npm run typecheck && vite build", "preview": "vite preview", "typecheck": "vue-tsc --noEmit", - "generate": "openapi --input http://127.0.0.1:5000/openapi.json --output ./src/__generated__ --client axios --useOptions --useUnionTypes --exportServices false --exportSchemas false --exportCore false" + "generate": "openapi --input http://127.0.0.1:3000/openapi.json --output ./src/__generated__ --client axios --useOptions --useUnionTypes --exportServices false --exportSchemas false --exportCore false" }, "dependencies": { "@mdi/font": "7.4.47", diff --git a/frontend/src/__generated__/index.ts b/frontend/src/__generated__/index.ts index 26f6b203e..4ef214ec2 100644 --- a/frontend/src/__generated__/index.ts +++ b/frontend/src/__generated__/index.ts @@ -60,6 +60,7 @@ export type { SearchCoverSchema } from './models/SearchCoverSchema'; export type { SearchRomSchema } from './models/SearchRomSchema'; export type { SiblingRomSchema } from './models/SiblingRomSchema'; export type { SimpleRomSchema } from './models/SimpleRomSchema'; +export type { SmartCollectionSchema } from './models/SmartCollectionSchema'; export type { StateSchema } from './models/StateSchema'; export type { StatsReturn } from './models/StatsReturn'; export type { SystemDict } from './models/SystemDict'; diff --git a/frontend/src/__generated__/models/CollectionSchema.ts b/frontend/src/__generated__/models/CollectionSchema.ts index c34d1d21c..7cda2d3e3 100644 --- a/frontend/src/__generated__/models/CollectionSchema.ts +++ b/frontend/src/__generated__/models/CollectionSchema.ts @@ -11,6 +11,8 @@ export type CollectionSchema = { path_cover_large: (string | null); path_covers_small: Array; path_covers_large: Array; + created_at: string; + updated_at: string; id: number; url_cover: (string | null); user_id: number; @@ -18,7 +20,5 @@ export type CollectionSchema = { is_public: boolean; is_favorite: boolean; is_virtual?: boolean; - created_at: string; - updated_at: string; }; diff --git a/frontend/src/__generated__/models/SmartCollectionSchema.ts b/frontend/src/__generated__/models/SmartCollectionSchema.ts new file mode 100644 index 000000000..268e908bc --- /dev/null +++ b/frontend/src/__generated__/models/SmartCollectionSchema.ts @@ -0,0 +1,24 @@ +/* generated using openapi-typescript-codegen -- do not edit */ +/* istanbul ignore file */ +/* tslint:disable */ +/* eslint-disable */ +export type SmartCollectionSchema = { + name: string; + description?: string; + rom_ids?: Array; + rom_count: number; + path_cover_small: (string | null); + path_cover_large: (string | null); + path_covers_small: Array; + path_covers_large: Array; + created_at: string; + updated_at: string; + id: number; + filter_criteria: Record; + filter_summary: string; + user_id: number; + user__username: string; + is_public: boolean; + is_smart?: boolean; +}; + diff --git a/frontend/src/__generated__/models/VirtualCollectionSchema.ts b/frontend/src/__generated__/models/VirtualCollectionSchema.ts index c4e048d02..737070d74 100644 --- a/frontend/src/__generated__/models/VirtualCollectionSchema.ts +++ b/frontend/src/__generated__/models/VirtualCollectionSchema.ts @@ -11,12 +11,12 @@ export type VirtualCollectionSchema = { path_cover_large: (string | null); path_covers_small: Array; path_covers_large: Array; + created_at: string; + updated_at: string; id: string; type: string; is_public?: boolean; is_favorite?: boolean; is_virtual?: boolean; - created_at: string; - updated_at: string; }; diff --git a/frontend/src/components/Gallery/AppBar/Collection/Base.vue b/frontend/src/components/Gallery/AppBar/Collection/Base.vue index d62f401ed..7ce6cf944 100644 --- a/frontend/src/components/Gallery/AppBar/Collection/Base.vue +++ b/frontend/src/components/Gallery/AppBar/Collection/Base.vue @@ -6,23 +6,34 @@ import storeNavigation from "@/stores/navigation"; import storeRoms from "@/stores/roms"; import { storeToRefs } from "pinia"; import { useDisplay } from "vuetify"; +import { computed } from "vue"; // Props const { xs } = useDisplay(); const navigationStore = storeNavigation(); const romsStore = storeRoms(); -const { currentCollection } = storeToRefs(romsStore); +const { currentCollection, currentVirtualCollection, currentSmartCollection } = + storeToRefs(romsStore); + +// Get the currently active collection (any type) +const activeCollection = computed(() => { + return ( + currentCollection.value || + currentVirtualCollection.value || + currentSmartCollection.value + ); +});