Files
threshold-ui/addons/api/addon/models/host-set.js
T

82 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-08-13 17:05:09 -04:00
import GeneratedHostSetModel from '../generated/models/host-set';
2020-08-19 18:38:18 -04:00
import { fragmentArray } from 'ember-data-model-fragments/attributes';
2020-08-13 17:05:09 -04:00
2020-08-19 18:38:18 -04:00
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
/**
* Host IDs are read-only under normal circumstances. But these can
* be persisted via a dedicated call to `addHosts()`.
2020-08-19 18:38:18 -04:00
*/
2020-09-12 11:20:38 -04:00
@fragmentArray('fragment-string', {
readOnly: true,
2020-09-16 14:29:02 -04:00
emptyArrayIfMissing: true,
})
host_ids;
2020-08-19 18:38:18 -04:00
// =methods
/**
* Adds hosts via the `add-hosts` method.
2020-08-19 18:38:18 -04:00
* See serializer and adapter for more information.
* @param {[string]} hostIDs
2020-08-20 12:04:54 -04:00
* @param {object} options
* @param {object} options.adapterOptions
2020-08-19 18:38:18 -04:00
* @return {Promise}
*/
2020-09-16 14:29:02 -04:00
addHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-hosts',
2020-09-16 14:29:02 -04:00
hostIDs,
};
return this.save({
...options,
2020-08-19 18:38:18 -04:00
adapterOptions: {
...defaultAdapterOptions,
2020-09-16 14:29:02 -04:00
...options.adapterOptions,
},
});
}
/**
* Add a single host via the `add-hosts` method.
* @param {string} hostID
* @param {object} options
* @return {Promise}
*/
addHost(hostID, options) {
return this.addHosts([hostID], options);
}
/**
* Delete hosts via the `remove-hosts` method.
* See serializer and adapter for more information.
* @param {[string]} hostIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
2020-09-16 14:29:02 -04:00
removeHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-hosts',
2020-09-16 14:29:02 -04:00
hostIDs,
2020-08-20 12:04:54 -04:00
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
2020-09-16 14:29:02 -04:00
...options.adapterOptions,
},
2020-08-19 18:38:18 -04:00
});
}
/**
* Delete a single host via the `remove-hosts` method.
* @param {string} hostID
* @param {object} options
* @return {Promise}
*/
removeHost(hostID, options) {
return this.removeHosts([hostID], options);
}
2020-08-19 18:38:18 -04:00
}