chore: 🤖 find the currently selected org and project for UI
This commit is contained in:
2 files changed
+29
-9
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { hash } from 'rsvp';
|
||||
import { A } from '@ember/array';
|
||||
|
||||
export default class ScopesScopeRoute extends Route {
|
||||
@@ -43,14 +42,22 @@ export default class ScopesScopeRoute extends Route {
|
||||
* a project. These are used for scope navigation.
|
||||
*/
|
||||
async afterModel(model) {
|
||||
const scopes = {
|
||||
orgs: this.store.query('scope', { scope_id: 'global' }).catch(() => A([]))
|
||||
};
|
||||
// First, load orgs and, if necessary, projects
|
||||
let orgs, projects;
|
||||
orgs = await this.store.query('scope', { scope_id: 'global' })
|
||||
.catch(() => A([]));
|
||||
if (model.isProject) {
|
||||
this.projects = this.store.query('scope', { scope_id: model.scopeID })
|
||||
projects = await this.store.query('scope', { scope_id: model.scopeID })
|
||||
.catch(() => A([]))
|
||||
}
|
||||
this.scopes = await hash(scopes);
|
||||
// Then pull out the "selected" scopes, if relevant
|
||||
let selectedOrg, selectedProject;
|
||||
if (model.isGlobal || model.isOrg) selectedOrg = model;
|
||||
if (model.isProject) {
|
||||
selectedProject = model;
|
||||
selectedOrg = this.store.peekRecord('scope', model.scopeID);
|
||||
}
|
||||
this.scopes = { orgs, projects, selectedOrg, selectedProject };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +66,8 @@ export default class ScopesScopeRoute extends Route {
|
||||
*/
|
||||
setupController(controller) {
|
||||
super.setupController(...arguments);
|
||||
controller.setProperties({ scopes: this.scopes });
|
||||
const scopes = this.scopes;
|
||||
controller.setProperties({ scopes });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +82,6 @@ export default class ScopesScopeRoute extends Route {
|
||||
this.render('scopes/scope/-header-nav', {
|
||||
into: 'application',
|
||||
outlet: 'header-nav',
|
||||
model: model,
|
||||
});
|
||||
|
||||
this.render('scopes/scope/-sidebar', {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<Rose::Dropdown
|
||||
@text={{this.model.displayName}}
|
||||
@text={{this.scopes.selectedOrg.displayName}}
|
||||
@icon="app-icons/org" as |dropdown|
|
||||
>
|
||||
{{#if this.session.data.authenticated.isGlobal}}
|
||||
@@ -18,3 +18,16 @@
|
||||
</dropdown.link>
|
||||
{{/if}}
|
||||
</Rose::Dropdown>
|
||||
|
||||
{{#if this.scopes.selectedProject}}
|
||||
<Rose::Dropdown
|
||||
@text={{this.scopes.selectedProject.displayName}}
|
||||
@icon="app-icons/project" as |dropdown|
|
||||
>
|
||||
{{#each this.scopes.projects as |scope|}}
|
||||
<dropdown.link @route="scopes.scope" @model={{scope.id}}>
|
||||
{{scope.displayName}}
|
||||
</dropdown.link>
|
||||
{{/each}}
|
||||
</Rose::Dropdown>
|
||||
{{/if}}
|
||||
Reference in new issue
Block a user