mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
move ProjectSorter to package model to avoid package import cycle
This commit is contained in:
parent
3305e0406d
commit
1c2babda0a
@ -68,7 +68,7 @@ func (s *SearchAPI) Get() {
|
||||
}
|
||||
}
|
||||
|
||||
projectSorter := &utils.ProjectSorter{Projects: projects}
|
||||
projectSorter := &models.ProjectSorter{Projects: projects}
|
||||
sort.Sort(projectSorter)
|
||||
projectResult := []map[string]interface{}{}
|
||||
for _, p := range projects {
|
||||
|
@ -37,3 +37,23 @@ type Project struct {
|
||||
Role int `json:"current_user_role_id"`
|
||||
RepoCount int `json:"repo_count"`
|
||||
}
|
||||
|
||||
// ProjectSorter holds an array of projects
|
||||
type ProjectSorter struct {
|
||||
Projects []Project
|
||||
}
|
||||
|
||||
// Len returns the length of array in ProjectSorter
|
||||
func (ps *ProjectSorter) Len() int {
|
||||
return len(ps.Projects)
|
||||
}
|
||||
|
||||
// Less defines the comparison rules of project
|
||||
func (ps *ProjectSorter) Less(i, j int) bool {
|
||||
return ps.Projects[i].Name < ps.Projects[j].Name
|
||||
}
|
||||
|
||||
// Swap swaps the position of i and j
|
||||
func (ps *ProjectSorter) Swap(i, j int) {
|
||||
ps.Projects[i], ps.Projects[j] = ps.Projects[j], ps.Projects[i]
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ package utils
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/harbor/models"
|
||||
)
|
||||
|
||||
// Repository holds information about repository
|
||||
@ -35,26 +33,6 @@ func (r *Repository) GetProject() string {
|
||||
return r.Name[0:strings.LastIndex(r.Name, "/")]
|
||||
}
|
||||
|
||||
// ProjectSorter holds an array of projects
|
||||
type ProjectSorter struct {
|
||||
Projects []models.Project
|
||||
}
|
||||
|
||||
// Len returns the length of array in ProjectSorter
|
||||
func (ps *ProjectSorter) Len() int {
|
||||
return len(ps.Projects)
|
||||
}
|
||||
|
||||
// Less defines the comparison rules of project
|
||||
func (ps *ProjectSorter) Less(i, j int) bool {
|
||||
return ps.Projects[i].Name < ps.Projects[j].Name
|
||||
}
|
||||
|
||||
// Swap swaps the position of i and j
|
||||
func (ps *ProjectSorter) Swap(i, j int) {
|
||||
ps.Projects[i], ps.Projects[j] = ps.Projects[j], ps.Projects[i]
|
||||
}
|
||||
|
||||
// FormatEndpoint formats endpoint
|
||||
func FormatEndpoint(endpoint string) string {
|
||||
endpoint = strings.TrimSpace(endpoint)
|
||||
|
Loading…
Reference in New Issue
Block a user