93 lines
2.3 KiB
Vue
93 lines
2.3 KiB
Vue
<template lang="pug">
|
|
#userlist
|
|
h3 Registered Users ({{ pagination.total }})
|
|
pagination(:page="pagination.page" :pages="pagination.pages" v-on:page="getUsers")
|
|
.list.users
|
|
.searchbox
|
|
input(v-model="search" placeholder="Begin typing a name or email address..")
|
|
.message.error(v-if="error") {{ error }}
|
|
user(v-else v-for='user in users' v-bind="user" :key="user.id")
|
|
ban-modal(:show='banning' @close='banning = 0' :id='banning')
|
|
user-modal(:show='editing' @close='editing = 0' :id='editing')
|
|
</template>
|
|
|
|
<script>
|
|
import Pagination from './Pagination.vue'
|
|
import User from './User.vue'
|
|
import BanModal from './BanModal.vue'
|
|
import UserModal from './UserModal.vue'
|
|
|
|
import qs from 'querystring'
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').content
|
|
|
|
export default {
|
|
data: function () {
|
|
return {
|
|
pagination: {
|
|
offset: 0,
|
|
page: 1,
|
|
pages: 1,
|
|
perPage: 6,
|
|
total: 0
|
|
},
|
|
users: [],
|
|
banning: 0,
|
|
editing: 0,
|
|
search: '',
|
|
error: ''
|
|
}
|
|
},
|
|
components: {
|
|
Pagination, User, BanModal, UserModal
|
|
},
|
|
methods: {
|
|
getUsers: function (page) {
|
|
this.error = ''
|
|
this.$http.get('/admin/api/users?page=' + page).then(data => {
|
|
if (data.body && data.body.error) return
|
|
this.pagination = data.body.page
|
|
this.users = data.body.users
|
|
})
|
|
},
|
|
searchUsers: function () {
|
|
this.error = ''
|
|
this.$http.get('/admin/api/search/users?' + qs.stringify({
|
|
terms: this.search,
|
|
scopes: 'email,username,display_name'
|
|
})).then(data => {
|
|
if (data.body.error) {
|
|
this.error = data.body.error
|
|
return
|
|
}
|
|
|
|
this.users = data.body
|
|
})
|
|
}
|
|
},
|
|
watch: {
|
|
search: function () {
|
|
if (this.search === '') {
|
|
this.getUsers(1)
|
|
} else {
|
|
this.searchUsers(this.search)
|
|
}
|
|
}
|
|
},
|
|
mounted: function () {
|
|
this.getUsers(1)
|
|
|
|
this.$on('ban', function (id) {
|
|
this.banning = id
|
|
})
|
|
|
|
this.$on('edit', function (id) {
|
|
this.editing = id
|
|
})
|
|
|
|
this.$root.$on('reload_users', () => {
|
|
this.getUsers(this.pagination.page)
|
|
})
|
|
}
|
|
}
|
|
</script>
|