Merge branch 'develop' into ICU-562-remove-host-set-within-a-target

This commit is contained in:
Randall Morey authored and GitHub committed 2020-08-31 10:05:40 -04:00
commit a4e327b346
22 files changed
+355 -27

No files matched your search

@@ -13,6 +13,11 @@ export default class GeneratedHostSetModel extends BaseModel {
readOnly: true
}) type;
@attr('string', {
description: 'The owning host catalog ID.',
readOnly: true
}) host_catalog_id;
@attr('string', {
description: 'Optional name for identification purposes'
}) name;
+13
View File
@@ -1,5 +1,6 @@
import GeneratedHostSetModel from '../generated/models/host-set';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
//import { computed } from '@ember/object';
export default class HostSetModel extends GeneratedHostSetModel {
@@ -11,6 +12,18 @@ export default class HostSetModel extends GeneratedHostSetModel {
*/
@fragmentArray('fragment-string', {readOnly: true}) host_ids;
// TODO this is here in case we want it in the future,
// especially for the target / add host sets workflow
/**
* Returns the host catalog instance associated with this host set if
* it is already loaded into the store.
* @type {?HostCatalogModel}
*/
// @computed('host_catalog_id')
// get hostCatalog() {
// return this.store.peekRecord('host-catalog', this.host_catalog_id);
// }
// =methods
/**
@@ -1,8 +1,18 @@
<LinkTo
...attributes
@route={{if @route @route "index"}}
@model={{@model}}
class="rose-dropdown-link {{if @style (concat "rose-dropdown-link-" @style)}}"
>
{{yield}}
</LinkTo>
{{#if @model}}
<LinkTo
...attributes
@route={{@route}}
@model={{@model}}
class="rose-dropdown-link {{if @style (concat "rose-dropdown-link-" @style)}}"
>
{{yield}}
</LinkTo>
{{else}}
<LinkTo
...attributes
@route={{@route}}
class="rose-dropdown-link {{if @style (concat "rose-dropdown-link-" @style)}}"
>
{{yield}}
</LinkTo>
{{/if}}
@@ -0,0 +1,44 @@
<Rose::Form
class="full-width"
@onSubmit={{fn this.submit @submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.actions
@submitText={{t "actions.add-host-sets"}}
@cancelText={{t "actions.cancel"}} />
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.type'}}</row.headerCell>
<row.headerCell>{{t 'resources.host-catalog'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each this.filteredHostSets as |hostSet|}}
<body.row as |row|>
<row.cell>
<form.checkbox
@label={{hostSet.id}}
@description={{hostSet.description}}
onChange={{fn this.toggleHostSet hostSet}} />
</row.cell>
<row.cell>{{hostSet.name}}</row.cell>
<row.cell>
<Rose::Badge @style="outline">{{hostSet.type}}</Rose::Badge>
</row.cell>
<row.cell>
<code>{{hostSet.host_catalog_id}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
</Rose::Form>
@@ -0,0 +1,44 @@
import Component from '@glimmer/component';
import { computed, action } from '@ember/object';
import { A } from '@ember/array';
export default class FormTargetAddHostSetsComponent extends Component {
// =properties
/**
* Array of selected host set IDs.
* @type {EmberArray}
*/
selectedHostSetIDs = A();
/**
* Host sets not already added to the target.
* @type {[HostSetModel]}
*/
@computed('args.{hostSets.[],model.host_sets.[]}')
get filteredHostSets() {
// Get IDs for host sets already added to the current target
const alreadyAddedHostSetIDs = this.args.model.host_sets
.map(({ host_set_id }) => host_set_id);
const notAddedHostSets = this.args.hostSets
.filter(({ id }) => !alreadyAddedHostSetIDs.includes(id));
return notAddedHostSets;
}
// =actions
@action
toggleHostSet(hostSet) {
if (!this.selectedHostSetIDs.includes(hostSet.id)) {
this.selectedHostSetIDs.addObject(hostSet.id);
} else {
this.selectedHostSetIDs.removeObject(hostSet.id);
}
}
@action
submit(fn) {
fn(this.selectedHostSetIDs);
}
}
@@ -0,0 +1,19 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsController extends Controller {
// =services
@service intl;
// =attributes
/**
* @type {string}
*/
get breadCrumb() {
return this.intl.t('actions.add-host-sets');
}
}
+1
View File
@@ -40,6 +40,7 @@ Router.map(function () {
this.route('host-sets', function() {
this.route('host-set', { path: ':host_set_id'}, function() {});
});
this.route('add-host-sets');
});
this.route('new');
});
@@ -15,4 +15,28 @@ export default class ScopesScopeProjectsProjectTargetsTargetRoute extends Route
return this.store.findRecord('target', target_id, { adapterOptions: { scopeID } });
}
/**
* Renders the target-specific templates for header, navigation,
* and actions page sections.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/projects/project/targets/target/-header', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'header',
});
this.render('scopes/scope/projects/project/targets/target/-navigation', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'navigation',
});
this.render('scopes/scope/projects/project/targets/target/-actions', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'actions',
});
}
}
@@ -0,0 +1,89 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { all } from 'rsvp';
export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Emtpy out any previously loaded host catalogs and host sets.
*/
beforeModel() {
this.store.unloadAll('host-catalog');
this.store.unloadAll('host-set');
}
/**
* Returns the current target, all host catalogs, and all host sets.
* @return {{target: TargetModel, hostCatalogs: [HostCatalogModel], hostSets: [HostSetModel]}}
*/
async model() {
const target =
this.modelFor('scopes.scope.projects.project.targets.target');
const { scopeID } = target;
const hostCatalogs =
await this.store.findAll('host-catalog', { adapterOptions: { scopeID } });
await all(hostCatalogs.map(({ id: hostCatalogID }) =>
this.store
.findAll('host-set', { adapterOptions: { scopeID, hostCatalogID } })
));
const hostSets = this.store.peekAll('host-set');
return {
target,
hostCatalogs,
hostSets
};
}
/**
* Renders the add-host-sets-specific header template.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/projects/project/targets/target/add-host-sets/-header', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'header',
});
this.render('-empty', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'navigation',
});
this.render('-empty', {
into: 'scopes/scope/projects/project/targets/target',
outlet: 'actions',
});
}
// =actions
@action
async save(target, hostSetIDs) {
try {
await target.addHostSets(hostSetIDs);
this.replaceWith('scopes.scope.projects.project.targets.target.host-sets');
this.notify.success(this.intl.t('notify.save-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
/**
* Redirect to target host sets as if nothing ever happened.
*/
@action
cancel() {
this.replaceWith('scopes.scope.projects.project.targets.target.host-sets');
}
}
@@ -1,3 +1,5 @@
{{title @model.displayName}}
<Rose::Layout::Page as |page|>
<page.breadcrumbs>
@@ -5,30 +7,15 @@
</page.breadcrumbs>
<page.header>
<h2>{{t "resources.target"}}</h2>
{{outlet "header"}}
</page.header>
<page.navigation>
<Rose::Nav::Tabs as |nav|>
<nav.link @route='scopes.scope.projects.project.targets.target.index'>
{{t 'titles.details'}}
</nav.link>
<nav.link @route='scopes.scope.projects.project.targets.target.host-sets'>
{{t 'titles.host-sets'}}
</nav.link>
</Rose::Nav::Tabs>
{{outlet "navigation"}}
</page.navigation>
<page.actions>
<Rose::Dropdown @text="{{t 'form.label.manage'}}" @dropdownRight={{true}} as |dropdown|>
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
>
{{t 'actions.delete-target'}}
</dropdown.button>
</Rose::Dropdown>
{{outlet "actions"}}
</page.actions>
<page.body>
@@ -0,0 +1,12 @@
<Rose::Dropdown @text="{{t 'form.label.manage'}}" @dropdownRight={{true}} as |dropdown|>
<dropdown.link @route="scopes.scope.projects.project.targets.target.add-host-sets">
{{t 'actions.add-host-sets'}}
</dropdown.link>
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
>
{{t 'actions.delete-target'}}
</dropdown.button>
</Rose::Dropdown>
@@ -0,0 +1 @@
<h2>{{t "resources.target"}}</h2>
@@ -0,0 +1,8 @@
<Rose::Nav::Tabs as |nav|>
<nav.link @route='scopes.scope.projects.project.targets.target.index'>
{{t 'titles.details'}}
</nav.link>
<nav.link @route='scopes.scope.projects.project.targets.target.host-sets'>
{{t 'titles.host-sets'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,21 @@
{{title (t 'actions.add-host-sets')}}
{{#if @model.hostSets}}
<Form::Target::AddHostSets
@model={{@model.target}}
@hostCatalogs={{@model.hostCatalogs}}
@hostSets={{@model.hostSets}}
@submit={{route-action "save" @model.target}}
@cancel={{route-action "cancel"}}
/>
{{/if}}
{{#unless @model.hostSets}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "titles.no-host-sets-for-target"}} as |message|>
<message.description>
{{t "descriptions.no-host-sets-for-target"}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/unless}}
@@ -0,0 +1 @@
<h2>{{t "actions.add-host-sets"}}</h2>
+3 -1
View File
@@ -1,3 +1,5 @@
import factory from '../generated/factories/host-set';
export default factory.extend();
export default factory.extend({
id: (i) => `host-set-id-${i}`
});
+1
View File
@@ -13,6 +13,7 @@ export default ApplicationSerializer.extend({
_hashForModel(model) {
const json = ApplicationSerializer.prototype._hashForModel.apply(this, arguments);
json.host_ids = model.hostIds;
json.host_catalog_id = model.hostCatalogId;
return json;
}
+8
View File
@@ -66,4 +66,12 @@ module('Acceptance | targets', function (hooks) {
test('can delete a host sets', async function(assert) {
assert.expect(0);
});
test('select and save host sets to add', async function (assert) {
assert.expect(0);
});
test('select and cancel host sets to add', async function (assert) {
assert.expect(0);
});
});
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
// import { render } from '@ember/test-helpers';
// import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | form/target/add-host-sets', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
assert.expect(0);
});
});
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Controller | scopes/scope/projects/project/targets/target/add-host-sets', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:scopes/scope/projects/project/targets/target/add-host-sets');
assert.ok(controller);
});
});
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | scopes/scope/projects/project/targets/target/add-host-sets', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:scopes/scope/projects/project/targets/target/add-host-sets');
assert.ok(route);
});
});
+3
View File
@@ -21,6 +21,7 @@ actions:
delete-target: Delete target
add-host-set: Create Host Set
add-host: Create Host
add-host-sets: Add Host Sets
auth:
titles:
no-scopes: No Scopes Available
@@ -89,6 +90,7 @@ titles:
targets: Targets
global: Global
no-host-set-hosts: No Hosts Available
no-host-sets-for-target: No Host Sets Available
descriptions:
host-catalogs: Overview of collections of hosts and host sets.
empty-set: There are no items to display yet. You may be able to add items or try back later.
@@ -103,6 +105,7 @@ descriptions:
targets-welcome: Targets provide Users the means to connect to and interact networked services. A Target contains a collection of Hosts and a collection of Credentials.
target-host-sets-welcome: Add Host Sets to this target to provide access.
no-host-set-hosts: Before associating hosts with this host set, create hosts within the host catalog.
no-host-sets-for-target: No host sets are available to add to this target.
states:
info: Info
success: Success