Skip to content

Commit b8b28c2

Browse files
author
ege-dw
committed
display the name of the connected user
Signed-off-by: ege-dw <[email protected]>
1 parent 12c67b7 commit b8b28c2

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

src/containers/DefaultHeaderProfileDropdown.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
boundary="viewport"
99
tag="div"
1010
class="text-center">
11-
<strong>{{ $t('message.profile') }}</strong>
11+
{{ $t('message.connected_as') }}
12+
<strong>{{ user }}</strong>
1213
</b-dropdown-header>
1314
<b-dropdown-item v-if="canUpdateProfile()" v-b-modal.profileEditModal><i class="fa fa-user text-primary" /> {{ $t('message.profile_update') }}</b-dropdown-item>
1415
<b-dropdown-item v-if="canChangePassword()" to="/change-password"><i class="fa fa-key text-primary" /> {{ $t('message.change_password') }}</b-dropdown-item>
@@ -22,18 +23,25 @@
2223
import { HeaderDropdown as AppHeaderDropdown } from '@coreui/vue'
2324
import EventBus from '../shared/eventbus';
2425
import { decodeToken, getToken } from '../shared/permissions'
26+
import globalVarsMixin from "../mixins/globalVarsMixin";
2527
2628
export default {
2729
name: 'DefaultHeaderProfileDropdown',
30+
mixins: [globalVarsMixin],
2831
components: {
2932
AppHeaderDropdown
3033
},
3134
data: () => {
32-
return {
35+
return {
3336
itemsCount: 42,
3437
identityProvider: decodeToken(getToken()).idp
3538
}
3639
},
40+
computed: {
41+
user() {
42+
return this.currentUser.fullname || this.currentUser.username
43+
}
44+
},
3745
methods: {
3846
logout: function () {
3947
// Instructs all tabs (via localStorage event) that the session is being invalidated

src/i18n/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
"component_removed": "Component removed",
276276
"required_project_name": "The project name is required",
277277
"project_name_desc": "The name of the project or component as provided by the supplier",
278-
"profile": "Profile",
278+
"connected_as": "Connected as",
279279
"profile_update": "Update Profile",
280280
"profile_updated": "Profile updated",
281281
"logout": "Logout",

src/mixins/globalVarsMixin.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import Vue from 'vue'
22
import axios from "axios";
3+
import EventBus from "@/shared/eventbus";
34

45
export default {
56
data () {
67
return {
7-
dtrack: Object
8+
dtrack: Object,
9+
currentUser: Object
810
}
911
},
1012
created() {
@@ -17,5 +19,19 @@ export default {
1719
}
1820
);
1921
}
22+
if (this.$currentUser) {
23+
this.currentUser = this.$currentUser;
24+
} else {
25+
EventBus.$emit('profileUpdated');
26+
}
27+
},
28+
mounted() {
29+
EventBus.$on('profileUpdated', () => {
30+
axios.get(`${Vue.prototype.$api.BASE_URL}/${Vue.prototype.$api.URL_USER_SELF}`)
31+
.then((result) => {
32+
this.currentUser = result.data;
33+
}
34+
);
35+
});
2036
}
2137
}

src/router/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ router.beforeEach((to, from, next) => {
262262
// let backend verify the token
263263
router.app.axios.get(`${router.app.$api.BASE_URL}/${router.app.$api.URL_USER_SELF}`, {
264264
headers: { 'Authorization': `Bearer ${jwt}` }
265-
}).then(() => {
265+
}).then((result) => {
266+
Vue.prototype.$currentUser = result.data
266267
// allowed to proceed
267268
next();
268269
}).catch(() => {

src/views/components/ProfileEditModal.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
<script>
2121
import BInputGroupFormInput from "../../forms/BInputGroupFormInput";
22+
import globalVarsMixin from "@/mixins/globalVarsMixin";
23+
import EventBus from "@/shared/eventbus";
2224
2325
export default {
2426
name: "ProfileEditModal",
27+
mixins: [globalVarsMixin],
2528
components: {
2629
BInputGroupFormInput
2730
},
@@ -34,12 +37,9 @@
3437
},
3538
methods: {
3639
getSelf: function() {
37-
const url = `${this.$api.BASE_URL}/${this.$api.URL_USER_SELF}`;
38-
this.axios.get(url).then((result) => {
39-
this.username = result.data.username;
40-
this.fullname = result.data.fullname;
41-
this.email = result.data.email;
42-
});
40+
this.username = this.currentUser.username;
41+
this.fullname = this.currentUser.fullname;
42+
this.email = this.currentUser.email;
4343
},
4444
updateUser: function() {
4545
let url = `${this.$api.BASE_URL}/${this.$api.URL_USER_MANAGED}`;
@@ -48,6 +48,7 @@
4848
fullname: this.fullname,
4949
email: this.email
5050
}).then((response) => {
51+
EventBus.$emit('profileUpdated');
5152
this.$emit('refreshTable');
5253
this.$toastr.s(this.$t('message.profile_updated'));
5354
}).catch((error) => {

0 commit comments

Comments
 (0)