2019-07-25 12:37:50 +02:00
|
|
|
<template lang="pug">
|
2020-08-05 17:30:41 +02:00
|
|
|
v-container
|
2020-07-28 12:24:39 +02:00
|
|
|
v-card-title {{$t('common.users')}}
|
|
|
|
v-spacer
|
|
|
|
v-text-field(v-model='search'
|
|
|
|
append-icon='mdi-magnify'
|
|
|
|
label='Search',
|
|
|
|
single-line hide-details)
|
2020-08-05 17:30:41 +02:00
|
|
|
v-btn(text color='primary' small @click='newUserDialog = true') <v-icon>mdi-plus-user</v-icon> {{$t('common.new_user')}}
|
2019-07-25 12:37:50 +02:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
//- ADD NEW USER
|
2020-07-28 12:24:39 +02:00
|
|
|
v-dialog(v-model='newUserDialog' width='500')
|
2020-07-25 21:41:22 +02:00
|
|
|
|
|
|
|
v-card
|
2020-07-28 12:24:39 +02:00
|
|
|
v-card-title {{$t('common.new_user')}}
|
2020-07-25 21:41:22 +02:00
|
|
|
v-card-text
|
2020-07-28 12:24:39 +02:00
|
|
|
v-form
|
2020-07-25 21:41:22 +02:00
|
|
|
v-text-field(v-model='new_user.email'
|
2020-07-28 12:24:39 +02:00
|
|
|
:label="$t('common.email')"
|
2020-09-05 01:21:47 +02:00
|
|
|
:rules="[$validators.required('email')]")
|
2020-07-25 21:41:22 +02:00
|
|
|
v-switch(v-model='new_user.is_admin' :label="$t('common.admin')" inset)
|
|
|
|
v-alert(type='info' :closable='false') {{$t('admin.user_add_help')}}
|
|
|
|
v-card-actions
|
2020-08-05 17:30:41 +02:00
|
|
|
v-spacer
|
|
|
|
v-btn(@click='newUserDialog=false' color='error') {{$t('common.cancel')}}
|
2020-07-28 12:24:39 +02:00
|
|
|
v-btn(@click='createUser' color='primary') {{$t('common.send')}}
|
2020-07-25 21:41:22 +02:00
|
|
|
|
2020-08-05 17:30:41 +02:00
|
|
|
v-card-text
|
|
|
|
//- USERS LIST
|
|
|
|
v-data-table(
|
|
|
|
:headers='headers'
|
|
|
|
:items='users'
|
|
|
|
:search='search')
|
|
|
|
template(v-slot:item.actions='{item}')
|
|
|
|
v-btn(text small @click='toggle(item)'
|
|
|
|
:color='item.is_active?"warning":"success"') {{item.is_active?$t('common.deactivate'):$t('common.activate')}}
|
|
|
|
v-btn(text small @click='toggleAdmin(item)'
|
|
|
|
:color='item.is_admin?"warning":"error"') {{item.is_admin?$t('common.remove_admin'):$t('common.admin')}}
|
|
|
|
v-btn(text small @click='deleteUser(item)'
|
|
|
|
color='error') {{$t('admin.delete_user')}}
|
2019-07-27 21:58:55 +02:00
|
|
|
|
2019-07-25 12:37:50 +02:00
|
|
|
</template>
|
|
|
|
<script>
|
2019-11-09 15:04:37 +01:00
|
|
|
import { mapState } from 'vuex'
|
2019-07-25 12:37:50 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Users',
|
2020-07-25 21:41:22 +02:00
|
|
|
props: {
|
|
|
|
users: { type: Array, default: () => [] }
|
|
|
|
},
|
2019-07-25 12:37:50 +02:00
|
|
|
data () {
|
|
|
|
return {
|
2020-07-28 12:24:39 +02:00
|
|
|
newUserDialog: false,
|
2019-07-25 12:37:50 +02:00
|
|
|
new_user: {
|
|
|
|
email: '',
|
2019-09-11 19:12:24 +02:00
|
|
|
is_admin: false
|
2019-07-25 12:37:50 +02:00
|
|
|
},
|
2020-07-28 12:24:39 +02:00
|
|
|
search: '',
|
2020-07-25 21:41:22 +02:00
|
|
|
headers: [
|
|
|
|
{ value: 'email', text: 'Email' },
|
2020-07-28 12:24:39 +02:00
|
|
|
{ value: 'is_active', text: 'Active' },
|
2020-07-25 21:41:22 +02:00
|
|
|
{ value: 'actions', text: 'Actions', align: 'right' }
|
|
|
|
]
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
2019-07-25 12:37:50 +02:00
|
|
|
},
|
2020-07-25 21:41:22 +02:00
|
|
|
computed: mapState(['settings']),
|
2019-07-25 12:37:50 +02:00
|
|
|
methods: {
|
2020-08-05 17:30:41 +02:00
|
|
|
async deleteUser (user) {
|
|
|
|
const ret = await this.$root.$confirm(this.$t('common.confirm'),
|
|
|
|
this.$t('admin.delete_user_confirm'),
|
|
|
|
{ type: 'error' })
|
|
|
|
if (!ret) { return }
|
|
|
|
await this.$axios.delete(`/user/${user.id}`)
|
|
|
|
this.$root.$message({ message: this.$t('admin.user_remove_ok') })
|
|
|
|
this.users_ = this.users_.filter(u => u.id !== user.id)
|
2019-07-25 12:37:50 +02:00
|
|
|
},
|
2020-01-15 23:40:16 +01:00
|
|
|
toggle (user) {
|
2019-07-25 12:37:50 +02:00
|
|
|
user.is_active = !user.is_active
|
|
|
|
this.$axios.$put('/user', user)
|
|
|
|
},
|
2019-09-11 19:12:24 +02:00
|
|
|
async toggleAdmin (user) {
|
2019-07-25 12:37:50 +02:00
|
|
|
try {
|
|
|
|
user.is_admin = !user.is_admin
|
|
|
|
await this.$axios.$put('/user', user)
|
2019-09-11 19:12:24 +02:00
|
|
|
} catch (e) {
|
2019-07-25 12:37:50 +02:00
|
|
|
}
|
|
|
|
},
|
2020-07-28 12:24:39 +02:00
|
|
|
async createUser () {
|
2019-07-25 12:37:50 +02:00
|
|
|
try {
|
|
|
|
this.loading = true
|
|
|
|
const user = await this.$axios.$post('/user', this.new_user)
|
|
|
|
this.new_user = { email: '', is_admin: false }
|
2020-07-28 12:24:39 +02:00
|
|
|
|
2020-08-05 17:30:41 +02:00
|
|
|
this.$root.$message({
|
2019-07-25 12:37:50 +02:00
|
|
|
type: 'success',
|
|
|
|
message: this.$t('admin.user_create_ok')
|
|
|
|
})
|
|
|
|
this.users_.push(user)
|
|
|
|
} catch (e) {
|
2020-08-05 17:30:41 +02:00
|
|
|
this.$root.$message({
|
2019-07-25 12:37:50 +02:00
|
|
|
type: 'error',
|
2019-09-06 11:55:38 +02:00
|
|
|
message: this.$t(e)
|
2019-07-25 12:37:50 +02:00
|
|
|
})
|
|
|
|
}
|
2019-09-11 19:12:24 +02:00
|
|
|
}
|
2019-07-25 12:37:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|