feat: Init targets route
This commit is contained in:
14 files changed
+124
-10
No files matched your search
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,4 +14,8 @@ export default class ScopeService extends Service {
|
||||
*/
|
||||
@tracked org;
|
||||
|
||||
/**
|
||||
* @type {[ScopeModel]}
|
||||
*/
|
||||
@tracked projects;
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<Rose::Table as |table|>
|
||||
<table.header as |header|>
|
||||
<header.row as |row|>
|
||||
<row.headerCell>Scope</row.headerCell>
|
||||
<row.headerCell>{{t 'scope.title'}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
>
|
||||
{{!-- {{#if this.session.data.authenticated.isGlobal}} --}}
|
||||
<dropdown.link @route="scopes.scope" @model="global">
|
||||
{{t "titles.global"}}
|
||||
{{t "scope.global.title"}}
|
||||
</dropdown.link>
|
||||
<dropdown.separator />
|
||||
{{!-- {{/if}} --}}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
{{outlet}}
|
||||
|
||||
<Rose::Table as |table|>
|
||||
<table.header as |header|>
|
||||
<header.row as |row|>
|
||||
<row.headerCell>{{t "name.label"}}</row.headerCell>
|
||||
<row.headerCell>{{t "type.label"}}</row.headerCell>
|
||||
<row.headerCell>{{t "id.label"}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
<table.body as |body|>
|
||||
{{#each @model as |target|}}
|
||||
<body.row as |row|>
|
||||
<row.cell>
|
||||
{{target.name}}
|
||||
<p>{{target.description}}</p>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
{{target.type}}
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
{{target.id}}
|
||||
</row.cell>
|
||||
</body.row>
|
||||
{{/each}}
|
||||
</table.body>
|
||||
</Rose::Table>
|
||||
@@ -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');
|
||||
});
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
titles:
|
||||
global: Global
|
||||
@@ -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
|
||||
@@ -0,0 +1,8 @@
|
||||
scope:
|
||||
title: Scope
|
||||
title_plural: Scopes
|
||||
global:
|
||||
title: Global
|
||||
target:
|
||||
title: Target
|
||||
title_plural: Targets
|
||||
Reference in new issue
Block a user