Markers scene filter (#5097)

* Add scene filter to markers
* Fix labels for scenes
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
dogwithakeyboard 2024-08-27 08:23:34 +01:00 committed by GitHub
parent 62ff6f3c7f
commit 3089e1ad69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 3 deletions

View File

@ -191,6 +191,8 @@ input SceneMarkerFilterType {
scene_tags: HierarchicalMultiCriterionInput
"Filter to only include scene markers with these performers"
performers: MultiCriterionInput
"Filter to only include scene markers from these scenes"
scenes: MultiCriterionInput
"Filter by creation time"
created_at: TimestampCriterionInput
"Filter by last update time"

View File

@ -9,6 +9,8 @@ type SceneMarkerFilterType struct {
SceneTags *HierarchicalMultiCriterionInput `json:"scene_tags"`
// Filter to only include scene markers with these performers
Performers *MultiCriterionInput `json:"performers"`
// Filter to only include scene markers from these scenes
Scenes *MultiCriterionInput `json:"scenes"`
// Filter by created at
CreatedAt *TimestampCriterionInput `json:"created_at"`
// Filter by updated at

View File

@ -40,6 +40,7 @@ func (qb *sceneMarkerFilterHandler) criterionHandler() criterionHandler {
qb.tagsCriterionHandler(sceneMarkerFilter.Tags),
qb.sceneTagsCriterionHandler(sceneMarkerFilter.SceneTags),
qb.performersCriterionHandler(sceneMarkerFilter.Performers),
qb.scenesCriterionHandler(sceneMarkerFilter.Scenes),
&timestampCriterionHandler{sceneMarkerFilter.CreatedAt, "scene_markers.created_at", nil},
&timestampCriterionHandler{sceneMarkerFilter.UpdatedAt, "scene_markers.updated_at", nil},
&dateCriterionHandler{sceneMarkerFilter.SceneDate, "scenes.date", qb.joinScenes},
@ -187,3 +188,18 @@ func (qb *sceneMarkerFilterHandler) performersCriterionHandler(performers *model
handler(ctx, f)
}
}
func (qb *sceneMarkerFilterHandler) scenesCriterionHandler(scenes *models.MultiCriterionInput) criterionHandlerFunc {
addJoinsFunc := func(f *filterBuilder) {
f.addLeftJoin(sceneTable, "markers_scenes", "markers_scenes.id = scene_markers.scene_id")
}
h := multiCriterionHandlerBuilder{
primaryTable: sceneMarkerTable,
foreignTable: "markers_scenes",
joinTable: "",
primaryFK: sceneIDColumn,
foreignFK: sceneIDColumn,
addJoinsFunc: addJoinsFunc,
}
return h.handler(scenes)
}

View File

@ -1,6 +1,7 @@
import React from "react";
import { Form } from "react-bootstrap";
import { FilterSelect, SelectObject } from "src/components/Shared/Select";
import { objectTitle } from "src/core/files";
import { galleryTitle } from "src/core/galleries";
import { Criterion } from "src/models/list-filter/criteria/criterion";
import { ILabeledId } from "src/models/list-filter/types";
@ -31,8 +32,11 @@ export const LabeledIdFilter: React.FC<ILabeledIdFilterProps> = ({
}
function getLabel(i: SelectObject) {
if (inputType === "galleries") {
return galleryTitle(i);
switch (inputType) {
case "galleries":
return galleryTitle(i);
case "scenes":
return objectTitle(i);
}
return i.name ?? i.title ?? "";

View File

@ -1,4 +1,9 @@
import { ILabeledIdCriterion, ILabeledIdCriterionOption } from "./criterion";
import {
CriterionOption,
ILabeledIdCriterion,
ILabeledIdCriterionOption,
} from "./criterion";
import { CriterionModifier } from "src/core/generated-graphql";
const inputType = "scenes";
@ -15,3 +20,25 @@ export class ScenesCriterion extends ILabeledIdCriterion {
super(ScenesCriterionOption);
}
}
const modifierOptions = [
CriterionModifier.Includes,
CriterionModifier.Excludes,
];
const defaultModifier = CriterionModifier.Includes;
export const MarkersScenesCriterionOption = new CriterionOption({
messageID: "scenes",
type: "scenes",
modifierOptions,
defaultModifier,
inputType,
makeCriterion: () => new MarkersScenesCriterion(),
});
export class MarkersScenesCriterion extends ILabeledIdCriterion {
constructor() {
super(MarkersScenesCriterionOption);
}
}

View File

@ -1,4 +1,5 @@
import { PerformersCriterionOption } from "./criteria/performers";
import { MarkersScenesCriterionOption } from "./criteria/scenes";
import { SceneTagsCriterionOption, TagsCriterionOption } from "./criteria/tags";
import { ListFilterOptions } from "./filter-options";
import { DisplayMode } from "./types";
@ -18,6 +19,7 @@ const sortByOptions = [
const displayModeOptions = [DisplayMode.Wall];
const criterionOptions = [
TagsCriterionOption,
MarkersScenesCriterionOption,
SceneTagsCriterionOption,
PerformersCriterionOption,
createMandatoryTimestampCriterionOption("created_at"),