fixed concernement field recording

This commit is contained in:
Bachir Soussi Chiadmi 2025-06-03 12:38:26 +02:00
parent b9f9551efa
commit cc943c5776
6 changed files with 129 additions and 15 deletions

View File

@ -61,6 +61,7 @@ export default {
'concernements', 'concernements',
'concernementsByID', 'concernementsByID',
'opened_concernement', 'opened_concernement',
'concernement_is_updating_nid',
'opened_entite_id', 'opened_entite_id',
'opened_recit', 'opened_recit',
'allSuperpositions', 'allSuperpositions',
@ -122,11 +123,17 @@ export default {
this.paper.view.onClick = function(event) { this.paper.view.onClick = function(event) {
// console.log("view onClick", this, event.target); // console.log("view onClick", this, event.target);
if(event.target._id === "paper-view-0") { if(event.target._id === "paper-view-0") {
this.resetConcernementOpened(); // // unfocus any active element to trigger recording if needed
this.$router.push({ // document.activeElement.blur();
name: 'home', // // setTimeout to let time for editable fields to focus out and record changes
hash: `#${this.map_mode}` // setTimeout(() => {
}); // this.resetConcernementOpened();
// this.$router.push({
// name: 'home',
// hash: `#${this.map_mode}`
// });
// }, 1);
this.closeConcernement();
} }
}.bind(this); }.bind(this);
@ -1543,6 +1550,26 @@ export default {
}); });
wall_rects.addChildren(children); wall_rects.addChildren(children);
} }
},
closeConcernement(){
// unfocus any active element to trigger recording if needed
document.activeElement.blur();
// setTimeout to let time for editable fields to focus out and record changes
this.waitForUpdatingEnded();
},
waitForUpdatingEnded(){
setTimeout(() => {
if (!this.concernement_is_updating_nid) {
this.resetConcernementOpened();
this.$router.push({
name: 'home',
hash: `#${this.map_mode}`
});
} else {
this.waitForUpdatingEnded();
}
}, 1);
} }
}, },
beforeUpdate () { beforeUpdate () {

View File

@ -211,8 +211,10 @@ export default {
...mapActions(ConcernementsStore, ['setActiveRevision', ...mapActions(ConcernementsStore, ['setActiveRevision',
'setDetailsZoomValue', 'setDetailsZoomValue',
'loadConcernements', 'loadConcernements',
'setConcernementIsUpdating',
'reloadConcernements', 'reloadConcernements',
'reloadConcernementEntites', 'reloadConcernementEntites',
'reloadConcernementField',
'reloadProximites' 'reloadProximites'
]), ]),
...mapActions(UserStore, ['getUserEntitees']), ...mapActions(UserStore, ['getUserEntitees']),
@ -258,6 +260,22 @@ export default {
this.headerreduced = false; this.headerreduced = false;
} }
}, },
// triggered when focus out and gql patch xhr triggered
onFieldIsUpdating(cid){
this.setConcernementIsUpdating(cid);
},
// triggered when gql patch done
onFieldUpdated(cid){
this.setConcernementIsUpdating(null);
this.reloadConcernementEntites(cid);
},
concernementFieldIsUpdating(field){
this.setConcernementIsUpdating(this.cid);
},
concernementFieldUpdated(field){
this.setConcernementIsUpdating(null);
this.reloadConcernementField(this.cid, field);
},
onContentEditableFocusOut(e){ onContentEditableFocusOut(e){
console.log('onContentEditableFocusOut', e); console.log('onContentEditableFocusOut', e);
let new_field_content = e.target.innerText; let new_field_content = e.target.innerText;
@ -531,7 +549,8 @@ export default {
id: this.entite.id, id: this.entite.id,
field: {field_name: 'title', value:'value'} field: {field_name: 'title', value:'value'}
}" }"
v-on:updated="reloadConcernementEntites(cid)"/> v-on:updating="onFieldIsUpdating(cid)"
v-on:updated="onFieldUpdated(cid)"/>
<!-- proximité --> <!-- proximité -->
<section <section
@ -635,7 +654,9 @@ export default {
bundle: 'concernement', bundle: 'concernement',
id: this.concernement.id, id: this.concernement.id,
field: {field_name: 'field_description', value:'value'} field: {field_name: 'field_description', value:'value'}
}" /> }"
v-on:updating="concernementFieldIsUpdating('description')"
v-on:updated="concernementFieldUpdated('description')"/>
</section> </section>
<section v-if="concernement.caillou || concernement.can_update" class="caillou"> <section v-if="concernement.caillou || concernement.can_update" class="caillou">
@ -651,7 +672,9 @@ export default {
bundle: 'concernement', bundle: 'concernement',
id: this.concernement.id, id: this.concernement.id,
field: {field_name: 'field_caillou', value:'value'} field: {field_name: 'field_caillou', value:'value'}
}" /> }"
v-on:updating="concernementFieldIsUpdating('caillou')"
v-on:updated="concernementFieldUpdated('caillou')"/>
</section> </section>
<template v-if="concernement.can_update"> <template v-if="concernement.can_update">
@ -666,7 +689,15 @@ export default {
</template> </template>
<!-- entite --> <!-- entite -->
<Entite v-if="entite" :concernement="concernement" :entite="entite" :eid="eid" v-on:reloadEntite="loadEntite"/> <Entite
v-if="entite"
:concernement="concernement"
:entite="entite"
:eid="eid"
v-on:reloadEntite="loadEntite"/>
<!-- v-on:updating="onFieldIsUpdating(cid)"
v-on:updated="onFieldUpdated(cid)" -->
</template> </template>
<template v-slot:footer> <template v-slot:footer>

View File

@ -29,7 +29,7 @@ export default {
default : 'Ajouter du texte' default : 'Ajouter du texte'
} }
}, },
emits: ['updated'], emits: ['updating', 'updated'],
data(){ data(){
return { return {
editor: null, editor: null,
@ -74,6 +74,7 @@ export default {
} }
}, },
save(content){ save(content){
this.$emit('updating');
// console.log('save csrf_token', this.csrf_token); // console.log('save csrf_token', this.csrf_token);
const params = { const params = {
type: this.data.bundle, type: this.data.bundle,

View File

@ -54,7 +54,15 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(ConcernementsStore,['setMapMode']), ...mapActions(ConcernementsStore,['setMapMode',"setConcernementIsUpdating","reloadConcernementField"]),
// triggered when focus out and gql patch xhr triggered
concernementFieldIsUpdating(field){
this.setConcernementIsUpdating(this.cid);
},
concernementFieldUpdated(field){
this.setConcernementIsUpdating(null);
this.reloadConcernementField(this.cid, field);
}
}, },
components: { components: {
SvgIcon, SvgIcon,
@ -78,7 +86,9 @@ export default {
bundle: 'concernement', bundle: 'concernement',
id: this.concernement.id, id: this.concernement.id,
field: {field_name: 'title', value:'value'} field: {field_name: 'title', value:'value'}
}" /> }"
v-on:updating="concernementFieldIsUpdating('title')"
v-on:updated="concernementFieldUpdated('title')"/>
<!-- <nav class="icons"> <!-- <nav class="icons">

View File

@ -50,6 +50,7 @@ export const ConcernementsStore = defineStore({
concernements_are_loading: false, concernements_are_loading: false,
concernement_active_revision: null, concernement_active_revision: null,
detailsZoomValue: 1, detailsZoomValue: 1,
concernement_is_updating_nid: null
}), }),
getters: { getters: {
@ -309,6 +310,9 @@ export const ConcernementsStore = defineStore({
// console.log(`end of parsing concernements`); // console.log(`end of parsing concernements`);
}, },
setConcernementIsUpdating(nid){
this.concernement_is_updating_nid = nid;
},
reloadConcernements () { reloadConcernements () {
console.log('reloadConcernements'); console.log('reloadConcernements');
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -429,9 +433,36 @@ export const ConcernementsStore = defineStore({
}) })
}) })
}, },
reloadConcernementField(nid, field){
console.log('reloadConcernementField', nid, field);
// let tmp_conc = this.concernementsByID[nid];
return new Promise((resolve, reject) => {
const ast = gql`{
concernement(id:${nid}) {
id
${field}
}
}
`
GQL.post('', { query: print(ast) })
.then(({ data : { data : { concernement } } }) => {
console.log(`reloadConcernementField loaded ${field}`, concernement)
let tmp_conc = this.concernementsByID[concernement.id];
// merge old concernement besoins with new once
_merge(tmp_conc, concernement);
resolve(concernement);
})
.catch(error => {
console.warn('Issue with reloadConcernementField', error)
reject(error);
Promise.reject(error)
})
});
},
reloadConcernementBesoins(nid){ reloadConcernementBesoins(nid){
let tmp_conc = this.concernementsByID[nid]; let tmp_conc = this.concernementsByID[nid];
console.log(`reloadConcernementEntites len: ${tmp_conc.entites.length} revision: ${tmp_conc.revision_id} nid: ${nid}`); // console.log(`reloadConcernementBesoins len: ${tmp_conc.entites.length} revision: ${tmp_conc.revision_id} nid: ${nid}`);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const ast = gql`{ const ast = gql`{
concernement(id:${nid}) { concernement(id:${nid}) {

View File

@ -40,7 +40,8 @@ export default {
...mapState(ConcernementsStore,['map_mode', ...mapState(ConcernementsStore,['map_mode',
'opened_concernement', 'opened_concernement',
'concernements_loaded', 'concernements_loaded',
'allSuperpositions_clustered']), 'allSuperpositions_clustered',
'concernement_is_updating_nid']),
...mapState(CommonStore,['cartouch_width']), ...mapState(CommonStore,['cartouch_width']),
// //
main_cid_eid () { main_cid_eid () {
@ -203,7 +204,20 @@ export default {
}, },
closeConcernement(){ closeConcernement(){
this.resetConcernementOpened(); // unfocus any active element to trigger recording if needed
document.activeElement.blur();
// setTimeout to let time for editable fields to focus out and record changes
this.waitForUpdatingEnded();
},
waitForUpdatingEnded(){
setTimeout(() => {
if (!this.concernement_is_updating_nid) {
this.resetConcernementOpened();
} else {
this.waitForUpdatingEnded();
}
}, 1);
} }
}, },
components: { components: {