in app/scripts/modules/core/instance/instanceListBody.directive.js [96:149]
function instanceSorter(a1, b1) {
let filterSplit = scope.sortFilter.instanceSort.key.split('-'),
filterType = filterSplit.length === 1 ? filterSplit[0] : filterSplit[1],
reverse = filterSplit.length === 2,
a = reverse ? b1 : a1,
b = reverse ? a1 : b1;
switch(filterType) {
case 'id':
return a.id.localeCompare(b.id);
case 'launchTime':
return a.launchTime === b.launchTime ? a.id.localeCompare(b.id) : a.launchTime - b.launchTime;
case 'availabilityZone':
return a.availabilityZone === b.availabilityZone ?
a.launchTime === b.launchTime ?
a.id.localeCompare(b.id) :
a.launchTime - b.launchTime :
a.availabilityZone.localeCompare(b.availabilityZone);
case 'discoveryState':
let aHealth = (a.health || []).filter((health) => health.type === 'Discovery'),
bHealth = (b.health || []).filter((health) => health.type === 'Discovery');
if (aHealth.length && !bHealth.length) {
return -1;
}
if (!aHealth.length && bHealth.length) {
return 1;
}
return (!aHealth.length && !bHealth.length) || aHealth[0].state === bHealth[0].state ?
a.launchTime === b.launchTime ?
a.id.localeCompare(b.id) :
a.launchTime - b.launchTime :
aHealth[0].state.localeCompare(bHealth[0].state);
case 'loadBalancerSort':
let aHealth2 = (a.health || []).filter((health) => health.type === 'LoadBalancer')
.sort((h1, h2) => h1.name.localeCompare(h2.name)),
bHealth2 = (b.health || []).filter((health) => health.type === 'LoadBalancer')
.sort((h1, h2) => h1.name.localeCompare(h2.name));
if (aHealth2.length && !bHealth2.length) {
return -1;
}
if (!aHealth2.length && bHealth2.length) {
return 1;
}
let aHealthStr = aHealth2.map((h) => h.name + ':' + h.state).join(','),
bHealthStr = bHealth2.map((h) => h.name + ':' + h.state).join(',');
return aHealthStr === bHealthStr ?
a.launchTime === b.launchTime ?
a.id.localeCompare(b.id) :
a.launchTime - b.launchTime :
aHealthStr.localeCompare(bHealthStr);
default:
return -1;
}
}