stash/pkg/models/model_joins.go
WithoutPants bcf0fda7ac
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
2024-08-30 11:43:44 +10:00

75 lines
1.5 KiB
Go

package models
import (
"fmt"
"strconv"
)
type GroupsScenes struct {
GroupID int `json:"movie_id"`
// SceneID int `json:"scene_id"`
SceneIndex *int `json:"scene_index"`
}
func (s GroupsScenes) SceneMovieInput() SceneMovieInput {
return SceneMovieInput{
MovieID: strconv.Itoa(s.GroupID),
SceneIndex: s.SceneIndex,
}
}
func (s GroupsScenes) Equal(o GroupsScenes) bool {
return o.GroupID == s.GroupID && ((o.SceneIndex == nil && s.SceneIndex == nil) ||
(o.SceneIndex != nil && s.SceneIndex != nil && *o.SceneIndex == *s.SceneIndex))
}
type UpdateGroupIDs struct {
Groups []GroupsScenes `json:"movies"`
Mode RelationshipUpdateMode `json:"mode"`
}
func (u *UpdateGroupIDs) SceneMovieInputs() []SceneMovieInput {
if u == nil {
return nil
}
ret := make([]SceneMovieInput, len(u.Groups))
for _, id := range u.Groups {
ret = append(ret, id.SceneMovieInput())
}
return ret
}
func (u *UpdateGroupIDs) AddUnique(v GroupsScenes) {
for _, vv := range u.Groups {
if vv.GroupID == v.GroupID {
return
}
}
u.Groups = append(u.Groups, v)
}
func GroupsScenesFromInput(input []SceneMovieInput) ([]GroupsScenes, error) {
ret := make([]GroupsScenes, len(input))
for i, v := range input {
mID, err := strconv.Atoi(v.MovieID)
if err != nil {
return nil, fmt.Errorf("invalid movie ID: %s", v.MovieID)
}
ret[i] = GroupsScenes{
GroupID: mID,
SceneIndex: v.SceneIndex,
}
}
return ret, nil
}
type GroupIDDescription struct {
GroupID int `json:"group_id"`
Description string `json:"description"`
}