Skip to content

Commit cb7a6a9

Browse files
committed
add a store attribute node
1 parent 92a9eb3 commit cb7a6a9

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/js/modules/common_evaluators/evaluator_nodes_templates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { mathDataCompare } from "./templates/math_data_compare.js";
1313
import { readRelations } from "./templates/data_read_relations.js";
1414
import { settingsNodeColors as nodeColors} from "./templates/settings_node_colors.js";
1515
import { deriveRelations, extractRelations } from "./templates/data_derive_relations.js";
16+
import { storeAttribute } from "./templates/attribute_store_attribute.js";
1617

1718

1819
var getProp = function(props,propName, data){
@@ -29,6 +30,7 @@ var evaluatorTemplates = {}
2930

3031

3132
evaluatorTemplates.filter = filter
33+
evaluatorTemplates.storeAttribute = storeAttribute
3234
evaluatorTemplates.readAttribute = readAttribute
3335
evaluatorTemplates.mathDataCompare = mathDataCompare
3436
evaluatorTemplates.readRelations = readRelations
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { settingsNodeColors as nodeColors } from "./settings_node_colors.js"
2+
3+
export var storeAttribute = {
4+
templateName : "storeAttribute",
5+
name : "Store Attribute",
6+
style:{
7+
headerColor:nodeColors.inputObject,
8+
},
9+
category:"attribute",
10+
11+
props :[
12+
{id:"output", expect:"data", label:"output", type:"hidden", editable:false, socket:"output", value:"output"},
13+
// {id:"paramName", expect:"text", label:"Param Name", type:"text", editable:true, socket:"input", value:"...."},
14+
// {id:"paramIndex", expect:"text", label:"Param Name", type:"text", editable:true, socket:"input", value:"...."},
15+
{id:"a", expect:"data", label:"Data", type:"text", editable:true, socket:"input", value:"0"},
16+
// {id:"selection", expect:"array", label:"Selection", type:"hidden", editable:false, socket:"input", value:"...."},
17+
{id:"attributeName", expect:"text", label:"Name", type:"text", editable:true, socket:"input", value:"Attribue"},
18+
{id:"attribute", expect:"array", label:"Attribute", type:"hidden", editable:false, socket:"input", value:"...."},
19+
],
20+
methods:{
21+
},
22+
event:{
23+
onEvaluate:(props, globals) =>{
24+
25+
if (Array.isArray(props.a.get()) && props.a.get()[0] && props.a.get()[0].attributes.type) {
26+
var oldDataSet = props.a.get()
27+
var newDataSet = []
28+
for (let i = 0; i < oldDataSet.length; i++) {
29+
const element = oldDataSet[i];
30+
// var condition = props.selection.get(element) //TODO read condition
31+
// console.log(condition);
32+
// // alert("eee")
33+
// if (condition == 1) {
34+
// newDataSet.push(element)
35+
// }
36+
if (Array.isArray(props.attribute.get()) && props.attribute.get()[i]) { //if is an array
37+
if (props.attribute.get()[i].relations) { //if field is type relation
38+
element.attributes[props.attributeName.get()] = props.attribute.get()[i].relations
39+
}else{
40+
element.attributes[props.attributeName.get()] = props.attribute.get()[i]
41+
}
42+
43+
}
44+
45+
newDataSet.push(element)
46+
}
47+
props.output.set(newDataSet)
48+
}
49+
},
50+
// onInit:(props) =>{
51+
// },
52+
},
53+
}

src/js/modules/common_evaluators/templates/data_derive_relations.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export var deriveRelations = {
4040
for (let i = 0; i < relationFieldToDerive.length; i++) {
4141
const relationsToDerive = relationFieldToDerive[i].relations;
4242
var localField = []
43+
var localFieldNonSeparated = []
4344
for (let j = 0; j < relationsToDerive.length; j++) {
4445

4546
const relations = relationsToDerive[j];
@@ -58,18 +59,22 @@ export var deriveRelations = {
5859
var relationSource = instancesRepo.getById(relation.from)
5960
targetsOfRelation.push(relationSource)
6061
relatedRelation.push({displayAs:"relation", relation:relation, direction:"incoming", callback:(id)=>showPopupInstancePreview(id), target:relationSource})
62+
localFieldNonSeparated.push({displayAs:"relation", relation:relation, direction:"incoming", callback:(id)=>showPopupInstancePreview(id), target:relationSource})
6163
}else if (relation.type == props.method.getOptionId() ) {
6264
var relationTarget = instancesRepo.getById(relation.to)
6365
targetsOfRelation.push(relationTarget)
6466
relatedRelation.push({displayAs:"relation", relation:relation, direction:"outgoing", callback:(id)=>showPopupInstancePreview(id), target:relationTarget})
67+
localFieldNonSeparated.push({displayAs:"relation", relation:relation, direction:"outgoing", callback:(id)=>showPopupInstancePreview(id), target:relationTarget})
6568
}
6669

6770

6871
}
6972
console.log(relatedRelation);
70-
localField.push(relatedRelation)
73+
localField.push(relatedRelation) //TODO choose between concat and push
74+
// localField.push(localFieldNonSeparated)
7175
}
72-
outputField.push({relations:localField})
76+
// outputField.push({relations:localField})
77+
outputField.push({relations:localFieldNonSeparated})//TODO choose between concat and push
7378
}
7479
console.log(outputField);
7580
props.output.set(outputField)

0 commit comments

Comments
 (0)