Skip to content

Commit 2af78eb

Browse files
committed
vuetify : fix the resetting actions
1 parent 546d645 commit 2af78eb

File tree

5 files changed

+76
-19
lines changed

5 files changed

+76
-19
lines changed

templates/vue-common/mixins/ShowMixin.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@ export default {
3535
deleteError(message) {
3636
message && this.showError(message);
3737
}
38+
},
39+
beforeDestroy() {
40+
this.reset();
3841
}
3942
};

templates/vue-common/mixins/UpdateMixin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export default {
3131
formatDateTime,
3232
reset() {
3333
this.$refs.updateForm.$v.$reset();
34+
this.updateReset();
35+
this.delReset();
3436
this.createReset();
3537
},
3638

templates/vue-common/store/modules/crud.js

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ import { getField, updateField } from 'vuex-map-fields';
33
import remove from 'lodash/remove';
44
import SubmissionError from '../../error/SubmissionError';
55

6+
const initialState = {
7+
allIds: [],
8+
byId: {},
9+
created: null,
10+
deleted: null,
11+
error: '',
12+
isLoading: false,
13+
resetList: false,
14+
selectItems: null,
15+
totalItems: 0,
16+
updated: null,
17+
view: null,
18+
violations: null
19+
};
20+
621
const handleError = (commit, e) => {
722
commit(ACTIONS.TOGGLE_LOADING);
823

@@ -18,12 +33,13 @@ const handleError = (commit, e) => {
1833
commit(ACTIONS.SET_ERROR, e.message);
1934
};
2035

21-
const ACTIONS = {
36+
export const ACTIONS = {
2237
ADD: 'ADD',
23-
MERCURE_DELETED: 'MERCURE_DELETED',
24-
MERCURE_MESSAGE: 'MERCURE_MESSAGE',
25-
MERCURE_OPEN: 'MERCURE_OPEN',
38+
RESET_CREATE: 'RESET_CREATE',
39+
RESET_DELETE: 'RESET_DELETE',
2640
RESET_LIST: 'RESET_LIST',
41+
RESET_SHOW: 'RESET_SHOW',
42+
RESET_UPDATE: 'RESET_UPDATE',
2743
SET_CREATED: 'SET_CREATED',
2844
SET_DELETED: 'SET_DELETED',
2945
SET_ERROR: 'SET_ERROR',
@@ -71,6 +87,8 @@ export default function makeCrudModule({
7187
fetchAll: ({ commit, state }, params) => {
7288
if (!service) throw new Error('No service specified!');
7389

90+
commit(ACTIONS.TOGGLE_LOADING);
91+
7492
service
7593
.findAll({ params })
7694
.then(response => response.json())
@@ -123,6 +141,18 @@ export default function makeCrudModule({
123141
})
124142
.catch(e => handleError(commit, e));
125143
},
144+
resetCreate: ({ commit }) => {
145+
commit(ACTIONS.RESET_CREATE);
146+
},
147+
resetDelete: ({ commit }) => {
148+
commit(ACTIONS.RESET_DELETE);
149+
},
150+
resetShow: ({ commit }) => {
151+
commit(ACTIONS.RESET_SHOW);
152+
},
153+
resetUpdate: ({ commit }) => {
154+
commit(ACTIONS.RESET_UPDATE);
155+
},
126156
update: ({ commit }, item) => {
127157
commit(ACTIONS.SET_ERROR, '');
128158
commit(ACTIONS.TOGGLE_LOADING);
@@ -150,16 +180,48 @@ export default function makeCrudModule({
150180
updateField,
151181
[ACTIONS.ADD]: (state, item) => {
152182
Vue.set(state.byId, item['@id'], item);
183+
Vue.set(state, 'isLoading', false);
153184
if (state.allIds.includes(item['@id'])) return;
154185
state.allIds.push(item['@id']);
155186
},
187+
[ACTIONS.RESET_CREATE]: state => {
188+
Object.assign(state, {
189+
isLoading: false,
190+
error: '',
191+
created: null,
192+
violations: null
193+
});
194+
},
195+
[ACTIONS.RESET_DELETE]: state => {
196+
Object.assign(state, {
197+
isLoading: false,
198+
error: '',
199+
deleted: null
200+
});
201+
},
156202
[ACTIONS.RESET_LIST]: state => {
157203
Object.assign(state, {
158204
allIds: [],
159205
byId: {},
206+
error: '',
207+
isLoading: false,
160208
resetList: false
161209
});
162210
},
211+
[ACTIONS.RESET_SHOW]: state => {
212+
Object.assign(state, {
213+
error: '',
214+
isLoading: false
215+
});
216+
},
217+
[ACTIONS.RESET_UPDATE]: state => {
218+
Object.assign(state, {
219+
error: '',
220+
isLoading: false,
221+
updated: null,
222+
violations: null
223+
});
224+
},
163225
[ACTIONS.SET_CREATED]: (state, created) => {
164226
Object.assign(state, { created });
165227
},
@@ -203,19 +265,6 @@ export default function makeCrudModule({
203265
}
204266
},
205267
namespaced: true,
206-
state: {
207-
allIds: [],
208-
byId: {},
209-
created: null,
210-
deleted: null,
211-
error: '',
212-
isLoading: false,
213-
resetList: false,
214-
selectItems: null,
215-
totalItems: 0,
216-
updated: null,
217-
view: null,
218-
violations: null
219-
}
268+
state: initialState
220269
};
221270
}

templates/vuetify/views/foo/Show.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default {
8484
methods: {
8585
...mapActions('{{{lc}}}', {
8686
deleteItem: 'del',
87-
reset: 'reset',
87+
reset: 'resetShow',
8888
retrieve: 'load'
8989
})
9090
}

templates/vuetify/views/foo/Update.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ export default {
4949
5050
methods: {
5151
...mapActions('{{{lc}}}', {
52+
createReset: 'resetCreate',
5253
deleteItem: 'del',
54+
delReset: 'resetDelete',
5355
retrieve: 'load',
5456
update: 'update',
57+
updateReset: 'resetUpdate'
5558
})
5659
}
5760
};

0 commit comments

Comments
 (0)