forked from kaverti/website
173 lines
5.6 KiB
Vue
173 lines
5.6 KiB
Vue
<style>
|
|
.limit{
|
|
margin-top: 0.5rem;
|
|
word-break: break-all;
|
|
}
|
|
</style>
|
|
<template>
|
|
<main>
|
|
<br>
|
|
<div class="container">
|
|
<div class="">
|
|
<div class="box is-half" style="border-width: 5px;" v-for='user in users' :key='"user-row" + user.username' v-show="user && !user.hidden">
|
|
<header class="card-header">
|
|
<figure class="image is-48x48">
|
|
<avatar-icon :user="user"/>
|
|
</figure>
|
|
<p class="card-header-title">
|
|
<router-link :to='"/user/" + user.username' style="color: #000000;">{{user.username + ' '}}</router-link>
|
|
|
|
<tooltips style="padding-left: 5px;">
|
|
<b-tooltip v-if='user && user.system' class="is-success" label="This user is a system user operated by administrators that mainly run API operations.">
|
|
<b-tag rounded class="is-success"> SYSTEM <i class="fas fa-info-circle"></i></b-tag>
|
|
</b-tooltip>
|
|
|
|
<b-tooltip v-if='user && user.bot' class="is-info" label="This user is a bot account that can run automated API operations.">
|
|
<b-tag rounded class="is-info"> BOT <i class="fas fa-info-circle"></i></b-tag>
|
|
</b-tooltip>
|
|
|
|
<b-tooltip v-if='user && user.admin' class="is-danger" label="User is an official Kaverti administrator.">
|
|
<b-tag class="is-danger" rounded> ADMIN <i class="fas fa-info-circle"></i></b-tag>
|
|
</b-tooltip>
|
|
|
|
<b-tooltip v-if='user && user.hidden' class="is-info" label="User is not discoverable in the user list.">
|
|
<b-tag rounded> HIDDEN <i class="fas fa-info-circle"></i></b-tag>
|
|
</b-tooltip>
|
|
|
|
<b-tooltip v-if='user && user.booster' class="is-light" label="User is boosting the Kaverti Discord server.">
|
|
<b-tag class="is-light" rounded> BOOSTER <i class="fas fa-info-circle"></i></b-tag>
|
|
</b-tooltip>
|
|
|
|
</tooltips>
|
|
</p>
|
|
</header>
|
|
<div class="card-content">
|
|
<div class="content limit" v-if="user.description">
|
|
{{user.description | truncate(200)}}
|
|
</div>
|
|
<div class="content" v-if="!user.description">
|
|
No description set.
|
|
</div>
|
|
<div class="content">
|
|
Post count: {{user.postCount}}<br>
|
|
<time v-bind:datetime="user.createdAt">Created at {{user.createdAt | formatDate}}</time>
|
|
</div>
|
|
</div>
|
|
<footer class="card-footer">
|
|
<router-link :to='"/user/" + user.username' class="card-footer-item">View Profile</router-link>
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<p name='fade' mode='out-in'>
|
|
<center><loading-message key='loading' v-if='loading'></loading-message></center>
|
|
<center><div class='overlay_message' v-if='!loading && !users.length'>
|
|
Something went wrong while loading the users, check your internet connection, or check the <a href="https://status.troplo.com">Service Status</a>
|
|
</div></center></p>
|
|
</main>
|
|
</template>
|
|
<script>
|
|
import LoadingMessage from '../LoadingMessage';
|
|
import AvatarIcon from '../AvatarIcon';
|
|
import throttle from 'lodash.throttle';
|
|
import AjaxErrorHandler from '../../assets/js/errorHandler';
|
|
|
|
export default {
|
|
name: 'UserList',
|
|
components: {
|
|
LoadingMessage,
|
|
AvatarIcon
|
|
},
|
|
data () {
|
|
return {
|
|
search: '',
|
|
users: [],
|
|
|
|
loading: true,
|
|
offset: 0,
|
|
limit: 15,
|
|
|
|
roleOptions: [
|
|
{ name: 'Admins', value: 'admin' },
|
|
{ name: 'Users', value: 'user' }
|
|
],
|
|
roleSelected: ['admin', 'user'],
|
|
|
|
tableSort: {
|
|
column: 'username',
|
|
sort: 'desc'
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
fetchData () {
|
|
if(this.offset === null) return;
|
|
|
|
let url = `/api/v1/user?
|
|
sort=${this.tableSort.column}
|
|
&order=${this.tableSort.sort}
|
|
&offset=${this.offset}
|
|
`;
|
|
if(this.roleSelected.length === 1) {
|
|
url += '&role=' + this.roleSelected[0];
|
|
}
|
|
if(this.search.length) {
|
|
url += '&search=' + encodeURIComponent(this.search.trim());
|
|
}
|
|
|
|
this.loading = true;
|
|
this.axios
|
|
.get(url)
|
|
.then(res => {
|
|
this.users.push(...res.data);
|
|
this.loading = /*loading =*/ false;
|
|
|
|
//If returned data is less than the limit
|
|
//then there must be no more pages to paginate
|
|
if(res.data.length < this.limit) {
|
|
this.offset = null;
|
|
} else {
|
|
this.offset+= this.limit;
|
|
}
|
|
})
|
|
.catch(e => {
|
|
AjaxErrorHandler(this.$store)(e);
|
|
this.loading = /*loading =*/ false;
|
|
});
|
|
},
|
|
resetFetchData () {
|
|
this.offset = 0;
|
|
this.users = [];
|
|
|
|
this.fetchData();
|
|
}
|
|
},
|
|
getNewerUsers () {
|
|
this.loadingNewer = true
|
|
|
|
this.axios
|
|
.get('/api/v1/users' + '?limit=' + this.newUsers)
|
|
.then(res => {
|
|
this.loadingNewer = false
|
|
this.newUsers = 0
|
|
|
|
this.threads.unshift(...res.data.Threads)
|
|
})
|
|
.catch((e) => {
|
|
this.loadingNewer = false
|
|
AjaxErrorHandler(this.$store)(e)
|
|
})
|
|
},
|
|
mounted () {
|
|
this.fetchData();
|
|
},
|
|
watch: {
|
|
tableSort: 'resetFetchData',
|
|
roleSelected: 'resetFetchData',
|
|
search: throttle(function () {
|
|
this.resetFetchData();
|
|
}, 200)
|
|
}
|
|
}
|
|
</script>
|