Merge pull request #203 from hashicorp/feature-sessions-status
Feature sessions status
This commit is contained in:
8 files changed
+81
-3
No files matched your search
@@ -12,6 +12,7 @@ export default class GeneratedSessionModel extends BaseModel {
|
||||
|
||||
@attr('string', {
|
||||
description: 'The name of the current status of this session.',
|
||||
readOnly: true,
|
||||
})
|
||||
status;
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { all, hash } from 'rsvp';
|
||||
import { task, timeout } from 'ember-concurrency';
|
||||
|
||||
const POLL_TIMEOUT_SECONDS = 2.5;
|
||||
|
||||
export default class ScopesScopeProjectsProjectSessionsRoute extends Route {
|
||||
|
||||
@@ -10,6 +13,25 @@ export default class ScopesScopeProjectsProjectSessionsRoute extends Route {
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* A simple Ember Concurrency-based polling task that refreshes the route
|
||||
* every POLL_TIMEOUT_SECONDS seconds. This is necessary to display changes
|
||||
* to session `status` that may occur.
|
||||
*
|
||||
* NOTE: tasks are sort of attributes and sort of methods, but they are not
|
||||
* language-level constructs. Thus we annotate this task as if it
|
||||
* is an attribute.
|
||||
* @type {Task}
|
||||
*/
|
||||
@task(function * () {
|
||||
while(true) {
|
||||
yield timeout(POLL_TIMEOUT_SECONDS * 1000);
|
||||
yield this.refresh();
|
||||
}
|
||||
}).drop() poller;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
@@ -29,6 +51,22 @@ export default class ScopesScopeProjectsProjectSessionsRoute extends Route {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When this route is activated (entered), begin polling for changes.
|
||||
*/
|
||||
activate() {
|
||||
this.poller.perform();
|
||||
}
|
||||
|
||||
/**
|
||||
* When this route is deactivated (exited), stop polling for changes.
|
||||
*/
|
||||
deactivate() {
|
||||
this.poller.cancelAll();
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Cancels the specified session and notifies user of success or error.
|
||||
* @param {SessionModel}
|
||||
|
||||
@@ -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 "form.label.status"}}</row.headerCell>
|
||||
<row.headerCell>{{t "titles.actions"}}</row.headerCell>
|
||||
</header.row>
|
||||
</table.header>
|
||||
@@ -35,6 +36,9 @@
|
||||
{{format-date-iso-human sessionAggregate.session.created_time}}
|
||||
</time>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
<Rose::Badge>{{sessionAggregate.session.status}}</Rose::Badge>
|
||||
</row.cell>
|
||||
<row.cell>
|
||||
<Rose::Button @style="secondary" {{on "click" (route-action "cancelSession" sessionAggregate.session)}}>
|
||||
{{t "actions.cancel"}}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import config from '../config/environment';
|
||||
import { authHandler, deauthHandler } from './route-handlers/auth';
|
||||
import { pickRandomStatusString } from './factories/session';
|
||||
//import { Response } from 'miragejs';
|
||||
|
||||
export default function() {
|
||||
@@ -295,10 +296,22 @@ export default function() {
|
||||
|
||||
// session
|
||||
|
||||
// To simulate changes to `session.status` that may occur in the backend,
|
||||
// we quietly randomize the value of the field on GET.
|
||||
this.get('/sessions', function ({ sessions }, { queryParams: { scope_id } }) {
|
||||
return sessions.where(session => session.scopeId === scope_id);
|
||||
sessions.where(session => session.scopeId === scope_id)
|
||||
.models
|
||||
.forEach(session => session.update({
|
||||
status: pickRandomStatusString()
|
||||
}));
|
||||
return sessions.where(session => session.scopeId === scope_id)
|
||||
});
|
||||
this.get('/sessions/:id', function ({ sessions }, { params: { id } }) {
|
||||
const session = sessions.find(id);
|
||||
return session.update({
|
||||
status: pickRandomStatusString()
|
||||
});
|
||||
});
|
||||
this.get('/sessions/:id');
|
||||
this.post('/sessions/:idMethod', function ({ sessions }, { params: { idMethod } }) {
|
||||
const attrs = this.normalizedRequestAttrs();
|
||||
const id = idMethod.split(':')[0];
|
||||
@@ -308,7 +321,7 @@ export default function() {
|
||||
version: attrs.version
|
||||
};
|
||||
if (method === 'cancel') {
|
||||
updatedAttrs.status = 'canceled';
|
||||
updatedAttrs.status = 'canceling';
|
||||
}
|
||||
return session.update(updatedAttrs);
|
||||
});
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import factory from '../generated/factories/target';
|
||||
import { trait } from 'ember-cli-mirage';
|
||||
import { random } from 'faker';
|
||||
|
||||
const statusStrings = [
|
||||
'pending',
|
||||
'active',
|
||||
'canceling',
|
||||
'terminated'
|
||||
];
|
||||
|
||||
export const pickRandomStatusString = () => random.arrayElement(statusStrings);
|
||||
|
||||
export default factory.extend({
|
||||
|
||||
id: (i) => `session-id-${i}`,
|
||||
status: pickRandomStatusString,
|
||||
|
||||
/**
|
||||
* Sessions generated with this trait will automatically form
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"ember-cli-sri": "^2.1.1",
|
||||
"ember-cli-template-lint": "^1.0.0-beta.3",
|
||||
"ember-cli-uglify": "^3.0.0",
|
||||
"ember-concurrency": "^1.3.0",
|
||||
"ember-data": "~3.16.0",
|
||||
"ember-data-model-fragments": "5.0.0-beta.0",
|
||||
"ember-exam": "^5.0.1",
|
||||
|
||||
@@ -163,6 +163,7 @@ form:
|
||||
current_password: Current Password
|
||||
new_password: New Password
|
||||
started: Started
|
||||
status: Status
|
||||
errors:
|
||||
titles:
|
||||
unauthenticated-error: You are not signed in
|
||||
|
||||
@@ -8923,6 +8923,15 @@ ember-compatibility-helpers@^1.1.1, ember-compatibility-helpers@^1.1.2, ember-co
|
||||
ember-cli-version-checker "^2.1.1"
|
||||
semver "^5.4.1"
|
||||
|
||||
ember-concurrency@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/ember-concurrency/-/ember-concurrency-1.3.0.tgz#66f90fb792687470bcee1172adc0ebf33f5e8b9c"
|
||||
integrity sha512-DwGlfWFpYyAkTwsedlEtK4t1DznJSculAW6Vq5S1C0shVPc5b6tTpHB2FFYisannSYkm+wpm1f1Pd40qiNPtOQ==
|
||||
dependencies:
|
||||
ember-cli-babel "^7.7.3"
|
||||
ember-compatibility-helpers "^1.2.0"
|
||||
ember-maybe-import-regenerator "^0.1.6"
|
||||
|
||||
ember-cookies@^0.5.0, ember-cookies@^0.5.2:
|
||||
version "0.5.2"
|
||||
resolved "https://registry.yarnpkg.com/ember-cookies/-/ember-cookies-0.5.2.tgz#06e33463f2f83254fefaf224cc944dec3fb9d3ba"
|
||||
|
||||
Reference in new issue
Block a user