dashboard/models/catalog.cattle.io.clusterre...

62 lines
1.1 KiB
JavaScript

import Vue from 'vue';
import { parse } from '@/utils/url';
export default {
applyDefaults() {
return () => {
if ( !this.spec ) {
Vue.set(this, 'spec', { url: '' });
}
};
},
isRancher() {
let parsed;
if ( this.spec?.url && this.spec?.gitRepo ) {
// Well that's suspicious...
return false;
}
if ( this.spec?.url ) {
parsed = parse(this.spec.url);
if ( parsed && ok(parsed.host) ) {
return true;
}
}
if ( this.spec?.gitRepo ) {
parsed = parse(this.spec.gitRepo);
if ( parsed && ok(parsed.host) ) {
return true;
}
}
return false;
function ok(host) {
host = (host || '').toLowerCase();
return host === 'rancher.io' || host.endsWith('.rancher.io');
}
},
canLoad() {
return this.metadata?.state?.name === 'active';
},
displayType() {
if ( this.spec.gitRepo ) {
return 'git';
} else if ( this.spec.url ) {
return 'http';
} else {
return '?';
}
},
displayUrl() {
return this.status?.url || this.spec.gitRepo || this.spec.url;
},
};