feat(webui): display latest user connection in settings

This commit is contained in:
Gauthier Roebroeck 2021-06-28 14:11:05 +08:00
parent b118959775
commit 58478c21ff
3 changed files with 52 additions and 14 deletions

View file

@ -2,6 +2,7 @@
<div style="position: relative">
<v-list
elevation="3"
two-line
>
<div v-for="(u, index) in users" :key="index">
<v-list-item
@ -22,6 +23,18 @@
<v-list-item-title>
{{ u.email }}
</v-list-item-title>
<v-list-item-subtitle v-if="usersLastActivity[u.id] !== undefined">
{{
$t('settings_user.latest_activity', {
date:
new Intl.DateTimeFormat($i18n.locale, {
dateStyle: 'medium',
timeStyle: 'short'
}).format(new Date(usersLastActivity[u.id]))
})
}}
</v-list-item-subtitle>
<v-list-item-subtitle v-else>{{ $t('settings_user.no_recent_activity') }}</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
@ -122,6 +135,7 @@ export default Vue.extend({
userToEdit: {} as UserDto,
modalChangePassword: false,
userToChangePassword: {} as UserDto,
usersLastActivity: {} as any,
}),
computed: {
users(): UserWithSharedLibrariesDto[] {
@ -131,6 +145,16 @@ export default Vue.extend({
return this.$store.state.komgaUsers.me
},
},
watch: {
users(val) {
val.forEach((u: UserDto) => {
this.$komgaUsers.getLatestAuthenticationActivityForUser(u)
.then(value => this.$set(this.usersLastActivity, `${u.id}`, value.dateTime))
.catch(e => {
})
})
},
},
async mounted() {
await this.$store.dispatch('getAllUsers')
},

View file

@ -4,8 +4,8 @@
"pageText": "{0}-{1} of {2}"
},
"dataIterator": {
"noResultsText": "No matching records found",
"loadingText": "Loading items..."
"loadingText": "Loading items...",
"noResultsText": "No matching records found"
},
"dataTable": {
"itemsPerPageText": "Rows per page:",
@ -21,6 +21,14 @@
"account_settings": "Account Settings",
"change_password": "change password"
},
"authentication_activity": {
"datetime": "Date Time",
"email": "Email",
"error": "Error",
"ip": "Ip",
"success": "Success",
"user_agent": "User Agent"
},
"author_roles": {
"colorist": "colorists",
"cover": "cover",
@ -183,6 +191,7 @@
"pages": "pages",
"pages_n": "No pages | 1 page | {count} pages",
"password": "Password",
"pending_tasks": "No pending tasks | 1 pending task | {count} pending tasks",
"publisher": "Publisher",
"read": "Read",
"readlists": "Read Lists",
@ -192,8 +201,7 @@
"series": "Series",
"tags": "Tags",
"use_filter_panel_to_change_filter": "Use the filter panel to change the active filter",
"year": "year",
"pending_tasks": "No pending tasks | 1 pending task | {count} pending tasks"
"year": "year"
},
"dashboard": {
"keep_reading": "Keep Reading",
@ -583,6 +591,8 @@
"change_password": "Change password",
"edit_shared_libraries": "Edit shared libraries",
"edit_user": "Edit user",
"latest_activity": "Latest activity: {date}",
"no_recent_activity": "No recent activity",
"role_administrator": "Administrator",
"role_user": "User"
},
@ -609,20 +619,12 @@
"USER": "User"
},
"users": {
"users": "Users",
"authentication_activity": "Authentication Activity"
"authentication_activity": "Authentication Activity",
"users": "Users"
},
"welcome": {
"add_library": "Add library",
"no_libraries_yet": "No libraries have been added yet!",
"welcome_message": "Welcome to Komga"
},
"authentication_activity": {
"ip": "Ip",
"user_agent": "User Agent",
"email": "Email",
"success": "Success",
"error": "Error",
"datetime": "Date Time"
}
}

View file

@ -161,4 +161,16 @@ export default class KomgaUsersService {
throw new Error(msg)
}
}
async getLatestAuthenticationActivityForUser(user: UserDto): Promise<AuthenticationActivityDto> {
try {
return (await this.http.get(`${API_USERS}/${user.id}/authentication-activity/latest`)).data
} catch (e) {
let msg = `An error occurred while trying to retrieve latest authentication activity for user ${user.email}`
if (e.response.data.message) {
msg += `: ${e.response.data.message}`
}
throw new Error(msg)
}
}
}