Skip to content

Commit

Permalink
Merge pull request #198 from netcreateorg/dev-bl/flatten
Browse files Browse the repository at this point in the history
Flattened Data
  • Loading branch information
benloh committed Mar 9, 2022
2 parents bf656b2 + a34e319 commit be7f7e7
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 166 deletions.
6 changes: 3 additions & 3 deletions build/app/assets/templates/_default.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ hidden = false

[nodeDefs.id]
type = "number"
displayLabel = "id"
displayLabel = "Id"
exportLabel = "ID"
help = "System-generated unique id number"

[nodeDefs.label]
type = "string"
displayLabel = "label"
displayLabel = "Label"
exportLabel = "Label"
help = "Display name of the node"
includeInGraphTooltip = true
Expand Down Expand Up @@ -101,7 +101,7 @@ hidden = false

[edgeDefs.id]
type = "number"
displayLabel = "id"
displayLabel = "Id"
exportLabel = "ID"
help = "System-generated unique id number"

Expand Down
12 changes: 11 additions & 1 deletion build/app/unisys/server-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ function m_MigrateJSONtoTOML(JSONtemplate) {
label: o.label,
color: o.color
}
})
});
// make sure field type is set to "select" -- older templates do not set type
nodeDefs[k].type = 'select';
console.log(PR,'...migrating nodeDefs field', k,'with options, forcing type to "select"')
nodeDefs[k].options = options;
}
})
Expand Down Expand Up @@ -225,6 +228,10 @@ function m_MigrateJSONtoTOML(JSONtemplate) {
exportLabel: field.label,
help: field.help,
hidden: field.hidden || false // default to not hidden
// If necessary, user can edit template to hide it again.
// We want it visible by default, because of migrations
// the original field may not be defined.
// e.g. orig template uses "Relationship" not "type"
}
if (k === 'type') {
// special handling for type options
Expand All @@ -234,6 +241,9 @@ function m_MigrateJSONtoTOML(JSONtemplate) {
color: o.color
}
})
// make sure field type is set to "select" -- older templates do not set type
edgeDefs[k].type = 'select';
console.log(PR,'...migrating edgeDefs field', k,'with options, forcing type to "select"')
edgeDefs[k].options = options;
}
})
Expand Down
44 changes: 20 additions & 24 deletions build/app/view/netcreate/components/EdgeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class EdgeEditor extends UNISYS.Component {
formData: { // Holds the state of the form fields
sourceId: '',
targetId: '',
relationship: '',
type: '',
info: '',
notes: '',
citation: '',
Expand Down Expand Up @@ -329,7 +329,7 @@ class EdgeEditor extends UNISYS.Component {
formData: {
sourceId: '',
targetId: '',
relationship: '',
type: '',
info: '',
notes: '',
citation: '',
Expand Down Expand Up @@ -415,13 +415,11 @@ class EdgeEditor extends UNISYS.Component {
source: parseInt(sourceNodes[0].id), // REVIEW: d3data 'source' is id, rename this to 'sourceId'?
// though after d3 processes, source does become an object.
target: undefined,
attributes: {
Relationship: '',
Info: '',
Citations: '',
Category: '',
Notes: ''
}
type: '',
notes: '',
info: '',
citation: '',
category: ''
}
// Expand this EdgeEditor and set it to Edit mode.
this.setState({
Expand Down Expand Up @@ -466,11 +464,11 @@ class EdgeEditor extends UNISYS.Component {
id: parseInt(edge.id) || '',
sourceId: edge.source,
targetId: edge.target,
relationship: edge.attributes["Relationship"] || '', // Make sure there's valid data
info: edge.attributes["Info"] || '',
citation: edge.attributes["Citations"] || '',
category: edge.attributes["Category"] || '',
notes: edge.attributes["Notes"] || '',
type: edge.type || '', // Make sure there's valid data
info: edge.info || '',
citation: edge.citation || '',
category: edge.category || '',
notes: edge.notes || '',
isNewEdge: false
},
sourceNode: sourceNode,
Expand Down Expand Up @@ -796,7 +794,7 @@ class EdgeEditor extends UNISYS.Component {
/*/
/*/ onRelationshipChange (event) {
let formData = this.state.formData;
formData.relationship = event.target.value;
formData.type = event.target.value;
this.setState({formData: formData});
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -840,13 +838,11 @@ class EdgeEditor extends UNISYS.Component {
source: this.state.sourceNode.id, // REVIEW: d3data 'source' is id, rename this to 'sourceId'?
// though after d3 processes, source does become an object.
target: this.state.targetNode.id, // REVIEW: d3data 'target' is id, rename this to 'targetId'?
attributes: {
Relationship: formData.relationship,
Info: formData.info,
Citations: formData.citation,
Category: formData.category,
Notes: formData.notes
}
type: formData.type,
info: formData.info,
citation: formData.citation,
category: formData.category,
notes: formData.notes
}
if (DBG) console.group('EdgeEntry.onSubmit submitting',edge)

Expand Down Expand Up @@ -937,7 +933,7 @@ class EdgeEditor extends UNISYS.Component {
style={{ backgroundColor: "#a9d3ff", borderColor: 'transparent', width: '100%', marginBottom: '3px', textAlign: "left", overflow: "hidden" }}
onClick={this.onEdgeClick}
>{parentNodeLabel === sourceNode.label ? me : sourceNode.label}
&nbsp;<span title={formData.relationship}>&#x2794;</span>&nbsp;
&nbsp;<span title={formData.type}>&#x2794;</span>&nbsp;
{parentNodeLabel === targetNode.label ? me : targetNode.label}
</Button>
</div>
Expand Down Expand Up @@ -988,7 +984,7 @@ class EdgeEditor extends UNISYS.Component {
</Col>
<Col sm={9}>
<Input type="select" name="relationship"
value={formData.relationship}
value={formData.type}
onChange={this.onRelationshipChange}
disabled={!this.state.isBeingEdited}
>
Expand Down
49 changes: 35 additions & 14 deletions build/app/view/netcreate/components/EdgeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class EdgeTable extends UNISYS.Component {
return undefined;
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ DEPRECATED -- 'attributes' is no longer being used
/*/ sortByAttribute (edges, key) {
if (edges) {
return edges.sort( (a,b) => {
Expand All @@ -230,9 +230,30 @@ class EdgeTable extends UNISYS.Component {
}
return undefined;
}

/// ---
sortByUpdated(edges) {
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ sortByKey (edges, key) {
if (edges) {
return edges.sort( (a,b) => {
let akey = a[key],
bkey = b[key];
if (akey<bkey) return -1*Number(this.sortDirection);
if (akey>bkey) return 1*Number(this.sortDirection);
if (akey===bkey) {
// Secondary sort on Source label
let source_a = a.source.label;
let source_b = b.source.label;
if (source_a<source_b) return -1*Number(this.sortDirection);
if (source_a>source_b) return 1*Number(this.sortDirection);
}
return 0;
});
}
return undefined;
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ sortByUpdated(edges) {
if (edges) {
return edges.sort( (a,b) => {
let akey = (a.meta.revision > 0 ? a.meta.updated : a.meta.created),
Expand All @@ -258,23 +279,23 @@ class EdgeTable extends UNISYS.Component {
return this.sortByTargetLabel(edges);
break;
case 'Info':
return this.sortByAttribute(edges, 'Info');
return this.sortByKey(edges, 'info');
break;
case 'Notes':
return this.sortByAttribute(edges, 'Notes');
return this.sortByKey(edges, 'notes');
break;
case 'Category':
return this.sortByAttribute(edges, 'Category');
return this.sortByKey(edges, 'category');
break;
case 'Citations':
return this.sortByAttribute(edges, 'Citations');
return this.sortByKey(edges, 'citation');
break;
case 'Updated':
return this.sortByUpdated(edges);
break;
case 'Relationship':
default:
return this.sortByAttribute(edges, 'Relationship');
return this.sortByKey(edges, 'type');
break;
}
}
Expand Down Expand Up @@ -472,16 +493,16 @@ class EdgeTable extends UNISYS.Component {
<td hidden={!DBG}>{edge.source.id}</td>
<td><a href="#" onClick={(e)=>this.selectNode(edge.source.id,e)}
>{edge.source.label || edge.source}</a></td>
<td>{edge.attributes["Relationship"]}</td>
<td>{edge.type}</td>
<td hidden={!DBG}>{edge.target.id}</td>
<td><a href="#" onClick={(e)=>this.selectNode(edge.target.id,e)}
>{edge.target.label || edge.target}</a></td>
<td hidden={edgeDefs.category.hidden}>{edge.attributes["Category"]}</td>
<td hidden={edgeDefs.citation.hidden}>{edge.attributes["Citations"]}</td>
<td hidden={edgeDefs.category.hidden}>{edge.category}</td>
<td hidden={edgeDefs.citation.hidden}>{edge.citation}</td>
<td hidden={edgeDefs.notes.hidden}>
{edge.attributes["Notes"] ? <MarkdownNote text={edge.attributes["Notes"]} /> : "" }
{edge.notes ? <MarkdownNote text={edge.notes} /> : "" }
</td>
<td hidden={edgeDefs.info.hidden}>{edge.attributes["Info"]}</td>
<td hidden={edgeDefs.info.hidden}>{edge.info}</td>
<td hidden={!isLocalHost}>{this.displayUpdated(edge)}</td>
</tr>
))}
Expand Down
8 changes: 4 additions & 4 deletions build/app/view/netcreate/components/NodeDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class NodeDetail extends UNISYS.Component {
let node = hilitedNode || {};
node.attributes = node.attributes || {}; // validate attributes
this.setState({
label : node.label,
type : node.attributes["Node_Type"], // HACK This needs to be updated when
info : node.attributes["Extra Info"], // the data format is updated
notes : node.attributes["Notes"] // These were bad keys from Fusion Tables.
label: node.label,
type: node.type,
info: node.info,
notes: node.notes
});
} // handleSelection

Expand Down
27 changes: 13 additions & 14 deletions build/app/view/netcreate/components/NodeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,19 @@ class NodeSelector extends UNISYS.Component {
if (isNaN(newNode.id)) { newNode.id = parseInt(newNode.id); }
//
node.label = newNode.label || '';
node.id = newNode.id || '';
node.attributes["Node_Type"] = newNode.attributes["Node_Type"] || '';
node.attributes["Extra Info"] = newNode.attributes["Extra Info"] || '';
node.attributes["Notes"] = newNode.attributes["Notes"] || '';
node.id = newNode.id || '';
node.type = newNode.type;
node.info = newNode.info;
node.notes = newNode.notes;

// Copy to form
this.releaseOpenEditor();
this.setState({
formData: {
label: node.label,
type: node.attributes["Node_Type"], // HACK This needs to be updated when
info: node.attributes["Extra Info"], // the data format is updated
notes: node.attributes["Notes"], // These were bad keys from Fusion Tables.
label: node.label,
type: node.type,
info: node.info,
notes: node.notes,
id: node.id,
isNewNode: false
},
Expand Down Expand Up @@ -915,12 +916,10 @@ class NodeSelector extends UNISYS.Component {
let formData = this.state.formData;
let node = {
label : formData.label?formData.label:'',
id : formData.id,
attributes: {
'Node_Type' : formData.type,
'Extra Info' : formData.info,
'Notes' : formData.notes
}
id: formData.id,
type: formData.type,
info: formData.info,
notes: formData.notes
};
this.releaseOpenEditor();
this.setState({ isBeingEdited: false });
Expand Down
35 changes: 24 additions & 11 deletions build/app/view/netcreate/components/NodeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class NodeTable extends UNISYS.Component {
return 0;
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ DEPRECATED -- 'attributes' is no longer being used
/*/ sortByAttribute (nodes, key) {
if (nodes) {
return nodes.sort( (a,b) => {
Expand All @@ -219,7 +219,20 @@ class NodeTable extends UNISYS.Component {
}
return 0;
}

/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ sortByKey (nodes, key) {
if (nodes) {
return nodes.sort( (a,b) => {
let akey = a[key],
bkey = b[key];
if (akey<bkey) return -1*Number(this.sortDirection);
if (akey>bkey) return 1*Number(this.sortDirection);
return 0;
});
}
return 0;
}
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*/
/*/ sortByUpdated(nodes) {
Expand Down Expand Up @@ -247,15 +260,15 @@ class NodeTable extends UNISYS.Component {
return this.sortByEdgeCount(nodes);
break;
case 'type':
return this.sortByAttribute(nodes, 'Node_Type');
return this.sortByKey(nodes, 'type');
break;
case 'notes':
return this.sortByAttribute(nodes, 'Notes');
return this.sortByKey(nodes, 'notes');
break;
case 'info':
return this.sortByAttribute(nodes, 'Extra Info');
return this.sortByKey(nodes, 'info');
break;
case 'Updated':
case 'updated':
return this.sortByUpdated(nodes);
break;
case 'label':
Expand Down Expand Up @@ -387,8 +400,8 @@ render() {
onClick={()=>this.setSortKey("notes")}
>{nodeDefs.notes.displayLabel} {this.sortSymbol("notes")}</Button></th>
<th width="10%"hidden={!isLocalHost}><Button size="sm"
onClick={()=>this.setSortKey("Updated")}
>Updated {this.sortSymbol("Updated")}</Button></th>
onClick={()=>this.setSortKey("updated")}
>Updated {this.sortSymbol("updated")}</Button></th>
</tr>
</thead>
<tbody style={{maxHeight: tableHeight}}>
Expand All @@ -407,10 +420,10 @@ render() {
<td>{node.degrees}</td>
<td><a href="#" onClick={(e)=>this.selectNode(node.id,e)}
>{node.label}</a></td>
<td hidden={nodeDefs.type.hidden}>{node.attributes["Node_Type"]}</td>
<td hidden={nodeDefs.info.hidden}>{node.attributes["Extra Info"]}</td>
<td hidden={nodeDefs.type.hidden}>{node.type}</td>
<td hidden={nodeDefs.info.hidden}>{node.info}</td>
<td hidden={nodeDefs.notes.hidden}>
{node.attributes["Notes"] ? <MarkdownNote text={node.attributes["Notes"]} /> : "" }
{node.notes ? <MarkdownNote text={node.notes} /> : "" }
</td>
<td hidden={!isLocalHost}>{this.displayUpdated(node)}</td>
</tr>
Expand Down
Loading

0 comments on commit be7f7e7

Please sign in to comment.