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:
WithoutPants
2024-08-30 11:43:44 +10:00
committed by GitHub
parent 96fdd94a01
commit bcf0fda7ac
99 changed files with 5388 additions and 935 deletions

112
pkg/group/update.go Normal file
View File

@@ -0,0 +1,112 @@
package group
import (
"context"
"fmt"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/sliceutil"
)
type SubGroupAlreadyInGroupError struct {
GroupIDs []int
}
func (e *SubGroupAlreadyInGroupError) Error() string {
return fmt.Sprintf("subgroups with IDs %v already in group", e.GroupIDs)
}
type ImageInput struct {
Image []byte
Set bool
}
func (s *Service) UpdatePartial(ctx context.Context, id int, updatedGroup models.GroupPartial, frontImage ImageInput, backImage ImageInput) (*models.Group, error) {
if err := s.validateUpdate(ctx, id, updatedGroup); err != nil {
return nil, err
}
r := s.Repository
group, err := r.UpdatePartial(ctx, id, updatedGroup)
if err != nil {
return nil, err
}
// update image table
if frontImage.Set {
if err := r.UpdateFrontImage(ctx, id, frontImage.Image); err != nil {
return nil, err
}
}
if backImage.Set {
if err := r.UpdateBackImage(ctx, id, backImage.Image); err != nil {
return nil, err
}
}
return group, nil
}
func (s *Service) AddSubGroups(ctx context.Context, groupID int, subGroups []models.GroupIDDescription, insertIndex *int) error {
// get the group
existing, err := s.Repository.Find(ctx, groupID)
if err != nil {
return err
}
// ensure it exists
if existing == nil {
return models.ErrNotFound
}
// ensure the subgroups aren't already sub-groups of the group
subGroupIDs := sliceutil.Map(subGroups, func(sg models.GroupIDDescription) int {
return sg.GroupID
})
existingSubGroupIDs, err := s.Repository.FindSubGroupIDs(ctx, groupID, subGroupIDs)
if err != nil {
return err
}
if len(existingSubGroupIDs) > 0 {
return &SubGroupAlreadyInGroupError{
GroupIDs: existingSubGroupIDs,
}
}
// validate the hierarchy
d := &models.UpdateGroupDescriptions{
Groups: subGroups,
Mode: models.RelationshipUpdateModeAdd,
}
if err := s.validateUpdateGroupHierarchy(ctx, existing, nil, d); err != nil {
return err
}
// validate insert index
if insertIndex != nil && *insertIndex < 0 {
return ErrInvalidInsertIndex
}
// add the subgroups
return s.Repository.AddSubGroups(ctx, groupID, subGroups, insertIndex)
}
func (s *Service) RemoveSubGroups(ctx context.Context, groupID int, subGroupIDs []int) error {
// get the group
existing, err := s.Repository.Find(ctx, groupID)
if err != nil {
return err
}
// ensure it exists
if existing == nil {
return models.ErrNotFound
}
// add the subgroups
return s.Repository.RemoveSubGroups(ctx, groupID, subGroupIDs)
}