chore: 🤖 add sessions property to target

This commit is contained in:
Randall Morey committed 2021-02-05 16:57:06 -05:00
1 parent f4f0beaca7
commit 80842a9b7e
4 files changed
+86 -2

No files matched your search

+6 -2
View File
@@ -1,5 +1,6 @@
import GeneratedSessionModel from '../generated/models/session';
import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
import { attr } from '@ember-data/model';
export default class SessionModel extends GeneratedSessionModel {
@@ -9,12 +10,15 @@ export default class SessionModel extends GeneratedSessionModel {
@attr('string', { readOnly: true }) proxy_address;
@attr('number', { readOnly: true }) proxy_port;
@equal('status', 'active') isActive;
@equal('status', 'pending') isPending;
/**
* @type {boolean}
*/
@computed('status')
@computed('isActive', 'isPending')
get isCancelable() {
return this.status?.match(/(active)|(pending)/i);
return this.isActive || this.isPending;
}
/**
+18
View File
@@ -36,6 +36,24 @@ export default class TargetModel extends GeneratedTargetModel {
.filter((hostSetRef) => hostSetRef.model !== null);
}
/**
* Sessions associated with this target (but only already loaded sessions).
* @type {SessionModel[]}
*/
get sessions() {
return this.store.peekAll('session').filter(s => s.target_id === this.id);
}
/**
* True if any sessions associated with this target are active or pending.
* @type {boolean}
*/
get isActive() {
const pendingOrActiveSessions =
this.sessions.filter(s => s.isActive || s.isPending);
return Boolean(pendingOrActiveSessions.length);
}
// =methods
/**