refactored mapitem (main and clones) generation for better superpositions opening
This commit is contained in:
136
src/App.vue
136
src/App.vue
@@ -13,6 +13,13 @@ import MapConcernements from '@components/MapConcernements.vue'
|
||||
import ConcernementMapItem from '@components/ConcernementMapItem.vue'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
mapitems: [],
|
||||
// not_cloned_mapitems: [],
|
||||
// superposed_cloned_mapitems: []
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.loadContentTypeDefinition();
|
||||
this.loadConcernements()
|
||||
@@ -25,48 +32,92 @@ export default {
|
||||
...mapState(UserStore,['isloggedin']),
|
||||
...mapState(ConcernementsStore,['map_mode',
|
||||
'concernements',
|
||||
'concernements_loaded',
|
||||
'concernementsByID',
|
||||
'allSuperpositions_byid',
|
||||
'opened_recit']),
|
||||
superposed_clones_concernements () {
|
||||
let clones = [];
|
||||
// loop through all superposition grouped by concernements couples
|
||||
for(let [couple_id, superpositions] of Object.entries(this.allSuperpositions_byid)){
|
||||
// loop through all superpositions for one concernement couple and mark the first as NOT cloned and clone the others and mark them as cloned
|
||||
let i = 0;
|
||||
for(let [superposition_id, superposition] of Object.entries(superpositions)){
|
||||
i++
|
||||
if (i === 1) {
|
||||
// first superposition of the couple is not cloned
|
||||
this.allSuperpositions_byid[couple_id][superposition_id].cloned = false;
|
||||
continue;
|
||||
}
|
||||
// following superpositions of the couple generate concernement map_item clones
|
||||
// first concernement of the couple
|
||||
clones.push({
|
||||
concernement: this.concernementsByID[superposition[0].cid],
|
||||
superposition_id: superposition_id
|
||||
})
|
||||
// second concernement of the couple
|
||||
clones.push({
|
||||
concernement: this.concernementsByID[superposition[1].cid],
|
||||
superposition_id: superposition_id
|
||||
})
|
||||
|
||||
this.allSuperpositions_byid[couple_id][superposition_id].cloned = true;
|
||||
},
|
||||
watch: {
|
||||
concernements_loaded:{
|
||||
handler (n, o) {
|
||||
if(n && !o){
|
||||
this.parseMapitems()
|
||||
}
|
||||
}
|
||||
return clones;
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(ConcernementsStore,['loadConcernements']),
|
||||
...mapActions(ConcernementsStore,['loadContentTypeDefinition']),
|
||||
...mapActions(UserStore,['checkUser']),
|
||||
// parseSuperposedMapitemsClones () {
|
||||
// let clones = [];
|
||||
// // loop through all superposition grouped by concernements couples
|
||||
// for(let [couple_id, superpositions] of Object.entries(this.allSuperpositions_byid)){
|
||||
// // loop through all superpositions for one concernement couple and mark the first as NOT cloned and clone the others and mark them as cloned
|
||||
// let i = 0;
|
||||
// for(let [superposition_id, superposition] of Object.entries(superpositions)){
|
||||
// i++
|
||||
// if (i === 1) {
|
||||
// // first superposition of the couple is not cloned
|
||||
// this.allSuperpositions_byid[couple_id][superposition_id].cloned = false;
|
||||
// continue;
|
||||
// }
|
||||
// // following superpositions of the couple generate concernement map_item clones
|
||||
// // first concernement of the couple
|
||||
// clones.push({
|
||||
// concernement: this.concernementsByID[superposition[0].cid],
|
||||
// superposition_id: superposition_id
|
||||
// })
|
||||
// // second concernement of the couple
|
||||
// clones.push({
|
||||
// concernement: this.concernementsByID[superposition[1].cid],
|
||||
// superposition_id: superposition_id
|
||||
// })
|
||||
|
||||
// mapitem_opened(concernement){
|
||||
// return concernement.opened;
|
||||
// }
|
||||
// this.allSuperpositions_byid[couple_id][superposition_id].cloned = true;
|
||||
// }
|
||||
// }
|
||||
// this.superposed_cloned_mapitems = clones;
|
||||
// },
|
||||
parseMapitems() {
|
||||
let couple_ids = Object.keys(this.allSuperpositions_byid);
|
||||
console.log('App couple_ids', couple_ids);
|
||||
// loop through all concernement
|
||||
for(let [concernement_id, concernement] of Object.entries(this.concernementsByID)){
|
||||
// create the main mapitem object
|
||||
let mapitem = {
|
||||
id: concernement.id,
|
||||
concernement: concernement,
|
||||
superposition_ids: [],
|
||||
clone: false,
|
||||
}
|
||||
// loop through superposistions couples
|
||||
couple_ids.forEach(couple_id => {
|
||||
let cids = couple_id.match(/(\d+)-(\d+)/i);
|
||||
// console.log('cids', cids);
|
||||
if (concernement.id === parseInt(cids[1]) || concernement.id === parseInt(cids[2])) {
|
||||
let i = 0;
|
||||
for(let [superposition_id, superposition] of Object.entries(this.allSuperpositions_byid[couple_id])){
|
||||
i++;
|
||||
if (i === 1) {
|
||||
mapitem.superposition_ids.push(superposition_id)
|
||||
}else{
|
||||
this.mapitems.push({
|
||||
id: `${concernement.id}___${superposition_id}`,
|
||||
concernement: concernement,
|
||||
superposition_ids: [superposition_id],
|
||||
clone: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.mapitems.push(mapitem)
|
||||
}
|
||||
console.log('App mapitems', this.mapitems);
|
||||
}
|
||||
},
|
||||
components: {
|
||||
MapConcernements,
|
||||
@@ -96,25 +147,22 @@ export default {
|
||||
|
||||
<div id="main-content">
|
||||
<MapConcernements>
|
||||
<template v-for="(concernement,index) in concernements">
|
||||
<template v-for="(mapitem,index) in mapitems">
|
||||
<ConcernementMapItem
|
||||
v-if="concernement.visible"
|
||||
:key="index"
|
||||
:concernement="concernement"
|
||||
:active_revision="concernement.active_revision"
|
||||
v-if="mapitem.concernement.visible && ((map_mode === 'superposition' && mapitem.clone) || !mapitem.clone)"
|
||||
:key="mapitem.id"
|
||||
:mapitem="mapitem"
|
||||
/>
|
||||
</template>
|
||||
<template v-if="map_mode === 'superposition'">
|
||||
<template v-for="(superposition,index) in superposed_clones_concernements">
|
||||
<!-- <template v-if="map_mode === 'superposition'">
|
||||
<template v-for="(mapitem,index) in superposed_cloned_mapitems">
|
||||
<ConcernementMapItem
|
||||
v-if="superposition.concernement.visible"
|
||||
:key="index"
|
||||
:concernement="superposition.concernement"
|
||||
:active_revision="superposition.concernement.active_revision"
|
||||
:superposition_id="superposition.superposition_id"
|
||||
v-if="mapitem.concernement.visible"
|
||||
:key="mapitem.id"
|
||||
:mapitem="mapitem"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</template> -->
|
||||
</MapConcernements>
|
||||
<div id="content" :class="{'recit-opened':opened_recit}">
|
||||
<RouterView />
|
||||
|
||||
Reference in New Issue
Block a user