Skip to content

Commit

Permalink
Add scenes filter to galleries (#4840)
Browse files Browse the repository at this point in the history
  • Loading branch information
bob123491234 authored May 20, 2024
1 parent 769540b commit 3e3e8b9
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions graphql/schema/types/filters.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ input GalleryFilterType {
average_resolution: ResolutionCriterionInput
"Filter to only include galleries that have chapters. `true` or `false`"
has_chapters: String
"Filter to only include galleries with these scenes"
scenes: MultiCriterionInput
"Filter to only include galleries with this studio"
studios: HierarchicalMultiCriterionInput
"Filter to only include galleries with these tags"
Expand Down
2 changes: 2 additions & 0 deletions pkg/models/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type GalleryFilterType struct {
AverageResolution *ResolutionCriterionInput `json:"average_resolution"`
// Filter to only include scenes which have chapters. `true` or `false`
HasChapters *string `json:"has_chapters"`
// Filter to only include galleries with these scenes
Scenes *MultiCriterionInput `json:"scenes"`
// Filter to only include galleries with this studio
Studios *HierarchicalMultiCriterionInput `json:"studios"`
// Filter to only include galleries with these tags
Expand Down
2 changes: 1 addition & 1 deletion pkg/scraper/stashbox/graphql/generated_models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/sqlite/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ func (qb *GalleryStore) makeFilter(ctx context.Context, galleryFilter *models.Ga
query.handleCriterion(ctx, galleryPerformersCriterionHandler(qb, galleryFilter.Performers))
query.handleCriterion(ctx, galleryPerformerCountCriterionHandler(qb, galleryFilter.PerformerCount))
query.handleCriterion(ctx, hasChaptersCriterionHandler(galleryFilter.HasChapters))
query.handleCriterion(ctx, galleryScenesCriterionHandler(qb, galleryFilter.Scenes))
query.handleCriterion(ctx, studioCriterionHandler(galleryTable, galleryFilter.Studios))
query.handleCriterion(ctx, galleryPerformerTagsCriterionHandler(qb, galleryFilter.PerformerTags))
query.handleCriterion(ctx, galleryAverageResolutionCriterionHandler(qb, galleryFilter.AverageResolution))
Expand Down Expand Up @@ -827,6 +828,17 @@ func galleryURLsCriterionHandler(url *models.StringCriterionInput) criterionHand
return h.handler(url)
}

func (qb *GalleryStore) getMultiCriterionHandlerBuilder(foreignTable, joinTable, foreignFK string, addJoinsFunc func(f *filterBuilder)) multiCriterionHandlerBuilder {
return multiCriterionHandlerBuilder{
primaryTable: galleryTable,
foreignTable: foreignTable,
joinTable: joinTable,
primaryFK: galleryIDColumn,
foreignFK: foreignFK,
addJoinsFunc: addJoinsFunc,
}
}

func (qb *GalleryStore) galleryPathCriterionHandler(c *models.StringCriterionInput) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if c != nil {
Expand Down Expand Up @@ -958,6 +970,15 @@ func galleryTagCountCriterionHandler(qb *GalleryStore, tagCount *models.IntCrite
return h.handler(tagCount)
}

func galleryScenesCriterionHandler(qb *GalleryStore, scenes *models.MultiCriterionInput) criterionHandlerFunc {
addJoinsFunc := func(f *filterBuilder) {
qb.scenesRepository().join(f, "", "galleries.id")
f.addLeftJoin("scenes", "", "scenes_galleries.scene_id = scenes.id")
}
h := qb.getMultiCriterionHandlerBuilder(sceneTable, galleriesScenesTable, "scene_id", addJoinsFunc)
return h.handler(scenes)
}

func galleryPerformersCriterionHandler(qb *GalleryStore, performers *models.MultiCriterionInput) criterionHandlerFunc {
h := joinedMultiCriterionHandlerBuilder{
primaryTable: galleryTable,
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/components/List/Filters/LabeledIdFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const LabeledIdFilter: React.FC<ILabeledIdFilterProps> = ({
inputType !== "scene_tags" &&
inputType !== "performer_tags" &&
inputType !== "tags" &&
inputType !== "scenes" &&
inputType !== "movies" &&
inputType !== "galleries"
) {
Expand Down
3 changes: 3 additions & 0 deletions ui/v2.5/src/components/Shared/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface ITypeProps {
| "tags"
| "scene_tags"
| "performer_tags"
| "scenes"
| "movies"
| "galleries";
}
Expand Down Expand Up @@ -379,6 +380,8 @@ export const FilterSelect: React.FC<IFilterProps & ITypeProps> = (props) => {
return <PerformerSelect {...props} creatable={false} />;
case "studios":
return <StudioSelect {...props} creatable={false} />;
case "scenes":
return <SceneSelect {...props} creatable={false} />;
case "movies":
return <MovieSelect {...props} creatable={false} />;
case "galleries":
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/models/list-filter/criteria/criterion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export type InputType =
| "studios"
| "tags"
| "performer_tags"
| "scenes"
| "scene_tags"
| "movies"
| "galleries"
Expand Down
17 changes: 17 additions & 0 deletions ui/v2.5/src/models/list-filter/criteria/scenes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ILabeledIdCriterion, ILabeledIdCriterionOption } from "./criterion";

const inputType = "scenes";

export const ScenesCriterionOption = new ILabeledIdCriterionOption(
"scenes",
"scenes",
true,
inputType,
() => new ScenesCriterion()
);

export class ScenesCriterion extends ILabeledIdCriterion {
constructor() {
super(ScenesCriterionOption);
}
}
2 changes: 2 additions & 0 deletions ui/v2.5/src/models/list-filter/galleries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { OrganizedCriterionOption } from "./criteria/organized";
import { HasChaptersCriterionOption } from "./criteria/has-chapters";
import { PerformersCriterionOption } from "./criteria/performers";
import { AverageResolutionCriterionOption } from "./criteria/resolution";
import { ScenesCriterionOption } from "./criteria/scenes";
import { StudiosCriterionOption } from "./criteria/studios";
import {
PerformerTagsCriterionOption,
Expand Down Expand Up @@ -61,6 +62,7 @@ const criterionOptions = [
createMandatoryNumberCriterionOption("performer_age"),
PerformerFavoriteCriterionOption,
createMandatoryNumberCriterionOption("image_count"),
ScenesCriterionOption,
StudiosCriterionOption,
createStringCriterionOption("url"),
createMandatoryNumberCriterionOption("file_count", "zip_file_count"),
Expand Down
1 change: 1 addition & 0 deletions ui/v2.5/src/models/list-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export type CriterionType =
| "tag_count"
| "performers"
| "studios"
| "scenes"
| "movies"
| "galleries"
| "birth_year"
Expand Down

0 comments on commit 3e3e8b9

Please sign in to comment.