浏览代码

Separating query modifying routines from crfVisit.js into runQuery.js

Andrej Studen 2 年之前
父节点
当前提交
35ac65a934
共有 2 个文件被更改,包括 86 次插入1 次删除
  1. 2 1
      views/visit.view.xml
  2. 84 0
      web/crf/runQuery.js

+ 2 - 1
views/visit.view.xml

@@ -1,6 +1,7 @@
 <view xmlns="http://labkey.org/data/xml/view" title="CRF Form">
 	<dependencies>
-		<dependency path="crf/crfVisit.js"/>
+      <dependency path="crf/runQuery.js"/>
+      <dependency path="crf/crfVisit.js"/>
 		<dependency path="crf/crfReview.js"/>
 		<!--local copy of pdfkit, version 0.10.0-->
 		<!--https://github.com/devongovett/pdfkit/releases/download/v0.10.0/pdfkit.standalone.js-->

+ 84 - 0
web/crf/runQuery.js

@@ -0,0 +1,84 @@
+//external dependencies:
+//LABKEY.Query
+//print -> configObject.print
+
+function makeQuery(targetObject,containerName,queryName,fieldName,filterArray){
+   //call with makeQuery(config.formConfig,getContainer(name),...
+	let e=new Object();
+	e.containerName=containerName;
+	e.queryName=queryName;
+	e.fieldName=fieldName;
+	e.filterArray=filterArray;
+   e.targetObject=targetObject;
+	return e;
+}
+
+function getDataFromQueries(queryArray,cb){
+	//queryArray should contain elements with
+	//- fieldName to set the data variable
+	//- containerName to select container (data,config,CRF)
+	//- queryName to select query
+	//- filterArray to perform filtering, empty array works
+	//- callback cb to be called with no arguments
+	//
+	afterQuery(new Object(),-1,queryArray,cb);
+}
+
+function afterQuery(data,id,queryArray,cb){
+	//queryArray should contain elements with
+	//- fieldName to set the data variable
+	//- containerName to select container (data,config,CRF)
+	//- queryName to select query
+	//- filterArray to perform filtering, empty array works
+	//- callback cb to be called with no arguments
+	//
+	//it should be called with id -1.
+	//
+	//targetObject.print('afterQuery1['+id+'/'+queryArray.length+']: ');
+
+	if (id>-1){
+	   let e1=queryArray[id];
+		let fieldName=e1.fieldName;
+		e1.targetObject.print('afterQuery['+fieldName+']: '+data.rows.length);
+		e1.targetObject[fieldName]=data;
+	}
+	id+=1;
+	if (id==queryArray.length) {
+		cb();
+		return;
+	}
+
+
+	let e=queryArray[id];
+	let qconfig=new Object();
+	qconfig.containerPath=e.targetObject.getContainer(e.containerName);
+	qconfig.schemaName="lists";
+	if ("schemaName" in e){
+		e.targetObject.print('afterQuery: schemaName='+e.schemaName);
+		qconfig.schemaName=e.schemaName;
+	}
+
+	if ("columns" in e){
+		e.targetObject.print('afterQuery: columns='+e.columns);
+		qconfig.columns=e.columns;
+	}
+	qconfig.queryName=e.queryName;
+	//this should point to configuration container
+	//don't filter -> so we can pick up other forms (say registration) later on
+	//qconfig.filterArray=[LABKEY.Filter.create('Key',config.formId)];
+	if ("filterArray" in e)
+		qconfig.filterArray=e.filterArray;
+	
+	//qconfig.filterArray=[LABKEY.Filter.create('formStatus',1)]
+	qconfig.success=function(data){afterQuery(data,id,queryArray,cb);};
+	qconfig.failure=function(errorInfo,responseObj){onFailure(e.targetObject,errorInfo,responseObj);};
+	LABKEY.Query.selectRows(qconfig);
+
+}
+
+function onFailure(targetObj, errorInfo, responseObj){
+   //don't have configObject to rely to
+   targetObj.print('[afterQuery]: Failure: '+errorInfo.exception);
+
+}
+