front end handle saving catalog
This commit is contained in:
@ -79,6 +79,7 @@ export const store = new Vuex.Store({
|
|||||||
selectedModelID: null,
|
selectedModelID: null,
|
||||||
selectedMaterial: null,
|
selectedMaterial: null,
|
||||||
loadingCatalog: true,
|
loadingCatalog: true,
|
||||||
|
savingCatalog: false,
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
//
|
//
|
||||||
@ -130,6 +131,10 @@ export const store = new Vuex.Store({
|
|||||||
loadingCatalog(state) {
|
loadingCatalog(state) {
|
||||||
return state.loadingCatalog
|
return state.loadingCatalog
|
||||||
},
|
},
|
||||||
|
|
||||||
|
savingCatalog(state) {
|
||||||
|
return state.savingCatalog
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
// SET_CAT_SECTIONS: (state, payload) => {
|
// SET_CAT_SECTIONS: (state, payload) => {
|
||||||
@ -167,6 +172,10 @@ export const store = new Vuex.Store({
|
|||||||
state.loadingCatalog = value
|
state.loadingCatalog = value
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setSavingCatalog(state, value) {
|
||||||
|
state.savingCatalog = value
|
||||||
|
},
|
||||||
|
|
||||||
setCatalogProperty(state, { key, value }) {
|
setCatalogProperty(state, { key, value }) {
|
||||||
console.log('mutation set prop', key, value)
|
console.log('mutation set prop', key, value)
|
||||||
if (state.catalog) {
|
if (state.catalog) {
|
||||||
@ -199,28 +208,55 @@ export const store = new Vuex.Store({
|
|||||||
// context.commit('ADD_TODO',payload)
|
// context.commit('ADD_TODO',payload)
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
setCatalogProperty(context, data) {
|
||||||
|
context.commit('setCatalogProperty', data)
|
||||||
|
},
|
||||||
|
|
||||||
async loadCatalog({ commit }, id) {
|
async loadCatalog({ commit }, id) {
|
||||||
try {
|
try {
|
||||||
commit('setLoadingCatalog', true)
|
commit('setLoadingCatalog', true)
|
||||||
const response = await axios.get('/api/v1/catalogs/id/' + id)
|
const response = await axios.get('/api/v1/catalogs/id/' + id)
|
||||||
if ('catalog' in response.data) {
|
if (response.data) {
|
||||||
console.log('recieved catalog:', response.data.catalog)
|
console.log('recieved catalog:', response.data)
|
||||||
commit('setCatalog', response.data.catalog)
|
commit('setCatalog', response.data)
|
||||||
|
commit('setCatalogID', id)
|
||||||
} else {
|
} else {
|
||||||
console.log('no catalog')
|
console.log('no catalog')
|
||||||
commit('setCatalog', null)
|
commit('setCatalog', null)
|
||||||
|
commit('setCatalogID', null)
|
||||||
}
|
}
|
||||||
commit('setLoadingCatalog', false)
|
commit('setLoadingCatalog', false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// TODO set loading error property
|
// TODO set loading error property
|
||||||
console.error('error loading catalog: ', error)
|
console.error('error loading catalog: ', error)
|
||||||
commit('setCatalog', null)
|
commit('setCatalog', null)
|
||||||
|
commit('setCatalogID', null)
|
||||||
commit('setLoadingCatalog', false)
|
commit('setLoadingCatalog', false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setCatalogProperty(context, data) {
|
async saveCatalog({ commit, state }) {
|
||||||
context.commit('setCatalogProperty', data)
|
commit('setSavingCatalog', true)
|
||||||
|
|
||||||
|
axios.post('/api/v1/catalogs/save', state.catalog)
|
||||||
|
.then(function(response) {
|
||||||
|
console.log('save response', response)
|
||||||
|
if (response.data) {
|
||||||
|
console.log('recieved catalog:', response.data)
|
||||||
|
commit('setCatalog', response.data)
|
||||||
|
commit('setCatalogID', response.data.id)
|
||||||
|
} else {
|
||||||
|
console.error('no catalog returned from save!')
|
||||||
|
commit('setCatalog', null)
|
||||||
|
commit('setCatalogID', null)
|
||||||
|
}
|
||||||
|
commit('setSavingCatalog', false)
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
// TODO set saving error property
|
||||||
|
console.error('error saving catalog: ', error)
|
||||||
|
commit('setSavingCatalog', false)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user