Add showing and modifying user name #306

Merged
konrad merged 10 commits from feature/user-name into master 2020-11-21 21:25:00 +00:00
14 changed files with 92 additions and 10 deletions

View File

@ -45,7 +45,7 @@
<div class="dropdown is-right is-active">
<div class="dropdown-trigger">
<button @click.stop="userMenuActive = !userMenuActive" class="button noshadow">
<span class="username">{{ userInfo.username }}</span>
<span class="username">{{ userInfo.name !== '' ? userInfo.name : userInfo.username }}</span>
<span class="icon is-small">
<icon icon="chevron-down"/>
</span>

View File

@ -6,8 +6,8 @@
:width="avatarSize"
alt=""
class="avatar"
v-tooltip="user.username"/>
<span class="username" v-if="showUsername">{{ user.username }}</span>
v-tooltip="user.getDisplayName()"/>
<span class="username" v-if="showUsername">{{ user.getDisplayName() }}</span>
</div>
</template>

View File

@ -52,7 +52,7 @@
</div>
</td>
<td>
{{ s.sharedBy.username }}
{{ s.sharedBy.getDisplayName() }}
</td>
<td class="type">
<template v-if="s.right === rights.ADMIN">

View File

@ -46,7 +46,7 @@
<tbody>
<tr :key="s.id" v-for="s in sharables">
<template v-if="shareType === 'user'">
<td>{{ s.username }}</td>
<td>{{ s.getDisplayName() }}</td>
<td>
<template v-if="s.id === userInfo.id">
<b class="is-success">You</b>

View File

@ -107,7 +107,7 @@
<label class="label" for="">Assignees</label>
<ul class="assingees">
<li :key="a.id" v-for="(a, index) in taskEditTask.assignees">
{{ a.username }}
{{ a.getDisplayName() }}
<a @click="deleteAssigneeByIndex(index)">
<icon icon="times"/>
</a>

View File

@ -17,7 +17,7 @@
<div class="media-content">
<div class="comment-info">
<img :src="c.author.getAvatarUrl(20)" alt="" class="image is-avatar" height="20" width="20"/>
<strong>{{ c.author.username }}</strong>&nbsp;
<strong>{{ c.author.getDisplayName() }}</strong>&nbsp;
<span v-tooltip="formatDate(c.created)">{{ formatDateSince(c.created) }}</span>
<span v-if="+new Date(c.created) !== +new Date(c.updated)" v-tooltip="formatDate(c.updated)">
· edited {{ formatDateSince(c.updated) }}

View File

@ -12,6 +12,7 @@ export default class UserModel extends AbstractModel {
id: 0,
email: '',
username: '',
name: '',
created: null,
updated: null,
}
@ -20,4 +21,12 @@ export default class UserModel extends AbstractModel {
getAvatarUrl(size = 50) {
return `${window.API_URL}/${this.username}/avatar?size=${size}`
}
getDisplayName() {
if (this.name !== '') {
return this.name
}
return this.username
}
}

10
src/models/userName.js Normal file
View File

@ -0,0 +1,10 @@
import AbstractModel from './abstractModel'
export default class UserNameModel extends AbstractModel {
defaults() {
return {
name: '',
}
}
}

10
src/services/userName.js Normal file
View File

@ -0,0 +1,10 @@
import AbstractService from './abstractService'
export default class UserNameService extends AbstractService {
constructor() {
super({
update: '/user/settings/name',
})
}
}

View File

@ -16,6 +16,9 @@ export default {
state.info = info
state.avatarUrl = info.getAvatarUrl()
},
setUserName(state, name) {
state.info.name = name
},
authenticated(state, authenticated) {
state.authenticated = authenticated
},

View File

@ -1,6 +1,6 @@
<template>
<div class="content has-text-centered">
<h2>Hi {{ userInfo.username }}!</h2>
<h2>Hi {{ userInfo.name !== '' ? userInfo.name : userInfo.username }}!</h2>
<template v-if="!hasTasks">
<p>Click on a list or namespace on the left to get started.</p>
<router-link

View File

@ -346,7 +346,7 @@
<!-- Created / Updated [by] -->
<p class="created">
Created <span v-tooltip="formatDate(task.created)">{{ formatDateSince(task.created) }}</span> by {{ task.createdBy.username }}
Created <span v-tooltip="formatDate(task.created)">{{ formatDateSince(task.created) }}</span> by {{ task.createdBy.getDisplayName() }}
<template v-if="+new Date(task.created) !== +new Date(task.updated)">
<br/>
<!-- Computed properties to show the actual date every time it gets updated -->

View File

@ -106,7 +106,7 @@
<table class="table is-striped is-hoverable is-fullwidth">
<tbody>
<tr :key="m.id" v-for="m in team.members">
<td>{{ m.username }}</td>
<td>{{ m.getDisplayName() }}</td>
<td>
<template v-if="m.id === userInfo.id">
<b class="is-success">You</b>

View File

@ -106,6 +106,38 @@
</div>
</div>
<!-- Name -->
<div class="card">
<header class="card-header">
<p class="card-header-title">
Update your name
</p>
</header>
<div class="card-content">
<div class="content">
<div class="field">
<label class="label" for="newEmail">Name</label>
<div class="control">
<input
@keyup.enter="updateName"
class="input"
id="newEmail"
placeholder="The new name"
type="text"
v-model="name"/>
</div>
</div>
<div class="bigbuttons">
<button :class="{ 'is-loading': userNameService.loading}" @click="updateName()"
class="button is-primary is-fullwidth">
Save
</button>
</div>
</div>
</div>
</div>
<!-- Avatar -->
<avatar-settings/>
@ -234,6 +266,8 @@ import EmailUpdateService from '../../services/emailUpdate'
import EmailUpdateModel from '../../models/emailUpdate'
import TotpModel from '../../models/totp'
import TotpService from '../../services/totp'
import UserNameService from '../../services/userName'
import UserNameModel from '../../models/userName'
import {mapState} from 'vuex'
@ -260,6 +294,9 @@ export default {
totpDisablePassword: '',
caldavUrl: '',
name: '',
userNameService: UserNameService,
}
},
components: {
@ -275,6 +312,9 @@ export default {
this.totpService = new TotpService()
this.totp = new TotpModel()
this.userNameService = new UserNameService()
this.name = this.$store.state.auth.info.name
this.totpStatus()
this.buildCaldavUrl()
},
@ -359,6 +399,16 @@ export default {
})
.catch(e => this.error(e, this))
},
updateName() {
const name = new UserNameModel({name: this.name})
this.userNameService.update(name)
.then(() => {
this.$store.commit('auth/setUserName', this.name)
this.success({message: 'The name was successfully changed.'}, this)
})
.catch(e => this.error(e, this))
},
buildCaldavUrl() {
const apiBase = window.API_URL.replace('/api/v1', '')
this.caldavUrl = `${apiBase}/dav/principals/${this.userInfo.username}/`