This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
IcyNet.eu/src/script/component/OAuthClients.vue

77 lines
1.9 KiB
Vue

<template lang="pug">
#clientlist
button.btn.btn-primary.mt-1(@click="editing = -1") New Client
.message.error(v-if="error") {{ error }}
.entry(v-else)
pagination(:page="pagination.page" :pages="pagination.pages" v-on:page="getClients")
.list.client
o-auth-client(v-for="client in clients" v-bind="client" :key="client.id")
client-modal(:show="editing != 0" @close='editing = 0', :id='editing')
</template>
<script type="text/javascript">
import Pagination from './Pagination.vue'
import OAuthClient from './OAuthClient.vue'
import ClientModal from './ClientModal.vue'
const csrfToken = document.querySelector('meta[name="csrf-token"]').content
export default {
data: function () {
return {
clients: [],
pagination: {
offset: 0,
page: 1,
pages: 1,
perPage: 6,
total: 0
},
editing: 0,
error: ''
}
},
components: {
ClientModal, Pagination, OAuthClient
},
methods: {
getClients: function (page) {
this.pagination.total = 0
this.error = ''
this.$http.get('/admin/api/clients?page=' + page).then(data => {
if (data.body && data.body.error) {
this.error = data.body.error
return
}
this.pagination = data.body.page
this.clients = data.body.clients
})
},
deleteClient: function (id) {
this.$http.post('/admin/api/client/delete', {
id: id,
csrf: csrfToken
}).then(data => {
this.getClients(1)
})
}
},
mounted: function () {
this.getClients(1)
this.$root.$on('reload_clients', () => {
this.getClients(this.pagination.page)
})
this.$on('edit', function (id) {
this.editing = id
})
this.$on('delete', function (id) {
this.deleteClient(id)
})
}
}
</script>