|
|
@@ -5,7 +5,8 @@ if ('undefined' === typeof PRIMARY_KEY) throw "Missing PRIMARY_KEY";
|
|
|
// if ('undefined' === typeof FUNCTION_FETCH_CHILDRENS) throw "Missing FUNCTION_FETCH_CHILDRENS";
|
|
|
// if ('undefined' === typeof FUNCTION_FETCH_PARENTS) throw "Missing FUNCTION_FETCH_PARENTS";
|
|
|
// if ('undefined' === typeof JS_CHANNEL_UPDATE_NAME) throw "Missing JS_CHANNEL_UPDATE_NAME";
|
|
|
-var DBG = DBG || 0;
|
|
|
+var DBG = DBG || false;
|
|
|
+var DBG1 = true;
|
|
|
|
|
|
var _isFullScreen = true; // TODO: get from arg
|
|
|
var _html = {
|
|
|
@@ -63,12 +64,12 @@ var _defaultVisJsOptions = {
|
|
|
var wfsParams = Object.assign({}, _defaultWfsParams, {
|
|
|
primaryKey: PRIMARY_KEY,
|
|
|
})
|
|
|
- if(DBG)console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
|
|
|
+ DBG && console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
|
|
|
p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
- if(DBG)console.log('features', features)
|
|
|
+ DBG && console.log('features', features)
|
|
|
updateWfsResponse(features, featureTypeName)
|
|
|
}).catch(function (e) {
|
|
|
- if(DBG)console.warn(e)
|
|
|
+ DBG && console.warn(e)
|
|
|
p5UI__notifyAjaxCallback({ type: 'error', msg: e })
|
|
|
})
|
|
|
|
|
|
@@ -76,7 +77,7 @@ var _defaultVisJsOptions = {
|
|
|
})();
|
|
|
|
|
|
function updateWfsResponse(features, featureTypeName) {
|
|
|
- if(DBG)console.log('updateWfsResponse', { features: features, featureTypeName: featureTypeName })
|
|
|
+ DBG && console.log('updateWfsResponse', { features: features, featureTypeName: featureTypeName })
|
|
|
// if (_network !== null) {
|
|
|
// _network.destroy();
|
|
|
// _network = null;
|
|
|
@@ -94,7 +95,7 @@ function updateWfsResponse(features, featureTypeName) {
|
|
|
try {
|
|
|
_nodes.add(node)
|
|
|
} catch (e) {
|
|
|
- if(DBG)console.log('_graphData.nodes.add error:', e);
|
|
|
+ DBG && console.log('_graphData.nodes.add error:', e);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -103,7 +104,7 @@ function updateWfsResponse(features, featureTypeName) {
|
|
|
try {
|
|
|
_edges.add(edge)
|
|
|
} catch (e) {
|
|
|
- if(DBG)console.log('_graphData.edges.add error:', e);
|
|
|
+ DBG && console.log('_graphData.edges.add error:', e);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -112,38 +113,39 @@ function updateWfsResponse(features, featureTypeName) {
|
|
|
|
|
|
|
|
|
var options = _defaultVisJsOptions
|
|
|
- if(DBG)console.log('_graphData', _graphData)
|
|
|
+ DBG && console.log('_graphData', _graphData)
|
|
|
if (!_network) {
|
|
|
_network = new vis.Network(_html['container'], _graphData, options); // graphData: { nodes: [], edges: [] }
|
|
|
-
|
|
|
- // add event listeners
|
|
|
- _network.on('selectNode', function (params) {
|
|
|
- if(DBG)console.log('Selection: ', params.nodes)
|
|
|
- var featureID = params.nodes[0]
|
|
|
- if (!featureID) return;
|
|
|
- if ('-loading' === featureID.substr(-1 * '-loading'.length)) {
|
|
|
- // TODO: gui msg...
|
|
|
- if(DBG)console.log('loading nodes connected with: "' +featureID.substr(0, featureID.length - '-loading'.length) + '" ...')
|
|
|
- return;
|
|
|
- }
|
|
|
- var selectedNode = _nodes.get(featureID)
|
|
|
- if (!selectedNode) return;
|
|
|
-
|
|
|
- if ('ref' === selectedNode._type) {
|
|
|
- fetchNodeMoreRefs(selectedNode, featureID)
|
|
|
- } else {
|
|
|
- renderSelectedNode(selectedNode)
|
|
|
- if (selectedNode._loaded) return;
|
|
|
- fetchNodeRecurse(selectedNode, featureID)
|
|
|
- }
|
|
|
- });
|
|
|
+ _network.on('selectNode', handleNetworkSelectNode);
|
|
|
+ // _network.on('stabilized', handleNetworkStabilized);
|
|
|
}
|
|
|
}
|
|
|
+var handleNetworkSelectNode = function (params) {
|
|
|
+ DBG && console.log('Selection: ', params.nodes)
|
|
|
+ var featureID = params.nodes[0]
|
|
|
+ if (!featureID) return;
|
|
|
+ if ('-loading' === featureID.substr(-1 * '-loading'.length)) {
|
|
|
+ // TODO: gui msg...
|
|
|
+ DBG && console.log('loading nodes connected with: "' +featureID.substr(0, featureID.length - '-loading'.length) + '" ...')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var selectedNode = _nodes.get(featureID)
|
|
|
+ if (!selectedNode) return;
|
|
|
+
|
|
|
+ if ('ref' === selectedNode._type) {
|
|
|
+ fetchNodeMoreRefs(selectedNode, featureID)
|
|
|
+ } else {
|
|
|
+ renderSelectedNode(selectedNode)
|
|
|
+ if (selectedNode._loaded) return;
|
|
|
+ fetchNodeRecurse(selectedNode, featureID)
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
|
|
|
function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) {
|
|
|
var level = level || 0
|
|
|
var parentNodeId = parentNodeId || null
|
|
|
- if(DBG)console.log('DBG::parseResponseRec', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
|
|
|
+ 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)) {
|
|
|
// TODO: create named group
|
|
|
var isXlinkList = (json.length > 0 && p5Utils__isString(json[0]))
|
|
|
@@ -181,13 +183,13 @@ function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) {
|
|
|
parseResponseRec(_todoGraphData, value, fieldName, nodeId, level + 1)
|
|
|
})
|
|
|
} else if (p5Utils__isString(json)) {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec isString');
|
|
|
+ DBG && console.log('TODO: Not implemented - parseResponseRec isString');
|
|
|
} else {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec is not string, not array and not object');
|
|
|
+ DBG && console.log('TODO: Not implemented - parseResponseRec is not string, not array and not object');
|
|
|
}
|
|
|
}
|
|
|
function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId, level) {
|
|
|
- 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)});
|
|
|
+ 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",
|
|
|
var nodeId = json.substr(json.indexOf('#') + 1)
|
|
|
var objectName = typeName.substr(typeName.indexOf(':') + 1)
|
|
|
@@ -208,7 +210,7 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
}
|
|
|
}
|
|
|
} else if (p5Utils__isObject(json)) {
|
|
|
- if(DBG)console.log('parseResponseRec isObject - fetch more xlink object');
|
|
|
+ DBG && console.log('parseResponseRec isObject - fetch more xlink object');
|
|
|
// example json: { type: "next",
|
|
|
// @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
|
|
|
// @backRefPK: "42",
|
|
|
@@ -221,7 +223,7 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
|
|
|
switch (json.type) {
|
|
|
case 'next': {
|
|
|
- if(DBG)console.log('TODO: next "'+json.type+'" - fetch more xlink object');
|
|
|
+ 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,
|
|
|
@@ -238,7 +240,7 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
_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');
|
|
|
+ DBG && console.log('TODO: Not implemented - parseResponseRec isObject with type "'+json.type+'" - fetch more xlink object');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -255,7 +257,7 @@ function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId,
|
|
|
// }
|
|
|
// }
|
|
|
} else {
|
|
|
- if(DBG)console.log('TODO: Not implemented - parseResponseRec:XlinkList is not string and not object');
|
|
|
+ DBG && console.log('TODO: Not implemented - parseResponseRec:XlinkList is not string and not object');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -283,7 +285,7 @@ function fetchNodeMoreRefs(selectedNode, featureID) {
|
|
|
// count: 3,
|
|
|
};
|
|
|
p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
- if(DBG)console.log('features', features)
|
|
|
+ DBG && console.log('features', features)
|
|
|
if (!features.length) throw "Brak danych"
|
|
|
features.forEach(function (feature) {
|
|
|
// TODO: validate
|
|
|
@@ -323,9 +325,9 @@ function fetchNodeMoreRefs(selectedNode, featureID) {
|
|
|
// to: nodeId
|
|
|
// })
|
|
|
// } catch (e) {
|
|
|
- // if(DBG)console.warn('TODO: XXX: ' + e)
|
|
|
+ // DBG && console.warn('TODO: XXX: ' + e)
|
|
|
// }
|
|
|
- if(DBG)console.log('TODO: remove selected after: ', {
|
|
|
+ DBG && console.log('TODO: remove selected after: ', {
|
|
|
idSelectedNode: idSelectedNode,
|
|
|
idSelectedEdge: idSelectedEdge,
|
|
|
})
|
|
|
@@ -338,13 +340,13 @@ function fetchNodeMoreRefs(selectedNode, featureID) {
|
|
|
_nodes.remove({ id: idSelectedNode })
|
|
|
_edges.remove({ id: idSelectedEdge })
|
|
|
}).catch(function (e) {
|
|
|
- if(DBG)console.warn(e)
|
|
|
+ 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)
|
|
|
+ DBG && console.warn(e)
|
|
|
}
|
|
|
}
|
|
|
function fetchNodeRecurse(selectedNode, featureID) {
|
|
|
@@ -376,7 +378,7 @@ function fetchNodeRecurse(selectedNode, featureID) {
|
|
|
label: makeShortLabel(selectedNodeId) + ' ...'
|
|
|
})
|
|
|
p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
|
|
|
- if(DBG)console.log('features', features)
|
|
|
+ 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)
|
|
|
@@ -392,14 +394,14 @@ function fetchNodeRecurse(selectedNode, featureID) {
|
|
|
// _edges.remove({ id: fakeLoadingNodeID })
|
|
|
_nodes.update({ id: featureID, label: makeShortLabel(selectedNodeId), _loaded: true })
|
|
|
}).catch(function (e) {
|
|
|
- if(DBG)console.warn(e)
|
|
|
+ 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)
|
|
|
+ DBG && console.warn(e)
|
|
|
}
|
|
|
}
|
|
|
|