chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1298376 - in /chemistry/playground/chemistry-opencmis-javascript-client/src: main/webapp/cmislib.js main/webapp/index.html test/resources/testcmislib.js
Date Thu, 08 Mar 2012 12:58:32 GMT
Author: jens
Date: Thu Mar  8 12:58:31 2012
New Revision: 1298376

URL: http://svn.apache.org/viewvc?rev=1298376&view=rev
Log:
add a query example

Modified:
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
    chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
    chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js?rev=1298376&r1=1298375&r2=1298376&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/cmislib.js Thu
Mar  8 12:58:31 2012
@@ -34,6 +34,7 @@ function OperationContext() {
     this.includePathSegments = false;
     this.orderBy = null;
     this.includePropertyDefinitions = true;
+    this.searchAllVersions = true;
 }
 
 
@@ -294,11 +295,34 @@ function CmisSession(urlPrefix, reposito
         this.doJson(url, data, cbFct);        
     };
     
+    this.doQuery = function(queryString, cbFct) {
+        var url = this.getUrl();
+        var properties = {
+            q: queryString,
+            cmisaction: "query",
+            skipCount: this.opCtx.skipCount,
+            searchAllVersions: this.opCtx.searchAllVersions,
+            includeAllowableAction: this.opCtx.searchAllVersions,
+            includeRelationships: this.opCtx.includeRelationships,
+            skipCount: this.opCtx.skipCount,
+            suppressResponseCodes: true
+        };
+
+        trace("doQuery() " + url);
+        $.ajax( { 
+            url: url,
+            data: properties,
+            type:  "POST",
+            success: cbFct        
+        });
+
+    };
+    
     this.getObjectFromTransaction = function (transId, cbFct) {
         var url = this.getUrl();
         var data = {
             cmisselector: "lastResult",
-            transaction: transId,
+            cmistransaction: transId,
             suppressResponseCodes: true
         };
 

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html?rev=1298376&r1=1298375&r2=1298376&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html (original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/main/webapp/index.html Thu
Mar  8 12:58:31 2012
@@ -74,6 +74,7 @@
         
         
     }
+    
     function createTable(children, baseType) {
         var row;
         var tbody;
@@ -124,6 +125,47 @@
         return tbl;
     }
 
+    function createQueryTable(children) {
+        var row;
+        var tbody;
+        var tbl = $('<table>').attr('id', 'childrenTable').attr('border', 1);
+        
+        var propsToDisplay = [];
+        var propsToDisplayLabel = [];
+        for (var child in children.objects) {
+	        for (var prop in children.objects[child].properties) {
+	            var propQueryName = children.objects[child].properties[prop].queryName;
+	            if ($.inArray(propQueryName, propsToDisplay) < 0) {
+	                propsToDisplay.push(propQueryName);
+	                propsToDisplayLabel.push(children.objects[child].properties[prop].queryName);
+	        	}
+	        }
+        }
+
+        tbl.append($('<thead>').append(row = $('<tr>')));
+        for (var propKey in propsToDisplay) {
+			row.append($('<td>').text(propsToDisplayLabel[propKey]));
+        }
+        
+        tbl.append(tbody = $('<tbody>'));
+        for (var child in children.objects) {
+            row = null;
+            tbody.append(row = $('<tr>'));
+            for (var propKey in propsToDisplay) {
+                var props = children.objects[child].properties;
+                var prop = props[propsToDisplay[propKey]];
+                if (null != prop && null != prop.value) {
+                    var text = convertValue(prop.value, prop.type);
+                    var cell = $('<td>').html(text.toString());
+                 	row.append(cell);
+                } else
+                    row.append($('<td>'));
+            }
+        }
+		
+        return tbl;
+    }
+
     function getTypesRecursive(typeId, tbl) {
         trace("getTypesRecursive: " + typeId );
     	session.getTypeChildren(typeId, function(types) {
@@ -168,14 +210,13 @@
     }
     
     function prepareCreate() {
-        // dynamically create an invisible iframe:
-        // <iframe id="createresultframeid" name="createresultframe" style="width:0px;height:0px;visibility:hidden"
onload="createDocumentDone()"> </iframe>	    
 		checkSession("#responsesection");
 		if (!session)
 		    return false;
 
-//		$('#invisibleareaid').html($('<iframe>').attr('id', 'createresultframe').attr('style',
"width:0px;height:0px;visibility:hidden").
-//		        attr('onload', "createDocumentDone()").attr('name', 'createresultframe')); 	

+        // dynamically create an invisible iframe:
+		// $('#invisibleareaid').html($('<iframe>').attr('id', 'createresultframe').attr('style',
"width:0px;height:0px;visibility:hidden").
+		// attr('onload', "createDocumentDone()").attr('name', 'createresultframe')); 		
         $("#transactionId").val(createRandomString());
         $("#createdochtmlid").attr("action", session.getRootUrl());
         trace("create doc from html form with action: " + $("#createdochtmlid").attr("action"));
@@ -335,6 +376,18 @@
            	});
         });
 
+        $('#doquery').click(function() {
+            checkSession("#queryresponsesection");
+            $("#queryresponsesection *").remove();
+            trace("doing query: " + $('#queryfield').val());
+           	session.doQuery($('#queryfield').val(), function(data) {
+           	 	if (!checkError(data, "#queryresponsesection")) {
+                  	var tbl = createQueryTable(data);
+                  	$("#queryresponsesection").append(tbl);
+           	 	}
+           	});
+        });
+
     });    
     </script>
     
@@ -465,7 +518,7 @@
 	   <input name="propertyId[0]" type="hidden" value="cmis:name" />
        <input name="propertyId[1]" type="hidden" value="cmis:objectTypeId" />
        <input name="cmisaction" type="hidden" value="createDocument" />
-       <input id="transactionId" name="transaction" type="hidden" value="" />     
   
+       <input id="transactionId" name="cmistransaction" type="hidden" value="" /> 
       
 	</form>
 	<div id="responsesection">
 	</div>
@@ -500,5 +553,21 @@
     <button id="createfolder">Create Folder!</button>  <br/>
     <div id="createfoldersection">
     </div>   
+
+    <p/>
+    <div id="doquerysection">
+    </div>        
+    <h3> Make a Query: </h3>
+    <form >
+	  <fieldset>
+	    <legend>Enter a query</legend>
+	    <textarea id="queryfield" cols="80" rows="5">SELECT * from cmis:document
+	    </textarea>
+	  </fieldset>
+	</form>
+    <button id="doquery">Do query!</button>  <br/>
+    <div id="queryresponsesection">
+    </div>   
+
   </body>
 </html>
\ No newline at end of file

Modified: chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js?rev=1298376&r1=1298375&r2=1298376&view=diff
==============================================================================
--- chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
(original)
+++ chemistry/playground/chemistry-opencmis-javascript-client/src/test/resources/testcmislib.js
Thu Mar  8 12:58:31 2012
@@ -182,6 +182,21 @@ test("testCreateDocumentMustFail()", fun
     });
 });
 
+asyncTest("testDoQuery", function() {
+    trace("testDoQuery ");
+    this.session.doQuery("SELECT * FROM cmis:document", function(results) {
+        ok(results.exception == null, "Test for error in doQuery()");
+        ok (results.objects.length > 0, "doQuery result is empty");
+        for (var row in results.objects) {
+            var baseTypeId = results.objects[row].properties["cmis:baseTypeId"].value;
+            ok(baseTypeId === "cmis:document" || baseTypeId === "cmis:folder", "child is
document or folder");
+            ok(null != results.objects[row].properties["cmis:name"].value, "child has name");
+        }
+        trace("testDoQuery done.");
+        start();
+    });
+});
+
 test("testGetTypeDefinition()", function() {
     trace("testGetTypeDefinition ");
     expect(3);



Mime
View raw message