chore: Add save and delete workflow to a target
This commit is contained in:
13 files changed
+224
-3
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<Rose::Form
|
||||
@onSubmit={{@submit}}
|
||||
@cancel={{@cancel}}
|
||||
@disabled={{@model.isSaving}}
|
||||
@error={{@model.errors.base}}
|
||||
as |form|
|
||||
>
|
||||
|
||||
<form.input
|
||||
@name="name"
|
||||
@type="name"
|
||||
@value={{@model.name}}
|
||||
@label={{t "form.label.name"}}
|
||||
@error={{@model.errors.name}}
|
||||
readonly={{false}}
|
||||
as |field|>
|
||||
{{#if @model.errors.name}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.name as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.input>
|
||||
|
||||
<form.textarea
|
||||
@name="description"
|
||||
@type="description"
|
||||
@value={{@model.description}}
|
||||
@label={{t "form.label.description"}}
|
||||
@error={{@model.errors.description}}
|
||||
disabled={{@model.isSaving}}
|
||||
readonly={{false}}
|
||||
as |field|>
|
||||
{{#if @model.errors.description}}
|
||||
<field.errors as |errors|>
|
||||
{{#each @model.errors.description as |error|}}
|
||||
<errors.message>{{error.message}}</errors.message>
|
||||
{{/each}}
|
||||
</field.errors>
|
||||
{{/if}}
|
||||
</form.textarea>
|
||||
|
||||
<form.actions
|
||||
@disabled={{if @model.cannotSave @model.cannotSave}}
|
||||
@submitText={{t "actions.save"}}
|
||||
@cancelText={{t "actions.cancel"}} />
|
||||
|
||||
</Rose::Form>
|
||||
@@ -29,7 +29,9 @@ Router.map(function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
this.route('targets', function() {});
|
||||
this.route('targets', function() {
|
||||
this.route('target', { path: ':target_id' }, function() {});
|
||||
});
|
||||
});
|
||||
this.route('new');
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogRoute exte
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Renders the host-catalog specific templates for header, navigation, and actions page sections.
|
||||
* @override
|
||||
* @param {object} controller
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
|
||||
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -11,4 +19,56 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
|
||||
const scopeID = this.modelFor('scopes.scope.projects.project').id;
|
||||
return this.store.findAll('target', { adapterOptions: { scopeID } });
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on a target.
|
||||
* @param {TargetModel} target
|
||||
*/
|
||||
@action
|
||||
cancel(target) {
|
||||
const { isNew } = target;
|
||||
target.rollbackAttributes();
|
||||
if (isNew) this.transitionTo('scopes.scope.projects.project.targets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle save.
|
||||
* @param {TargetModel} target
|
||||
* @param {Event} e
|
||||
*/
|
||||
@action
|
||||
async save(target) {
|
||||
const { isNew } = target;
|
||||
try {
|
||||
await target.save();
|
||||
this.refresh();
|
||||
this.notify.success(
|
||||
this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success')
|
||||
);
|
||||
this.transitionTo('scopes.scope.projects.project.targets.target', target);
|
||||
} catch (error) {
|
||||
// TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a target and redirects to targets index.
|
||||
* @param {TargetModel} target
|
||||
*/
|
||||
@action
|
||||
async delete(target) {
|
||||
try {
|
||||
await target.destroyRecord();
|
||||
this.refresh();
|
||||
this.notify.success(this.intl.t('notify.delete-success'));
|
||||
this.transitionTo('scopes.scope.projects.project.targets');
|
||||
} catch (error) {
|
||||
// TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeProjectsProjectTargetsTargetRoute extends Route {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Load a target.
|
||||
* @param {object} params
|
||||
* @param {string} params.target_id
|
||||
* @return {TargetModel}
|
||||
*/
|
||||
async model({ target_id }) {
|
||||
const { id: scopeID } = this.modelFor('scopes.scope.projects.project');
|
||||
return this.store.findRecord('target', target_id, { adapterOptions: { scopeID } });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeProjectsProjectTargetsTargetIndexRoute extends Route {
|
||||
}
|
||||
@@ -20,7 +20,12 @@
|
||||
{{#each @model as |target|}}
|
||||
<body.row as |row|>
|
||||
<row.cell>
|
||||
{{target.displayName}}
|
||||
<LinkTo
|
||||
@route="scopes.scope.projects.project.targets.target"
|
||||
@model={{target}}
|
||||
>
|
||||
{{target.displayName}}
|
||||
</LinkTo>
|
||||
<p>{{target.description}}</p>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{{outlet}}
|
||||
@@ -0,0 +1,35 @@
|
||||
<Rose::Layout::Page as |page|>
|
||||
|
||||
<page.header>
|
||||
<h2>{{t "resources.target"}}</h2>
|
||||
</page.header>
|
||||
|
||||
<page.navigation>
|
||||
<Rose::Nav::Tabs as |nav|>
|
||||
<nav.link @route='scopes.scope.projects.project.targets.target'>
|
||||
{{t 'titles.details'}}
|
||||
</nav.link>
|
||||
</Rose::Nav::Tabs>
|
||||
</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>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::Target
|
||||
@model={{@model}}
|
||||
@submit={{route-action "save" @model}}
|
||||
@cancel={{route-action "cancel" @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
</Rose::Layout::Page>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
import { render, find } from '@ember/test-helpers';
|
||||
import { hbs } from 'ember-cli-htmlbars';
|
||||
|
||||
module('Integration | Component | form/target', function (hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function (assert) {
|
||||
// Set any properties with this.set('myProperty', 'value');
|
||||
// Handle any actions with this.set('myAction', function(val) { ... });
|
||||
this.submit = () => {};
|
||||
this.cancel = () => {};
|
||||
|
||||
await render(hbs`
|
||||
<Form::Target
|
||||
@submit={{this.submit}}
|
||||
@cancel={{this.cancel}}
|
||||
/>`);
|
||||
|
||||
assert.ok(find('form'));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/projects/project/targets/target', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/projects/project/targets/target');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Route | scopes/scope/projects/project/targets/target/index', function(hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function(assert) {
|
||||
let route = this.owner.lookup('route:scopes/scope/projects/project/targets/target/index');
|
||||
assert.ok(route);
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,7 @@ actions:
|
||||
delete-host-catalog: Delete host catalog
|
||||
delete-auth-method: Delete auth method
|
||||
delete-host-set: Delete host set
|
||||
delete-target: Delete target
|
||||
add-host-set: Create Host Set
|
||||
auth:
|
||||
titles:
|
||||
@@ -52,6 +53,7 @@ resources:
|
||||
auth-methods: Auth Methods
|
||||
host-set: Host Set
|
||||
host-sets: Host Sets
|
||||
target: Target
|
||||
targets: Targets
|
||||
titles:
|
||||
iam: IAM
|
||||
|
||||
Reference in new issue
Block a user