mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
add previous selection
This commit is contained in:
parent
8959695349
commit
ca23f3f190
@ -3,6 +3,7 @@ package piwigotools
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
@ -53,8 +54,10 @@ func (t Tags) JoinIds(sep string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t Tags) Selector(exclude *regexp.Regexp, keepFilter bool) func() Tags {
|
func (t Tags) Selector(exclude *regexp.Regexp, keepFilter bool) func() Tags {
|
||||||
options := make([]string, 0, len(t))
|
options := make([]string, 1, len(t))
|
||||||
|
options[0] = "Same as before"
|
||||||
tags := map[string]*Tag{}
|
tags := map[string]*Tag{}
|
||||||
|
tags[options[0]] = nil
|
||||||
for _, tag := range t {
|
for _, tag := range t {
|
||||||
if exclude != nil && exclude.MatchString(tag.Name) {
|
if exclude != nil && exclude.MatchString(tag.Name) {
|
||||||
continue
|
continue
|
||||||
@ -63,6 +66,7 @@ func (t Tags) Selector(exclude *regexp.Regexp, keepFilter bool) func() Tags {
|
|||||||
tags[tag.Name] = tag
|
tags[tag.Name] = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var previousTags Tags
|
||||||
return func() Tags {
|
return func() Tags {
|
||||||
answer := []string{}
|
answer := []string{}
|
||||||
|
|
||||||
@ -72,10 +76,29 @@ func (t Tags) Selector(exclude *regexp.Regexp, keepFilter bool) func() Tags {
|
|||||||
PageSize: 20,
|
PageSize: 20,
|
||||||
}, &answer, survey.WithKeepFilter(keepFilter))
|
}, &answer, survey.WithKeepFilter(keepFilter))
|
||||||
|
|
||||||
result := make([]*Tag, len(answer))
|
result := make([]*Tag, 0, len(answer))
|
||||||
for i, a := range answer {
|
alreadySelected := map[int]bool{}
|
||||||
result[i] = tags[a]
|
for _, a := range answer {
|
||||||
|
if tags[a] == nil {
|
||||||
|
for _, p := range previousTags {
|
||||||
|
if _, ok := alreadySelected[p.Id]; !ok {
|
||||||
|
result = append(result, p)
|
||||||
|
}
|
||||||
|
alreadySelected[p.Id] = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, ok := alreadySelected[tags[a].Id]; !ok {
|
||||||
|
result = append(result, tags[a])
|
||||||
|
}
|
||||||
|
alreadySelected[tags[a].Id] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
return result[i].Name < result[j].Name
|
||||||
|
})
|
||||||
|
|
||||||
|
previousTags = result
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user