admin-fe/src/views/users/index.vue

322 lines
10 KiB
Vue
Raw Normal View History

2019-02-22 18:06:48 +00:00
<template>
<div class="users-container">
2019-05-05 21:51:52 +00:00
<h1>
{{ $t('users.users') }}
<span class="user-count">({{ normalizedUsersCount }})</span>
</h1>
2019-03-06 19:52:18 +00:00
<div class="search-container">
2019-03-29 14:25:53 +00:00
<users-filter/>
2019-05-21 19:24:48 +00:00
<el-input :placeholder="$t('users.search')" v-model="search" class="search" @input="handleDebounceSearchInput"/>
2019-03-06 19:44:37 +00:00
</div>
2019-05-26 18:39:26 +00:00
<dropdown-actions-menu
:selected-users="selectedUsers"
@apply-action="clearSelection"/>
<el-table
v-loading="loading"
ref="usersTable"
:data="users"
row-key="id"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
v-if="isDesktop"
type="selection"
reserve-selection
width="44"
align="center"/>
2019-03-22 21:27:31 +00:00
<el-table-column :min-width="width" :label="$t('users.id')" prop="id" />
<el-table-column :label="$t('users.name')" prop="nickname">
2019-03-22 21:18:57 +00:00
<template slot-scope="scope">
{{ scope.row.nickname }}
<el-tag v-if="isDesktop" type="info" size="mini">
2019-03-22 21:27:31 +00:00
<span>{{ scope.row.local ? $t('users.local') : $t('users.external') }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
</template>
</el-table-column>
2019-03-22 21:27:31 +00:00
<el-table-column :min-width="width" :label="$t('users.status')">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-03-06 19:52:18 +00:00
<el-tag :type="scope.row.deactivated ? 'danger' : 'success'">
2019-03-22 21:27:31 +00:00
<span v-if="isDesktop">{{ scope.row.deactivated ? $t('users.deactivated') : $t('users.active') }}</span>
2019-03-06 19:52:18 +00:00
<i v-else :class="activationIcon(scope.row.deactivated)"/>
</el-tag>
2019-03-22 21:18:57 +00:00
<el-tag v-if="scope.row.roles.admin">
2019-03-22 21:27:31 +00:00
<span>{{ isDesktop ? $t('users.admin') : getFirstLetter($t('users.admin')) }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
<el-tag v-if="scope.row.roles.moderator">
2019-03-22 21:27:31 +00:00
<span>{{ isDesktop ? $t('users.moderator') : getFirstLetter($t('users.moderator')) }}</span>
2019-03-22 21:18:57 +00:00
</el-tag>
2019-02-26 19:50:25 +00:00
</template>
</el-table-column>
2019-03-22 21:27:31 +00:00
<el-table-column :label="$t('users.actions')" fixed="right">
2019-02-26 19:50:25 +00:00
<template slot-scope="scope">
2019-05-06 15:49:03 +00:00
<el-dropdown size="small" trigger="click">
2019-03-22 21:18:57 +00:00
<span class="el-dropdown-link">
2019-03-22 21:27:31 +00:00
{{ $t('users.moderation') }}
2019-03-22 21:18:57 +00:00
<i v-if="isDesktop" class="el-icon-arrow-down el-icon--right"/>
</span>
<el-dropdown-menu slot="dropdown">
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showAdminAction(scope.row)"
@click.native="toggleUserRight(scope.row, 'admin')">
2019-03-22 21:27:31 +00:00
{{ scope.row.roles.admin ? $t('users.revokeAdmin') : $t('users.grantAdmin') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showAdminAction(scope.row)"
@click.native="toggleUserRight(scope.row, 'moderator')">
2019-03-22 21:27:31 +00:00
{{ scope.row.roles.moderator ? $t('users.revokeModerator') : $t('users.grantModerator') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showDeactivatedButton(scope.row.id)"
:divided="showAdminAction(scope.row)"
@click.native="handleDeactivation(scope.row)">
2019-03-22 21:27:31 +00:00
{{ scope.row.deactivated ? $t('users.activateAccount') : $t('users.deactivateAccount') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="showDeactivatedButton(scope.row.id)"
@click.native="handleDeletion(scope.row)">
2019-03-22 21:27:31 +00:00
{{ $t('users.deleteAccount') }}
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:divided="showAdminAction(scope.row)"
:class="{ 'active-tag': scope.row.tags.includes('force_nsfw') }"
@click.native="toggleTag(scope.row, 'force_nsfw')">
2019-03-22 21:27:31 +00:00
{{ $t('users.forceNsfw') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('force_nsfw')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('strip_media') }"
@click.native="toggleTag(scope.row, 'strip_media')">
2019-03-22 21:27:31 +00:00
{{ $t('users.stripMedia') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('strip_media')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('force_unlisted') }"
@click.native="toggleTag(scope.row, 'force_unlisted')">
2019-03-22 21:27:31 +00:00
{{ $t('users.forceUnlisted') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('force_unlisted')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
:class="{ 'active-tag': scope.row.tags.includes('sandbox') }"
@click.native="toggleTag(scope.row, 'sandbox')">
2019-03-22 21:27:31 +00:00
{{ $t('users.sandbox') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('sandbox')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="scope.row.local"
:class="{ 'active-tag': scope.row.tags.includes('disable_remote_subscription') }"
@click.native="toggleTag(scope.row, 'disable_remote_subscription')">
2019-03-22 21:27:31 +00:00
{{ $t('users.disableRemoteSubscription') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('disable_remote_subscription')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
2019-03-29 14:25:53 +00:00
<el-dropdown-item
v-if="scope.row.local"
:class="{ 'active-tag': scope.row.tags.includes('disable_any_subscription') }"
@click.native="toggleTag(scope.row, 'disable_any_subscription')">
2019-03-22 21:27:31 +00:00
{{ $t('users.disableAnySubscription') }}
2019-03-29 14:25:53 +00:00
<i v-if="scope.row.tags.includes('disable_any_subscription')" class="el-icon-check"/>
2019-03-22 21:18:57 +00:00
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
2019-02-24 22:31:05 +00:00
</template>
</el-table-column>
</el-table>
<div v-if="users.length === 0" class="no-users-message">
<p>There are no users to display</p>
</div>
2019-02-27 22:13:20 +00:00
<div v-if="!loading" class="pagination">
<el-pagination
:total="usersCount"
2019-03-03 20:46:14 +00:00
:current-page="currentPage"
:page-size="pageSize"
2019-02-27 22:13:20 +00:00
background
layout="prev, pager, next"
2019-03-01 17:32:03 +00:00
@current-change="handlePageChange"
/>
2019-02-27 22:13:20 +00:00
</div>
2019-02-22 18:06:48 +00:00
</div>
</template>
<script>
2019-03-01 17:32:03 +00:00
import debounce from 'lodash.debounce'
2019-05-05 21:51:52 +00:00
import numeral from 'numeral'
2019-03-29 14:25:53 +00:00
import UsersFilter from './components/UsersFilter'
2019-05-26 18:39:26 +00:00
import DropdownActionsMenu from './components/DropdownActionsMenu'
2019-02-23 21:40:26 +00:00
2019-02-22 18:06:48 +00:00
export default {
name: 'Users',
2019-03-29 14:25:53 +00:00
components: {
UsersFilter,
2019-05-26 18:39:26 +00:00
DropdownActionsMenu
},
data: function() {
return {
selectedUsers: []
}
2019-03-29 14:25:53 +00:00
},
2019-05-21 19:24:48 +00:00
data() {
return {
search: ''
}
},
data() {
return {
search: ''
}
},
2019-02-24 22:31:05 +00:00
computed: {
loading() {
return this.$store.state.users.loading
},
2019-05-05 21:51:52 +00:00
normalizedUsersCount() {
return numeral(this.$store.state.users.totalUsersCount).format('0a')
},
2019-02-24 22:31:05 +00:00
users() {
return this.$store.state.users.fetchedUsers
2019-02-27 22:13:20 +00:00
},
usersCount() {
return this.$store.state.users.totalUsersCount
},
pageSize() {
return this.$store.state.users.pageSize
2019-03-03 20:46:14 +00:00
},
currentPage() {
return this.$store.state.users.currentPage
2019-03-06 19:44:37 +00:00
},
2019-03-06 19:52:18 +00:00
isDesktop() {
return this.$store.state.app.device === 'desktop'
},
isMobile() {
return this.$store.state.app.device === 'mobile'
},
width() {
2019-03-22 21:18:57 +00:00
return this.isMobile ? 55 : false
2019-02-22 18:06:48 +00:00
}
2019-02-23 21:40:26 +00:00
},
2019-03-01 17:32:03 +00:00
created() {
this.handleDebounceSearchInput = debounce((query) => {
this.$store.dispatch('SearchUsers', { query, page: 1 })
2019-03-01 17:32:03 +00:00
}, 500)
},
2019-02-23 21:40:26 +00:00
mounted: function() {
this.$store.dispatch('FetchUsers', { page: 1 })
2019-02-24 22:31:05 +00:00
},
methods: {
activationIcon(status) {
return status ? 'el-icon-error' : 'el-icon-success'
},
clearSelection() {
this.$refs.usersTable.clearSelection()
},
getFirstLetter(str) {
return str.charAt(0).toUpperCase()
},
2019-03-22 21:18:57 +00:00
handleDeactivation({ nickname }) {
2019-02-26 19:50:25 +00:00
this.$store.dispatch('ToggleUserActivation', nickname)
2019-02-27 22:13:20 +00:00
},
handleDeletion(user) {
this.$store.dispatch('DeleteUser', user)
},
2019-02-27 22:13:20 +00:00
handlePageChange(page) {
2019-03-03 20:01:00 +00:00
const searchQuery = this.$store.state.users.searchQuery
if (searchQuery === '') {
this.$store.dispatch('FetchUsers', { page })
2019-03-03 20:01:00 +00:00
} else {
this.$store.dispatch('SearchUsers', { query: searchQuery, page })
2019-03-03 20:01:00 +00:00
}
},
handleSelectionChange(value) {
this.$data.selectedUsers = value
},
2019-03-22 21:18:57 +00:00
showAdminAction({ local, id }) {
return local && this.showDeactivatedButton(id)
},
showDeactivatedButton(id) {
return this.$store.state.user.id !== id
2019-03-22 21:18:57 +00:00
},
toggleTag(user, tag) {
user.tags.includes(tag)
? this.$store.dispatch('RemoveTag', { users: [user], tag })
: this.$store.dispatch('AddTag', { users: [user], tag })
2019-03-22 21:27:31 +00:00
},
toggleUserRight(user, right) {
this.$store.dispatch('ToggleRight', { user, right })
2019-02-24 22:31:05 +00:00
}
2019-02-22 18:06:48 +00:00
}
}
</script>
2019-03-01 17:32:03 +00:00
<style rel='stylesheet/scss' lang='scss' scoped>
2019-03-29 14:25:53 +00:00
.active-tag {
color: #409EFF;
font-weight: 700;
.el-icon-check {
color: #409EFF;
float: right;
margin: 7px 0 0 15px;
}
}
2019-05-06 15:49:03 +00:00
.el-dropdown-link:hover {
cursor: pointer;
color: #409EFF;
}
2019-02-24 22:31:05 +00:00
.users-container {
h1 {
2019-03-29 14:25:53 +00:00
margin: 22px 0 0 15px;
2019-02-24 22:31:05 +00:00
}
2019-02-27 22:13:20 +00:00
.pagination {
2019-03-03 20:01:00 +00:00
margin: 25px 0;
2019-02-27 22:13:20 +00:00
text-align: center;
}
2019-02-24 22:31:05 +00:00
2019-03-01 17:32:03 +00:00
.search {
2019-03-29 14:25:53 +00:00
width: 350px;
2019-03-01 17:32:03 +00:00
float: right;
}
2019-03-06 19:52:18 +00:00
.search-container {
2019-03-06 19:44:37 +00:00
display: flex;
2019-03-29 14:25:53 +00:00
height: 36px;
2019-03-06 19:44:37 +00:00
justify-content: space-between;
2019-03-29 14:25:53 +00:00
align-items: center;
2019-05-26 18:39:26 +00:00
margin: 22px 15px 15px 15px
2019-03-06 19:44:37 +00:00
}
2019-05-05 21:51:52 +00:00
.user-count {
color: gray;
font-size: 28px;
2019-03-06 19:44:37 +00:00
}
2019-03-01 17:32:03 +00:00
}
2019-03-06 19:52:18 +00:00
@media
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px) {
.users-container {
h1 {
2019-03-29 14:25:53 +00:00
margin: 7px 10px 7px 10px;
2019-03-06 19:52:18 +00:00
}
2019-03-22 21:18:57 +00:00
.el-icon-arrow-down {
font-size: 12px;
}
2019-03-06 19:52:18 +00:00
.search {
2019-03-29 14:25:53 +00:00
width: 100%;
2019-03-06 19:52:18 +00:00
}
.search-container {
display: flex;
2019-03-29 14:25:53 +00:00
height: 82px;
flex-direction: column;
margin: 0 10px 7px 10px
2019-03-06 19:52:18 +00:00
}
2019-03-22 21:18:57 +00:00
.el-tag {
width: 30px;
display: inline-block;
margin-bottom: 4px;
font-weight: bold;
&.el-tag--success {
padding-left: 8px;
}
&.el-tag--danger {
padding-left: 8px;
}
}
2019-03-06 19:52:18 +00:00
}
}
2019-02-24 22:31:05 +00:00
</style>