You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2018/03/02 03:58:08 UTC

[sling-whiteboard] branch master updated: Enabling sorting of rows

This is an automated email from the ASF dual-hosted git repository.

dklco pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 71bfe54  Enabling sorting of rows
71bfe54 is described below

commit 71bfe54b41b239ed37e4476af150aef576e8f455
Author: Dan Klco <da...@gmail.com>
AuthorDate: Thu Mar 1 19:58:00 2018 -0800

    Enabling sorting of rows
---
 cms/ui/src/main/frontend/src/js/scripts.js         | 39 ++++++++++++++++++++++
 .../cms/columns/lastmodified/lastmodified.jsp      |  2 +-
 .../components/cms/columns/publish/publish.jsp     |  2 +-
 .../components/cms/contenttable/contenttable.jsp   |  5 +--
 4 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/cms/ui/src/main/frontend/src/js/scripts.js b/cms/ui/src/main/frontend/src/js/scripts.js
index 8bb38d5..425ac27 100644
--- a/cms/ui/src/main/frontend/src/js/scripts.js
+++ b/cms/ui/src/main/frontend/src/js/scripts.js
@@ -172,6 +172,45 @@ Sling.CMS = {
 			});
 			$('.content-filter input[type=text]').keyup(filterContent).change(filterContent);
 		}
+	};
+	
+	Sling.CMS.ext['content-sort'] = {
+		decorate: function($ctx) {
+			$ctx.find('.sortable').each(function(){
+				var $table = $(this);
+				$table.find('.sortable__header').click(function() {
+					var idx = Array.from(this.parentNode.children).indexOf(this);
+					var $h = $(this);
+					var sortStatus = 1;
+					if($h.data('sort-status')){
+						sortStatus = parseInt($h.data('sort-status'),10);
+					}
+					var name = $h.data('attribute');
+				    var list = $table.find(".sortable__row").get();
+				    list.sort(function(rowa, rowb) {
+				    		var vala = null;
+				    		var $ela = $($(rowa).find('td')[idx]);
+				    		if($ela.data('sort-value')){
+				    			vala = $ela.data('sort-value');
+				    		} else {
+				    			vala = $.trim($ela.text()).toLowerCase();
+				    		}
+				    		var valb = null;
+				    		var $elb = $($(rowb).find('td')[idx]);
+				    		if($elb.data('sort-value')){
+				    			valb = $elb.data('sort-value');
+				    		} else {
+				    			valb = $.trim($elb.text()).toLowerCase();
+				    		}
+				    		$h.data('sort-status', sortStatus * -1);
+				        return vala.localeCompare(valb) * sortStatus;
+				    });
+				    for (var i = 0; i < list.length; i++) {
+				        list[i].parentNode.appendChild(list[i]);
+				    }
+				});
+			});
+		}
 	}
 
 	Sling.CMS.ext['fetch-json'] = {
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/lastmodified/lastmodified.jsp b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/lastmodified/lastmodified.jsp
index 471d139..cea0ce6 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/lastmodified/lastmodified.jsp
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/lastmodified/lastmodified.jsp
@@ -20,7 +20,7 @@
 <c:set var="modifiedProperty" value="${colConfig.valueMap.subPath}jcr:lastModified" />
 <c:set var="modifiedByProperty" value="${colConfig.valueMap.subPath}jcr:lastModifiedBy" />
 <fmt:formatDate var="lastModified" type = "both"  dateStyle = "medium" timeStyle = "medium" value="${resource.valueMap[modifiedProperty].time}" />
-<td class="Cell-Static" title="${sling:encode(colValue,'HTML_ATTR')}">
+<td class="Cell-Static" title="${sling:encode(colValue,'HTML_ATTR')}" data-value="${resource.valueMap[modifiedProperty].time.time}">
 	<sling:encode value="${lastModified}" mode="HTML" /><br/>
 	<sling:encode value="${resource.valueMap[modifiedByProperty]}" mode="HTML" />
 </td>
\ No newline at end of file
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/publish/publish.jsp b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/publish/publish.jsp
index 71a7e00..427e240 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/publish/publish.jsp
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/columns/publish/publish.jsp
@@ -17,7 +17,7 @@
  * under the License.
  */ --%>
 <%@include file="/libs/sling-cms/global.jsp"%>
-<td class="Cell-Publish">
+<td class="Cell-Publish" data-value="${sling:getRelativeResource(resource,'jcr:content').valueMap.published ? 0 : 1}">
 	<c:choose>
 		<c:when test="${sling:getRelativeResource(resource,'jcr:content').valueMap.published}">
 			<a class="Button Fetch-Modal"  href="/cms/shared/unpublish.html${resource.path}" title="Content Published" data-title="Unpublish" data-path=".Main-Content form">
diff --git a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contenttable/contenttable.jsp b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contenttable/contenttable.jsp
index 312ea53..bef9eb8 100644
--- a/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contenttable/contenttable.jsp
+++ b/cms/ui/src/main/resources/jcr_root/libs/sling-cms/components/cms/contenttable/contenttable.jsp
@@ -21,8 +21,9 @@
 	<thead>
 		<tr>
 			<c:forEach var="column" items="${sling:listChildren(sling:getRelativeResource(resource,'columns'))}">
-				<th class="Column-${column.name}">
+				<th class="sortable__header" data-attribute="${column.name}">
 					<sling:encode value="${column.valueMap.title}" mode="HTML" />
+					<span class="sortable__indicator"></span>
 				</th>
 			</c:forEach>
 		</tr>
@@ -32,7 +33,7 @@
 		<c:forEach var="child" items="${sling:listChildren(sling:getResource(resourceResolver, parentPath))}">
 			<sling:getResource var="typeConfig" base="${resource}" path="types/${child.valueMap['jcr:primaryType']}" />
 			<c:if test="${typeConfig != null && !fn:contains(child.name,':')}">
-				<tr data-resource="${child.path}" data-type="${typeConfig.path}">
+				<tr class="sortable__row" data-resource="${child.path}" data-type="${typeConfig.path}">
 					<c:forEach var="column" items="${sling:listChildren(sling:getRelativeResource(typeConfig,'columns'))}">
 						<c:set var="configPath" value="columns/${column.name}"/>
 						<c:set var="colConfig" value="${sling:getRelativeResource(typeConfig,configPath)}" scope="request" />

-- 
To stop receiving notification emails like this one, please contact
dklco@apache.org.