Explorar el Código

fixed RefGraph recurse fetch with __backRef query

Piotr Labudda hace 8 años
padre
commit
a8e2f50fdc
Se han modificado 1 ficheros con 64 adiciones y 51 borrados
  1. 64 51
      SE/se-lib/Route/RefGraph.php.view.js

+ 64 - 51
SE/se-lib/Route/RefGraph.php.view.js

@@ -140,6 +140,16 @@ function updateWfsResponse(features, featureTypeName) {
 	}
 }
 
+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) {
 	var level = level || 0
 	var parentNodeId = parentNodeId || null
@@ -154,6 +164,9 @@ 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 - TODO', json);
+		parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
 	} else if (p5Utils__isObject(json)) {
 		var objectName = typeName.substr(typeName.indexOf(':') + 1)
 		var nodeId = objectName + '.' + json.ID // TODO: primaryKey?
@@ -207,57 +220,61 @@ 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('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",
-		//  @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 })
-				} 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 objectName = typeName
-		// {
-		// 	// _graphData.nodes.add({ id: nodeId, label: nodeId })
-		// 	if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
-		// 	_todoGraphData[level].nodes.push({ id: nodeId, label: nodeId, group: objectName })
-		// 	if (parentNodeId) {
-		// 		// _graphData.edges.add({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
-		// 		_todoGraphData[level].edges.push({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
-		// 	}
-		// }
+	} 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 - fetch more xlink object');
+	console.warn('parseResponseRec isObject - fetch more xlink object', 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 })
+			} 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 objectName = typeName
+	// {
+	// 	// _graphData.nodes.add({ id: nodeId, label: nodeId })
+	// 	if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
+	// 	_todoGraphData[level].nodes.push({ id: nodeId, label: nodeId, group: objectName })
+	// 	if (parentNodeId) {
+	// 		// _graphData.edges.add({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
+	// 		_todoGraphData[level].edges.push({ id: parentNodeId+nodeId, from: parentNodeId, to: nodeId })
+	// 	}
+	// }
+}
 
 function fetchNodeMoreRefs(selectedNode, featureID) {
 	try {
@@ -325,10 +342,6 @@ function fetchNodeMoreRefs(selectedNode, featureID) {
 			// } 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)
 			})