feat: Show active sessions under /target/:target_id route

This commit is contained in:
Susmitha Girumala committed 2021-02-04 16:18:04 -05:00
1 parent bd1cbb8748
commit c90e4fa69a
10 files changed
+87 -11

No files matched your search

@@ -1,5 +1,7 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeProjectsRoute extends Route {
// =services
@@ -25,4 +27,17 @@ export default class ScopesScopeProjectsRoute extends Route {
scope_id: currentScope.id,
});
}
// =actions
/**
* Cancels the specified session and notifies user of success or error.
* @param {SessionModel}
*/
@action
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.canceled-success')
async cancelSession(session) {
await session.cancelSession();
}
}
@@ -99,4 +99,5 @@ export default class ScopesScopeProjectsSessionsRoute extends Route {
deactivate() {
this.poller.cancelAll();
}
}
@@ -1,16 +1,36 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';
export default class ScopesScopeProjectsTargetsTargetRoute extends Route {
// =services
@service session;
// =methods
/**
* Load a target.
* Load a target and it's active sessions
* @param {object} params
* @param {string} params.target_id
* @return {TargetModel}
* @return {{TargetModel, [SessionModel]}}
*/
async model({ target_id }) {
return this.store.findRecord('target', target_id, { reload: true });
const userId = this.session.data.authenticated.user_id;
const target = await this.store.findRecord('target', target_id, { reload: true });
const sessions = await this.store.query('session', { scope_id: target.scopeID });
// Filter to current user, current target, and active state
const filteredSessions = sessions.filter(
session => session.user_id === userId &&
session.target_id === target.id &&
session.isCancelable
)
// Sort sessions by time created
const sortedSessions =
A(filteredSessions).sortBy('session.created_time').reverse();
return { target, sessions: sortedSessions };
}
/**
@@ -9,10 +9,10 @@ export default class ScopesScopeProjectsTargetsTargetHostsRoute extends Route {
* @return {Promise{[HostModel]}}
*/
async model() {
const { host_sets } = this.modelFor('scopes.scope.projects.targets.target');
const { target } = this.modelFor('scopes.scope.projects.targets.target');
// Load all host-sets
const hostSets = await all(
host_sets.map(({ host_set_id }) =>
target.host_sets.map(({ host_set_id }) =>
this.store.findRecord('host-set', host_set_id)
)
);
@@ -7,7 +7,7 @@ export default class ScopesScopeProjectsTargetsTargetIndexRoute extends Route {
* Navigate to hosts within a target.
*/
afterModel() {
this.transitionTo('scopes.scope.projects.targets.target.hosts');
this.transitionTo('scopes.scope.projects.targets.target.sessions');
}
}
@@ -4,9 +4,10 @@ export default class ScopesScopeProjectsTargetsTargetSessionsRoute extends Route
// =methods
/**
* Loads all sessions and filter to current target.
* Loads all sessions for current target.
* @return {Promise{[SessionModel]}}
*/
async model() {
return this.modelFor('scopes.scope.projects.targets.target').sessions;
}
}
@@ -15,6 +15,7 @@
<row.headerCell>{{t "resources.target.title"}}</row.headerCell>
<row.headerCell>{{t "form.started.label"}}</row.headerCell>
<row.headerCell>{{t "form.status.label"}}</row.headerCell>
<row.headerCell />
</header.row>
</table.header>
<table.body as |body|>
@@ -36,6 +37,13 @@
<row.cell>
<Rose::Badge>{{sessionAggregate.session.status}}</Rose::Badge>
</row.cell>
<row.cell>
{{#if sessionAggregate.session.isCancelable}}
<Rose::Button @style="secondary" {{on "click" (route-action "cancelSession" sessionAggregate.session)}}>
{{t "actions.cancel"}}
</Rose::Button>
{{/if}}
</row.cell>
</body.row>
{{/each}}
</table.body>
@@ -1,4 +1,4 @@
{{page-title @model.displayName}}
{{page-title @model.target.displayName}}
<Rose::Layout::Page as |page|>
@@ -1,4 +1,4 @@
<h2>
{{@model.displayName}}
{{@model.target.displayName}}
</h2>
<p>{{@model.description}}</p>
<p>{{@model.target.description}}</p>
@@ -1 +1,32 @@
{{outlet}}
<Rose::Table as |table|>
<table.body as |body|>
{{#each @model as |session|}}
<body.row as |row|>
<row.cell class="nowrap">
<Rose::Icon
class={{concat "session-status-" session.status}}
@name="app-icons/action-session"
@size="medium" />
{{session.id}}
</row.cell>
<row.cell>{{user.displayName}}</row.cell>
<row.cell>{{target.displayName}}</row.cell>
<row.cell>
<time datetime={{format-date-iso session.created_time}}>
{{format-date-iso-human session.created_time}}
</time>
</row.cell>
<row.cell>
<Rose::Badge>{{session.status}}</Rose::Badge>
</row.cell>
<row.cell>
{{#if session.isCancelable}}
<Rose::Button @style="secondary" {{on "click" (route-action "cancelSession" session)}}>
{{t "actions.cancel"}}
</Rose::Button>
{{/if}}
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>