From e284e4e78abe2397ffeba4f9f8ecee0992721187 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 26 Oct 2020 19:14:30 -0400 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20always=20attempt=20t?= =?UTF-8?q?o=20load=20org=20scopes=20for=20nav=20purposes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/app/routes/scopes/scope.js | 21 +++++++++++++++---- .../templates/scopes/scope/-header-nav.hbs | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ui/core/app/routes/scopes/scope.js b/ui/core/app/routes/scopes/scope.js index 7af8591f0..f0911b566 100644 --- a/ui/core/app/routes/scopes/scope.js +++ b/ui/core/app/routes/scopes/scope.js @@ -1,10 +1,13 @@ 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 { // =services @service intl; + @service session; // =methods @@ -35,14 +38,24 @@ export default class ScopesScopeRoute extends Route { } /** - * Adds the set of all org scopes to the controller, which is used by the - * scope navigation template. + * Load all scopes within the current scope context. For example, + * if **this** scope is a project, attempt to load all projects for the owning + * org, as well as all orgs. If **this** scope is an org, attempt to load all + * orgs within the global scope. These are used for scope navigation. + */ + async afterModel() { + this.scopes = await hash({ + orgs: this.store.query('scope', { scope_id: 'global' }).catch(() => A([])) + }); + } + + /** + * Adds the scopes hash to the controller context (see `afterModel`). * @param {Controller} controller */ setupController(controller) { super.setupController(...arguments); - const orgScopes = this.modelFor('scopes').filterBy('isOrg', true); - controller.setProperties({ orgScopes }); + controller.setProperties({ scopes: this.scopes }); } /** diff --git a/ui/core/app/templates/scopes/scope/-header-nav.hbs b/ui/core/app/templates/scopes/scope/-header-nav.hbs index 00484b51a..be1e33452 100644 --- a/ui/core/app/templates/scopes/scope/-header-nav.hbs +++ b/ui/core/app/templates/scopes/scope/-header-nav.hbs @@ -7,7 +7,7 @@ {{t "titles.global"}} - {{#each this.orgScopes as |scope|}} + {{#each this.scopes.orgs as |scope|}} {{scope.displayName}}