From b0377aabd0d3d2e6026ec3bac9ab101740e7e3a6 Mon Sep 17 00:00:00 2001 From: stephane Huart Date: Sat, 16 Mar 2024 22:32:37 +0100 Subject: [PATCH] improve notebook preview field --- .../common_notebook_attribute_editor.js | 115 ++++++++++++------ .../common_render_attributes.js | 2 +- .../common_select_dialogue/common_dialogue.js | 4 +- .../instance_card/instance_card.js | 3 +- .../textEditor.js/textArea.js | 3 +- 5 files changed, 81 insertions(+), 46 deletions(-) diff --git a/src/js/modules/common_attributes_editors/common_notebook_attribute_editor.js b/src/js/modules/common_attributes_editors/common_notebook_attribute_editor.js index d90d266..a286391 100644 --- a/src/js/modules/common_attributes_editors/common_notebook_attribute_editor.js +++ b/src/js/modules/common_attributes_editors/common_notebook_attribute_editor.js @@ -5,6 +5,7 @@ import createPropertyManagement from "../common_project_management/properties_ma import createDialogue from "../common_select_dialogue/common_dialogue.js"; import { createPropertiesSelectionOptions } from "../common_selectors/properties_selector.js"; import { textArea } from "../common_ui_components/textEditor.js/textArea.js"; +import showPopupInstancePreview from "../popup_instance_preview/popup_instance_preview.js"; var uuidFromSelection = function(data){ if (data && data[0]) { @@ -14,14 +15,25 @@ var uuidFromSelection = function(data){ } } +function extractSummary(stringifyData) { + var rx = /(?<=\"text\":\").*?(?=\")/s; + + var arr = rx.exec(stringifyData); + return arr[0] +"..."; + } + export function renderNotebookAttribute(attributeId,currentValue,bearingEntityId, callback){ // var attRepo= createPropertyManagement() // var att = attRepo.getById(attributeId) + var valueToDisplay if (!currentValue) { currentValue = "_" + valueToDisplay = "_" + }else{ + valueToDisplay = extractSummary(currentValue) } var domEl = document.createElement("div") - domEl.innerHTML=`
${currentValue}
` + domEl.innerHTML=`
${valueToDisplay}
` domEl.addEventListener('click', function (event) { createNotebookAttributeEditor(attributeId,currentValue,bearingEntityId, callback) if (callback) { @@ -31,17 +43,41 @@ export function renderNotebookAttribute(attributeId,currentValue,bearingEntityId return domEl } -function createTextAreaEditor(domElement) { +var setCurrentTags = function () { + var instancesRepo = createInstancesManagement() + var instances = instancesRepo.getAll() + + return instances.map(i=>({id:i.uuid, tag:i.name})) + } + +function createTextAreaEditor(domElement, currentValue, attributeId, bearingEntityId) { var editor = textArea.instance() editor.showExplorer = false; editor.showMenu = false; - if (currentInstance.attributes.desc) { - editor.defaultValue= JSON.parse(currentInstance.attributes.desc) + // console.log(currentValue); + // var currentInstance = undefined + // if (currentInstance || currentInstance?.attributes?.desc) { + // editor.defaultValue= JSON.parse(currentInstance.attributes.desc) + // } + if (currentValue && currentValue !="" & currentValue !="_") { + editor.defaultValue= JSON.parse(currentValue) } editor.onSave=(json,editor, currentDoc)=>{ - changeDescription(event, data, instance, json) + // changeDescription(event, data, instance, json) + var result = JSON.stringify(json) + console.log(result); + var attRepo= createPropertyManagement() + var att = attRepo.getById(attributeId) + var instancesRepo = createInstancesManagement() + var entity =instancesRepo.getById(bearingEntityId) + console.log(att, entity); + if (att && entity) { + var payload={uuid:bearingEntityId} + payload["prop_"+attributeId] = result + instancesRepo.update(payload) + } } editor.mentionsDefs= [ @@ -63,7 +99,7 @@ function createTextAreaEditor(domElement) { // "mention": [{name: 'John Doe', id: '101', email: 'joe@abc.com'}, {name: 'Joe Lewis', id: '102', email: 'lewis@abc.com'}], } - // instance.query(".textEditorArea").append(editor) + domElement.append(editor) } @@ -88,12 +124,12 @@ export function createNotebookAttributeEditor(attributeId,currentValue,bearingEn // value:useNodes, // } // }, - {type:"text", name:"text",config:{ - label:"Property Name", - value:currentValue, - autofocus:true, - } - }, + // {type:"text", name:"text",config:{ + // label:"Property Name", + // value:currentValue, + // autofocus:true, + // } + // }, // {type:"selection", name:"entitiesToDisplay", config:{ // multipleSelection:true, // label:"Entities to Display", @@ -117,35 +153,34 @@ export function createNotebookAttributeEditor(attributeId,currentValue,bearingEn // }, ], onRender:(domElem)=>{ - alert("fff") - domElem.innerHTML("fefsffesfes") + createTextAreaEditor(domElem,currentValue, attributeId, bearingEntityId) } , - onConfirm:(result)=>{ - console.log(result); - var attRepo= createPropertyManagement() - var att = attRepo.getById(attributeId) - var instancesRepo = createInstancesManagement() - var entity =instancesRepo.getById(bearingEntityId) - console.log(att, entity); - if (att && entity) { - var payload={uuid:bearingEntityId} - payload["prop_"+attributeId] = result.text - instancesRepo.update(payload) - } - // var newConfig = { - // useNodes : result.useNodes, - // entitiesToDisplay : uuidFromSelection(result.entitiesToDisplay), - // fieldsToDisplay : uuidFromSelection(result.propertiesToDisplay), - // relationsToDisplay : result.graph, - // } - // console.log(newConfig); - // if (callback) { - // callback(newConfig) - // } - // var added = [] - // var removed = [] - // var newSelection = result.selection - } + // onConfirm:(result)=>{ + // console.log(result); + // var attRepo= createPropertyManagement() + // var att = attRepo.getById(attributeId) + // var instancesRepo = createInstancesManagement() + // var entity =instancesRepo.getById(bearingEntityId) + // console.log(att, entity); + // if (att && entity) { + // var payload={uuid:bearingEntityId} + // payload["prop_"+attributeId] = result.text + // instancesRepo.update(payload) + // } + // // var newConfig = { + // // useNodes : result.useNodes, + // // entitiesToDisplay : uuidFromSelection(result.entitiesToDisplay), + // // fieldsToDisplay : uuidFromSelection(result.propertiesToDisplay), + // // relationsToDisplay : result.graph, + // // } + // // console.log(newConfig); + // // if (callback) { + // // callback(newConfig) + // // } + // // var added = [] + // // var removed = [] + // // var newSelection = result.selection + // } }) } \ No newline at end of file diff --git a/src/js/modules/common_attributes_editors/common_render_attributes.js b/src/js/modules/common_attributes_editors/common_render_attributes.js index c8ea448..3ecf04e 100644 --- a/src/js/modules/common_attributes_editors/common_render_attributes.js +++ b/src/js/modules/common_attributes_editors/common_render_attributes.js @@ -9,6 +9,6 @@ export var getAttributeRenderer = function (type) { notebook:renderNotebookAttribute, } - return table[type] + return table[type] || renderTextAttribute } \ No newline at end of file diff --git a/src/js/modules/common_select_dialogue/common_dialogue.js b/src/js/modules/common_select_dialogue/common_dialogue.js index 7a1fdbf..af55945 100644 --- a/src/js/modules/common_select_dialogue/common_dialogue.js +++ b/src/js/modules/common_select_dialogue/common_dialogue.js @@ -157,9 +157,7 @@ var createDialogue = function(params){ // choices.push({uuid:element, name:element, isIcon:true, iconPath:element}) // } containerPopup.mount() - console.log(params); - alert(parameters.onRender) - if (parameters.onRender) { + if (params.onRender) { var domElem = containerPopup.query(".main_popup_menu_area") params.onRender(domElem) } diff --git a/src/js/modules/common_ui_components/instance_card/instance_card.js b/src/js/modules/common_ui_components/instance_card/instance_card.js index a2fbda5..4c6611e 100644 --- a/src/js/modules/common_ui_components/instance_card/instance_card.js +++ b/src/js/modules/common_ui_components/instance_card/instance_card.js @@ -38,6 +38,7 @@ var addPropertyList = function (event, data, instance, currentInstance) { var propRepo = createPropertyManagement() var props = propRepo.getAll() var propsToShow=[] + // var propsTypeMapping = propRepo.getPropertiesTypes() for (let i = 0; i < props.length; i++) { var prop = props[i]; @@ -51,7 +52,7 @@ var addPropertyList = function (event, data, instance, currentInstance) { const element = entity.attributes[key]; if (key.substring(5) == prop.uuid) { - var AttributeDomElement = getAttributeRenderer("text")(prop.uuid,currentInstance.attributes[key],currentInstance.uuid, undefined) + var AttributeDomElement = getAttributeRenderer(prop.attributes.type)(prop.uuid,currentInstance.attributes[key],currentInstance.uuid, undefined) propsToShow.push({prop:prop, domElement:AttributeDomElement}) } // //TODO check if ref is still used diff --git a/src/js/modules/common_ui_components/textEditor.js/textArea.js b/src/js/modules/common_ui_components/textEditor.js/textArea.js index 2ebbe13..4848cc0 100644 --- a/src/js/modules/common_ui_components/textEditor.js/textArea.js +++ b/src/js/modules/common_ui_components/textEditor.js/textArea.js @@ -101,6 +101,7 @@ var textArea = createAdler({ padding: 15px; border-color: #363636; box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.1); + position:relative; } .action-writer-save{ position: absolute; @@ -129,7 +130,7 @@ var textArea = createAdler({ display: flex; column-gap: 11px; position: absolute; - top: 0px; + top: -23px; left: 40px; } .prosemirror-top-bar-item{