|
@@ -108,6 +108,8 @@ function updateWfsResponse(features, featureTypeName) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+ _todoGraphData = [ { nodes: [], edges: [] } ]; // clear to default values
|
|
|
|
|
+
|
|
|
|
|
|
|
|
var options = _defaultVisJsOptions
|
|
var options = _defaultVisJsOptions
|
|
|
if(DBG)console.log('_graphData', _graphData)
|
|
if(DBG)console.log('_graphData', _graphData)
|
|
@@ -126,57 +128,13 @@ function updateWfsResponse(features, featureTypeName) {
|
|
|
}
|
|
}
|
|
|
var selectedNode = _nodes.get(featureID)
|
|
var selectedNode = _nodes.get(featureID)
|
|
|
if (!selectedNode) return;
|
|
if (!selectedNode) return;
|
|
|
- renderSelectedNode(selectedNode)
|
|
|
|
|
- if (selectedNode._loaded) return;
|
|
|
|
|
- try {
|
|
|
|
|
- var featureEx = featureID.split('.')
|
|
|
|
|
- if (2 !== featureEx.length) throw "Not supported featureID format"
|
|
|
|
|
- var featureTypeName = 'default_db__x3A__' + featureEx[0] + ':' + featureEx[0]
|
|
|
|
|
- var wfsParams = Object.assign({}, _defaultWfsParams, {
|
|
|
|
|
- primaryKey: featureEx[1]
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- var fakeLoadingNodeID = featureID + '-loading'
|
|
|
|
|
- _nodes.add({
|
|
|
|
|
- id: fakeLoadingNodeID,
|
|
|
|
|
- label: 'loading...',
|
|
|
|
|
- })
|
|
|
|
|
- _edges.add({
|
|
|
|
|
- id: fakeLoadingNodeID,
|
|
|
|
|
- from: featureID,
|
|
|
|
|
- to: fakeLoadingNodeID
|
|
|
|
|
- })
|
|
|
|
|
|
|
|
|
|
- // view-source:http://visjs.org/examples/network/data/dynamicData.html
|
|
|
|
|
- _nodes.update({
|
|
|
|
|
- id: featureID,
|
|
|
|
|
- label: makeShortLabel(selectedNode.id)
|
|
|
|
|
- })
|
|
|
|
|
- p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
|
|
- if(DBG)console.log('features', features)
|
|
|
|
|
- if (!features.length || 1 !== features.length) throw "Brak danych" // require 1 feature with recurse
|
|
|
|
|
- var refFields = Object.keys(features[0]).filter(function (fieldName) {
|
|
|
|
|
- return (fieldName.indexOf(':') > -1)
|
|
|
|
|
- }).filter(function (fieldName) {
|
|
|
|
|
- return (features[0][fieldName].length > 0)
|
|
|
|
|
- })
|
|
|
|
|
- if (!refFields.length) return "Brak danych"
|
|
|
|
|
- updateWfsResponse(features, featureTypeName)
|
|
|
|
|
- return "Pobrano nowe dane"
|
|
|
|
|
- }).then(function (msg) {
|
|
|
|
|
- p5UI__notifyAjaxCallback({ type: 'info', msg: msg })
|
|
|
|
|
- _nodes.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
- _edges.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
- _nodes.update({ id: featureID, _loaded: true })
|
|
|
|
|
- }).catch(function (e) {
|
|
|
|
|
- if(DBG)console.warn(e)
|
|
|
|
|
- p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
|
|
- _nodes.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
- _edges.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
- _nodes.update({ id: featureID, _loaded: true })
|
|
|
|
|
- })
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- if(DBG)console.warn(e)
|
|
|
|
|
|
|
+ if ('ref' === selectedNode._type) {
|
|
|
|
|
+ fetchNodeMoreRefs(selectedNode, featureID)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ renderSelectedNode(selectedNode)
|
|
|
|
|
+ if (selectedNode._loaded) return;
|
|
|
|
|
+ fetchNodeRecurse(selectedNode, featureID)
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -232,7 +190,7 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
if(DBG)console.log('DBG::parseResponseRec:XlinkList', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
|
|
if(DBG)console.log('DBG::parseResponseRec:XlinkList', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
|
|
|
if (p5Utils__isString(json)) { // xlink "https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI#BI_audit_ENERGA_RUM_KONTRAHENCI.9233",
|
|
if (p5Utils__isString(json)) { // xlink "https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI#BI_audit_ENERGA_RUM_KONTRAHENCI.9233",
|
|
|
var nodeId = json.substr(json.indexOf('#') + 1)
|
|
var nodeId = json.substr(json.indexOf('#') + 1)
|
|
|
- var objectName = typeName
|
|
|
|
|
|
|
+ var objectName = typeName.substr(typeName.indexOf(':') + 1)
|
|
|
{
|
|
{
|
|
|
// _graphData.nodes.add({ id: nodeId, label: nodeId })
|
|
// _graphData.nodes.add({ id: nodeId, label: nodeId })
|
|
|
if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
|
|
if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
|
|
@@ -250,12 +208,40 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else if (p5Utils__isObject(json)) {
|
|
} else if (p5Utils__isObject(json)) {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject - fetch more xlink object');
|
|
|
|
|
|
|
+ if(DBG)console.log('parseResponseRec isObject - fetch more xlink object');
|
|
|
// example json: { type: "next",
|
|
// example json: { type: "next",
|
|
|
// @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
|
|
// @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
|
|
|
// @backRefPK: "42",
|
|
// @backRefPK: "42",
|
|
|
// @typeName: "default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_P…ow:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row",
|
|
// @typeName: "default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_P…ow:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row",
|
|
|
// @startIndex: "10" }
|
|
// @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 })
|
|
|
|
|
+ } break;
|
|
|
|
|
+ default: {
|
|
|
|
|
+ if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject with type "'+json.type+'" - fetch more xlink object');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// var nodeId = json.substr(json.indexOf('#') + 1)
|
|
// var nodeId = json.substr(json.indexOf('#') + 1)
|
|
|
// var objectName = typeName
|
|
// var objectName = typeName
|
|
@@ -273,6 +259,150 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function fetchNodeMoreRefs(selectedNode, featureID) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!selectedNode) throw "Missing featureID"
|
|
|
|
|
+ if (!featureID) throw "Missing featureID"
|
|
|
|
|
+ var idSelectedNode = selectedNode.id
|
|
|
|
|
+ var idSelectedEdge = selectedNode.parentNodeId + selectedNode.id
|
|
|
|
|
+ var parentNodeId = selectedNode.parentNodeId
|
|
|
|
|
+ var featureTypeName = selectedNode.ref['@typeName']
|
|
|
|
|
+ var backRefNS = selectedNode.ref['@backRefNS']
|
|
|
|
|
+ var backRefPK = selectedNode.ref['@backRefPK']
|
|
|
|
|
+ var backRefField = selectedNode.ref['@typeName']
|
|
|
|
|
+ var startIndex = selectedNode.ref['@startIndex']
|
|
|
|
|
+ _nodes.update({
|
|
|
|
|
+ id: idSelectedNode,
|
|
|
|
|
+ label: "Pobieranie danych..."
|
|
|
|
|
+ })
|
|
|
|
|
+ var wfsParams = {
|
|
|
|
|
+ backRefNS: backRefNS,
|
|
|
|
|
+ backRefPK: backRefPK,
|
|
|
|
|
+ backRefField: backRefField,
|
|
|
|
|
+ startIndex: startIndex,
|
|
|
|
|
+ // count: 3,
|
|
|
|
|
+ };
|
|
|
|
|
+ p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
|
|
+ if(DBG)console.log('features', features)
|
|
|
|
|
+ if (!features.length) throw "Brak danych"
|
|
|
|
|
+ features.forEach(function (feature) {
|
|
|
|
|
+ // TODO: validate
|
|
|
|
|
+ var objectName = featureTypeName.substr(featureTypeName.indexOf(':') + 1)
|
|
|
|
|
+ var nodeId = objectName + '.' + feature.ID // TODO: primaryKey?
|
|
|
|
|
+ _todoGraphData[0].edges.push({ id: parentNodeId + nodeId, from: parentNodeId, to: nodeId })
|
|
|
|
|
+ // _nodes.add({
|
|
|
|
|
+ // id: fakeLoadingNodeID,
|
|
|
|
|
+ // label: 'loading...',
|
|
|
|
|
+ // })
|
|
|
|
|
+ // _edges.add({
|
|
|
|
|
+ // id: parentNodeId + nodeId,
|
|
|
|
|
+ // from: parentNodeId,
|
|
|
|
|
+ // to: nodeId
|
|
|
|
|
+ // })
|
|
|
|
|
+ })
|
|
|
|
|
+ // var refFields = Object.keys(features[0]).filter(function (fieldName) {
|
|
|
|
|
+ // return (fieldName.indexOf(':') > -1)
|
|
|
|
|
+ // }).filter(function (fieldName) {
|
|
|
|
|
+ // return (features[0][fieldName].length > 0)
|
|
|
|
|
+ // })
|
|
|
|
|
+ // if (!refFields.length) return "Brak danych"
|
|
|
|
|
+ // features = features.map(function (feature) {
|
|
|
|
|
+ // return {
|
|
|
|
|
+ // feature
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // console.log('TODO: features: ', features);
|
|
|
|
|
+ // updateWfsResponse(features[0], featureTypeName) // TODO: RMME DBG
|
|
|
|
|
+ // updateWfsResponse(features[1], featureTypeName) // TODO: RMME DBG
|
|
|
|
|
+ // var feature = features[1]
|
|
|
|
|
+ // var nodeId = featureTypeName + '.' + feature['ID']
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // _edges.add({
|
|
|
|
|
+ // id: parentNodeId + nodeId,
|
|
|
|
|
+ // from: parentNodeId,
|
|
|
|
|
+ // to: nodeId
|
|
|
|
|
+ // })
|
|
|
|
|
+ // } catch (e) {
|
|
|
|
|
+ // if(DBG)console.warn('TODO: XXX: ' + e)
|
|
|
|
|
+ // }
|
|
|
|
|
+ if(DBG)console.log('TODO: remove selected after: ', {
|
|
|
|
|
+ idSelectedNode: idSelectedNode,
|
|
|
|
|
+ idSelectedEdge: idSelectedEdge,
|
|
|
|
|
+ })
|
|
|
|
|
+ features.forEach(function (feature) {
|
|
|
|
|
+ updateWfsResponse(feature, featureTypeName)
|
|
|
|
|
+ })
|
|
|
|
|
+ return "Pobrano nowe dane"
|
|
|
|
|
+ }).then(function (msg) {
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'info', msg: msg })
|
|
|
|
|
+ _nodes.remove({ id: idSelectedNode })
|
|
|
|
|
+ _edges.remove({ id: idSelectedEdge })
|
|
|
|
|
+ }).catch(function (e) {
|
|
|
|
|
+ if(DBG)console.warn(e)
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
|
|
+ _nodes.remove({ id: idSelectedNode })
|
|
|
|
|
+ _edges.remove({ id: idSelectedEdge })
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ if(DBG)console.warn(e)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+function fetchNodeRecurse(selectedNode, featureID) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ var selectedNodeId = selectedNode.id
|
|
|
|
|
+ if (!selectedNode) throw "Missing featureID"
|
|
|
|
|
+ if (!featureID) throw "Missing featureID"
|
|
|
|
|
+ var featureEx = featureID.split('.')
|
|
|
|
|
+ if (2 !== featureEx.length) throw "Not supported featureID format"
|
|
|
|
|
+ var featureTypeName = 'default_db__x3A__' + featureEx[0] + ':' + featureEx[0]
|
|
|
|
|
+ var wfsParams = Object.assign({}, _defaultWfsParams, {
|
|
|
|
|
+ primaryKey: featureEx[1]
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // var fakeLoadingNodeID = featureID + '-loading'
|
|
|
|
|
+ // _nodes.add({
|
|
|
|
|
+ // id: fakeLoadingNodeID,
|
|
|
|
|
+ // label: 'loading...',
|
|
|
|
|
+ // })
|
|
|
|
|
+ // _edges.add({
|
|
|
|
|
+ // id: fakeLoadingNodeID,
|
|
|
|
|
+ // from: featureID,
|
|
|
|
|
+ // to: fakeLoadingNodeID
|
|
|
|
|
+ // })
|
|
|
|
|
+
|
|
|
|
|
+ // view-source:http://visjs.org/examples/network/data/dynamicData.html
|
|
|
|
|
+ _nodes.update({
|
|
|
|
|
+ id: featureID,
|
|
|
|
|
+ label: makeShortLabel(selectedNodeId) + ' ...'
|
|
|
|
|
+ })
|
|
|
|
|
+ p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
|
|
+ if(DBG)console.log('features', features)
|
|
|
|
|
+ if (!features.length || 1 !== features.length) throw "Brak danych" // require 1 feature with recurse
|
|
|
|
|
+ var refFields = Object.keys(features[0]).filter(function (fieldName) {
|
|
|
|
|
+ return (fieldName.indexOf(':') > -1)
|
|
|
|
|
+ }).filter(function (fieldName) {
|
|
|
|
|
+ return (features[0][fieldName].length > 0)
|
|
|
|
|
+ })
|
|
|
|
|
+ if (!refFields.length) return "Brak danych"
|
|
|
|
|
+ updateWfsResponse(features, featureTypeName)
|
|
|
|
|
+ return "Pobrano nowe dane"
|
|
|
|
|
+ }).then(function (msg) {
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'info', msg: msg })
|
|
|
|
|
+ // _nodes.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
+ // _edges.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
+ _nodes.update({ id: featureID, label: makeShortLabel(selectedNodeId), _loaded: true })
|
|
|
|
|
+ }).catch(function (e) {
|
|
|
|
|
+ if(DBG)console.warn(e)
|
|
|
|
|
+ p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
|
|
+ // _nodes.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
+ // _edges.remove({ id: fakeLoadingNodeID })
|
|
|
|
|
+ _nodes.update({ id: featureID, label: makeShortLabel(selectedNodeId), _loaded: true })
|
|
|
|
|
+ })
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ if(DBG)console.warn(e)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function makeShortLabel(label) { // TODO: shorter name
|
|
function makeShortLabel(label) { // TODO: shorter name
|
|
|
// BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1234567
|
|
// BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1234567
|
|
|
if (label.length < 30) return label;
|
|
if (label.length < 30) return label;
|