2020-02-04 05:18:22 +01:00
|
|
|
package form
|
|
|
|
|
2020-06-24 12:01:25 +02:00
|
|
|
import "strings"
|
|
|
|
|
2023-07-23 17:57:48 +02:00
|
|
|
// Selection represents items selected in the user interface.
|
2020-02-04 05:18:22 +01:00
|
|
|
type Selection struct {
|
2023-07-23 17:57:48 +02:00
|
|
|
All bool `json:"all"`
|
2021-09-17 14:26:12 +02:00
|
|
|
Files []string `json:"files"`
|
|
|
|
Photos []string `json:"photos"`
|
|
|
|
Albums []string `json:"albums"`
|
|
|
|
Labels []string `json:"labels"`
|
|
|
|
Places []string `json:"places"`
|
|
|
|
Subjects []string `json:"subjects"`
|
2020-02-04 05:18:22 +01:00
|
|
|
}
|
|
|
|
|
2023-07-23 17:57:48 +02:00
|
|
|
// Empty checks if any specific items were selected.
|
2020-02-04 05:18:22 +01:00
|
|
|
func (f Selection) Empty() bool {
|
2020-05-25 19:10:44 +02:00
|
|
|
switch {
|
|
|
|
case len(f.Files) > 0:
|
|
|
|
return false
|
|
|
|
case len(f.Photos) > 0:
|
|
|
|
return false
|
|
|
|
case len(f.Albums) > 0:
|
|
|
|
return false
|
|
|
|
case len(f.Labels) > 0:
|
|
|
|
return false
|
|
|
|
case len(f.Places) > 0:
|
2020-02-04 05:18:22 +01:00
|
|
|
return false
|
2021-09-17 14:26:12 +02:00
|
|
|
case len(f.Subjects) > 0:
|
|
|
|
return false
|
2020-02-04 05:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2020-06-24 12:01:25 +02:00
|
|
|
|
2023-07-23 17:57:48 +02:00
|
|
|
// Get returns a string slice with the selected item UIDs.
|
|
|
|
func (f Selection) Get() []string {
|
2020-06-24 12:01:25 +02:00
|
|
|
var all []string
|
|
|
|
|
|
|
|
copy(all, f.Files)
|
|
|
|
|
|
|
|
all = append(all, f.Photos...)
|
|
|
|
all = append(all, f.Albums...)
|
|
|
|
all = append(all, f.Labels...)
|
|
|
|
all = append(all, f.Places...)
|
2021-09-17 14:26:12 +02:00
|
|
|
all = append(all, f.Subjects...)
|
2020-06-24 12:01:25 +02:00
|
|
|
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
2023-07-23 17:57:48 +02:00
|
|
|
// String returns a string containing all selected item UIDs.
|
2020-06-24 12:01:25 +02:00
|
|
|
func (f Selection) String() string {
|
2023-07-23 17:57:48 +02:00
|
|
|
return strings.Join(f.Get(), ", ")
|
2020-06-24 12:01:25 +02:00
|
|
|
}
|