chore: rip out scope service
This commit is contained in:
24 files changed
+6
-384
No files matched your search
@@ -1,16 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class AuthMethodAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) {
|
||||
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Auth method is scoped to org only.
|
||||
* @type {boolean}
|
||||
*/
|
||||
includeProject = false;
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class GroupAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Group is scoped to org only, for now.
|
||||
* @type {boolean}
|
||||
*/
|
||||
includeProject = false;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class HostCatalogAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) { }
|
||||
@@ -1,14 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class ProjectAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Project is scoped to org only, technically.
|
||||
* @type {boolean}
|
||||
*/
|
||||
includeProject = false;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class RoleAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Role is scoped to org only, for now.
|
||||
* @type {boolean}
|
||||
*/
|
||||
includeProject = false;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import ApplicationAdapter from './application';
|
||||
import ScopeAdapterMixin from '../mixins/scope-adapter';
|
||||
|
||||
export default class UserAdapter extends ApplicationAdapter.extend(
|
||||
ScopeAdapterMixin
|
||||
) {
|
||||
// =attributes
|
||||
|
||||
/**
|
||||
* Project is scoped to org only, technically.
|
||||
* @type {boolean}
|
||||
*/
|
||||
includeProject = false;
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
import Service from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { computed } from '@ember/object';
|
||||
|
||||
/**
|
||||
* This module includes two parts:
|
||||
*
|
||||
* - `Scope` class: a data structure representing an org/project tuple
|
||||
* - `ScopeService`: manages the scope and exposes it to the application
|
||||
*/
|
||||
|
||||
/**
|
||||
* Represents a _scope_, which is defined as an organization/project tuple.
|
||||
* This class is intended as a simple data structure and is used by the
|
||||
* scope service (see below).
|
||||
* Immutable.
|
||||
*/
|
||||
class Scope {
|
||||
/**
|
||||
* @type {?object}
|
||||
* @private
|
||||
*/
|
||||
#org = null;
|
||||
|
||||
/**
|
||||
* @type {?object}
|
||||
* @private
|
||||
*/
|
||||
#project = null;
|
||||
|
||||
/**
|
||||
* Initializes an instance of `Scope` with optional org and project.
|
||||
* A scope with only project is invalid and in thi scenario, project will
|
||||
* be null.
|
||||
* @param {?object} org
|
||||
* @param {?object} project
|
||||
*/
|
||||
constructor(org = null, project = null) {
|
||||
if (org) this.#org = org;
|
||||
if (org && project) this.#project = project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Org for this scope. Immutable.
|
||||
* @type {?object}
|
||||
*/
|
||||
get org() {
|
||||
return this.#org;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project for this scope.
|
||||
* @type {?object}
|
||||
*/
|
||||
get project() {
|
||||
return this.#project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JSON representation of this scope.
|
||||
* @return {?object}
|
||||
*/
|
||||
toJSON() {
|
||||
const { org, project } = this;
|
||||
return { org, project };
|
||||
}
|
||||
}
|
||||
|
||||
export { Scope };
|
||||
|
||||
/**
|
||||
* The scope service manages the current scope, making it available throughout
|
||||
* the Ember application. Use `service.org` and `service.project` directly,
|
||||
* rather than interacting with the internal `scope` member.
|
||||
*
|
||||
* @example
|
||||
* // inject the scope service
|
||||
* import { inject as service } from '@ember/service';
|
||||
* class MyClass {
|
||||
* @service scope;
|
||||
* }
|
||||
*
|
||||
* // set an org, project, or both
|
||||
* this.scope.org = {id: 1};
|
||||
* this.scope.project = {id: 2};
|
||||
*
|
||||
* // retrieve the org and/or project
|
||||
* const org = this.scope.org;
|
||||
* const project = this.scope.project;
|
||||
*/
|
||||
export default class ScopeService extends Service {
|
||||
/**
|
||||
* The currently selected scope. This is an internal member only.
|
||||
* @type {?Scope}
|
||||
*/
|
||||
@tracked scope = new Scope();
|
||||
|
||||
/**
|
||||
* When setting org, `service.org = {...}`, a new scope is instantiated,
|
||||
* since scopes are immutable.
|
||||
* @type {?object}
|
||||
*/
|
||||
@computed('scope.org')
|
||||
get org() {
|
||||
return this.scope ? this.scope.org : null;
|
||||
}
|
||||
set org(org) {
|
||||
this.scope = new Scope(org, this.project);
|
||||
}
|
||||
|
||||
/**
|
||||
* When setting project, `service.project = {...}`, a new scope is
|
||||
* instantiated, since scopes are immutable.
|
||||
* @type {?object}
|
||||
*/
|
||||
@computed('scope.project')
|
||||
get project() {
|
||||
return this.scope ? this.scope.project : null;
|
||||
}
|
||||
set project(project) {
|
||||
this.scope = new Scope(this.org, project);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user