mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 04:44:37 +03:00
Containing Group/Sub-Group relationships (#5105)
* Add UI support for setting containing groups * Show containing groups in group details panel * Move tag hierarchical filter code into separate type * Add depth to scene_count and add sub_group_count * Add sub-groups tab to groups page * Add containing groups to edit groups dialog * Show containing group description in sub-group view * Show group scene number in group scenes view * Add ability to drag move grid cards * Add sub group order option * Add reorder sub-groups interface * Separate page size selector component * Add interfaces to add and remove sub-groups to a group * Separate MultiSet components * Allow setting description while setting containing groups
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/stashapp/stash/pkg/ffmpeg"
|
||||
"github.com/stashapp/stash/pkg/fsutil"
|
||||
"github.com/stashapp/stash/pkg/gallery"
|
||||
"github.com/stashapp/stash/pkg/group"
|
||||
"github.com/stashapp/stash/pkg/image"
|
||||
"github.com/stashapp/stash/pkg/job"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
@@ -67,6 +68,10 @@ func Initialize(cfg *config.Config, l *log.Logger) (*Manager, error) {
|
||||
Folder: db.Folder,
|
||||
}
|
||||
|
||||
groupService := &group.Service{
|
||||
Repository: db.Group,
|
||||
}
|
||||
|
||||
sceneServer := &SceneServer{
|
||||
TxnManager: repo.TxnManager,
|
||||
SceneCoverGetter: repo.Scene,
|
||||
@@ -99,6 +104,7 @@ func Initialize(cfg *config.Config, l *log.Logger) (*Manager, error) {
|
||||
SceneService: sceneService,
|
||||
ImageService: imageService,
|
||||
GalleryService: galleryService,
|
||||
GroupService: groupService,
|
||||
|
||||
scanSubs: &subscriptionManager{},
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ type Manager struct {
|
||||
SceneService SceneService
|
||||
ImageService ImageService
|
||||
GalleryService GalleryService
|
||||
GroupService GroupService
|
||||
|
||||
scanSubs *subscriptionManager
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package manager
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/stashapp/stash/pkg/group"
|
||||
"github.com/stashapp/stash/pkg/image"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/scene"
|
||||
@@ -33,3 +34,12 @@ type GalleryService interface {
|
||||
|
||||
Updated(ctx context.Context, galleryID int) error
|
||||
}
|
||||
|
||||
type GroupService interface {
|
||||
Create(ctx context.Context, group *models.Group, frontimageData []byte, backimageData []byte) error
|
||||
UpdatePartial(ctx context.Context, id int, updatedGroup models.GroupPartial, frontImage group.ImageInput, backImage group.ImageInput) (*models.Group, error)
|
||||
|
||||
AddSubGroups(ctx context.Context, groupID int, subGroups []models.GroupIDDescription, insertIndex *int) error
|
||||
RemoveSubGroups(ctx context.Context, groupID int, subGroupIDs []int) error
|
||||
ReorderSubGroups(ctx context.Context, groupID int, subGroupIDs []int, insertPointID int, insertAfter bool) error
|
||||
}
|
||||
|
||||
@@ -1134,6 +1134,10 @@ func (t *ExportTask) exportGroup(ctx context.Context, wg *sync.WaitGroup, jobCha
|
||||
logger.Errorf("[groups] <%s> error getting group urls: %v", m.Name, err)
|
||||
continue
|
||||
}
|
||||
if err := m.LoadSubGroupIDs(ctx, r.Group); err != nil {
|
||||
logger.Errorf("[groups] <%s> error getting group sub-groups: %v", m.Name, err)
|
||||
continue
|
||||
}
|
||||
|
||||
newGroupJSON, err := group.ToJSON(ctx, groupReader, studioReader, m)
|
||||
|
||||
@@ -1150,6 +1154,25 @@ func (t *ExportTask) exportGroup(ctx context.Context, wg *sync.WaitGroup, jobCha
|
||||
|
||||
newGroupJSON.Tags = tag.GetNames(tags)
|
||||
|
||||
subGroups := m.SubGroups.List()
|
||||
if err := func() error {
|
||||
for _, sg := range subGroups {
|
||||
subGroup, err := groupReader.Find(ctx, sg.GroupID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting sub group: %v", err)
|
||||
}
|
||||
|
||||
newGroupJSON.SubGroups = append(newGroupJSON.SubGroups, jsonschema.SubGroupDescription{
|
||||
// TODO - this won't be unique
|
||||
Group: subGroup.Name,
|
||||
Description: sg.Description,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
logger.Errorf("[groups] <%s> %v", m.Name, err)
|
||||
}
|
||||
|
||||
if t.includeDependencies {
|
||||
if m.StudioID != nil {
|
||||
t.studios.IDs = sliceutil.AppendUnique(t.studios.IDs, *m.StudioID)
|
||||
|
||||
@@ -327,6 +327,7 @@ func (t *ImportTask) importStudio(ctx context.Context, studioJSON *jsonschema.St
|
||||
|
||||
func (t *ImportTask) ImportGroups(ctx context.Context) {
|
||||
logger.Info("[groups] importing")
|
||||
pendingSubs := make(map[string][]*jsonschema.Group)
|
||||
|
||||
path := t.json.json.Groups
|
||||
files, err := os.ReadDir(path)
|
||||
@@ -351,24 +352,72 @@ func (t *ImportTask) ImportGroups(ctx context.Context) {
|
||||
logger.Progressf("[groups] %d of %d", index, len(files))
|
||||
|
||||
if err := r.WithTxn(ctx, func(ctx context.Context) error {
|
||||
groupImporter := &group.Importer{
|
||||
ReaderWriter: r.Group,
|
||||
StudioWriter: r.Studio,
|
||||
TagWriter: r.Tag,
|
||||
Input: *groupJSON,
|
||||
MissingRefBehaviour: t.MissingRefBehaviour,
|
||||
return t.importGroup(ctx, groupJSON, pendingSubs, false)
|
||||
}); err != nil {
|
||||
var subError group.SubGroupNotExistError
|
||||
if errors.As(err, &subError) {
|
||||
missingSub := subError.MissingSubGroup()
|
||||
pendingSubs[missingSub] = append(pendingSubs[missingSub], groupJSON)
|
||||
continue
|
||||
}
|
||||
|
||||
return performImport(ctx, groupImporter, t.DuplicateBehaviour)
|
||||
}); err != nil {
|
||||
logger.Errorf("[groups] <%s> import failed: %v", fi.Name(), err)
|
||||
logger.Errorf("[groups] <%s> failed to import: %v", fi.Name(), err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range pendingSubs {
|
||||
for _, orphanGroupJSON := range s {
|
||||
if err := r.WithTxn(ctx, func(ctx context.Context) error {
|
||||
return t.importGroup(ctx, orphanGroupJSON, nil, true)
|
||||
}); err != nil {
|
||||
logger.Errorf("[groups] <%s> failed to create: %v", orphanGroupJSON.Name, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("[groups] import complete")
|
||||
}
|
||||
|
||||
func (t *ImportTask) importGroup(ctx context.Context, groupJSON *jsonschema.Group, pendingSub map[string][]*jsonschema.Group, fail bool) error {
|
||||
r := t.repository
|
||||
|
||||
importer := &group.Importer{
|
||||
ReaderWriter: r.Group,
|
||||
StudioWriter: r.Studio,
|
||||
TagWriter: r.Tag,
|
||||
Input: *groupJSON,
|
||||
MissingRefBehaviour: t.MissingRefBehaviour,
|
||||
}
|
||||
|
||||
// first phase: return error if parent does not exist
|
||||
if !fail {
|
||||
importer.MissingRefBehaviour = models.ImportMissingRefEnumFail
|
||||
}
|
||||
|
||||
if err := performImport(ctx, importer, t.DuplicateBehaviour); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, containingGroupJSON := range pendingSub[groupJSON.Name] {
|
||||
if err := t.importGroup(ctx, containingGroupJSON, pendingSub, fail); err != nil {
|
||||
var subError group.SubGroupNotExistError
|
||||
if errors.As(err, &subError) {
|
||||
missingSub := subError.MissingSubGroup()
|
||||
pendingSub[missingSub] = append(pendingSub[missingSub], containingGroupJSON)
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("failed to create containing group <%s>: %v", containingGroupJSON.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
delete(pendingSub, groupJSON.Name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *ImportTask) ImportFiles(ctx context.Context) {
|
||||
logger.Info("[files] importing")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user