Skip to content

Commit

Permalink
improve notebook preview field
Browse files Browse the repository at this point in the history
  • Loading branch information
shuart committed Mar 16, 2024
1 parent 9a73a11 commit b0377aa
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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=`<div>${currentValue}</div>`
domEl.innerHTML=`<div>${valueToDisplay}</div>`
domEl.addEventListener('click', function (event) {
createNotebookAttributeEditor(attributeId,currentValue,bearingEntityId, callback)
if (callback) {
Expand All @@ -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= [
Expand All @@ -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)

}

Expand All @@ -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",
Expand All @@ -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
// }
})

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export var getAttributeRenderer = function (type) {
notebook:renderNotebookAttribute,
}

return table[type]
return table[type] || renderTextAttribute

}
4 changes: 1 addition & 3 deletions src/js/modules/common_select_dialogue/common_dialogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +130,7 @@ var textArea = createAdler({
display: flex;
column-gap: 11px;
position: absolute;
top: 0px;
top: -23px;
left: 40px;
}
.prosemirror-top-bar-item{
Expand Down

0 comments on commit b0377aa

Please sign in to comment.