mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-26 18:48:02 +01:00
Merge pull request #5456 from zhoumeina/pr/fix_access_level_sort
Fix access level can not sort
This commit is contained in:
commit
4cb0a3ee52
@ -58,7 +58,7 @@ export class ListProjectComponent implements OnDestroy {
|
||||
roleInfo = RoleInfo;
|
||||
repoCountComparator: Comparator<Project> = new CustomComparator<Project>("repo_count", "number");
|
||||
timeComparator: Comparator<Project> = new CustomComparator<Project>("creation_time", "date");
|
||||
accessLevelComparator: Comparator<Project> = new CustomComparator<Project>("public", "number");
|
||||
accessLevelComparator: Comparator<Project> = new CustomComparator<Project>("public", "string");
|
||||
roleComparator: Comparator<Project> = new CustomComparator<Project>("current_user_role_id", "number");
|
||||
currentPage = 1;
|
||||
totalCount = 0;
|
||||
|
@ -143,8 +143,23 @@ export class CustomComparator<T> implements Comparator<T> {
|
||||
compare(a: { [key: string]: any | any[] }, b: { [key: string]: any | any[] }) {
|
||||
let comp = 0;
|
||||
if (a && b) {
|
||||
let fieldA = a[this.fieldName];
|
||||
let fieldB = b[this.fieldName];
|
||||
let fieldA, fieldB;
|
||||
for (let key of Object.keys(a)) {
|
||||
if (key === this.fieldName) {
|
||||
fieldA = a[key];
|
||||
fieldB = b[key];
|
||||
break;
|
||||
} else if (typeof a[key] === 'object') {
|
||||
let insideObject = a[key];
|
||||
for (let insideKey in insideObject) {
|
||||
if (insideKey === this.fieldName) {
|
||||
fieldA = insideObject[insideKey];
|
||||
fieldB = b[key][insideKey];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (this.type) {
|
||||
case "number":
|
||||
comp = fieldB - fieldA;
|
||||
@ -152,6 +167,9 @@ export class CustomComparator<T> implements Comparator<T> {
|
||||
case "date":
|
||||
comp = new Date(fieldB).getTime() - new Date(fieldA).getTime();
|
||||
break;
|
||||
case "string":
|
||||
comp = fieldB.localeCompare(fieldA);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return comp;
|
||||
|
Loading…
Reference in New Issue
Block a user