mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34: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:
@@ -133,3 +133,68 @@ func applyUpdate[T comparable](values []T, mode RelationshipUpdateMode, existing
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type UpdateGroupDescriptions struct {
|
||||
Groups []GroupIDDescription `json:"groups"`
|
||||
Mode RelationshipUpdateMode `json:"mode"`
|
||||
}
|
||||
|
||||
// Apply applies the update to a list of existing ids, returning the result.
|
||||
func (u *UpdateGroupDescriptions) Apply(existing []GroupIDDescription) []GroupIDDescription {
|
||||
if u == nil {
|
||||
return existing
|
||||
}
|
||||
|
||||
switch u.Mode {
|
||||
case RelationshipUpdateModeAdd:
|
||||
return u.applyAdd(existing)
|
||||
case RelationshipUpdateModeRemove:
|
||||
return u.applyRemove(existing)
|
||||
case RelationshipUpdateModeSet:
|
||||
return u.Groups
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UpdateGroupDescriptions) applyAdd(existing []GroupIDDescription) []GroupIDDescription {
|
||||
// overwrite any existing values with the same id
|
||||
ret := append([]GroupIDDescription{}, existing...)
|
||||
for _, v := range u.Groups {
|
||||
found := false
|
||||
for i, vv := range ret {
|
||||
if vv.GroupID == v.GroupID {
|
||||
ret[i] = v
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (u *UpdateGroupDescriptions) applyRemove(existing []GroupIDDescription) []GroupIDDescription {
|
||||
// remove any existing values with the same id
|
||||
var ret []GroupIDDescription
|
||||
for _, v := range existing {
|
||||
found := false
|
||||
for _, vv := range u.Groups {
|
||||
if vv.GroupID == v.GroupID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// if not found in the remove list, keep it
|
||||
if !found {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user