feat: 🎸 add cancel session feature

This commit is contained in:
Randall Morey committed 2020-09-18 15:38:32 -04:00
1 parent 4229658815
commit 2aa330fd36
9 files changed
+52 -4

No files matched your search

@@ -34,4 +34,8 @@
padding: sizing.rems(l) sizing.rems(s);
}
}
[class*="rose-button"] {
margin-bottom: 0;
}
}
@@ -1,8 +1,15 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { all, hash } from 'rsvp';
export default class ScopesScopeProjectsProjectSessionsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
@@ -22,4 +29,19 @@ export default class ScopesScopeProjectsProjectSessionsRoute extends Route {
);
}
/**
* Cancels the specified session and notifies user of success or error.
* @param {SessionModel}
*/
@action
async cancelSession(session) {
try {
await session.cancelSession();
this.notify.success(this.intl.t('notify.session-canceled'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -7,7 +7,7 @@
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
<row.headerCell>{{t "form.label.actions"}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
@@ -6,7 +6,7 @@
<row.headerCell>{{t "form.label.name"}}</row.headerCell>
<row.headerCell>{{t "form.label.type"}}</row.headerCell>
<row.headerCell>{{t "form.label.id"}}</row.headerCell>
<row.headerCell>{{t "form.label.actions"}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
@@ -19,6 +19,7 @@
<row.headerCell>{{t "resources.user"}}</row.headerCell>
<row.headerCell>{{t "resources.target"}}</row.headerCell>
<row.headerCell>{{t "form.label.started"}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
@@ -34,6 +35,11 @@
{{format-date-iso-human sessionAggregate.session.created_time}}
</time>
</row.cell>
<row.cell>
<Rose::Button @style="secondary" {{on "click" (route-action "cancelSession" sessionAggregate.session)}}>
{{t "actions.cancel"}}
</Rose::Button>
</row.cell>
</body.row>
{{/each}}
</table.body>
@@ -8,7 +8,7 @@
<row.headerCell>{{t "form.label.name"}}</row.headerCell>
<row.headerCell>{{t "form.label.type"}}</row.headerCell>
<row.headerCell>{{t "form.label.id"}}</row.headerCell>
<row.headerCell>{{t "form.label.actions"}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
@@ -8,7 +8,7 @@
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.type'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
<row.headerCell>{{t "form.label.actions"}}</row.headerCell>
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
+14
View File
@@ -299,4 +299,18 @@ export default function() {
return sessions.where(session => session.scopeId === scope_id);
});
this.get('/sessions/:id');
this.post('/sessions/:idMethod', function ({ sessions }, { params: { idMethod } }) {
const attrs = this.normalizedRequestAttrs();
const id = idMethod.split(':')[0];
const method = idMethod.split(':')[1];
const session = sessions.find(id);
const updatedAttrs = {
version: attrs.version
};
if (method === 'cancel') {
updatedAttrs.status = 'canceled';
}
return session.update(updatedAttrs);
});
}
+2
View File
@@ -117,6 +117,7 @@ titles:
account: Account
accounts-welcome: Welcome to Accounts
no-sessions: No Active Sessions
actions: Actions
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.
@@ -180,3 +181,4 @@ notify:
create-success: Created succesfully.
save-success: Saved succesfully.
delete-success: Deleted successfully.
session-canceled: Session canceled.