Skip to content

Commit ff70277

Browse files
committed
optional custom path for each crud operation
1 parent 2f58659 commit ff70277

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

src/utils/crud/components/Crud.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,14 @@ export default {
5656
type: String,
5757
default: null
5858
},
59-
path: String,
59+
path: {
60+
type: String,
61+
default: null
62+
},
63+
paths: {
64+
type: Object,
65+
default: {}
66+
},
6067
fieldsInfo: Array,
6168
detailsTitle: String,
6269
pageTitle: String,
@@ -163,6 +170,7 @@ export default {
163170
created() {
164171
this.setPrefix(this.prefix)
165172
this.setPath(this.path)
173+
this.setPaths(this.paths)
166174
this.setPage(this.pageTitle)
167175
let creationMode = this.watchForCreation ? 'inform' : 'ignore'
168176
this.setCreationMode(creationMode)
@@ -175,6 +183,7 @@ export default {
175183
"refreshTable",
176184
'setPrefix',
177185
'setPath',
186+
'setPaths',
178187
'setCreationMode',
179188
]),
180189
custom(name, item, index) {

src/utils/crud/store/actions.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let actions = {
55
// table data
66
getItems({commit, state, getters}) {
77
commit('setLoadingStatus', true)
8-
Vue.http.get(getters.path)
8+
Vue.http.get(getters.path('i'))
99
.then((response) => {
1010
commit('setItems', response.body)
1111
commit('setLoadingStatus', false)
@@ -16,7 +16,7 @@ let actions = {
1616
getItemsServerSide({commit, state, getters}, [params]) {
1717
return new Promise((resolve, reject) => {
1818
commit('setLoadingStatus', true)
19-
Vue.http.post(getters.path + '/search', params)
19+
Vue.http.post(getters.path('i') + '/search', params)
2020
.then((response) => {
2121
commit('setItemsServerSide', response.body)
2222
resolve()
@@ -29,7 +29,7 @@ let actions = {
2929
getItem({commit, state, getters}, [id]) {
3030
return new Promise((resolve, reject) => {
3131
commit('setDetailsLoader', true)
32-
Vue.http.get(getters.path + '/' + id)
32+
Vue.http.get(getters.path('sh') + '/' + id)
3333
.then((response) => {
3434
commit('setItem', response.body)
3535
commit('setDetailsLoader', false)
@@ -41,7 +41,7 @@ let actions = {
4141
},
4242
updateItem({commit, dispatch, state, getters}, [id, params, successText, errorText]) {
4343
return new Promise((resolve, reject) => {
44-
Vue.http.put(getters.path + '/' + id, params)
44+
Vue.http.put(getters.path('u') + '/' + id, params)
4545
.then((response) => {
4646
if (response.body.status == 0) {
4747
commit('alertSuccess', successText, { root: true })
@@ -61,7 +61,7 @@ let actions = {
6161
},
6262
storeItem({commit, dispatch, state, getters}, [params, successText, errorText]) {
6363
return new Promise((resolve, reject) => {
64-
Vue.http.post(getters.path, params)
64+
Vue.http.post(getters.path('st'), params)
6565
.then((response) => {
6666
if (response.body.status == 0) {
6767
commit('alertSuccess', successText, { root: true })
@@ -83,7 +83,7 @@ let actions = {
8383
})
8484
},
8585
deleteItem({commit, dispatch, state, getters}, [id, successText, errorText]) {
86-
Vue.http.delete(getters.path + '/' + id)
86+
Vue.http.delete(getters.path('d') + '/' + id)
8787
.then((response) => {
8888
commit('alertSuccess', successText, { root: true })
8989
commit('refreshTable')
@@ -92,7 +92,7 @@ let actions = {
9292
});
9393
},
9494
mulitipleItemsUpdate({commit, dispatch, state, getters}, [params, successText, errorText]){
95-
Vue.http.post(getters.path + '/multiple-update', params)
95+
Vue.http.post(getters.path('mu') + '/multiple-update', params)
9696
.then((response) => {
9797
commit('alertSuccess', successText, { root: true })
9898
commit('refreshTable')
@@ -101,7 +101,7 @@ let actions = {
101101
});
102102
},
103103
mulitipleItemsDelete({commit, dispatch, state, getters}, [ids, successText, errorText]){
104-
Vue.http.post(getters.path + '/multiple-delete', ids)
104+
Vue.http.post(getters.path('md') + '/multiple-delete', ids)
105105
.then((response) => {
106106
commit('alertSuccess', successText, { root: true })
107107
commit('refreshTable')
@@ -155,7 +155,7 @@ let actions = {
155155
getItemDetails({commit, state, getters}, [id]) {
156156
return new Promise((resolve, reject) => {
157157
commit('setDetailsLoader', true)
158-
Vue.http.get(getters.path + '/' + id)
158+
Vue.http.get(getters.path('sh') + '/' + id)
159159
.then((response) => {
160160
commit('itemDetails', response.body)
161161
commit('setDetailsLoader', false)
@@ -166,7 +166,7 @@ let actions = {
166166
})
167167
},
168168
updateItemDetail({commit, dispatch, state, getters}, [id, params, successText]) {
169-
Vue.http.put(getters.path + '/' + id, params)
169+
Vue.http.put(getters.path('u') + '/' + id, params)
170170
.then((response) => {
171171
if (response.body.status == 0) {
172172
commit('alertSuccess', successText, { root: true })

src/utils/crud/store/getters.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import { humanFileSize, getItemsList } from '@/utils/crud/helpers/functions.js'
22

33
let getters = {
4-
path: state => {
5-
return (state.prefix != null ? state.prefix + '/' : '') + state.path
4+
path: state => (operation) => {
5+
let path
6+
if(state.paths[operation] != undefined){
7+
path = state.paths[operation]
8+
}
9+
else{
10+
path = (state.prefix != null ? state.prefix + '/' : '') + state.path
11+
}
12+
return path
613
},
714
itemCreated: state => {
815
return state.createdElement.created

src/utils/crud/store/mutations.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ let mutations = {
88
setPath(state, path) {
99
state.path = path
1010
},
11+
setPaths(state, paths) {
12+
state.paths = paths
13+
},
1114
// table items
1215
setItems(state, data) {
1316
state.items = data

src/utils/crud/store/state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
let state = {
66
prefix: '',
77
path: '',
8+
paths: {},
89
tableReady: false,
910
detailsLoading: false,
1011
items: [],

0 commit comments

Comments
 (0)