folders beta 1

This commit is contained in:
2020-12-01 20:40:37 +01:00
parent 93c4707c45
commit 564a1638fc
12 changed files with 234 additions and 139 deletions

View File

@@ -19,6 +19,7 @@ export default {
canSearch: false,
roles: [],
flagcolls: false,
flagcollsLoadedItems: {},
openedCollid: null
},
@@ -83,8 +84,9 @@ export default {
state.canSearch = false
},
setFlagColls (state, flagcolls) {
console.log('User setFlagColls', flagcolls)
console.log('User pre setFlagColls', state.flagcolls)
state.flagcolls = flagcolls
// console.log('User post setFlagColls', state.flagcolls)
},
openFlagColl (state, collid) {
state.openedCollid = collid
@@ -96,7 +98,7 @@ export default {
console.log('setLoadedCollItems', data)
// if no data, we are just calling the mutation to trigger the component update
if (data) {
state.flagcolls[data.collid].loadedItems = data.items
state.flagcollsLoadedItems[data.collid] = data.items
}
}
},
@@ -236,66 +238,65 @@ export default {
})
})
},
flag ({ dispatch, commit, state }, args) {
console.log('user flag', args.uuid, args.collid)
flagUnflag ({ dispatch, commit, state }, { action, uuid, collid }) {
console.log('user flagUnflag', action, uuid, collid)
return new Promise((resolve, reject) => {
const params = {
flagid: state.flagcolls[args.collid].flag_id,
uuid: args.uuid,
flagcollid: args.collid
flagid: state.flagcolls[collid].flag_id,
uuid: uuid,
flagcollid: collid
}
return MA.post('materio_flag/flag', params)
return MA.post(`materio_flag/${action}`, params)
.then(({ data }) => {
console.log('user MA flag', data)
// reload the fulllist of flagcolleciton
dispatch('getUserFlagColls').then(() => {
resolve()
if (state.flagcolls[collid].items_uuids.length) {
dispatch('loadMaterials', {
uuids: state.flagcolls[collid].items_uuids,
imgStyle: 'card_medium_half',
callBack: 'loadMaterialsCallBack',
callBackArgs: { collid: collid }
}).then( () => {
resolve()
})
}else{
commit('setLoadedCollItems', { collid: collid, items: [] })
resolve()
}
})
})
.catch(error => {
console.warn('Issue USER MA flag', error)
})
})
},
unFlag ({ dispatch, commit, state }, args) {
console.log('user unFlag', args.uuid, args.collid)
return new Promise((resolve, reject) => {
const params = {
flagid: state.flagcolls[args.collid].flag_id,
uuid: args.uuid,
flagcollid: args.collid
}
return MA.post('materio_flag/unflag', params)
.then(({ data }) => {
console.log('user MA unFlag', data)
dispatch('getUserFlagColls').then(() => {
resolve()
})
})
.catch(error => {
console.warn('Issue USER MA unFlag', error)
console.warn('Issue USER MA flagUnflag', error)
})
})
},
openFlagColl ({ commit, dispatch, state }, collid) {
console.log('user openFlagColl', collid)
commit('openFlagColl', collid)
if (typeof state.flagcolls[collid].loadedItems === 'undefined') {
// if no loadedItems, load them
// loadMaterials is on mixins
// https://github.com/huybuidac/vuex-extensions
dispatch('loadMaterials', {
uuids: state.flagcolls[collid].items_uuids,
imgStyle: 'card_medium_half',
callBack: 'loadMaterialsCallBack',
callBackArgs: { collid: collid }
})
} else {
// call the mutation without data to only trigger the FlagCollection component update
commit('setLoadedCollItems')
if (state.flagcolls[collid].items_uuids.length) {
if (typeof state.flagcollsLoadedItems[collid] === 'undefined') {
console.log('loading flagcoll items')
// if no loadedItems, load them
// loadMaterials is on mixins
// https://github.com/huybuidac/vuex-extensions
dispatch('loadMaterials', {
uuids: state.flagcolls[collid].items_uuids,
imgStyle: 'card_medium_half',
callBack: 'loadMaterialsCallBack',
callBackArgs: { collid: collid }
})
} else {
// call the mutation without data to only trigger the FlagCollection component update
console.log('committing setLoadedCollItems without args')
commit('setLoadedCollItems')
}
}else{
commit('setLoadedCollItems', { collid: collid, items: [] })
}
},
loadMaterialsCallBack ({ commit }, { items, callBackArgs }) {
console.log('user loadMaterialsCallBack', items)
console.log('user loadMaterialsCallBack', items, callBackArgs)
commit('setLoadedCollItems', { collid: callBackArgs.collid, items: items })
},
closeFlagColl ({ commit, dispatch }) {