diff --git a/ui/desktop/app/router.js b/ui/desktop/app/router.js index 335c69db4..3d7c64eb5 100644 --- a/ui/desktop/app/router.js +++ b/ui/desktop/app/router.js @@ -8,6 +8,8 @@ export default class Router extends EmberRouter { Router.map(function () { this.route('scopes', function() { - this.route('scope', { path: ':scope_id' }, function() {}); + this.route('scope', { path: ':scope_id' }, function() { + this.route('targets'); + }); }); }); diff --git a/ui/desktop/app/routes/scopes/scope.js b/ui/desktop/app/routes/scopes/scope.js index 53ab105d3..54d771123 100644 --- a/ui/desktop/app/routes/scopes/scope.js +++ b/ui/desktop/app/routes/scopes/scope.js @@ -48,8 +48,18 @@ export default class ScopesScopeRoute extends Route { // Then pull out the "selected" scopes, if relevant let selectedOrg; if (model.isGlobal || model.isOrg) selectedOrg = model; + + let projects; + if(model.isGlobal) { + projects = orgs.map((id) => this.store.query('scope', { scope_id: id })); + } + if(model.isOrg) { + projects = this.store.query('scope', { scope_id: model.id }); + } + // Update the scope service with the current scope(s); this.scope.org = selectedOrg; + this.scope.projects = await projects; this.scopes = { orgs, selectedOrg }; } diff --git a/ui/desktop/app/routes/scopes/scope/index.js b/ui/desktop/app/routes/scopes/scope/index.js new file mode 100644 index 000000000..249d7f85a --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/index.js @@ -0,0 +1,12 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeIndexRoute extends Route { + // =methods + + /** + * Redirects to scopes route for further processing. + */ + redirect() { + this.transitionTo('scopes.scope.targets'); + } +} diff --git a/ui/desktop/app/routes/scopes/scope/targets.js b/ui/desktop/app/routes/scopes/scope/targets.js new file mode 100644 index 000000000..aefdb89e9 --- /dev/null +++ b/ui/desktop/app/routes/scopes/scope/targets.js @@ -0,0 +1,24 @@ +import Route from '@ember/routing/route'; +import { all } from 'rsvp'; +import { inject as service } from '@ember/service'; + +export default class ScopesScopeTargetsRoute extends Route { + // =services + + @service scope; + + // =methods + + /** + * Loads all targets under current scope. + * @return {Promise{[TargetModel]}} + */ + async model() { + let projectTargets = await all(this.scope.projects.map(({ id: scope_id }) => + this.store.query('target', { scope_id }) + )) + + return projectTargets.map((target) => target.toArray()).flat(); + } + +} diff --git a/ui/desktop/app/services/scope.js b/ui/desktop/app/services/scope.js index 37037eb23..a6b59db24 100644 --- a/ui/desktop/app/services/scope.js +++ b/ui/desktop/app/services/scope.js @@ -14,4 +14,8 @@ export default class ScopeService extends Service { */ @tracked org; + /** + * @type {[ScopeModel]} + */ + @tracked projects; } diff --git a/ui/desktop/app/templates/scopes/index.hbs b/ui/desktop/app/templates/scopes/index.hbs index cde799ad1..bcb29e68f 100644 --- a/ui/desktop/app/templates/scopes/index.hbs +++ b/ui/desktop/app/templates/scopes/index.hbs @@ -3,7 +3,7 @@ - Scope + {{t 'scope.title'}} diff --git a/ui/desktop/app/templates/scopes/scope/-header-nav.hbs b/ui/desktop/app/templates/scopes/scope/-header-nav.hbs index 4a383eb6d..eca77955c 100644 --- a/ui/desktop/app/templates/scopes/scope/-header-nav.hbs +++ b/ui/desktop/app/templates/scopes/scope/-header-nav.hbs @@ -4,7 +4,7 @@ > {{!-- {{#if this.session.data.authenticated.isGlobal}} --}} - {{t "titles.global"}} + {{t "scope.global.title"}} {{!-- {{/if}} --}} diff --git a/ui/desktop/app/templates/scopes/scope/targets.hbs b/ui/desktop/app/templates/scopes/scope/targets.hbs new file mode 100644 index 000000000..f9f7ea6f3 --- /dev/null +++ b/ui/desktop/app/templates/scopes/scope/targets.hbs @@ -0,0 +1,27 @@ +{{outlet}} + + + + + {{t "name.label"}} + {{t "type.label"}} + {{t "id.label"}} + + + + {{#each @model as |target|}} + + + {{target.name}} +

{{target.description}}

+
+ + {{target.type}} + + + {{target.id}} + +
+ {{/each}} +
+
diff --git a/ui/desktop/mirage/scenarios/default.js b/ui/desktop/mirage/scenarios/default.js index 7d8e3a5bb..0d837f64f 100644 --- a/ui/desktop/mirage/scenarios/default.js +++ b/ui/desktop/mirage/scenarios/default.js @@ -1,8 +1,5 @@ export default function(server) { - - // Scope resources - - // creates a global scope + // Scopes const globalScope = server.create('scope', { id: 'global', type: 'global', @@ -23,5 +20,4 @@ export default function(server) { server.createList('target', 2, { scope }, 'withRandomHostSets'); server.createList('session', 4, { scope }, 'withAssociations'); }); - } diff --git a/ui/desktop/tests/unit/routes/scopes/scope/index-test.js b/ui/desktop/tests/unit/routes/scopes/scope/index-test.js new file mode 100644 index 000000000..ba0a5bdba --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/index-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/index', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/index'); + assert.ok(route); + }); +}); diff --git a/ui/desktop/tests/unit/routes/scopes/scope/targets-test.js b/ui/desktop/tests/unit/routes/scopes/scope/targets-test.js new file mode 100644 index 000000000..45d66036b --- /dev/null +++ b/ui/desktop/tests/unit/routes/scopes/scope/targets-test.js @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Route | scopes/scope/targets', function(hooks) { + setupTest(hooks); + + test('it exists', function(assert) { + let route = this.owner.lookup('route:scopes/scope/targets'); + assert.ok(route); + }); +}); diff --git a/ui/desktop/translations/en-us.yaml b/ui/desktop/translations/en-us.yaml deleted file mode 100644 index 960b00647..000000000 --- a/ui/desktop/translations/en-us.yaml +++ /dev/null @@ -1,2 +0,0 @@ -titles: - global: Global diff --git a/ui/desktop/translations/form/en-us.yaml b/ui/desktop/translations/form/en-us.yaml new file mode 100644 index 000000000..cb3590c05 --- /dev/null +++ b/ui/desktop/translations/form/en-us.yaml @@ -0,0 +1,11 @@ +id: + label: ID +name: + label: Name + help: Name for identification purposes +description: + label: Description + help: Description for identification purposes +type: + label: Type + help: The type of the resource, to help differentiate schemas \ No newline at end of file diff --git a/ui/desktop/translations/resources/en-us.yaml b/ui/desktop/translations/resources/en-us.yaml new file mode 100644 index 000000000..01e8eef0f --- /dev/null +++ b/ui/desktop/translations/resources/en-us.yaml @@ -0,0 +1,8 @@ +scope: + title: Scope + title_plural: Scopes + global: + title: Global +target: + title: Target + title_plural: Targets \ No newline at end of file