front end handle saving catalog

This commit is contained in:
Seth Ladygo
2019-05-03 17:45:01 -07:00
parent 8badbe32d0
commit 82a8d8f953

View File

@ -79,6 +79,7 @@ export const store = new Vuex.Store({
selectedModelID: null,
selectedMaterial: null,
loadingCatalog: true,
savingCatalog: false,
},
getters: {
//
@ -130,6 +131,10 @@ export const store = new Vuex.Store({
loadingCatalog(state) {
return state.loadingCatalog
},
savingCatalog(state) {
return state.savingCatalog
},
},
mutations: {
// SET_CAT_SECTIONS: (state, payload) => {
@ -167,6 +172,10 @@ export const store = new Vuex.Store({
state.loadingCatalog = value
},
setSavingCatalog(state, value) {
state.savingCatalog = value
},
setCatalogProperty(state, { key, value }) {
console.log('mutation set prop', key, value)
if (state.catalog) {
@ -199,28 +208,55 @@ export const store = new Vuex.Store({
// context.commit('ADD_TODO',payload)
// },
setCatalogProperty(context, data) {
context.commit('setCatalogProperty', data)
},
async loadCatalog({ commit }, id) {
try {
commit('setLoadingCatalog', true)
const response = await axios.get('/api/v1/catalogs/id/' + id)
if ('catalog' in response.data) {
console.log('recieved catalog:', response.data.catalog)
commit('setCatalog', response.data.catalog)
if (response.data) {
console.log('recieved catalog:', response.data)
commit('setCatalog', response.data)
commit('setCatalogID', id)
} else {
console.log('no catalog')
commit('setCatalog', null)
commit('setCatalogID', null)
}
commit('setLoadingCatalog', false)
} catch (error) {
// TODO set loading error property
console.error('error loading catalog: ', error)
commit('setCatalog', null)
commit('setCatalogID', null)
commit('setLoadingCatalog', false)
}
},
setCatalogProperty(context, data) {
context.commit('setCatalogProperty', data)
async saveCatalog({ commit, state }) {
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)
})
},
}