Procházet zdrojové kódy

instances and types now working, FolderType Bug active, Icons for Nodes

DS před 1 rokem
rodič
revize
74668ce6c5
3 změnil soubory, kde provedl 156 přidání a 137 odebrání
  1. 69 30
      Backend/services.js
  2. 45 14
      index.html
  3. 42 93
      js/myEvents.js

+ 69 - 30
Backend/services.js

@@ -44,6 +44,7 @@ nsray.push(mt);
 let type_ar = ['datatypes', 'objecttypes', 'referencetypes', 'variabletypes'];
 let classes_ar = ['datatypes', 'objecttypes', 'referencetypes', 'variabletypes', 'objects', 'variables', 'methods'];
 let child_refs = ['Organizes','HasComponent','HasProperty','HasAddIn','HasSubtype'];
+let hier_refs = ['i=34','i=44','i=45','i=35', 'i=47', 'i=46' ]; //HasChild, Aggregates, HasSubtype, Organizes, HasComponent, HasProperty 
 
 /*
 async function gen_query(sql, params){
@@ -127,8 +128,10 @@ async function newNid(nid, i){ //Uni -> whatever is needed, global in i
 			const ul = parseInt(ret[0][0].nsurl);
 			command = "SELECT nsindex FROM ns"+i+"depends WHERE nsurl='"+ul+"';";
 			ret = await pool.query(command);
-			obj.ns_local = parseInt(ret[0][0].nsindex);
-			obj.combi_local = "ns="+obj.ns_local+";"+obj.ident_all;
+			if(ret[0].length > 0){
+				obj.ns_local = parseInt(ret[0][0].nsindex);
+				obj.combi_local = "ns="+obj.ns_local+";"+obj.ident_all;
+			}
 		}else{
 			const n1 = nid.split("=");
 			obj.ident = n1[1];
@@ -211,6 +214,7 @@ async function getLocalNid(nid, m){ // Uni -> local
 			obj.ident = n1[1];
 			obj.ident_all = nid;
 			obj.combi_local = nid;
+			obj.combi_uni = nid;
 	
 		}
 		return obj;
@@ -1012,7 +1016,7 @@ listRefType();
 */
 
 let arref = [];
-
+/*
 async function getThisNodeAttribute(ix, nid, classname, attr){
 	try{
 		var res = "";
@@ -1032,6 +1036,7 @@ async function getThisNodeAttribute(ix, nid, classname, attr){
 		console.log(err);
 	}
 }
+*/
 
 async function getThisNode(ix, nid, classname){
 	try{
@@ -1052,6 +1057,7 @@ async function getThisNode(ix, nid, classname){
 			obj0 = {
 				id: l.combi_uni,
 				text: resp.name,
+				type: ret[0][0].nodeclass,
 				data: ret[0][0],
 				children: flag_ch	
 			};
@@ -1070,34 +1076,64 @@ async function getThisNode(ix, nid, classname){
 async function getChildrenSql(ix, nid){ //Uni nodeid -> 4/ns=4;i=131
 	try{
 		let res = [];
+		var obj = {};
 		for(let i = ix; i < nsray.length; i++){
-			var obj = await newNid(nid, i);
+			obj = await newNid(nid, i);
 			var command = "SELECT nodeidorigin FROM ns"+i+"references WHERE target='"+obj.combi_local+"' AND isforward='false';";
+			console.log(command);
 			var ret = await pool.query(command);
-				const iterator = ret[0].values();
-				for (const value of iterator) {
-					var bb = await getUniNid(value.nodeidorigin, i)
-					var nc = "";
-					for(let j = 0; j < classes_ar.length; j++){
-						if(bb.ns_uni !== 0){
-							command = "SELECT nodeclass FROM ns"+bb.ns_uni+""+classes_ar[j]+" WHERE nodeid='ns=1;"+bb.ident_all+"';";
-							ret = await pool.query(command);
-							if(ret[0].length !== 0){
-								nc = ret[0][0].nodeclass;
-								res.push([bb.combi_uni, bb.ns_uni, nc]);
-							}	
-						}else{
-							command = "SELECT nodeclass FROM ns0"+classes_ar[j]+" WHERE nodeid='"+bb.ident_all+"';";
-							ret = await pool.query(command);		
-							if(ret[0].length !== 0){
-								nc = ret[0][0].nodeclass;
-								res.push([bb.combi_uni, bb.ns_uni, nc]);
-							}		
-						}
+			var iterator = ret[0].values();
+			for (const value of iterator) {
+				var bb = await getUniNid(value.nodeidorigin, i)
+				var nc = "";
+				for(let j = 0; j < classes_ar.length; j++){
+					if(bb.ns_uni !== 0){
+						command = "SELECT nodeclass FROM ns"+bb.ns_uni+""+classes_ar[j]+" WHERE nodeid='ns=1;"+bb.ident_all+"';";
+						ret = await pool.query(command);
+						if(ret[0].length !== 0){
+							nc = ret[0][0].nodeclass;
+							res.push([bb.combi_uni, bb.ns_uni, nc]);
+						}	
+					}else{
+						command = "SELECT nodeclass FROM ns0"+classes_ar[j]+" WHERE nodeid='"+bb.ident_all+"';";
+						ret = await pool.query(command);		
+						if(ret[0].length !== 0){
+							nc = ret[0][0].nodeclass;
+							res.push([bb.combi_uni, bb.ns_uni, nc]);
+						}		
+					}
+				}	
+			}
+		}	
+		obj = await getLocalNid(nid, ix);
+		command = "SELECT target FROM ns"+ix+"references WHERE nodeidorigin='"+obj.combi_local+"' AND isforward='undefined';"; //Search all hierarchical references!
+		console.log(command);
+		ret = await pool.query(command);
+		var iterator = ret[0].values();
+		for (const value of iterator) {
+			var bb = await getUniNid(value.target, ix)
+			var nc = "";
+			for(let j = 0; j < classes_ar.length; j++){
+				if(bb.ns_uni !== 0){
+					command = "SELECT nodeclass FROM ns"+bb.ns_uni+""+classes_ar[j]+" WHERE nodeid='ns=1;"+bb.ident_all+"';";
+					console.log(command);
+					ret = await pool.query(command);
+					if(ret[0].length !== 0){
+						nc = ret[0][0].nodeclass;
+						res.push([bb.combi_uni, bb.ns_uni, nc]);
 					}	
+				}else{
+					command = "SELECT nodeclass FROM ns0"+classes_ar[j]+" WHERE nodeid='"+bb.ident_all+"';";
+					console.log(command);
+					ret = await pool.query(command);		
+					if(ret[0].length !== 0){
+						nc = ret[0][0].nodeclass;
+						res.push([bb.combi_uni, bb.ns_uni, nc]);
+					}		
 				}
-			//}
+			}	
 		}
+		console.log(res);
 		return res;
 	}catch(err){
 		console.log(err);
@@ -2093,7 +2129,7 @@ app.post('/key', async function(req, res){
 
 })
 */
-
+/*
 app.get('/look/:ix/:id/:eclass/:attr', async function(req, res){
 	try{
 		var ix = req.params["ix"];
@@ -2119,7 +2155,7 @@ app.get('/look/:ix/:id/:eclass/:attr', async function(req, res){
 	}
 
 })
-
+*/
 app.get('/find/:ix/:id/:eclass', async function(req, res){
 	try{
 		var ix = req.params["ix"];
@@ -2150,7 +2186,7 @@ app.get('/children/sql/:ix/:id', async function(req, res){
 		var ix = req.params["ix"];
 		var id = req.params["id"];
 		var ret = await getChildrenSql(ix, id);
-		res.json({result:ret, success: true});
+		res.json({num:ret.length, result:ret, success: true});
 	}catch(err){
 		console.log(err);
 		res.json({result:"NOK"});
@@ -2553,7 +2589,7 @@ app.get('/lazy', async function(req, res) {
 	var ret_obj = [];
 	let node = {};
 	if(req.query.id == "#"){
-		res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object", nsindex:0},children:[{id:"i=85",text:"Objects",data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=86",text:"Types", data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=87",text:"View",data:{nodeclass:"Object", nsindex:0},children:true}]}]);
+		res.json([{id:"i=84",text:"Root", type:"Object", data:{nodeclass:"Object", nsindex:0},children:[{id:"i=85",text:"Objects",type:"Object",data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=86",text:"Types", type:"Object",data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=87",text:"View",type:"Object",data:{nodeclass:"Object", nsindex:0},children:true}]}]);
 		return 0;
 	}
 	
@@ -2576,6 +2612,7 @@ app.get('/lazy', async function(req, res) {
 	
 	var ch = await getChildrenSql(idx, obj.id);
 	//console.log(ch);
+	var child_arr = [];
 	for(let j = 0; j < ch.length; j++){
 		classn = ch[j][2];
 		switch(classn){
@@ -2591,10 +2628,12 @@ app.get('/lazy', async function(req, res) {
 		console.log(ch[j][1]+","+ch[j][0]+","+class_name);
 		var ch0 = await getThisNode(ch[j][1],ch[j][0],class_name);
 		console.log(ch0);
+		child_arr.push(ch0);
 	}
 	//console.log(ch);
 	
-	
+	res.json([{id:obj.id, text:obj.text, type:obj.data.nodeclass, data:obj.data, children:child_arr}]);
+	return 0;
 	
 	
 	

+ 45 - 14
index.html

@@ -262,7 +262,7 @@
 					<div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">Data Type</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3" placeholder="BaseDataType">
+						  <input type="email" class="form-control" id="datatype" placeholder="BaseDataType">
 						</div>
 					  </div>
 					  
@@ -271,9 +271,9 @@
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">Value</label>						
 						<div class="col-sm-2">
-							<label for="inputEmail3" class="col-form-label">Null</label>
+							<label for="inputEmail3" id="variablevalue" class="col-form-label">Null</label>
 							<div class="col-sm-2">
-								<input class="form-check-input" type="checkbox" value="" id="executablemethodcheck">
+								<input class="form-check-input" type="checkbox" value="" id="valuecheck">
 							</div>
 								<input type="email" class="form-control" id="inputEmail3" placeholder="...">
 						</div>
@@ -281,13 +281,13 @@
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">ValueRank</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3" placeholder="Scalar">
+						  <input type="email" class="form-control" id="variablevaluerank" placeholder="Scalar">
 						</div>
 					  </div>
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">ArrayDimensions</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3">
+						  <input type="email" class="form-control" id="variablearraydimensions">
 						</div>
 					  </div>
 					  <div class="row mb-3">
@@ -360,19 +360,19 @@
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">AccessLevelEx</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3" placeholder="None">
+						  <input type="email" class="form-control" id="accesslevelex" placeholder="None">
 						</div>
 					  </div>
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">Historizing</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3">
+						  <input type="email" class="form-control" id="variablehistorizing">
 						</div>
 					  </div>
 					  <div class="row mb-3">
 						<label for="inputEmail3" class="col-sm-2 col-form-label">MinimumSamplingInterval</label>
 						<div class="col-sm-10">
-						  <input type="email" class="form-control" id="inputEmail3" placeholder="0">
+						  <input type="email" class="form-control" id="minimumsamplinginterval" placeholder="0">
 						</div>
 					  </div>
 				  </div>
@@ -390,7 +390,7 @@
 						<label for="exampleFormControlInput6" class="col-sm-2 col-form-label">WriteMask</label>
 						<div class="col-sm-10">
 						<div class="input-group mb-3">
-						  <input type="text" class="form-control" aria-label="Text input with dropdown button"  id="instanceeventnotifier" placeholder="0">
+						  <input type="text" class="form-control" aria-label="Text input with dropdown button"  id="writemask" placeholder="0">
 						  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">...</button>
 						  <ul class="dropdown-menu dropdown-menu-end">
 							<li><a class="dropdown-item" href="#">
@@ -577,7 +577,7 @@
 						<label for="inputEmail3" class="col-sm-2 col-form-label">Executable</label>						
 						<div class="col-sm-10">
 						<div class="input-group mb-3">
-						  <input class="form-check-input" type="checkbox" value="" id="executablemethodcheck">
+						  <input class="form-check-input" type="checkbox" id="executablemethodcheck">
 						</div>
 					  </div>
 					</div>
@@ -715,15 +715,46 @@
 						//'url' : "https://www.jstree.com/fiddle/?lazy", 
 						'data' : function (node) {
 							if(node.id == '#'){
-							return { 'id' : node.id, 'nsindex': 0, 'nodeclass':'Object'}; 
+							return { 'id' : node.id, 'nsindex': 0, 'nodeclass':'Object', 'type':'Object'}; 
 							}else{
-							return { 'id' : node.id, 'nsindex': node.data.nsindex, 'nodeclass':node.data.nodeclass}; 
+							return { 'id' : node.id, 'nsindex': node.data.nsindex, 'nodeclass':node.data.nodeclass, 'type':node.data.nodeclass}; 
 							}
 						} 
 					}
-				}					
+				},
+				'contextmenu' : {
+					'items' : {addNode: {label: 'Add node'}, delNode: {label: 'Delete node'}}
+				},
+				'plugins' : [ 'contextmenu', 'types'],
+				'types': {
+					'Variable': {
+						'icon': 'variable_instances.png'
+					},
+					'VariableType': {
+						'icon': 'variable_types.png'
+					},
+					'DataType': {
+						'icon': 'data_types.png'
+					},
+					'ReferenceType': {
+						'icon': 'reference_types.png'
+					},
+					'Method': {
+						'icon': 'method.png'
+					},
+					'ObjectType': {
+						'icon': 'obj_types.png'
+					},
+					'Object': {
+						'icon': 'obj_inst.png'
+					},
+					'default': {
+						'icon': 'obj_inst.png'
+					}
+				},
 				}); 
-	
+		
+		
 	  </script>
 </body>
 </html>

+ 42 - 93
js/myEvents.js

@@ -24,43 +24,20 @@ $('#jstree_demo_div').on("select_node.jstree", function (e, data) {
 	var x = data.node.data.idx;
 	var nid = data.node.id;
 	var nc = data.node.data.nodeclass;
+	$('#instancenodeid').val(data.node.id);
+	$('#instancenodeidtype').val(data.node.data.nodeidtype);
+	$('#instancename').val(data.node.text);
+	$('#instancenamespace').val(data.node.data.nsindex +":"+data.node.data.nsurl );
+	$('#instancedisplayname1').val("");
+	$('#instancedisplayname2').val(data.node.data.displayname);
+	$('#instancebrowsename2').val(data.node.data.browsename);
+	
+	$('#instancenodeclass').val(nc);
 	if(nc == "Object"){
 		var ul = 'http://127.0.0.1:3001/look/'+x+'/'+nid+'/'+nc+'/';
-		$.ajax({
-			url: ul+'name',
-			type: 'GET',  // http method
-			success: function (resp, status, xhr) {
-				$('#instancename').val(resp.result);
-			},
-			error: function (jqXhr, textStatus, errorMessage) {
-					console.log('Error: ' + errorMessage);
-				}
-		});
-		//$('#instancename').val(data.node.text);
-		$.ajax({
-			url: ul+'nsurl',
-			type: 'GET',  // http method
-			success: function (resp, status, xhr) {
-				$('#instancenamespace').val(resp.result);
-			},
-			error: function (jqXhr, textStatus, errorMessage) {
-					console.log('Error: ' + errorMessage);
-				}
-		});
-		$('#instancenodeclass').val(nc);
+
 		//$('#instancetypedefinition').val(data.node.data.);
-		$('#instancenodeidtype').val();
-		$.ajax({
-			url: ul+'nodeidtype',
-			type: 'GET',  // http method
-			success: function (resp, status, xhr) {
-				$('#instancenodeidtype').val(resp.result);
-			},
-			error: function (jqXhr, textStatus, errorMessage) {
-					console.log('Error: ' + errorMessage);
-				}
-		});
-		$('#instancenodeid').val(nid);
+	
 		
 		$.ajax({
 			url: ul+'eventnotifier',
@@ -82,32 +59,7 @@ $('#jstree_demo_div').on("select_node.jstree", function (e, data) {
 			error: function (jqXhr, textStatus, errorMessage) {
 					console.log('Error: ' + errorMessage);
 				}
-		});
-		$('#instancedisplayname1').val("");
-
-		$.ajax({
-			url: ul+'displayname',
-			type: 'GET',  // http method
-			success: function (resp, status, xhr) {
-				$('#instancedisplayname2').val(resp.result);
-			},
-			error: function (jqXhr, textStatus, errorMessage) {
-					console.log('Error: ' + errorMessage);
-				}
-		});
-		//$('#instancedisplayname2').val(data.node.text);
-		$.ajax({
-			url: ul+'displayname',
-			type: 'GET',  // http method
-			success: function (resp, status, xhr) {
-				$('#instancebrowsename2').val(resp.result);
-			},
-			error: function (jqXhr, textStatus, errorMessage) {
-					console.log('Error: ' + errorMessage);
-				}
-		});
-
-		
+		});		
 		console.log("obj enabled");
 		$('#objectattributesbutton').prop('disabled', false);
 		$('#collapseTwo1').collapse('hide');
@@ -116,17 +68,29 @@ $('#jstree_demo_div').on("select_node.jstree", function (e, data) {
 		$('#methodattributesbutton').prop('disabled',true);
 	}
 	if(data.node.data.nodeclass == "Variable"){
-			/*$.ajax({
-				url: 'http://127.0.0.1:3001',
-				type: 'POST',  // http method
-				data: { key_id: name },  // data to submit
-				success: function (data, status, xhr) {
-					$('p').append('status: ' + status + ', data: ' + data);
-				},
-				error: function (jqXhr, textStatus, errorMessage) {
-						$('p').append('Error: ' + errorMessage);
-					}
-		});*/
+		$('#datatype').val(data.node.data.datatype);
+		$('#variablevalue').val(data.node.data.value);
+		$('#variablevaluerank').val(data.node.data.valuerank);
+		$('#variablearraydimensions').val(data.node.data.arraydimensions);
+		var aclev = data.node.data.accesslevel;
+		var plc = "";
+				switch(aclev){
+					case 0: plc = "0 (None)"; break;
+					case 1: plc = "1 (EventNotifierSubscribeToEvents)"; break;
+					case 4: plc = "4 (EventNotifierHistoryRead)"; break;
+					case 5: plc = "5 (EventNotifierSubscribeToEvents|EventNotifierHistoryRead)"; break;
+					case 8: plc = "8 (EventNotifierHistoryWrite)"; break;
+					case 9: plc = "9 (EventNotifierSubscribeToEvents|EventNotifierHistoryWrite)"; break;
+					case 12: plc = "12 (EventNotifierHistoryRead|EventNotifierHistoryWrite)"; break;
+					default: plc = "";
+				}
+		$('#instanceaccesslevel').val(data.node.data.accesslevel);
+		$('#accesslevelex').val(data.node.data.accesslevelex);
+		$('#variablehistorizing').val(data.node.data.historizing);
+		$('#minimumsamplinginterval').val(data.node.data.minsamplinginterval);
+		
+
+
 		$('#variableattributesbutton').prop('disabled', false);
 		$('#collapseTwo').collapse('hide');
 		$('#objectattributesbutton').prop('disabled',true);
@@ -134,17 +98,13 @@ $('#jstree_demo_div').on("select_node.jstree", function (e, data) {
 		$('#methodattributesbutton').prop('disabled',true);
 	}
 	if(data.node.data.nodeclass == "Method"){
-			/*$.ajax({
-				url: 'http://127.0.0.1:3001',
-				type: 'POST',  // http method
-				data: { key_id: name },  // data to submit
-				success: function (data, status, xhr) {
-					$('p').append('status: ' + status + ', data: ' + data);
-				},
-				error: function (jqXhr, textStatus, errorMessage) {
-						$('p').append('Error: ' + errorMessage);
-					}
-		});*/
+		//$('#writemask').val(data.node.data.accesslevelex);
+		if(data.node.data.executable == 1){
+		$('#executablemethodcheck').prop('checked', true);
+		}else if(data.node.data.executable == 0){
+			$('#executablemethodcheck').prop('checked', false);
+		}
+
 		$('#methodattributesbutton').prop('disabled',false);
 		$('#collapseTwo').collapse('hide');
 		$('#objectattributesbutton').prop('disabled',true);
@@ -152,17 +112,6 @@ $('#jstree_demo_div').on("select_node.jstree", function (e, data) {
 		$('#variableattributesbutton').prop('disabled',true);
 	}
 	
-	/*$.ajax({
-				url: 'http://127.0.0.1:3001',
-				type: 'POST',  // http method
-				data: { key_id: name },  // data to submit
-				success: function (data, status, xhr) {
-					$('p').append('status: ' + status + ', data: ' + data);
-				},
-				error: function (jqXhr, textStatus, errorMessage) {
-						$('p').append('Error: ' + errorMessage);
-					}
-		});*/
 });
 	
 $('#nodesetfile').on("open", function (e, data) {