chore: 🤖 cleanup model hooks

This commit is contained in:
Randall Morey committed 2020-08-27 09:52:44 -04:00
1 parent 63eabb8ba1
commit 16f94f739e
2 files changed
+27 -25

No files matched your search

@@ -1,5 +1,5 @@
import Route from '@ember/routing/route';
import { all } from 'rsvp';
import { all, hash } from 'rsvp';
export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extends Route {
// =methods
@@ -10,34 +10,32 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend
* @return {Promise{[HostSetModel, HostCatalogModel]}}
*/
beforeModel() {
const hostSets = [], hostCatalogs = [];
const target = this.modelFor('scopes.scope.projects.project.targets.target');
const scopeID = this.modelFor('scopes.scope.projects.project').id;
target.host_sets.map((hostSet) => {
hostSets.push(
this.store.findRecord(
'host-set',
hostSet.host_set_id,
{ adapterOptions : { scopeID, hostCatalogID: hostSet.host_catalog_id } }
)
const { scopeID, host_sets } =
this.modelFor('scopes.scope.projects.project.targets.target');
const promises = host_sets
.map(({ host_set_id, host_catalog_id: hostCatalogID }) =>
hash({
// TODO: multiple host sets may belong to the same catalog,
// resulting in the catalog being loaded multiple times.
// An improvement would be to find the unique set of catalogs first.
hostCatalog: this.store.findRecord(
'host-catalog',
hostCatalogID,
{ adapterOptions: { scopeID } }
),
hostSet: this.store.findRecord(
'host-set',
host_set_id,
{ adapterOptions: { scopeID, hostCatalogID } }
)
})
);
hostCatalogs.push(
this.store.findRecord(
'host-catalog',
hostSet.host_catalog_id,
{ adapterOptions : { scopeID } }
)
);
});
return all(hostSets.concat(hostCatalogs));
return all(promises);
}
/**
* Load current target and it's associated host-sets and host-catalogs
* @return {Promise{[TargetModel]}}
* Returns the previously loaded target instance.
* @return {TargetModel}
*/
model() {
return this.modelFor('scopes.scope.projects.project.targets.target');
+4
View File
@@ -58,4 +58,8 @@ module('Acceptance | targets', function (hooks) {
test('saving an existing target with invalid fields displays error messages', async function (assert) {
assert.expect(0);
});
test('viewing target host sets', async function (assert) {
assert.expect(0);
});
});