diff --git a/ui/desktop/app/router.js b/ui/desktop/app/router.js index afd04e391..8e4b8d71e 100644 --- a/ui/desktop/app/router.js +++ b/ui/desktop/app/router.js @@ -14,7 +14,9 @@ Router.map(function () { }); this.route('projects', function () { this.route('targets', function () { - this.route('target', { path: ':target_id' }, function() {}); + this.route('target', { path: ':target_id' }, function() { + this.route('hosts'); + }); }); this.route('sessions', function() {}); }); diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js index 5031c8a4a..29efcc413 100644 --- a/ui/desktop/app/routes/scopes/scope/projects/targets/target.js +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target.js @@ -13,6 +13,14 @@ export default class ScopesScopeProjectsTargetsTargetRoute extends Route { return this.store.findRecord('target', target_id, { reload: true }); } + /** + * Navigate to hostsets within a target. + * @param {TargetModel} model + */ + afterModel(model) { + this.transitionTo('scopes.scope.projects.targets.target.hosts', model); + } + /** * Renders the target-specific templates for header and navigation * page sections. diff --git a/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js new file mode 100644 index 000000000..bfc76764c --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/projects/targets/target/hosts.js @@ -0,0 +1,35 @@ +import Route from '@ember/routing/route'; +import { all, hash } from 'rsvp'; +import { A } from '@ember/array'; + +export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route { + // =methods + + /** + * Loads all host-sets and associated hosts under the current target. + * @return {Promise{[HostModel]}} + */ + async model() { + const { host_sets } = this.modelFor('scopes.scope.projects.targets.target'); + const hostSetsPromises = await all( + host_sets.map(({ host_set_id }) => + this.store.findRecord('host-set', host_set_id) + ) + ); + + // Extract host ids from all host set + const hostIds = A(); + hostSetsPromises.map(({ host_ids }) => + host_ids.forEach(({ value }) => hostIds.push(value) ) + ); + + // Fetch all hosts + const hostPromises = await all( + hostIds.uniq().map((hostId) => + this.store.findRecord('host', hostId) + ) + ) + + return all(hostPromises); + } +} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs index b27314ac2..bac5c17a3 100644 --- a/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/-navigation.hbs @@ -1,5 +1,5 @@ - - {{t 'resources.host-set.title_plural'}} + + {{t 'resources.host.title_plural'}} diff --git a/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs new file mode 100644 index 000000000..6cf921efd --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/projects/targets/target/hosts.hbs @@ -0,0 +1,23 @@ +{{page-title (t "resources.host-set.title_plural")}} + +{{#if @model}} + + + + {{#each @model as |host|}} + + + {{host.displayName}} +

{{host.description}}

+
+ {{host.id}} + {{host.attributes.address}} + + {{t (concat 'resources.host.types.' host.type)}} + +
+ {{/each}} +
+
+ +{{/if}} diff --git a/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js new file mode 100644 index 000000000..e28f35db7 --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/projects/targets/target/hosts-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/projects/targets/target/hosts', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/projects/targets/target/hosts'); + assert.ok(route); + }); +});