#114 mostrar current user en la top bar
This commit is contained in:
parent
e9ad6bf879
commit
bc13abbe50
|
@ -1,4 +1,8 @@
|
|||
<div style="position: fixed; top: 0; right: 0; padding: .8em 1.5em; z-index: 10;">
|
||||
<div
|
||||
id="user">
|
||||
<h6>{{currentUserName}}</h6>
|
||||
</div>
|
||||
<vn-icon
|
||||
id="apps"
|
||||
icon="apps"
|
||||
|
|
|
@ -2,20 +2,33 @@ import ngModule from '../../module';
|
|||
import './style.scss';
|
||||
|
||||
export default class MainMenu {
|
||||
constructor($translate, $window, modulesFactory) {
|
||||
constructor($translate, $scope, $http, $window, modulesFactory) {
|
||||
this.$ = $scope;
|
||||
this.$http = $http;
|
||||
this.$translate = $translate;
|
||||
this.$window = $window;
|
||||
this.modules = modulesFactory.getModules();
|
||||
this.langs = $translate.getAvailableLanguageKeys();
|
||||
}
|
||||
getCurrentUserName() {
|
||||
console.log('in getcurrentUserName');
|
||||
this.$http.get('/auth/api/Accounts/getCurrentUserName')
|
||||
.then(json => {
|
||||
this.$.currentUserName = json.data;
|
||||
});
|
||||
}
|
||||
|
||||
onLogoutClick() {
|
||||
this.$window.location = '/logout';
|
||||
}
|
||||
onChangeLangClick(lang) {
|
||||
this.$translate.use(lang);
|
||||
}
|
||||
$onInit() {
|
||||
this.getCurrentUserName();
|
||||
}
|
||||
}
|
||||
MainMenu.$inject = ['$translate', '$window', 'modulesFactory'];
|
||||
MainMenu.$inject = ['$translate', '$scope', '$http', '$window', 'modulesFactory'];
|
||||
|
||||
ngModule.component('vnMainMenu', {
|
||||
template: require('./main-menu.html'),
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
vn-main-menu {
|
||||
#user {
|
||||
display: inline-block;
|
||||
padding-right: 0.2em;
|
||||
}
|
||||
& > div > vn-icon {
|
||||
font-size: 2.2em;
|
||||
cursor: pointer;
|
||||
|
|
|
@ -13,4 +13,33 @@ module.exports = function(Self) {
|
|||
}
|
||||
next();
|
||||
});
|
||||
|
||||
Self.remoteMethod('getCurrentUserName', {
|
||||
description: 'Gets the current user name',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'context',
|
||||
type: 'object',
|
||||
http: function(ctx) {
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
verb: 'GET',
|
||||
path: '/getCurrentUserName'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getCurrentUserName = async function(ctx) {
|
||||
let filter = {fields: ['name']};
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let account = await Self.findById(userId, filter);
|
||||
|
||||
return account.name;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -9,7 +9,6 @@ module.exports = function(options) {
|
|||
if (loopbackContext) {
|
||||
loopbackContext.set('currentUser', req.accessToken.userId);
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue