2019-07-25 12:37:50 +02:00
|
|
|
<template lang="pug">
|
2020-07-25 21:41:22 +02:00
|
|
|
v-container
|
2019-07-25 12:37:50 +02:00
|
|
|
|
2020-07-25 21:41:22 +02:00
|
|
|
//- ADD NEW USER
|
|
|
|
|
v-dialog(v-model='newUser' width='500')
|
|
|
|
|
template(v-slot:activator="{ on }")
|
|
|
|
|
v-btn(text v-on='on') <v-icon>mdi-plus</v-icon> {{$t('common.new_user')}}
|
|
|
|
|
|
|
|
|
|
v-card
|
|
|
|
|
v-card-title <v-icon name='plus'/> {{$t('common.new_user')}}
|
|
|
|
|
v-card-text
|
|
|
|
|
v-form(inline @submit.native.prevent='create_user')
|
|
|
|
|
v-text-field(v-model='new_user.email'
|
|
|
|
|
:label="$t('common.email')")
|
|
|
|
|
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
|
|
|
|
|
v-btn(@click='create_user' color='success' plain) {{$t('common.send')}}
|
|
|
|
|
|
|
|
|
|
//- USERS LIST
|
|
|
|
|
v-data-table(
|
|
|
|
|
:headers='headers'
|
|
|
|
|
:items='users')
|
|
|
|
|
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='danger') {{$t('admin.delete_user')}}
|
|
|
|
|
|
|
|
|
|
//- el-table-column(label='Email' width='220')
|
|
|
|
|
//- template(slot-scope='data')
|
|
|
|
|
//- el-popover(trigger='hover' :content='data.row.description' width='400')
|
|
|
|
|
//- span(slot='reference') {{data.row.email}}
|
|
|
|
|
//- el-table-column(:label="$t('common.actions')")
|
|
|
|
|
//- template(slot-scope='data')
|
|
|
|
|
//- div(v-if='data.row.id!==$auth.user.id')
|
|
|
|
|
//- el-button-group
|
|
|
|
|
//- el-button(size='mini'
|
|
|
|
|
//- :type='data.row.is_active?"warning":"success"'
|
|
|
|
|
//- @click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
|
|
|
|
|
//- el-button(size='mini'
|
|
|
|
|
//- :type='data.row.is_admin?"danger":"warning"'
|
|
|
|
|
//- @click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
|
|
|
|
|
//- el-button(size='mini'
|
|
|
|
|
//- type='danger'
|
|
|
|
|
//- @click='delete_user(data.row)') {{$t('admin.delete_user')}}
|
|
|
|
|
//- div(v-else)
|
|
|
|
|
//- span {{$t('common.me')}}
|
|
|
|
|
//- v-pagination(:page-size='perPage' :currentPage.sync='userPage' v-if='perPage<users_.length' :total='users_.length')
|
2019-07-27 21:58:55 +02:00
|
|
|
|
2019-07-25 12:37:50 +02:00
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import { Message, MessageBox } from 'element-ui'
|
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 {
|
|
|
|
|
new_user: {
|
|
|
|
|
email: '',
|
2019-09-11 19:12:24 +02:00
|
|
|
is_admin: false
|
2019-07-25 12:37:50 +02:00
|
|
|
},
|
2020-07-25 21:41:22 +02:00
|
|
|
headers: [
|
|
|
|
|
{ value: 'email', text: 'Email' },
|
|
|
|
|
{ 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-07-25 21:41:22 +02:00
|
|
|
deleteUser (user) {
|
2019-07-25 12:37:50 +02:00
|
|
|
MessageBox.confirm(this.$t('admin.delete_user_confirm'),
|
|
|
|
|
this.$t('common.confirm'), {
|
|
|
|
|
confirmButtonText: this.$t('common.ok'),
|
|
|
|
|
cancelButtonText: this.$t('common.cancel'),
|
|
|
|
|
type: 'error'
|
|
|
|
|
})
|
2019-09-11 19:12:24 +02:00
|
|
|
.then(() => this.$axios.delete(`/user/${user.id}`))
|
|
|
|
|
.then(() => {
|
2019-07-25 12:37:50 +02:00
|
|
|
Message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: this.$t('admin.user_remove_ok')
|
|
|
|
|
})
|
2019-09-11 19:12:24 +02:00
|
|
|
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
|
|
|
console.error(e)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async create_user () {
|
|
|
|
|
try {
|
|
|
|
|
this.loading = true
|
|
|
|
|
const user = await this.$axios.$post('/user', this.new_user)
|
|
|
|
|
this.new_user = { email: '', is_admin: false }
|
|
|
|
|
Message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: this.$t('admin.user_create_ok')
|
|
|
|
|
})
|
|
|
|
|
this.users_.push(user)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Message({
|
|
|
|
|
showClose: true,
|
|
|
|
|
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>
|