You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/03/13 08:22:10 UTC
svn commit: r1299991 - in
/chemistry/playground/chemistry-opencmis-javascript-client/src:
main/webapp/cmislib.js main/webapp/index.html test/resources/testcmislib.js
Author: jens
Date: Tue Mar 13 07:22:10 2012
New Revision: 1299991
URL: http://svn.apache.org/viewvc?rev=1299991&view=rev
Log:
Reflect a bug fix in the browser binding protocol changing the query response
Add support for paging in a response (very experimental)
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=1299991&r1=1299990&r2=1299991&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 Tue Mar 13 07:22:10 2012
@@ -4,7 +4,7 @@
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
+ * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@@ -24,7 +24,7 @@ function trace(text) {
function OperationContext() {
this.propertyFilter = "*";
- this.maxItemsPerPage = 25;
+ this.maxItems = 25;
this.skipCount = 0;
this.includeAcls = false;
this.includeAllowableActions = false;
@@ -133,7 +133,8 @@ function CmisSession(urlPrefix, reposito
this.rootUrl = null;
this.opCtx = new OperationContext();
this.rootFolderId; // just use a place to store the id, must be filled by user of a CmisSession
- this.typeCache = new TypeCache();
+ this.typeCache = new TypeCache();
+ this.pagingContext = {};
this.getUrl = function() {
return this.urlPrefix + "/" + this.repId;
@@ -152,6 +153,39 @@ function CmisSession(urlPrefix, reposito
jsonObj.stacktrace);
};
+ this.addPagingContext = function (elementId, skipCount, numItemsTotal) {
+ this.pagingContext[elementId] = {
+ "skipCount": skipCount,
+ "totalItems" : numItemsTotal
+ }
+ };
+
+ this.getPagingContext = function (elementId) {
+ return this.pagingContext[elementId];
+ };
+
+ this.setPagingContextOffset = function (elementId, offset) {
+ var pgCtx = this.pagingContext[elementId];
+ if (pgCtx == undefined || pgCtx == null)
+ return false;
+ else {
+ this.pagingContext[elementId].skipCount = offset;
+ return true;
+ }
+ };
+
+ this.getPagingContextOffset = function (elementId) {
+ var pgCtx = this.pagingContext[elementId];
+ if (pgCtx == undefined || pgCtx == null)
+ return 0;
+ else
+ return this.pagingContext[elementId].skipCount;
+ };
+
+ this.deletePagingContext = function (elementId) {
+ this.pagingContext[elementId] = null;
+ };
+
this.getRepositoryInfo = function(cbFct) {
var url = this.getUrl();
var data = {
@@ -191,7 +225,7 @@ function CmisSession(urlPrefix, reposito
includeACL: this.opCtx.includeAcls,
includePathSegment: this.opCtx.includePathSegments,
skipCount: this.opCtx.skipCount,
- maxItemsPerPage: this.opCtx.maxItemsPerPage,
+ maxItems: this.opCtx.maxItems,
suppressResponseCodes: true
};
@@ -300,7 +334,7 @@ function CmisSession(urlPrefix, reposito
var properties = {
q: queryString,
cmisaction: "query",
- skipCount: this.opCtx.skipCount,
+ maxItems: this.opCtx.maxItems,
searchAllVersions: this.opCtx.searchAllVersions,
includeAllowableAction: this.opCtx.searchAllVersions,
includeRelationships: this.opCtx.includeRelationships,
@@ -315,9 +349,42 @@ function CmisSession(urlPrefix, reposito
type: "POST",
success: cbFct
});
+ };
+
+ this.doQueryPaged = function(queryString, elementId, cbFct) {
+ trace("doQueryPaged()");
+ var url = this.getUrl();
+ var pgCtx = this.getPagingContext(elementId);
+ var skipCount = this.getPagingContextOffset(elementId);
+ if (null == skipCount)
+ skipCount = 0;
+ var properties = {
+ q: queryString,
+ cmisaction: "query",
+ maxItems: this.opCtx.maxItems,
+ searchAllVersions: this.opCtx.searchAllVersions,
+ includeAllowableAction: this.opCtx.searchAllVersions,
+ includeRelationships: this.opCtx.includeRelationships,
+ skipCount: skipCount,
+ suppressResponseCodes: true
+ };
+ trace("doQuery() " + url);
+ $.ajax( {
+ url: url,
+ data: properties,
+ type: "POST",
+ success: function (data) {
+ if (null == pgCtx) {
+ session.addPagingContext(elementId, 0, data.numItems)
+ } else
+ pgCtx.totalItems = data.numItems;
+ return cbFct.call(this, data);
+ }
+ });
};
+
this.getObjectFromTransaction = function (transId, cbFct) {
var url = this.getUrl();
var data = {
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=1299991&r1=1299990&r2=1299991&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 Tue Mar 13 07:22:10 2012
@@ -95,6 +95,7 @@
}
tbl.append($('<thead>').append(row = $('<tr>')));
+ row.append($('<td>')); // document or folder icon
for (var propKey in propsToDisplay) {
row.append($('<td>').text(propsToDisplayLabel[propKey]));
}
@@ -105,6 +106,14 @@
if (baseType === children.objects[child].object.properties["cmis:baseTypeId"].value) {
row = null;
tbody.append(row = $('<tr>'));
+ // add icons for document, folder in first column:
+ if (baseType == "cmis:document") {
+ var src = $("<img>").attr("src", "images/document.png");
+ row.append($('<td>').html(src));
+ } else if (baseType == "cmis:folder") {
+ var src = $("<img>").attr("src", "images/folder.png");
+ row.append($('<td>').html(src));
+ }
for (var propKey in propsToDisplay) {
var props = children.objects[child].object.properties;
var prop = props[propsToDisplay[propKey]];
@@ -132,12 +141,12 @@
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;
+ for (var child in children.results) {
+ for (var prop in children.results[child].properties) {
+ var propQueryName = children.results[child].properties[prop].queryName;
if ($.inArray(propQueryName, propsToDisplay) < 0) {
propsToDisplay.push(propQueryName);
- propsToDisplayLabel.push(children.objects[child].properties[prop].queryName);
+ propsToDisplayLabel.push(children.results[child].properties[prop].queryName);
}
}
}
@@ -148,11 +157,11 @@
}
tbl.append(tbody = $('<tbody>'));
- for (var child in children.objects) {
+ for (var child in children.results) {
row = null;
tbody.append(row = $('<tr>'));
for (var propKey in propsToDisplay) {
- var props = children.objects[child].properties;
+ var props = children.results[child].properties;
var prop = props[propsToDisplay[propKey]];
if (null != prop && null != prop.value) {
var text = convertValue(prop.value, prop.type);
@@ -256,6 +265,50 @@
// }
}
+ function onClickQueryFirst() {
+ var pageCtx = session.getPagingContext("doquery");
+ pageCtx.skipCount = 0;
+ doQueryWithOffset();
+ }
+
+ function onClickQueryPrev() {
+ var pageCtx = session.getPagingContext("doquery");
+ pageCtx.skipCount = pageCtx.skipCount - session.opCtx.maxItems;
+ if (pageCtx.skipCount < 0)
+ pageCtx.skipCount = 0;
+ doQueryWithOffset();
+ }
+
+ function onClickQueryNext() {
+ var pageCtx = session.getPagingContext("doquery");
+ pageCtx.skipCount = pageCtx.skipCount + session.opCtx.maxItems;
+ if (pageCtx.skipCount >= pageCtx.totalItems)
+ pageCtx.skipCount = pageCtx.totalItems - session.opCtx.maxItems;
+ doQueryWithOffset();
+ }
+
+ function onClickQueryLast() {
+ var pageCtx = session.getPagingContext("doquery");
+ pageCtx.skipCount = pageCtx.totalItems - session.opCtx.maxItems;
+ doQueryWithOffset();
+ }
+
+ function doQueryWithOffset() {
+ checkSession("#queryresponsesection");
+ $("#queryresponsesection *").remove();
+ trace("doing query: " + $('#queryfield').val());
+ session.doQueryPaged($('#queryfield').val(), "doquery", function(data) {
+ if (!checkError(data, "#queryresponsesection")) {
+ var tbl = createQueryTable(data);
+ $("#queryresponsesection").append(tbl).append($("<br>"))
+ .append($("<button>").attr("onClick", "onClickQueryFirst()").append($("<img>").attr("src", "images/first.png")))
+ .append($("<button>").attr("onClick", "onClickQueryPrev()").append($("<img>").attr("src", "images/prev.png")))
+ .append($("<button>").attr("onClick", "onClickQueryNext()").append($("<img>").attr("src", "images/next.png")))
+ .append($("<button>").attr("onClick", "onClickQueryLast()").append($("<img>").attr("src", "images/last.png")));
+ }
+ });
+ };
+
$(document).ready(function() {
$(document).ajaxError(function(event, request, settings, excep){
@@ -349,9 +402,7 @@
var tbl1 = createTable(children, "cmis:folder");
var tbl2 = createTable(children, "cmis:document");
$("#childrensection *").remove();
- $("#childrensection").
- append($('<h4>').text("Folders")).append(tbl1).
- append($('<h4>').text("Documents")).append(tbl2);
+ $("#childrensection").append(tbl1).append(tbl2);
}
});
});
@@ -377,16 +428,10 @@
});
$('#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);
- }
- });
- });
+ session.opCtx.maxItems = 10; // set paging size to 10
+ session.deletePagingContext("doquery");
+ doQueryWithOffset();
+ });
});
</script>
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=1299991&r1=1299990&r2=1299991&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 Tue Mar 13 07:22:10 2012
@@ -186,11 +186,11 @@ 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 (results.results.length > 0, "doQuery result is empty");
+ for (var row in results.results) {
+ var baseTypeId = results.results[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");
+ ok(null != results.results[row].properties["cmis:name"].value, "child has name");
}
trace("testDoQuery done.");
start();
@@ -309,7 +309,7 @@ test("testTypeCache", function() {
ok(types[5] == typeCache.getType(types[5].id), "Just added element is there.");
});
-test("testGetTypeDefinitionWithCache()", function() {
+test("testGetTypeDefinitionWithCache", function() {
trace("testGetTypeDefinitionWithCache ");
expect(5);
@@ -335,3 +335,28 @@ test("testGetTypeDefinitionWithCache()",
start();
});
});
+
+test("testPagingContext", function() {
+ trace("testPagingContext");
+ this.session.addPagingContext("testId1", 0, 150);
+ this.session.addPagingContext("testId2", 0, 200);
+ ok(this.session.getPagingContext("testId1") != null, "Test getPagingContext1");
+ ok(this.session.getPagingContext("testId2") != null, "Test getPagingContext2");
+ ok(this.session.getPagingContext("foo") == undefined, "Test getPagingContext undef");
+ ok(this.session.getPagingContext("foo") == null, "Test getPagingContext unknown");
+ ok(this.session.getPagingContext("testId1") != this.session.getPagingContext("testId2"), "Compare PagingContext");
+ this.session.setPagingContextOffset("testId1", 20);
+ this.session.setPagingContextOffset("testId2", 25);
+ ok(this.session.getPagingContextOffset("testId1") == 20, "Test getPagingContextOffset1");
+ ok(this.session.getPagingContextOffset("testId2") == 25, "Test getPagingContextOffset2");
+ ok(this.session.getPagingContext("testId1").skipCount == 20, "Test getPagingContext1 after set");
+ ok(this.session.getPagingContext("testId2").skipCount == 25, "Test getPagingContext2 after set");
+ ok(this.session.getPagingContext("testId1").totalItems == 150, "Test getPagingContext1 total items after set");
+ ok(this.session.getPagingContext("testId2").totalItems == 200, "Test getPagingContext2 total items after set");
+ this.session.deletePagingContext("testId1");
+ ok(this.session.getPagingContext("testId1") == null, "Test deletePagingContext1");
+ ok(this.session.getPagingContext("testId2") != null, "Test deletePagingContext1");
+ this.session.deletePagingContext("testId2");
+ ok(this.session.getPagingContext("testId1") == null, "Test deletePagingContext2");
+ ok(this.session.getPagingContext("testId2") == null, "Test deletePagingContext2");
+});