2022-04-26 00:17:36 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2022-05-02 00:37:26 +00:00
|
|
|
"github.com/fvbommel/sortorder"
|
2022-04-26 00:17:36 +00:00
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EndpointsByName []portainer.Endpoint
|
|
|
|
|
|
|
|
func (e EndpointsByName) Len() int {
|
|
|
|
return len(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EndpointsByName) Swap(i, j int) {
|
|
|
|
e[i], e[j] = e[j], e[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EndpointsByName) Less(i, j int) bool {
|
2022-05-02 00:37:26 +00:00
|
|
|
return sortorder.NaturalLess(strings.ToLower(e[i].Name), strings.ToLower(e[j].Name))
|
2022-04-26 00:17:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type EndpointsByGroup []portainer.Endpoint
|
|
|
|
|
|
|
|
func (e EndpointsByGroup) Len() int {
|
|
|
|
return len(e)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EndpointsByGroup) Swap(i, j int) {
|
|
|
|
e[i], e[j] = e[j], e[i]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e EndpointsByGroup) Less(i, j int) bool {
|
|
|
|
if e[i].GroupID == e[j].GroupID {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
groupA := endpointGroupNames[e[i].GroupID]
|
|
|
|
groupB := endpointGroupNames[e[j].GroupID]
|
|
|
|
|
2022-05-02 00:37:26 +00:00
|
|
|
return sortorder.NaturalLess(strings.ToLower(groupA), strings.ToLower(groupB))
|
2022-04-26 00:17:36 +00:00
|
|
|
}
|