cluster_search_ui/commit

Improved image filter code, resolving #5

authorChris Dijkshoorn
Sat Dec 20 14:39:25 2014 +0100
committerChris Dijkshoorn
Sat Dec 20 14:39:25 2014 +0100
commit078604e4cf26ed318399dc24e12d49ddeb8df0e7
treead139eaa4aee0463664c857feb92286f40c2a198
parent550835056fd16ba534516832c06e982ed042c5f3
Diff style: patch stat
diff --git a/web/js/pagination.js b/web/js/pagination.js
index dc355da..70234ad 100644
--- a/web/js/pagination.js
+++ b/web/js/pagination.js
@@ -1,7 +1,7 @@
 /* Pagination
 *  Code for initializing bootstrap pagnination and handling interactions
 */
-function initPagination(numberOfPages, clusterId) {
+function pagination(numberOfPages, clusterId) {
 	// Don't use pagination if there are not enough items
 	if(numberOfPages==1) return "";
 	
diff --git a/web/js/search.js b/web/js/search.js
index ea68466..e03f714 100644
--- a/web/js/search.js
+++ b/web/js/search.js
@@ -117,8 +117,7 @@ function addPath(clusterId) {
 					// Add path to enrichedClusters for future reference
 					enrichedClusters[clusterId] = new cluster(path, 'undefined');
 				
-					$("#cluster"+clusterId).append(
-						pathHtmlElements(path, clusterId))}
+					$("#cluster"+clusterId).append(pathHtmlElements(path, clusterId))}
 				});
 }
 
@@ -169,8 +168,8 @@ function addItems(clusterId) {
 					clusters[clusterId] = clone(enrichedClusters[clusterId]);
 					filterCluster(clusters[clusterId]);
 					var pages = determineNumberOfPages(clusterId);
-					$("#cluster"+clusterId).append(initPagination(pages, clusterId));
-					$("#cluster"+clusterId).append(initThumbnails(clusterId));}
+					$("#cluster"+clusterId).append(pagination(pages, clusterId));
+					$("#cluster"+clusterId).append(thumbnails(clusterId));}
 				});
 }
 
@@ -244,20 +243,23 @@ function rankButtons() {
 									 $.el.a({'href':'javascript:clusterAbstractionTrigger(\'whatLevel\')'},
 											 'Who What Where'))));
 }
+
 function filterTrigger(type) {
-	var changeThumbs = false;
+	var changeShownContent = false;
 	console.log('Filtering type: ', type);
 	if(type == 'onlyImages' && !(displayOptions.imageFilter == 'onlyImages')) {
 		displayOptions.imageFilter = 'onlyImages';
-		changeThumbs = true;
+		changeShownContent = true;
 	}
 	if(type == 'allObjects'  && !(displayOptions.imageFilter == 'allObjects')) {
 		displayOptions.imageFilter = 'allObjects';
-		changeThumbs = true;
+		changeShownContent = true;
 	}
-	if(changeThumbs) {
-		console.log('Should change something');
-		filteredHtml = htmlResults();
+	console.log('Should change something', changeShownContent);
+	if(changeShownContent) {
+		clusters = clone(enrichedClusters);
+		filter();
+		updateClusters();
 	}
 }
 
@@ -277,22 +279,39 @@ function clusterAbstractionTrigger(type) {
 	}
 	if(changeClusterAbstraction) {
 		console.log("Should be changing the Cluster Abstraction Level");
-		htmlResults();
+		updateClusters();
+	}
+}
+
+function updateClusters() {
+	for(var i=0; i<clusters.length; i++) {
+		console.log('Adding clusters', clusters);
+		if(clusters[i].items.length==0) {
+			$("#cluster"+i).children().remove();
+			$("#cluster"+i).append(pathHtmlElements(clusters[i].path, i));
+			$("#cluster"+i).append(noFilterResultsHtml());
+		} else {
+			$("#cluster"+i).children().remove();;
+			$("#cluster"+i).append(pathHtmlElements(clusters[i].path, i));
+			var pages = determineNumberOfPages(i);
+			$("#cluster"+i).append(pagination(pages, i));
+			$("#cluster"+i).append(thumbnails(i));
+		}
 	}
 }
 
+function noFilterResultsHtml() {
+	return $.el.h4('No results due to filter: ',
+				 $.el.span({'class':'text-danger'},
+					displayOptions.imageFilter));
+}
+
 function filter() {
-	console.log('Filtering');
 	if(displayOptions.imageFilter == 'onlyImages') {
+		console.log('Filtering out objects without image');
 		// Remove all items without an image (read: with a stub)
 		for(var i=0; i<clusters.length; i++) {
 			filterCluster(clusters[i]);
-			// Remove empty clusters
-			if(clusters[i].items.length == 0) {
-				clusters[i].splice(i, 1);
-				// Move the index one back because of removal
-				i--;
-			}
 		}
 	}
 }
diff --git a/web/js/thumbnail.js b/web/js/thumbnail.js
index ecf1282..2f95290 100644
--- a/web/js/thumbnail.js
+++ b/web/js/thumbnail.js
@@ -1,7 +1,7 @@
 /* Thumbnail
 *  Code for initializing bootstrap thumbnails and handling changes
 */
-function initThumbnails(clusterId) {
+function thumbnails(clusterId) {
 	var items = clusters[clusterId].items;
 	var stop = displayOptions.numberDisplayedItems;
 	//Check if less results available then there are to be displayed