feat: 🎸 add smart scope breadcrumbs

This commit is contained in:
Randall Morey committed 2020-10-29 14:38:09 -04:00
1 parent 5b8e528174
commit b4be0e08cf
8 files changed
+123 -15

No files matched your search

+35 -15
View File
@@ -1,15 +1,35 @@
{{#if this.breadCrumbs}}
<Rose::Nav::Breadcrumbs as |crumbs|>
{{#each this.breadCrumbs as |crumb|}}
{{#if crumb.model}}
<crumbs.link @route={{crumb.path}} @model={{crumb.model}}>
{{crumb.label}}
</crumbs.link>
{{else}}
<crumbs.link @route={{crumb.path}}>
{{crumb.label}}
</crumbs.link>
{{/if}}
{{/each}}
</Rose::Nav::Breadcrumbs>
{{/if}}
<Rose::Nav::Breadcrumbs as |crumbs|>
{{#if this.scope.org}}
{{#unless this.scope.org.isGlobal}}
<crumbs.link @route="scopes.scope.scopes" @model="global">
{{t "resources.org.title_plural"}}
</crumbs.link>
<crumbs.link @route="scopes.scope.edit" @model={{this.scope.org.id}}>
{{this.scope.org.displayName}}
</crumbs.link>
{{/unless}}
{{/if}}
{{#if this.scope.project}}
<crumbs.link @route="scopes.scope.scopes" @model={{this.scope.org.id}}>
{{t "resources.project.title_plural"}}
</crumbs.link>
<crumbs.link @route="scopes.scope.edit" @model={{this.scope.project.id}}>
{{this.scope.project.displayName}}
</crumbs.link>
{{/if}}
{{#each this.breadCrumbs as |crumb|}}
{{#if crumb.model}}
<crumbs.link @route={{crumb.path}} @model={{crumb.model}}>
{{crumb.label}}
</crumbs.link>
{{else}}
<crumbs.link @route={{crumb.path}}>
{{crumb.label}}
</crumbs.link>
{{/if}}
{{/each}}
</Rose::Nav::Breadcrumbs>
+10
View File
@@ -0,0 +1,10 @@
import BreadCrumbsComponent from 'ember-breadcrumbs/components/bread-crumbs';
import { inject as service } from '@ember/service';
export default class crumbs extends BreadCrumbsComponent {
// =services
@service scope;
}
@@ -0,0 +1,27 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
export default class ScopesScopeScopesController extends Controller {
// =services
@service intl;
// =attributes
/**
* @type {string}
*/
@computed('model.currentScope.{isGlobal,isOrg}')
get breadCrumb() {
if (this.model.currentScope.isGlobal) {
return this.intl.t('resources.org.title_plural');
}
/* istanbul ignore else */
if (this.model.currentScope.isOrg) {
return this.intl.t('resources.project.title_plural');
}
/* istanbul ignore next */
return null;
}
}
+4
View File
@@ -11,6 +11,7 @@ export default class ScopesScopeRoute extends Route {
@service intl;
@service session;
@service scope;
// =methods
@@ -61,6 +62,9 @@ export default class ScopesScopeRoute extends Route {
selectedProject = model;
selectedOrg = this.store.peekRecord('scope', model.scopeID);
}
// Update the scope service with the current scope(s);
this.scope.org = selectedOrg;
this.scope.project = selectedProject;
this.scopes = { orgs, projects, selectedOrg, selectedProject };
}
+22
View File
@@ -0,0 +1,22 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
/**
* This simple non-functional service is used to retain references to
* the currently active scope or scopes.
*/
export default class ScopeService extends Service {
// =attributes
/**
* @type {ScopeModel}
*/
@tracked org;
/**
* @type {ScopeModel}
*/
@tracked project;
}
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Controller | scopes/scope/scopes', function(hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:scopes/scope/scopes');
assert.ok(controller);
});
});
+12
View File
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Service | scope', function(hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:scope');
assert.ok(service);
});
});
+1
View File
@@ -6,6 +6,7 @@ auth:
choose-org: Choose a scope to authenticate.
authenticating-with-org: "You are authenticating with {name}."
titles:
home: Home
iam: IAM
new: New
resources: Resources