|
|
|
@ -92,12 +92,6 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
|
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve environment groups from the database", err}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create endpoint groups as a map for more convenient access
|
|
|
|
|
endpointGroupNames = make(map[portainer.EndpointGroupID]string, 0)
|
|
|
|
|
for _, group := range endpointGroups {
|
|
|
|
|
endpointGroupNames[group.ID] = group.Name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endpoints, err := handler.DataStore.Endpoint().Endpoints()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve environments from the database", err}
|
|
|
|
@ -163,7 +157,7 @@ func (handler *Handler) endpointList(w http.ResponseWriter, r *http.Request) *ht
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort endpoints by field
|
|
|
|
|
sortEndpointsByField(filteredEndpoints, sortField, sortOrder == "desc")
|
|
|
|
|
sortEndpointsByField(filteredEndpoints, endpointGroups, sortField, sortOrder == "desc")
|
|
|
|
|
|
|
|
|
|
filteredEndpointCount := len(filteredEndpoints)
|
|
|
|
|
|
|
|
|
@ -260,7 +254,7 @@ func filterEndpointsByStatuses(endpoints []portainer.Endpoint, statuses []int, s
|
|
|
|
|
return filteredEndpoints
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sortEndpointsByField(endpoints []portainer.Endpoint, sortField string, isSortDesc bool) {
|
|
|
|
|
func sortEndpointsByField(endpoints []portainer.Endpoint, endpointGroups []portainer.EndpointGroup, sortField string, isSortDesc bool) {
|
|
|
|
|
|
|
|
|
|
switch sortField {
|
|
|
|
|
case "Name":
|
|
|
|
@ -271,10 +265,20 @@ func sortEndpointsByField(endpoints []portainer.Endpoint, sortField string, isSo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Group":
|
|
|
|
|
endpointGroupNames = make(map[portainer.EndpointGroupID]string, 0)
|
|
|
|
|
for _, group := range endpointGroups {
|
|
|
|
|
endpointGroupNames[group.ID] = group.Name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
endpointsByGroup := EndpointsByGroup{
|
|
|
|
|
endpointGroupNames: endpointGroupNames,
|
|
|
|
|
endpoints: endpoints,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if isSortDesc {
|
|
|
|
|
sort.Stable(sort.Reverse(EndpointsByGroup(endpoints)))
|
|
|
|
|
sort.Stable(sort.Reverse(endpointsByGroup))
|
|
|
|
|
} else {
|
|
|
|
|
sort.Stable(EndpointsByGroup(endpoints))
|
|
|
|
|
sort.Stable(endpointsByGroup)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "Status":
|
|
|
|
|