Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fix navigation errors during testing
Browse files Browse the repository at this point in the history
Resolves issue encountered in #1027 during testing.
jkleinsc committed Apr 11, 2017
1 parent 279abd7 commit 400314f
Showing 2 changed files with 36 additions and 27 deletions.
40 changes: 22 additions & 18 deletions app/components/nav-menu.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
import Ember from 'ember';
import UserSession from 'hospitalrun/mixins/user-session';

const {
computed,
get,
set
} = Ember;

export default Ember.Component.extend(UserSession, {
tagName: 'div',
callCloseSettings: 'closeSettings',
callNavAction: 'navAction',
classNames: ['primary-nav-item'],
isShowing: false,
nav: null,
tagName: 'div',

show: function() {
show: computed('nav', 'session.data.authenticated.userCaps', function() {
this._setupSubNav();
return this.currentUserCan(this.get('nav').capability);
}.property('nav', 'session.data.authenticated.userCaps'),

isShowing: false,
return this.currentUserCan(get(this, 'nav').capability);
}),

_setup: function() {
let nav = this.get('nav');
let nav = get(this, 'nav');
nav.closeSubnav = function() {
this.set('isShowing', false);
set(this, 'isShowing', false);
}.bind(this);
this._setupSubNav();
}.on('init'),

_setupSubNav() {
let nav = this.get('nav');
let nav = get(this, 'nav');
nav.subnav.forEach((item) => {
item.show = this.currentUserCan(item.capability);
set(item, 'show', this.currentUserCan(item.capability));
});
},

callNavAction: 'navAction',
callCloseSettings: 'closeSettings',

actions: {
toggleContent() {
this.set('isShowing', !this.get('isShowing'));
this.sendAction('callNavAction', this.nav);
},

resetNav() {
this.sendAction('callCloseSettings');
},

toggleContent() {
this.toggleProperty('isShowing');
this.sendAction('callNavAction', this.nav);
}
}
});
23 changes: 14 additions & 9 deletions app/mixins/navigation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Ember from 'ember';

const { camelize } = Ember.String;
const { isEqual } = Ember;
const {
get,
isEqual,
set
} = Ember;

export default Ember.Mixin.create({
navItems: [
@@ -365,19 +369,20 @@ export default Ember.Mixin.create({
// i18n will return a SafeString object, not a string
return typeof translation === 'string' ? original : translation;
};
return this.get('navItems').map((nav) => {
let i18n = get(this, 'i18n');
let navItems = get(this, 'navItems');
return navItems.map((nav) => {
let sectionKey = localizationPrefix + camelize(nav.title).toLowerCase();
let navTranslated = this.get('i18n').t(sectionKey);
let navTranslated = i18n.t(sectionKey);

Ember.set(nav, 'localizedTitle', translationOrOriginal(navTranslated, nav.title));
set(nav, 'localizedTitle', translationOrOriginal(navTranslated, nav.title));
// Map all of the sub navs, too
nav.subnav = nav.subnav.map((sub) => {
set(nav, 'subnav', nav.subnav.map((sub) => {
let subItemKey = `${localizationPrefix}subnav.${camelize(sub.title)}`;
let subTranslated = this.get('i18n').t(subItemKey);

sub.localizedTitle = translationOrOriginal(subTranslated, sub.title);
let subTranslated = i18n.t(subItemKey);
set(sub, 'localizedTitle', translationOrOriginal(subTranslated, sub.title));
return sub;
});
}));

return nav;
});

0 comments on commit 400314f

Please sign in to comment.