feat: 🎸 add host set management support for tagets in API layer
This commit is contained in:
8 files changed
+230
-3
No files matched your search
@@ -0,0 +1,16 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
export default class FragmentHostSetModel extends Fragment {
|
||||
|
||||
// =attributes
|
||||
|
||||
@attr('string', {
|
||||
description: 'ID of the related host set'
|
||||
}) host_set_id;
|
||||
|
||||
@attr('string', {
|
||||
description: 'ID of the catalog to which the host set belongs'
|
||||
}) host_catalog_id;
|
||||
|
||||
}
|
||||
@@ -1,3 +1,39 @@
|
||||
import GeneratedTargetModel from '../generated/models/target';
|
||||
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||
|
||||
export default class TargetModel extends GeneratedTargetModel {}
|
||||
export default class TargetModel extends GeneratedTargetModel {
|
||||
|
||||
// =attributes
|
||||
|
||||
@fragmentArray('fragment-host-set', {readOnly: true}) host_sets;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Saves the `host_set_ids` array on the via the `set-hosts` method.
|
||||
* See serializer and adapter for more information.
|
||||
* @param {object} options
|
||||
* @param {object} options.adapterOptions
|
||||
* @return {Promise}
|
||||
*/
|
||||
saveHostSets(options={ adapterOptions: {} }) {
|
||||
const defaultOptions = {
|
||||
adapterOptions: {
|
||||
method: 'set-host-sets',
|
||||
serializeHostSets: true
|
||||
}
|
||||
};
|
||||
// There is no "deep merge" in ES.
|
||||
// All of this nonsense is here to ensure we get
|
||||
// a decent merge of `adapterOptions`.
|
||||
return this.save({
|
||||
...defaultOptions,
|
||||
...options,
|
||||
adapterOptions: {
|
||||
...defaultOptions.adapterOptions,
|
||||
...options.adapterOptions
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user