return catalog materials when cat data is fetched

This commit is contained in:
Seth Ladygo
2019-05-14 16:05:55 -07:00
parent 3990774de3
commit 9d18b47aee
3 changed files with 55 additions and 71 deletions

View File

@ -9,73 +9,7 @@ Vue.use(Vuex)
export const store = new Vuex.Store({
state: {
catalog: null,
materials: {
'1001001': { id: '1001001', // call them sap maybe?
model: 'AW123',
family: 'MF123',
name: 'Targhee WP',
color: 'Green / Blue' },
'1001002': { id: '1001002',
model: 'AW123',
family: 'MF123',
name: 'Targhee WP',
color: 'Red / Purple' },
'1001011': { id: '1001011',
model: 'WA999',
family: 'MF123',
name: 'Targhee WP FA',
color: 'Green / Blue' },
'1001012': { id: '1001012',
model: 'WA999',
family: 'MF123',
name: 'Targhee WP FA',
color: 'Green / Blue' },
'1001021': { id: '1001021',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Green / Blue' },
'1001022': { id: '1001022',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Red / Blue' },
'1001023': { id: '1001023',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Blue / Green' },
'1001024': { id: '1001024',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Red / Green' },
'1001025': { id: '1001025',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Orange / Blue' },
'1001026': { id: '1001026',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Yellow / Blue' },
'1001027': { id: '1001027',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Yellow / Blue' },
'1001028': { id: '1001028',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Yellow / Blue' },
'1001029': { id: '1001029',
model: 'BBB22',
family: 'BBBMF',
name: 'Slither',
color: 'Yellow / Blue' },
},
materials: {},
selectedSectionID: null,
//selectedFamilyID: null,
selectedModelID: null,
@ -280,6 +214,15 @@ export const store = new Vuex.Store({
// state.selectedMaterial = payload
// },
addMaterialsToLibrary(state, materials) {
console.log('adding', materials.length, 'materials')
let map = {}
for (let m of materials) {
map[m.id] = m
}
state.materials = { ...state.materials, ...map }
},
setCatalog(state, cat) {
state.catalog = cat
},
@ -417,9 +360,17 @@ export const store = new Vuex.Store({
try {
commit('setLoadingCatalog', true)
const response = await axios.get('/api/v1/catalogs/id/' + id)
if (response.data) {
console.log('recieved catalog:', response.data)
commit('setCatalog', response.data)
// bundled materials
if (response.data && response.data.products) {
console.log('recieved materials:', response.data.products)
commit('addMaterialsToLibrary', response.data.products)
} else {
console.log('no materials')
}
// the catalog
if (response.data && response.data.catalog) {
console.log('recieved catalog:', response.data.catalog)
commit('setCatalog', response.data.catalog)
} else {
console.log('no catalog')
commit('setCatalog', null)