Skip to content

Commit 64bc381

Browse files
committed
Added delete functionality and started login
1 parent 5832b63 commit 64bc381

9 files changed

Lines changed: 496 additions & 509 deletions

File tree

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"name": "vuestic-admin",
3-
"version": "2.0.0",
2+
"name": "gamehoarder-admin",
3+
"version": "0.0.1",
44
"private": false,
5-
"description": "Vue.js admin template",
6-
"author": "smartapant <smartapant@gmail.com>",
5+
"description": "Vue.js admin page for ",
76
"scripts": {
87
"serve": "vue-cli-service serve",
98
"build": "vue-cli-service build",

src/app/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import VueClipboard from 'vue-clipboard2'
1515
import VeeValidate from 'vee-validate'
1616

1717
import '../metrics'
18+
import Axios from 'axios'
1819

1920
// NOTE: workaround for VeeValidate + vuetable-2
2021
Vue.use(VeeValidate, { fieldsBagName: 'formFields' })
@@ -48,3 +49,9 @@ new Vue({
4849
store,
4950
render: h => h(App),
5051
})
52+
53+
Vue.prototype.$http = Axios
54+
const token = localStorage.getItem('token')
55+
if (token) {
56+
Vue.prototype.$http.defaults.headers.common['Authorization'] = token
57+
}

src/components/admin/app-sidebar/NavigationRoutes.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,12 @@ export const navigationRoutes = {
44
displayName: 'navigationRoutes.home',
55
},
66
routes: [
7-
{
8-
name: 'dashboard',
9-
displayName: 'menu.dashboard',
10-
meta: {
11-
iconClass: 'vuestic-iconset-dashboard',
12-
},
13-
},
147
{
158
name: 'user-table',
169
displayName: 'menu.dataTables',
1710
meta: {
1811
iconClass: 'vuestic-iconset-tables',
1912
},
2013
},
21-
{
22-
name: 'pages',
23-
displayName: 'menu.pages',
24-
meta: {
25-
iconClass: 'vuestic-iconset-files',
26-
},
27-
disabled: true,
28-
children: [
29-
{
30-
name: 'login',
31-
displayName: 'Login/Signup',
32-
},
33-
{
34-
name: '404-pages',
35-
displayName: '404 Pages',
36-
},
37-
],
38-
},
3914
],
4015
}

src/components/auth/login/Login.vue

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<template>
22
<form @submit.prevent="onsubmit">
33
<va-input
4-
v-model="email"
5-
type="email"
6-
:label="$t('auth.email')"
7-
:error="!!emailErrors.length"
8-
:error-messages="emailErrors"
4+
v-model="username"
5+
type="text"
6+
:label="$t('username')"
97
/>
108

119
<va-input
@@ -27,7 +25,7 @@ export default {
2725
name: 'login',
2826
data () {
2927
return {
30-
email: '',
28+
username: '',
3129
password: '',
3230
keepLoggedIn: false,
3331
emailErrors: [],
@@ -41,12 +39,32 @@ export default {
4139
},
4240
methods: {
4341
onsubmit () {
44-
this.emailErrors = this.email ? [] : ['Email is required']
4542
this.passwordErrors = this.password ? [] : ['Password is required']
4643
if (!this.formReady) {
4744
return
4845
}
49-
this.$router.push({ name: 'dashboard' })
46+
47+
this.$http.post('http://localhost:8000/en/api/login', { username: this.username, password: this.password })
48+
.then(res => {
49+
if (res.data.token) {
50+
this.loginSuccessful(res)
51+
}
52+
}).catch(() => {
53+
this.loginFailed()
54+
})
55+
},
56+
loginSuccessful (req) {
57+
if (!req.data.token) {
58+
this.loginFailed()
59+
return
60+
}
61+
localStorage.setItem('token', req.data.token)
62+
this.error = false
63+
this.$router.replace(this.$route.query.redirect || '/')
64+
},
65+
loginFailed () {
66+
this.error = 'Login failed!'
67+
localStorage.removeItem('token')
5068
},
5169
},
5270
}
Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
<template>
2-
<va-card :title="$t('tables.serverSidePagination')">
2+
<va-card :title="$t('Users')" :key="tableKey"> <!-- TODO should be update when something is deleted -->
33
<va-data-table
44
:fields="fields"
55
:data="users"
6-
:loading="loading"
7-
@page-selected="readItems"
8-
api-mode
6+
:per-page="10"
97
>
10-
<template slot="avatar" slot-scope="props">
11-
<img :src="props.rowData.avatar" class="data-table-server-pagination---avatar">
8+
<template slot="actions" slot-scope="props">
9+
10+
<va-popover :message="`${$t('tables.edit')} ${props.rowData.username}`" placement="top">
11+
<router-link :to="{ name: 'change group', params: {username} }">
12+
<va-button flat small color="gray" icon="fa fa-pencil"/>
13+
</router-link>
14+
</va-popover>
15+
16+
<va-popover :message="`${$t('tables.delete')} ${props.rowData.username}`" placement="top">
17+
<va-button flat small color="gray" icon="fa fa-trash" v-on:click="deleteUser(props.rowData.username)"/>
18+
</va-popover>
1219
</template>
1320
</va-data-table>
1421
</va-card>
1522
</template>
1623

1724
<script>
25+
1826
import axios from 'axios'
1927
2028
export default {
2129
data () {
2230
return {
23-
perPage: 3,
24-
totalPages: 0,
2531
users: [],
26-
loading: false,
32+
tableKey: 1,
2733
}
2834
},
2935
computed: {
@@ -39,6 +45,9 @@ export default {
3945
}, {
4046
name: 'groups__name',
4147
title: 'groups',
48+
}, {
49+
name: '__slot:actions',
50+
dataClass: 'text-right',
4251
}]
4352
},
4453
},
@@ -47,22 +56,23 @@ export default {
4756
},
4857
methods: {
4958
readItems () {
50-
this.loading = true
51-
52-
axios.get('http://192.168.0.4:8000/en/api/users')
59+
this.$http.get('http://localhost:8000/en/api/users')
5360
.then(response => {
54-
this.users = response.data
55-
this.loading = false
61+
this.users = response.data.data
62+
console.log(this.users)
5663
})
5764
},
65+
66+
deleteUser: function (username) {
67+
this.$http.post('http://localhost:8000/en/api/users/delete', { username: username })
68+
69+
alert(username + ' deleted')
70+
this.readItems()
71+
this.tableKey += 1
72+
},
5873
},
5974
}
6075
</script>
6176

6277
<style lang="scss">
63-
.data-table-server-pagination---avatar {
64-
width: 40px;
65-
height: 40px;
66-
border-radius: 50%;
67-
}
6878
</style>

src/components/data-tables/scenarios/DataTableServerPagination.vue

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
<va-card :title="$t('tables.serverSidePagination')">
33
<va-data-table
44
:fields="fields"
5-
:data="items"
5+
:data="users"
66
:loading="loading"
7-
:totalPages="totalPages"
87
@page-selected="readItems"
98
api-mode
109
>
11-
<template slot="avatar" slot-scope="props">
12-
<img :src="props.rowData.avatar" class="data-table-server-pagination---avatar">
13-
</template>
1410
</va-data-table>
1511
</va-card>
1612
</template>
@@ -23,45 +19,36 @@ export default {
2319
return {
2420
perPage: 3,
2521
totalPages: 0,
26-
items: [],
22+
users: [],
2723
loading: false,
2824
}
2925
},
3026
computed: {
3127
fields () {
3228
return [{
33-
name: '__slot:avatar',
34-
width: '60px',
35-
}, {
36-
name: 'first_name',
37-
title: this.$t('tables.headings.firstName'),
29+
name: 'username',
30+
title: 'username',
3831
width: '20%',
3932
}, {
40-
name: 'last_name',
41-
title: this.$t('tables.headings.lastName'),
33+
name: 'email',
34+
title: 'email',
4235
width: '20%',
4336
}, {
44-
name: 'email',
45-
title: this.$t('tables.headings.email'),
37+
name: 'groups__name',
38+
title: 'groups',
4639
}]
4740
},
4841
},
4942
created () {
5043
this.readItems()
5144
},
5245
methods: {
53-
readItems (page = 0) {
46+
readItems () {
5447
this.loading = true
5548
56-
const params = {
57-
per_page: this.perPage,
58-
page: page,
59-
}
60-
61-
axios.get('https://reqres.in/api/users', { params })
49+
axios.get('http://127.0.0.1:8000/en/api/users')
6250
.then(response => {
63-
this.items = response.data.data
64-
this.totalPages = response.data.total_pages
51+
this.users = response.data
6552
this.loading = false
6653
})
6754
},

0 commit comments

Comments
 (0)