-
Notifications
You must be signed in to change notification settings - Fork 24
/
App.vue
181 lines (161 loc) · 5.44 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<template>
<!-- If you want to use your own custom unauthorized page you just have to provide it like: -->
<!-- <Admin :authProvider="authProvider" :unauthorized="UnauthorizedCustomView"> -->
<Admin :authProvider="authProvider" :unauthorized="UnauthorizedCustomView">
<!-- Articles Resource -->
<Resource
name="articles"
:resourceIdName="resourceIdName"
:userPermissionsField="userPermissionsField"
:apiUrl="articlesApiUrl"
:redirect="articlesRedirect"
>
<View slot="list" :component="ListArticles" :permissions="['admin']" />
<View slot="show" :component="ShowArticles" :permissions="['admin']" />
<View
slot="create"
:component="CreateArticles"
:permissions="['admin']"
/>
<View slot="edit" :component="EditArticles" :isPublic="true" />
</Resource>
<!-- Magazines Resource -->
<Resource
name="magazines"
:resourceIdName="resourceIdName"
:apiUrl="magazinesApiUrl"
:redirect="magazinesRedirect"
>
<View slot="list" :component="ListMagazines" :isPublic="true" />
<View slot="show" :component="ShowMagazines" :isPublic="true" />
<View slot="create" :component="CreateMagazines" :isPublic="true" />
<View slot="edit" :component="EditMagazines" :isPublic="true" />
</Resource>
<!-- Authors Resource -->
<Resource
name="authors"
:resourceIdName="resourceIdName"
:apiUrl="authorsApiUrl"
:redirect="authorsRedirect"
>
<View slot="list" :component="ListAuthors" :isPublic="true" />
<View slot="show" :component="ShowAuthors" :isPublic="true" />
<View slot="create" :component="CreateAuthors" :isPublic="true" />
<View slot="edit" :component="EditAuthors" :isPublic="true" />
</Resource>
</Admin>
</template>
<script>
import Admin from '@components/Admin'
import Resource from '@components/Resource'
import UnauthorizedView from './components/UnauthorizedView'
import UnauthorizedCustomView from './components/UnauthorizedCustomView'
import CustomSidebar from './components/CustomSidebar'
import ListArticles from './components/articles/ListArticles'
import ShowArticles from './components/articles/ShowArticles'
import CreateArticles from './components/articles/CreateArticles'
import EditArticles from './components/articles/EditArticles'
import ListMagazines from './components/magazines/ListMagazines'
import ShowMagazines from './components/magazines/ShowMagazines'
import CreateMagazines from './components/magazines/CreateMagazines'
import EditMagazines from './components/magazines/EditMagazines'
import CreateAuthors from './components/authors/CreateAuthors'
import EditAuthors from './components/authors/EditAuthors'
import ListAuthors from './components/authors/ListAuthors'
import ShowAuthors from './components/authors/ShowAuthors'
import AuthCustomView from './components/AuthCustomView'
import createAxiosAdapter from './va-auth-adapter/axios.adapter'
import axios from 'axios'
const authFields = { username: 'username', password: 'password' }
const authUrl = 'http://localhost:8888/api/auth'
const client = axios
const storageKey = 'token'
const userField = 'user'
const authProvider = createAxiosAdapter(client, {
authFields,
authUrl,
storageKey,
userField,
})
/**
* Redirect objects
*/
const articlesRedirect = {
views: {
create: 'list',
edit: 'show',
},
}
const magazinesRedirect = articlesRedirect
const authorsRedirect = articlesRedirect
// The name of the id attribute
export const resourceIdName = 'id'
// The name of the permissions field
const userPermissionsField = 'permissions'
// Use case of a parsed response using feathers
// This has to be done because every server client returns different responses. - sgobotta
//
// const parseFeathersResponses = {
// parseList: (response) => {
// const { data } = response
// return Object.assign({}, response, {
// data: data.data // Vue Admin expects a 'data' object with an array of objects
// })
// },
// parseSingle: (response) => {
// const { data } = response
// return Object.assign({}, response, {
// data // Vue Admin expects a 'data' object as response
// })
// }
// }
const articlesApiUrl = 'http://localhost:8888/api/'
const magazinesApiUrl = 'http://localhost:8888/api/'
const authorsApiUrl = 'http://localhost:8888/api/'
export default {
name: 'App',
components: {
Admin,
Resource,
},
data() {
return {
// Admin props
authProvider,
AuthCustomView,
UnauthorizedView,
UnauthorizedCustomView,
CustomSidebar,
// Common Resource props
resourceIdName,
userPermissionsField,
// Server Urls
articlesApiUrl,
magazinesApiUrl,
authorsApiUrl,
// Articles Views as Components
ListArticles,
ShowArticles,
CreateArticles,
EditArticles,
articlesRedirect,
// Magazines Views as Custom Components
ListMagazines,
ShowMagazines,
CreateMagazines,
EditMagazines,
magazinesRedirect,
// Authors Views as Components
ListAuthors,
ShowAuthors,
CreateAuthors,
EditAuthors,
authorsRedirect,
// #23 - To use a feathers server just add the parseResponses attribute
// below, pass ':parseResponses='parseResponses' to Resource in the
// template and update the resourceIdName to '_id'. - sgobotta
// parseResponses: parseFeathersResponses
}
},
}
</script>