#114 mostrar current user en la top bar

This commit is contained in:
Carlos Jimenez 2018-03-06 11:13:05 +01:00
parent e9ad6bf879
commit bc13abbe50
5 changed files with 52 additions and 3 deletions

View File

@ -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"

View File

@ -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'),

View File

@ -1,4 +1,8 @@
vn-main-menu {
#user {
display: inline-block;
padding-right: 0.2em;
}
& > div > vn-icon {
font-size: 2.2em;
cursor: pointer;

View File

@ -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;
};
};

View File

@ -9,7 +9,6 @@ module.exports = function(options) {
if (loopbackContext) {
loopbackContext.set('currentUser', req.accessToken.userId);
}
next();
};
};