chore: 🤖 add isType convenience boolean getters/setters

This commit is contained in:
Randall Morey committed 2020-07-15 09:43:30 -04:00
1 parent eb4b29ac1b
commit a43efaddfa
2 files changed
+61 -2

No files matched your search

+41
View File
@@ -1,5 +1,12 @@
import GeneratedScopeModel from '../generated/models/scope';
import { belongsTo, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
export const scopeTypes = {
global: 'global',
org: 'org',
project: 'project'
};
export default class ScopeModel extends GeneratedScopeModel {
@@ -17,4 +24,38 @@ export default class ScopeModel extends GeneratedScopeModel {
*/
@hasMany('scope', {inverse: 'parentScope'}) childrenScopes;
// =computed
/**
* @type {boolean}
*/
@computed('type')
get isGlobal() {
return this.type === scopeTypes.global;
}
// There is only one global scope and it cannot be created by clients,
// thus no set.
/**
* @type {boolean}
*/
@computed('type')
get isOrg() {
return this.type === scopeTypes.org;
}
set isOrg(value) {
if (value) this.type = scopeTypes.org;
}
/**
* @type {boolean}
*/
@computed('type')
get isProject() {
return this.type === scopeTypes.project;
}
set isProject(value) {
if (value) this.type = scopeTypes.project;
}
}