|
|
@@ -11,6 +11,71 @@ var nodes = null; // [ { id: '', label: '' }, ... ]
|
|
|
var edges = null; // [ { id: '', from: '', to: '' }, ... ]
|
|
|
var network = null; // graph object
|
|
|
|
|
|
+function dataMakeNode(params) {
|
|
|
+ var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
|
|
|
+ var nodeId = objectName + '.' + params.primaryKey // TODO: primaryKey?
|
|
|
+ return {
|
|
|
+ id: nodeId,
|
|
|
+ label: makeShortLabel(nodeId), // TODO: get from schema assert @label attribute
|
|
|
+ group: objectName,
|
|
|
+ _loaded: true,
|
|
|
+ typeName: params.typeName,
|
|
|
+ primaryKey: params.primaryKey // TODO: _primaryKey
|
|
|
+ }
|
|
|
+}
|
|
|
+function dataMakeEdge(parentNodeId, nodeObject) {
|
|
|
+ return {
|
|
|
+ id: parentNodeId + nodeObject.id,
|
|
|
+ from: parentNodeId,
|
|
|
+ to: nodeObject.id,
|
|
|
+ }
|
|
|
+}
|
|
|
+function dataMakeXlinkNode(params) {
|
|
|
+ var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
|
|
|
+ var nodeId = params.xlink.substr(params.xlink.indexOf('#') + 1)
|
|
|
+ var primaryKey = nodeId.substr(nodeId.lastIndexOf('.') + 1)
|
|
|
+ return {
|
|
|
+ id: nodeId,
|
|
|
+ label: makeShortLabel(nodeId) + ' (+)',
|
|
|
+ group: objectName,
|
|
|
+ _loaded: false,
|
|
|
+ typeName: params.typeName,
|
|
|
+ primaryKey: primaryKey
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function dataMakeFetchMoreNode(params) {
|
|
|
+ // params = {
|
|
|
+ // parentNodeId: parentNodeId,
|
|
|
+ // type: json.type,
|
|
|
+ // objectName: objectName,
|
|
|
+ // ref: json,
|
|
|
+ // }
|
|
|
+ if(DBG)console.log('DBG dataMakeFetchMoreNode(params)', params)
|
|
|
+ var nodeId = params.parentNodeId+'fetch-more-features-'+params.type+'-on-' + params.objectName;
|
|
|
+ return {
|
|
|
+ id: nodeId,
|
|
|
+ label: 'Pobierz więcej (+)',
|
|
|
+ group: 'fetch-more-data', // params.objectName,
|
|
|
+ _loaded: false,
|
|
|
+ _type: 'ref',
|
|
|
+ parentNodeId: params.parentNodeId,
|
|
|
+ ref: params.ref,
|
|
|
+ // typeName: typeName,
|
|
|
+ // primaryKey: nodeId.substr(nodeId.lastIndexOf('.') + 1)
|
|
|
+ };
|
|
|
+}
|
|
|
+function dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode) {
|
|
|
+ // @param parentNodeId - from node id
|
|
|
+ // @param fetchMoreNode - from dataMakeFetchMoreNode
|
|
|
+ if(DBG)console.log('DBG dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode)', {parentNodeId:parentNodeId, fetchMoreNode:fetchMoreNode})
|
|
|
+ return {
|
|
|
+ id: fetchMoreNode.id,
|
|
|
+ from: parentNodeId,
|
|
|
+ to: fetchMoreNode.id
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
function _dataUpdatedCallback(data, envelope) {
|
|
|
console.log('refGraph:postal:updated', {data: data, envelope: envelope})
|
|
|
|
|
|
@@ -92,13 +157,23 @@ var subscription = postal.subscribe({
|
|
|
callback: _dataUpdatedCallback
|
|
|
});
|
|
|
|
|
|
+function isP5LinkObject(json) {
|
|
|
+ if ( !('type' in json) || !json['type'] ) return false;
|
|
|
+ if ( !('value' in json) || !json['value'] ) return false;
|
|
|
+ if ( !('@typeName' in json) || !json['@typeName'] ) return false;
|
|
|
+ if ( !('@startIndex' in json) || !json['@startIndex'] ) return false;
|
|
|
+ if ( !('@backRefPK' in json) || !json['@backRefPK'] ) return false;
|
|
|
+ if ( !('@backRefNS' in json) || !json['@backRefNS'] ) return false;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) { // @used global _edgeIdAutoIncrement
|
|
|
var level = level || 0
|
|
|
var parentNodeId = parentNodeId || null
|
|
|
console.log('DBG::_todoGraphData level('+level+')', _todoGraphData);
|
|
|
if(DBG)console.log('DBG::parseResponseRec', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
|
|
|
if (p5Utils__isArray(json)) {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec isArray');
|
|
|
+ if(DBG)console.log('DBG::parseResponseRec isArray', json);
|
|
|
// TODO: create named group
|
|
|
var isXlinkList = (json.length > 0 && p5Utils__isString(json[0]))
|
|
|
json.forEach(function (subJson) {
|
|
|
@@ -108,8 +183,11 @@ function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) {
|
|
|
parseResponseRec(_todoGraphData, subJson, typeName, parentNodeId, level)
|
|
|
}
|
|
|
})
|
|
|
+ } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
|
|
|
+ if(DBG)console.log('DBG::parseResponseRec isP5LinkObject', json);
|
|
|
+ parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
|
|
|
} else if (p5Utils__isObject(json)) {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject');
|
|
|
+ if(DBG)console.log('DBG::parseResponseRec isObject', json);
|
|
|
var objectName = typeName.substr(typeName.indexOf(':') + 1)
|
|
|
var nodeId = objectName + '.' + json.ID // TODO: primaryKey?
|
|
|
{
|
|
|
@@ -150,12 +228,58 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
_todoGraphData[level].edges.push({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
|
|
|
}
|
|
|
}
|
|
|
- } else if (p5Utils__isObject(json)) {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject - fetch more xlink object');
|
|
|
+ } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
|
|
|
+ parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
|
|
|
} else {
|
|
|
if(DBG)console.log('TODO: Not implemented - parseResponseRec:XlinkList is not string and not object');
|
|
|
}
|
|
|
}
|
|
|
+function parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level) {
|
|
|
+ if(DBG)console.log('parseResponseRec isObject and P5Link - fetch more xlink object');
|
|
|
+ console.warn("TODO: parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)", json);
|
|
|
+ // example json: { type: "next",
|
|
|
+ // @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
|
|
|
+ // @backRefPK: "42",
|
|
|
+ // @typeName: "default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_P…ow:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row",
|
|
|
+ // @startIndex: "10" }
|
|
|
+ if (!parentNodeId) throw "Missing parentNodeId for ref link object";
|
|
|
+ var objectName = typeName.substr(typeName.indexOf(':') + 1)
|
|
|
+ {
|
|
|
+ // _graphData.nodes.add({ id: nodeId, label: nodeId })
|
|
|
+ if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
|
|
|
+ switch (json.type) {
|
|
|
+ case 'next': {
|
|
|
+ if(DBG)console.log('TODO: next "'+json.type+'" - fetch more xlink object');
|
|
|
+ // var nodeId = 'fetch-more-features-'+json.type+'-on-' + objectName;
|
|
|
+ // _todoGraphData[level].nodes.push({
|
|
|
+ // id: nodeId,
|
|
|
+ // label: 'Pobierz więcej (+)',
|
|
|
+ // group: objectName,
|
|
|
+ // _loaded: false,
|
|
|
+ // _type: 'ref',
|
|
|
+ // parentNodeId: parentNodeId,
|
|
|
+ // ref: json,
|
|
|
+ // // typeName: typeName,
|
|
|
+ // // primaryKey: nodeId.substr(nodeId.lastIndexOf('.') + 1)
|
|
|
+ // })
|
|
|
+ // // _graphData.edges.add({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
|
|
|
+ // _todoGraphData[level].edges.push({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
|
|
|
+
|
|
|
+ var nodeObject = dataMakeFetchMoreNode({
|
|
|
+ parentNodeId: parentNodeId,
|
|
|
+ type: json.type,
|
|
|
+ objectName: objectName,
|
|
|
+ ref: json,
|
|
|
+ })
|
|
|
+ _todoGraphData[level].nodes.push(nodeObject)
|
|
|
+ _todoGraphData[level].edges.push(dataMakeFetchMoreEdge(parentNodeId, nodeObject))
|
|
|
+ } break;
|
|
|
+ default: {
|
|
|
+ if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject with type "'+json.type+'" - fetch more xlink object');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
|
|
|
function refGraphFetchChildrens() {
|