Files
threshold-ui/addons/api/addon/models/host-catalog.js
T
2022-01-31 13:16:03 -08:00

72 lines
1.5 KiB
JavaScript

import GeneratedHostCatalogModel from '../generated/models/host-catalog';
export const types = ['aws', 'azure'];
export default class HostCatalogModel extends GeneratedHostCatalogModel {
// =attributes
/**
* True if the host catalog is static.
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
/**
* True if the host catalog is a plugin.
* @type {boolean}
*/
get isPlugin() {
return this.type === 'plugin';
}
/**
* True if the host catalog is an unknown type.
* @type {boolean}
*/
get isUnknown() {
return this.isPlugin && !types.includes(this.plugin.name);
}
/**
* True if host catalog plugin type is AWS.
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
}
/**
* True if host catalog plugin type is Azure.
* @type {boolean}
*/
get isAzure() {
return this.compositeType === 'azure';
}
/**
* If host catalog is a plugin return `plugin.name`,
* otherwise return the host catalog type.
* @type {string}
*/
get compositeType() {
if (this.isUnknown) return 'unknown';
if (this.isPlugin) return this.plugin.name;
return 'static';
}
/**
* Sets `type`. If type is different than `static`, sets `type` to `plugin`
* and `plugin.name` to the specified type.
*/
set compositeType(type) {
if (type === 'static') {
this.type = 'static';
} else {
this.type = 'plugin';
this.plugin = { name: type };
}
}
}