fix: Add/remove custom methods in mirage
This commit is contained in:
4 files changed
+28
-14
No files matched your search
@@ -28,7 +28,7 @@ export default class FormHostSetAddHostsIndexComponent extends Component {
|
||||
*/
|
||||
@computed('args.{model,hosts}')
|
||||
get filteredHosts() {
|
||||
const currentHostIDs = this.args.hosts.map(host => host.id);
|
||||
const currentHostIDs = this.args.model.host_ids.map(host => host.value);
|
||||
return this.args.hosts.filter(({ id }) => !currentHostIDs.includes(id));
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -25,11 +25,12 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHo
|
||||
*/
|
||||
async model() {
|
||||
const scopeID = this.modelFor('scopes.scope.projects.project').id;
|
||||
const hostCatalogID = this.modelFor('scopes.scope.projects.project.host-catalogs.host-catalog').id;
|
||||
const hostSet = this.modelFor('scopes.scope.projects.project.host-catalogs.host-catalog.host-sets.host-set');
|
||||
return hash({
|
||||
hostSet,
|
||||
hosts: all(hostSet.host_ids.map(id =>
|
||||
this.store.findRecord('host', id, { adapterOptions: { scopeID } })
|
||||
hostSet: this.store.findRecord('host-set', hostSet.id, { adapterOptions: { scopeID, hostCatalogID } }),
|
||||
hosts: all(hostSet.host_ids.map(hostFragment =>
|
||||
this.store.findRecord('host', hostFragment.value, { adapterOptions: { scopeID, hostCatalogID } })
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
-8
@@ -1,13 +1,5 @@
|
||||
{{title (t "actions.add-hosts")}}
|
||||
|
||||
{{!-- <Form::HostSet::Hosts
|
||||
@model={{@model.hostSet}}
|
||||
@hosts={{@model.hosts}}
|
||||
@submit={{route-action "save" @model.hostSet}}
|
||||
@cancel={{route-action "cancel" @model.hostSet}}
|
||||
@toggleHost={{route-action "toggleHost" @model.hostSet}}
|
||||
/> --}}
|
||||
|
||||
<Form::HostSet::AddHosts
|
||||
@model={{@model.hostSet}}
|
||||
@hosts={{@model.hosts}}
|
||||
|
||||
@@ -183,9 +183,30 @@ export default function() {
|
||||
this.post('/scopes/:scope_id/host-catalogs/:hostCatalogId/host-sets/:idMethod', function ({ hostSets }, { params: { idMethod } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const id = idMethod.split(':')[0];
|
||||
const method = idMethod.split(':')[1];
|
||||
const hostSet = hostSets.find(id);
|
||||
attrs.id = id;
|
||||
return hostSet.update(attrs);
|
||||
const updatedAttrs = {
|
||||
version: attrs.version,
|
||||
hostIds: hostSet.hostIds
|
||||
}
|
||||
|
||||
// If adding hosts, push them into the array
|
||||
if(method === 'add-hosts') {
|
||||
attrs.hostIds.forEach(id => {
|
||||
if(!updatedAttrs.hostIds.includes(id)) {
|
||||
updatedAttrs.hostIds.push(id);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// If deleting hosts, filter them out of the array
|
||||
if (method === 'remove-hosts') {
|
||||
updatedAttrs.hostIds = updatedAttrs.hostIds.filter(id => {
|
||||
return !attrs.hostIds.includes(id);
|
||||
});
|
||||
}
|
||||
|
||||
return hostSet.update(updatedAttrs);
|
||||
});
|
||||
|
||||
// target
|
||||
|
||||
Reference in new issue
Block a user