Skip to content

Commit

Permalink
add types to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
shuart committed Mar 16, 2024
1 parent 4e34922 commit 9a73a11
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 8 deletions.
99 changes: 99 additions & 0 deletions src/js/modules/common_add_editors/common_attributes_add_editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

import createEntityManagement from "../common_project_management/entity_management.js";
import createInstancesManagement from "../common_project_management/instances_management.js";
import createPropertyManagement from "../common_project_management/properties_management.js";
import createDialogue from "../common_select_dialogue/common_dialogue.js";
import { createEntitiesSelectionOptions } from "../common_selectors/entities_selector.js";
import { createPropertiesSelectionOptions } from "../common_selectors/properties_selector.js";

var uuidFromSelection = function(data){
if (data && data[0]) {
return data.map(i=>i.uuid)
}else{
return []
}
}

function createAttributesTypeOptions(allowedList) {
var repo = createPropertyManagement()
var attributesTypes = repo.getPropertiesTypesList()


var options =[]
for (let i = 0; i < attributesTypes.length; i++) {
const e = attributesTypes[i];
if (allowedList) {
if (allowedList.includes(e.uuid)) {
options.push({name:e.name, uuid:e.uuid, iconPath:e.iconPath, color:e.color})
}
}else{
options.push({name:e.name, uuid:e.uuid, iconPath:e.iconPath, color:e.color})
}

}

return options
}

export function createAttributesAddEditor(entitiesID,name, callback) {
//OPTIONS
var options = createAttributesTypeOptions(entitiesID)
// var propertiesOptions = createPropertiesSelectionOptions()
//DEFAULTS
// var useNodes = comp.renderSettings?.useNodes || false
// var relationsToDisplay = comp.renderSettings?.relationsToDisplay || []
// var entitiesToDisplay = comp.renderSettings?.entitiesToDisplay || []
// var propertiesToDisplay = comp.renderSettings?.fieldsToDisplay || []
//DIALOGUE
createDialogue({
header:"Add element",
fields:[
// {type:"boolean", name:"useNodes",config:{
// label:"Use Nodes",
// value:useNodes,
// }
// },
{type:"text", name:"name",config:{
label:"New Element Name",
confirmOnEnter:true,
value:"New Attribute",
autofocus:true,
}
},
{type:"selection", name:"entitiesType", config:{
multipleSelection:false,
label:"Element type",
list: options,
selected:["text"],
}
},
// {type:"selection", name:"propertiesToDisplay", config:{
// multipleSelection:true,
// label:"Properties to Display",
// list: propertiesOptions,
// selected:propertiesToDisplay,
// }
// },
// {type:"graph", name:"graph", config:{
// multipleSelection:true,
// label:"Show Relations With",
// list: options,
// selected:relationsToDisplay,
// }
// },
],
onConfirm:(result)=>{
console.log(result);

var attributeRepo = createPropertyManagement()
var payload={name:result.name, type:result.entitiesType[0].uuid, iconPath:result.entitiesType[0].iconPath}
attributeRepo.add(payload)

if (callback) {
callback(payload)
}

}
})

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@

import createEntityManagement from "../common_project_management/entity_management.js";
import createInstancesManagement from "../common_project_management/instances_management.js";
import createPropertyManagement from "../common_project_management/properties_management.js";
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";

var uuidFromSelection = function(data){
if (data && data[0]) {
return data.map(i=>i.uuid)
}else{
return []
}
}

export function renderNotebookAttribute(attributeId,currentValue,bearingEntityId, callback){
// var attRepo= createPropertyManagement()
// var att = attRepo.getById(attributeId)
if (!currentValue) {
currentValue = "_"
}
var domEl = document.createElement("div")
domEl.innerHTML=`<div>${currentValue}</div>`
domEl.addEventListener('click', function (event) {
createNotebookAttributeEditor(attributeId,currentValue,bearingEntityId, callback)
if (callback) {
callback()
}
})
return domEl
}

function createTextAreaEditor(domElement) {
var editor = textArea.instance()
editor.showExplorer = false;
editor.showMenu = false;
if (currentInstance.attributes.desc) {
editor.defaultValue= JSON.parse(currentInstance.attributes.desc)

}

editor.onSave=(json,editor, currentDoc)=>{
changeDescription(event, data, instance, json)
}

editor.mentionsDefs= [
{name:"hashtag", key:"#", attributes:["id", "tag"], attributeToDisplay:'tag'},
// {name:"mention", key:"@", attributes:["name", "id","email"], attributeToDisplay:'name'},
// {name:"arrow", key:"->", attributes:["id","tag"], attributeToDisplay:'tag'},
]
editor.mentionsCallback={
// "arrow": (e,view)=> console.log(e),
"hashtag": (e,view)=> {
console.log(e);
showPopupInstancePreview(e.originalTarget.dataset.hashtagId);
},
// "mention": (e,view)=> console.log(e),
}
editor.mentionsOptions ={
// "arrow": [{id:1,tag: '-> abc'}, {id:2,tag: '-> 123'},],
"hashtag": setCurrentTags(),
// "mention": [{name: 'John Doe', id: '101', email: 'joe@abc.com'}, {name: 'Joe Lewis', id: '102', email: 'lewis@abc.com'}],
}

// instance.query(".textEditorArea").append(editor)

}

export function createNotebookAttributeEditor(attributeId,currentValue,bearingEntityId, callback) {
//OPTIONS
// var options = createEntitiesSelectionOptions()
// var propertiesOptions = createPropertiesSelectionOptions()
//DEFAULTS
// var useNodes = comp.renderSettings?.useNodes || false
// var relationsToDisplay = comp.renderSettings?.relationsToDisplay || []
// var entitiesToDisplay = comp.renderSettings?.entitiesToDisplay || []
// var propertiesToDisplay = comp.renderSettings?.fieldsToDisplay || []
//DIALOGUE
if (currentValue == "_") {
currentValue=""
}
createDialogue({
header:"Edit Notebook",
fields:[
// {type:"boolean", name:"useNodes",config:{
// label:"Use Nodes",
// value:useNodes,
// }
// },
{type:"text", name:"text",config:{
label:"Property Name",
value:currentValue,
autofocus:true,
}
},
// {type:"selection", name:"entitiesToDisplay", config:{
// multipleSelection:true,
// label:"Entities to Display",
// list: options,
// selected:entitiesToDisplay,
// }
// },
// {type:"selection", name:"propertiesToDisplay", config:{
// multipleSelection:true,
// label:"Properties to Display",
// list: propertiesOptions,
// selected:propertiesToDisplay,
// }
// },
// {type:"graph", name:"graph", config:{
// multipleSelection:true,
// label:"Show Relations With",
// list: options,
// selected:relationsToDisplay,
// }
// },
],
onRender:(domElem)=>{
alert("fff")
domElem.innerHTML("fefsffesfes")
} ,
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
@@ -1,10 +1,12 @@
import { renderNameAttribute } from "./common_name_attribute_editor.js"
import { renderNotebookAttribute } from "./common_notebook_attribute_editor.js"
import { renderTextAttribute } from "./common_text_attribute_editor.js"

export var getAttributeRenderer = function (type) {
var table={
text:renderTextAttribute,
name:renderNameAttribute,
notebook:renderNotebookAttribute,
}

return table[type]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,33 @@ var propertyAggregate = function(aggregate, projectStore){
return aggregate
}

var customRepoMethods = function (projectStore,createAggregate) {
var repo = {}
repo.getPropertiesTypes = function () {
return {
"text":{name:"Text", uuid:"text", iconPath:"text.svg"},
"notebook":{name:"Notebook", uuid:"notebook", iconPath:"book-text.svg"},
"choice":{name:"Choices", uuid:"choice", iconPath:"list-todo.svg"}
}
}
repo.getPropertiesTypesList=function () {
var list= []
var objElement = repo.getPropertiesTypes()
for (const key in objElement) {
if (Object.hasOwnProperty.call(objElement, key)) {
list.push(objElement[key]);

}
}
return list
}


return repo
}

var createPropertyManagement = function () {
return createRepoManagement(projectManagement.getCurrent().id, 'properties', propertyAggregate)
return createRepoManagement(projectManagement.getCurrent().id, 'properties', propertyAggregate,customRepoMethods)
}

export default createPropertyManagement
6 changes: 6 additions & 0 deletions src/js/modules/common_select_dialogue/common_dialogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ 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) {
var domElem = containerPopup.query(".main_popup_menu_area")
params.onRender(domElem)
}

}

Expand Down
16 changes: 10 additions & 6 deletions src/js/modules/common_settings/model_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createSimpleSummaryPageForEntities } from "../common_quick_settings/com
import { createAttributeSettingsTable } from "./settings_tables/attributes_table.js";
import { createRelationsSettingsTable } from "./settings_tables/relations_table.js";
import { createEntitiesSettingsTable } from "./settings_tables/entities_table.js";
import { createAttributesAddEditor } from "../common_add_editors/common_attributes_add_editor.js";
// import createViewManagement from "../common_project_management/view_management.js";

var getCurrentUser = function(){
Expand All @@ -25,14 +26,17 @@ var getCurrentProject = function(){
var addEntityToProject = function(event, data, instance){
var projectId = projectManagement.getCurrent().id
console.log(projectId)
var name= prompt("Name")
if (name) {
if (data.modelElementType == "attributes") {
data.modelElementType = "properties"
if (data.modelElementType="attributes") {
// data.modelElementType = "properties"
createAttributesAddEditor()
}else{
var name= prompt("Name")
if (name) {
projectManagement.getProjectStore(projectId,data.modelElementType).add({name:name ,theTime:Date.now()})
// instance.getNodes().table.do.softUpdate()
}
projectManagement.getProjectStore(projectId,data.modelElementType).add({name:name ,theTime:Date.now()})
// instance.getNodes().table.do.softUpdate()
}

// instance.update()
}
var getItemsList = function (data, instance){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ export function createAttributeSettingsTable (projectId) {
for (let i = 0; i < list.length; i++) {
const attribute = list[i];
attribute.assignedTo=[]
attribute.isOfType=[]
for (let j = 0; j < entities.length; j++) {
const entity = entities[j];
console.log(entity);
console.log(attribute);
if (entity.attributes['prop_'+attribute.uuid]) {
attribute.assignedTo.push(entity)
}

}
if (attribute.attributes.iconPath) {
attribute.iconPath = attribute.attributes.iconPath
}
if (attribute.attributes['type']) {
var typeObject = propRepo.getPropertiesTypes()[ attribute.attributes['type'] ]
if (typeObject) {
attribute.isOfType.push(typeObject)
}
}

}
console.log(list);

Expand All @@ -68,6 +75,13 @@ export function createAttributeSettingsTable (projectId) {
}
}
},
{title:"Type", customTags:true, field:"isOfType",
// cellClick:(e,cell)=>showEntitiesSelector({
// selected : cell.getData()["assignedTo"].map(d=>d.uuid),
// onChange: (e,f)=> changeAssignedItems(cell.getData().uuid, f.added, f.removed)
// }),
// callback :(id)=>state_manager.goTo("/:/settings/details/entities/"+id)
},
{title:"Assigned To", customObjects:true, field:"assignedTo",
cellClick:(e,cell)=>showEntitiesSelector({
selected : cell.getData()["assignedTo"].map(d=>d.uuid),
Expand Down
Loading

0 comments on commit 9a73a11

Please sign in to comment.