cubash-archive/frontend/src/components/routes/AdminMarketplace.vue

263 lines
7.2 KiB
Vue

<style>
.team-img {
border-radius: 50%;
}
.vertical-alt {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.limit{
margin-top: 0.5rem;
word-break: break-all;
}
</style>
<template>
<main>
<modal-window v-model='banModal' style='z-index: 100' width='25rem' :no-padding='true' :is-error="true">
<div slot="header">
Deleting {{selectedTeam}}
</div>
<div slot='main' class="card-content">
<p style='margin: 1rem;'>You are deleting this item, are you sure you want to?</p>
</div>
<button
slot='footer'
class='button is-danger'
style='z-index: 100; width: 50%;'
@click='teamBan(selectedTeam)'
ref='ajaxErrorsModalButton'
>
Delete
</button>
<button
slot='footer'
class='button is-info'
style='z-index: 100; width: 20%; float: right;'
@click='banModal = false'
ref='ajaxErrorsModalButton'
>
Close
</button>
</modal-window>
<div class="section">
<section v-if='$store.state.experimentsStore.teams' class="hero is-info">
<div class="hero-body" style="padding: 1rem 1rem !important;">
<div class="mobile-container">
<div class="container">
<p style="text-align: center;">Remember, do not approve items that use the default template with 0 modifications, or if the image fails to load correctly.</p>
</div>
</div>
</div>
</section>
<div class="">
<scroll-load
key='user-row'
class='columns is-multiline'
v-if='users.length'
:loading='loading'
@loadNext='fetchData'
>
<div class="column is-6" v-for='user in users' :key='"user-row" + user.username' v-show="user && !user.banned"><div class="card">
<div class="card-content">
<router-link :to="'/m/' + user.id"><b-button style="float:right;">View</b-button></router-link>
<div class="media">
<div class="media-left">
<figure class="image is-128x128">
<img :src="'http://localhost/marketplace/avatars/' + user.previewFile + '.png'">
</figure>
</div>
<div class="media-content">
<p class="title is-4">{{user.name}}</p>
<p class="subtitle is-6">Created by @{{user.User.username}}</p>
</div>
</div>
<div class="content limit">
{{user.description | truncate(70)}}
</div>
<b-button @click="teamApprove(user.id)" class="is-info">Approve</b-button> <b-button @click="initialTeamBan(user.id)" class="is-danger">Delete item</b-button>
</div>
</div>
</div>
</scroll-load>
</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'>
Nothing to display
</div></center></p>
</main>
</template>
<script>
import LoadingMessage from '../LoadingMessage';
import ScrollLoad from '../ScrollLoad';
import ModalWindow from '../ModalWindow'
import throttle from 'lodash.throttle';
import AjaxErrorHandler from '../../assets/js/errorHandler';
export default {
name: 'AdminMarketplace',
components: {
LoadingMessage,
ScrollLoad,
ModalWindow
},
data () {
return {
search: '',
users: [],
loading: true,
offset: 0,
limit: 15,
showTeamTab: 0,
createTeamModal: false,
reason: "None provided",
banModal: false,
selectedTeam: "Unknown Item",
tcreateProd: {
username: '',
name: '',
loading: false,
errors: {
username: '',
name: ''
}
},
roleOptions: [
{ name: 'Admins', value: 'admin' },
{ name: 'Users', value: 'user' }
],
roleSelected: ['admin', 'user'],
tableSort: {
column: 'username',
sort: 'desc'
}
}
},
methods: {
teamApprove(id) {
this.axios
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'admin/marketplace/approve', {
id: id,
approve: true,
delete: false
})
.then(() => {
this.showBadgeModal = false
this.resetFetchData()
})
.catch(e => {
AjaxErrorHandler(this.$store)(e, error => {
this.description.error = error.message
})
})
},
initialTeamBan(username) {
this.selectedTeam = username
this.banModal = true
},
teamBan(id) {
this.axios
.put(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'admin/marketplace/approve', {
id: id,
approve: false,
delete: true
})
.then(() => {
this.showBadgeModal = false
this.resetFetchData()
})
.catch(e => {
AjaxErrorHandler(this.$store)(e, error => {
this.description.error = error.message
})
})
},
clearTeamErrors() {
this.tcreateProd.errors.username = ''
this.tcreateProd.errors.name = ''
},
closeAccountModal() {
this.createTeamModal = false
},
fetchData () {
if(this.offset === null) return;
let url = process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + `/` + `admin/marketplace/pending?
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(process.env.VUE_APP_APIENDPOINT + process.env.VUE_APP_APIVERSION + '/' + 'admin/marketplace/pending' + '?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>