Prioritize display endpoints

https://github.com/rancher/rancher/issues/13694
This commit is contained in:
loganhz 2018-06-15 13:52:58 +08:00
parent b0363bb03b
commit ce867bcbe9
2 changed files with 42 additions and 1 deletions

View File

@ -6,7 +6,7 @@ export default Mixin.create({
displayEndpoints: function () {
let parts = [];
const endpoints = (get(this, 'publicEndpoints') || []);
const endpoints = (get(this, 'publicEndpoints') || []).sort(Util.compareDisplayEndpoint);
endpoints.forEach((endpoint) => {
if ( !get(endpoint, 'isReady') ){

View File

@ -13,6 +13,46 @@ export function arrayIntersect(a, b) {
});
}
export function compareDisplayEndpoint(i1, i2) {
if ( !i1 ) {
return 1;
}
if ( !i2 ) {
return -1;
}
const in1 = i1.displayEndpoint;
const in2 = i2.displayEndpoint;
if ( !in1 ) {
return 1;
}
if ( !in2 ) {
return -1;
}
if ( in1.startsWith('/') && !in2.startsWith('/') ) {
return -1;
} else if ( !in1.startsWith('/') && in2.startsWith('/') ) {
return 1;
}
if ( in1 === '80/http' && in2 !== '80/http' ) {
return -1;
} else if ( in1 !== '80/http' && in2 === '80/http' ) {
return 1;
}
if ( in1 === '443/https' && in2 !== '443/https' ) {
return -1;
} else if ( in1 !== '443/https' && in2 === '443/https' ) {
return 1;
}
return in1.localeCompare(in2);
}
export function filterByValues(ary,field,values) {
return ary.filter((obj) => {
return values.includes(obj.get(field));
@ -352,6 +392,7 @@ var Util = {
addQueryParams: addQueryParams,
arrayDiff: arrayDiff,
arrayIntersect: arrayIntersect,
compareDisplayEndpoint: compareDisplayEndpoint,
camelToTitle: camelToTitle,
constructUrl: constructUrl,
download: download,