udpate resource list order

1, order label by creation time.
2, order webhook policy by creation time.
3, order replication policy by creation time.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
wang yan 2020-08-18 17:52:27 +08:00
parent da52e677e5
commit 648b80bc34
4 changed files with 4 additions and 4 deletions

View File

@ -60,7 +60,7 @@ func ListLabels(query *models.LabelQuery) ([]*models.Label, error) {
qs = qs.Offset((query.Page - 1) * query.Size)
}
}
qs = qs.OrderBy("Name")
qs = qs.OrderBy("-CreationTime")
labels := []*models.Label{}
_, err := qs.All(&labels)

View File

@ -32,7 +32,7 @@ func GetNotificationPolicyByName(name string, projectID int64) (*models.Notifica
// GetNotificationPolicies returns all notification policy in project
func GetNotificationPolicies(projectID int64) ([]*models.NotificationPolicy, error) {
var policies []*models.NotificationPolicy
qs := dao.GetOrmer().QueryTable(new(models.NotificationPolicy)).Filter("ProjectID", projectID)
qs := dao.GetOrmer().QueryTable(new(models.NotificationPolicy)).Filter("ProjectID", projectID).OrderBy("-CreationTime")
_, err := qs.All(&policies)
if err != nil {

View File

@ -61,7 +61,7 @@ func GetPolicies(queries ...*model.PolicyQuery) (int64, []*models.RepPolicy, err
if query.Page > 0 && query.Size > 0 {
qs = qs.Limit(query.Size, (query.Page-1)*query.Size)
}
_, err = qs.All(&policies)
_, err = qs.OrderBy("-CreationTime").All(&policies)
if err != nil {
return total, nil, err
}

View File

@ -97,7 +97,7 @@ func TestGetPolicies(t *testing.T) {
}{
{name: "GetTotalOfRepPolicies nil", args: args{name: "Test 0"}, wantPolicies: []*models.RepPolicy{}},
{name: "GetTotalOfRepPolicies 1", args: args{name: "Test 1"}, wantPolicies: []*models.RepPolicy{testPolic1}},
{name: "GetTotalOfRepPolicies 2", args: args{name: "Test", page: 1, pageSize: 2}, wantPolicies: []*models.RepPolicy{testPolic1, testPolic2}},
{name: "GetTotalOfRepPolicies 2", args: args{name: "Test", page: 1, pageSize: 2}, wantPolicies: []*models.RepPolicy{testPolic3, testPolic2}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {