boussole UI now support new paragraphe and referenced entity title change

This commit is contained in:
Bachir Soussi Chiadmi 2023-02-06 18:13:01 +01:00
parent 3cf5440537
commit 190a8d27f7
2 changed files with 55 additions and 14 deletions

View File

@ -251,6 +251,10 @@
transform: translate(-5px, -5px); transform: translate(-5px, -5px);
cursor:move; cursor:move;
} }
#boussole-layout .boussole-wrapper .boussole .entity.ajax-new{
background-color: #fff;
border: 1px solid black;
}
#boussole-layout .boussole-wrapper .boussole .entity.hide{ #boussole-layout .boussole-wrapper .boussole .entity.hide{
display: none; display: none;
} }

View File

@ -21,8 +21,13 @@
let entities = {}; let entities = {};
[...$form_entities].forEach($entity => { [...$form_entities].forEach($entity => {
console.log($entity); console.log($entity);
let ajax_new_content = $entity.classList.contains('ajax-new-content');
if(ajax_new_content){
// its a new paragraph just added by ajax
$entity = $entity.querySelector(':scope>div');
}
let id = $entity.getAttribute('id'); let id = $entity.getAttribute('id');
let $title = $entity.querySelector('.paragraphs-subform>.field--type-entity-reference.field--name-field-entite td.inline-entity-form-node-label');
let $af = $entity.querySelector('.paragraphs-subform .field--name-field-actuel-future'); let $af = $entity.querySelector('.paragraphs-subform .field--name-field-actuel-future');
let $p = $entity.querySelector('.paragraphs-subform .field--name-field-prise input'); let $p = $entity.querySelector('.paragraphs-subform .field--name-field-prise input');
let $mm = $entity.querySelector('.paragraphs-subform .field--name-field-menace-maintien-degres input'); let $mm = $entity.querySelector('.paragraphs-subform .field--name-field-menace-maintien-degres input');
@ -32,8 +37,8 @@
id: id id: id
}, },
title: { title: {
$dom: $title, $dom: null,
value: $title.textContent value: null
}, },
af: { af: {
$dom: $af, $dom: $af,
@ -48,6 +53,17 @@
value: parseFloat($mm.value) value: parseFloat($mm.value)
} }
} }
// title does not exists when we add an "entité intégrée" as we also have to create the referenced node
let $title = $entity.querySelector('.paragraphs-subform>.field--type-entity-reference.field--name-field-entite td.inline-entity-form-node-label');
if ($title) {
e.title= {
$dom: $title,
value: $title.textContent
};
}
entities[id] = e; entities[id] = e;
}); });
console.log(entities); console.log(entities);
@ -120,18 +136,18 @@
updateCreateEntities(entities){ updateCreateEntities(entities){
// console.log('Class Boussole update entities', entities); // console.log('Class Boussole update entities', entities);
for (const [id, values] of Object.entries(entities)) { for (const [id, values] of Object.entries(entities)) {
// console.log(id, typeof this.entities[id], values); console.log(id, typeof this.entities[id], values);
if (typeof this.entities[id] === 'undefined') { if (typeof this.entities[id] === 'undefined') {
this.entities[id] = new Entity(this.$boussole, id, values); this.entities[id] = new Entity(this.$boussole, id, values);
}else{ }else{
this.entities[id].updateValues(values); this.entities[id].updateValuesFromForm(values);
} }
} }
} }
updateEntities(){ updateEntities(){
for (const [id, entity] of Object.entries(this.entities)) { for (const [id, entity] of Object.entries(this.entities)) {
entity.update(); entity.updatePos();
} }
} }
} }
@ -158,13 +174,31 @@
this.$e = document.createElement('div'); this.$e = document.createElement('div');
this.$e.classList.add('entity'); this.$e.classList.add('entity');
this.$e.setAttribute('id', `${this.id}-boussole-point`); this.$e.setAttribute('id', `${this.id}-boussole-point`);
if (this.values.title.value) {
// the paragraph as an entity referenced
this.$e.setAttribute('title', this.values.title.value); this.$e.setAttribute('title', this.values.title.value);
}else{
// new paragraph with no entity referenced
this.$e.classList.add('ajax-new');
}
this.$container.append(this.$e); this.$container.append(this.$e);
console.log(this.$e); console.log(this.$e);
this.updatePos(); this.updatePos();
this.initDraggable() this.initDraggable()
} }
updateDomElemt(){
if (this.values.title.value) {
// the paragraph as an entity referenced
this.$e.setAttribute('title', this.values.title.value);
this.$e.classList.remove('ajax-new');
}else{
// new paragraph with no entity referenced
this.$e.classList.add('ajax-new');
}
}
initDraggable(){ initDraggable(){
this.$e.setAttribute('draggable', true); this.$e.setAttribute('draggable', true);
this.$e.addEventListener('dragstart', event => { this.$e.addEventListener('dragstart', event => {
@ -193,10 +227,10 @@
dropedOnBoussole(data){ dropedOnBoussole(data){
this.$e.style.left = data.clientX + data.dragging_start_x + 'px'; this.$e.style.left = data.clientX + data.dragging_start_x + 'px';
this.$e.style.top = data.clientY + data.dragging_start_y + 'px'; this.$e.style.top = data.clientY + data.dragging_start_y + 'px';
this.updateValuesFromBoussole(); this.updateFormValuesFromBoussole();
} }
updateValuesFromBoussole(){ updateFormValuesFromBoussole(values){
let compstyle = window.getComputedStyle(this.$e); let compstyle = window.getComputedStyle(this.$e);
// AF // AF
let top = parseInt(compstyle.top); let top = parseInt(compstyle.top);
@ -240,8 +274,16 @@
}) })
} }
updateValuesFromForm(values){
this.values = values;
this.updateDomElemt();
}
updatePos(){ updatePos(){
console.log('update pos'); console.log('update pos');
this.updateSceneSize()
// converte degres to radian, inverse it and rotate it // converte degres to radian, inverse it and rotate it
let a = parseInt((this.values.mm.value) * -1 + 90) * (Math.PI/180); let a = parseInt((this.values.mm.value) * -1 + 90) * (Math.PI/180);
// https://stackoverflow.com/questions/5731863/mapping-a-numeric-range-onto-another // https://stackoverflow.com/questions/5731863/mapping-a-numeric-range-onto-another
@ -268,11 +310,6 @@
this.$e.style.top = top+'px'; this.$e.style.top = top+'px';
} }
update(){
console.log('Entity update');
this.updateSceneSize()
this.updatePos()
}
} }