mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Filter tag by hierarchy (#1746)
* Add API support for filtering tags by parent / children * Add parent & child tags filters for tags to UI * Add API support for filtering tags by parent / child count * Add parent & child count filters for tags to UI * Update db generator * Add missing build tag * Add unit tests Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -151,6 +151,11 @@ const (
|
||||
tagIdxWithGallery
|
||||
tagIdx1WithGallery
|
||||
tagIdx2WithGallery
|
||||
tagIdxWithChildTag
|
||||
tagIdxWithParentTag
|
||||
tagIdxWithGrandChild
|
||||
tagIdxWithParentAndChild
|
||||
tagIdxWithGrandParent
|
||||
// new indexes above
|
||||
// tags with dup names start from the end
|
||||
tagIdx1WithDupName
|
||||
@@ -345,6 +350,14 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
tagParentLinks = [][2]int{
|
||||
{tagIdxWithChildTag, tagIdxWithParentTag},
|
||||
{tagIdxWithGrandChild, tagIdxWithParentAndChild},
|
||||
{tagIdxWithParentAndChild, tagIdxWithGrandParent},
|
||||
}
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
ret := runTests(m)
|
||||
os.Exit(ret)
|
||||
@@ -499,6 +512,10 @@ func populateDB() error {
|
||||
return fmt.Errorf("error linking gallery studios: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := linkTagsParent(r.Tag()); err != nil {
|
||||
return fmt.Errorf("error linking tags parent: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := createMarker(r.SceneMarker(), sceneIdxWithMarker, tagIdxWithPrimaryMarker, []int{tagIdxWithMarker}); err != nil {
|
||||
return fmt.Errorf("error creating scene marker: %s", err.Error())
|
||||
}
|
||||
@@ -865,6 +882,22 @@ func getTagPerformerCount(id int) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func getTagParentCount(id int) int {
|
||||
if id == tagIDs[tagIdxWithParentTag] || id == tagIDs[tagIdxWithGrandParent] || id == tagIDs[tagIdxWithParentAndChild] {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func getTagChildCount(id int) int {
|
||||
if id == tagIDs[tagIdxWithChildTag] || id == tagIDs[tagIdxWithGrandChild] || id == tagIDs[tagIdxWithParentAndChild] {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
//createTags creates n tags with plain Name and o tags with camel cased NaMe included
|
||||
func createTags(tqb models.TagReaderWriter, n int, o int) error {
|
||||
const namePlain = "Name"
|
||||
@@ -1231,6 +1264,25 @@ func linkStudiosParent(qb models.StudioWriter) error {
|
||||
})
|
||||
}
|
||||
|
||||
func linkTagsParent(qb models.TagReaderWriter) error {
|
||||
return doLinks(tagParentLinks, func(parentIndex, childIndex int) error {
|
||||
tagID := tagIDs[childIndex]
|
||||
parentTags, err := qb.FindByChildTagID(tagID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var parentIDs []int
|
||||
for _, parentTag := range parentTags {
|
||||
parentIDs = append(parentIDs, parentTag.ID)
|
||||
}
|
||||
|
||||
parentIDs = append(parentIDs, tagIDs[parentIndex])
|
||||
|
||||
return qb.UpdateParentTags(tagID, parentIDs)
|
||||
})
|
||||
}
|
||||
|
||||
func addTagImage(qb models.TagWriter, tagIndex int) error {
|
||||
return qb.UpdateImage(tagIDs[tagIndex], models.DefaultTagImage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user