[Pkg-owncloud-commits] [owncloud] 17/83: backport search scrollto & filter to stable5

David Prévot taffit at moszumanska.debian.org
Wed Dec 18 13:05:25 UTC 2013


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch 5.0
in repository owncloud.

commit cb656c8321e71812809044c19525bf0b9a639b2c
Author: Jörn Friedrich Dreyer <jfd at butonic.de>
Date:   Mon Nov 18 14:18:08 2013 +0100

    backport search scrollto & filter to stable5
---
 apps/files/css/files.css     |  3 +++
 apps/files/js/filelist.js    | 31 +++++++++++++++++++++++++
 apps/files/js/files.js       |  5 ++++
 core/js/js.js                | 22 ++++++++++++++++++
 lib/search/provider/file.php |  3 ++-
 lib/search/result.php        |  3 ++-
 search/js/result.js          | 55 +++++++++++++++++++++++++++++++++++---------
 7 files changed, 109 insertions(+), 13 deletions(-)

diff --git a/apps/files/css/files.css b/apps/files/css/files.css
index 37a9c7e..e16088b 100644
--- a/apps/files/css/files.css
+++ b/apps/files/css/files.css
@@ -63,6 +63,9 @@
 tbody tr { background-color:#fff; height:2.5em; }
 tbody tr:hover, tbody tr:active, tbody tr.selected { background-color:#f8f8f8; }
 tbody tr.selected { background-color:#eee; }
+#filestable tbody tr.searchresult {
+	background-color: rgb(240,240,240);
+}
 tbody a { color:#000; }
 span.extension, span.uploading, td.date { color:#999; }
 span.extension { text-transform:lowercase; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=70)"; filter:alpha(opacity=70); opacity:.7; -webkit-transition:opacity 300ms; -moz-transition:opacity 300ms; -o-transition:opacity 300ms; transition:opacity 300ms; }
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 5dd9d45..fc1ebab 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -367,6 +367,37 @@ var FileList={
 						});
 					}
 				});
+	},
+	scrollTo:function(file) {
+		//scroll to and highlight preselected file
+		var $scrolltorow = $('tr[data-file="'+file+'"]');
+		if ($scrolltorow.exists()) {
+			$scrolltorow.addClass('searchresult');
+			$(window).scrollTop($scrolltorow.position().top);
+			//remove highlight when hovered over
+			$scrolltorow.one('hover', function() {
+				$scrolltorow.removeClass('searchresult');
+			});
+		}
+	},
+	filter:function(query) {
+		$('#fileList tr:not(.summary)').each(function(i,e) {
+			if ($(e).data('file').toLowerCase().indexOf(query.toLowerCase()) !== -1) {
+				$(e).addClass("searchresult");
+			} else {
+				$(e).removeClass("searchresult");
+			}
+		});
+		//do not use scrollto to prevent removing searchresult css class
+		var first = $('#fileList tr.searchresult').first();
+		if (first.exists()) {
+			$(window).scrollTop(first.position().top);
+		}
+	},
+	unfilter:function() {
+		$('#fileList tr.searchresult').each(function(i,e) {
+			$(e).removeClass("searchresult");
+		});
 	}
 };
 
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 4163ef8..d8aca4d 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -546,6 +546,11 @@ $(document).ready(function() {
 			}
 		});
 	}
+
+	//scroll to and highlight preselected file
+	if (getURLParameter('scrollto')) {
+		FileList.scrollTo(getURLParameter('scrollto'));
+	}
 });
 
 function scanFiles(force, dir, users){
diff --git a/core/js/js.js b/core/js/js.js
index 586d698..73711b3 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -666,11 +666,17 @@ $(document).ready(function(){
 			}
 		}else if(event.keyCode===27){//esc
 			OC.search.hide();
+			if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
+				FileList.unfilter();
+			}
 		}else{
 			var query=$('#searchbox').val();
 			if(OC.search.lastQuery!==query){
 				OC.search.lastQuery=query;
 				OC.search.currentResult=-1;
+				if (FileList && typeof FileList.filter === 'function') { //TODO add hook system
+						FileList.filter(query);
+				}
 				if(query.length>2){
 					OC.search(query);
 				}else{
@@ -808,6 +814,13 @@ function formatDate(date){
 	return $.datepicker.formatDate(datepickerFormatDate, date)+' '+date.getHours()+':'+((date.getMinutes()<10)?'0':'')+date.getMinutes();
 }
 
+// taken from http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery
+function getURLParameter(name) {
+	return decodeURI(
+			(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]
+			);
+}
+
 /**
  * takes an absolute timestamp and return a string with a human-friendly relative date
  * @param int a Unix timestamp
@@ -892,6 +905,15 @@ $.fn.selectRange = function(start, end) {
 };
 
 /**
+ * check if an element exists.
+ * allows you to write if ($('#myid').exists()) to increase readability
+ * @link http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery
+ */
+jQuery.fn.exists = function(){
+	return this.length > 0;
+};
+
+/**
  * Calls the server periodically every 15 mins to ensure that session doesnt
  * time out
  */
diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php
index 4d88c2a..9bd5093 100644
--- a/lib/search/provider/file.php
+++ b/lib/search/provider/file.php
@@ -10,6 +10,7 @@ class OC_Search_Provider_File extends OC_Search_Provider{
 			$mime = $fileData['mimetype'];
 
 			$name = basename($path);
+			$container = dirname($path);
 			$text = '';
 			$skip = false;
 			if($mime=='httpd/unix-directory') {
@@ -37,7 +38,7 @@ class OC_Search_Provider_File extends OC_Search_Provider{
 				}
 			}
 			if(!$skip) {
-				$results[] = new OC_Search_Result($name, $text, $link, $type);
+				$results[] = new OC_Search_Result($name, $text, $link, $type, $container);
 			}
 		}
 		return $results;
diff --git a/lib/search/result.php b/lib/search/result.php
index 08beaea..6a6300b 100644
--- a/lib/search/result.php
+++ b/lib/search/result.php
@@ -15,10 +15,11 @@ class OC_Search_Result{
 	 * @param string $link link for the result
 	 * @param string $type the type of result as human readable string ('File', 'Music', etc)
 	 */
-	public function __construct($name, $text, $link, $type) {
+	public function __construct($name, $text, $link, $type, $container) {
 		$this->name=$name;
 		$this->text=$text;
 		$this->link=$link;
 		$this->type=$type;
+		$this->container=$container;
 	}
 }
diff --git a/search/js/result.js b/search/js/result.js
index 78fa8ef..2bad993 100644
--- a/search/js/result.js
+++ b/search/js/result.js
@@ -8,15 +8,23 @@ OC.search.catagorizeResults=function(results){
 		types[type].push(results[i]);
 	}
 	return types;
-}
+};
 OC.search.hide=function(){
 	$('#searchresults').hide();
 	if($('#searchbox').val().length>2){
 		$('#searchbox').val('');
+		if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
+			FileList.unfilter();
+		}
 	};
+	if ($('#searchbox').val().length === 0) {
+		if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
+			FileList.unfilter();
 }
+	}
+};
 OC.search.showResults=function(results){
-	if(results.length==0){
+	if(results.length === 0){
 		return;
 	}
 	if(!OC.search.showResults.loaded){
@@ -30,6 +38,9 @@ OC.search.showResults=function(results){
 			});
 			$(document).click(function(event){
 				OC.search.hide();
+				if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system
+					FileList.unfilter();
+				}
 			});
 			OC.search.lastResults=results;
 			OC.search.showResults(results);
@@ -39,30 +50,52 @@ OC.search.showResults=function(results){
 		$('#searchresults').show();
 		$('#searchresults tr.result').remove();
 		var index=0;
-		for(var name in types){
-			var type=types[name];
+		for(var typeid in types){
+			var type=types[typeid];
 			if(type.length>0){
 				for(var i=0;i<type.length;i++){
 					var row=$('#searchresults tr.template').clone();
 					row.removeClass('template');
 					row.addClass('result');
-					if (i == 0){
-						row.children('td.type').text(name);
+					row.data('type', typeid);
+					row.data('name', type[i].name);
+					row.data('text', type[i].text);
+					row.data('container', type[i].container);
+					if (i === 0){
+						row.children('td.type').text(typeid);
 					}
-					row.find('td.result a').attr('href',type[i].link);
 					row.find('td.result div.name').text(type[i].name);
 					row.find('td.result div.text').text(type[i].text);
+					if (type[i].container) {
+						var containerName = OC.basename(type[i].container);
+						if (containerName === '') {
+							containerName = '/';
+						}
+						var containerLink = OC.linkTo('files', 'index.php')
+							+'?dir='+encodeURIComponent(type[i].container)
+							+'&scrollto='+encodeURIComponent(type[i].name);
+						row.find('td.result a')
+							.attr('href', containerLink)
+							.attr('title', t('core', 'Show in {folder}', {folder: containerName}));
+					} else {
+						row.find('td.result a').attr('href', type[i].link);
+					}
 					row.data('index',index);
 					index++;
-					if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
-						OC.search.customResults[name](row,type[i]);
+					if(OC.search.customResults[typeid]){//give plugins the ability to customize the entries in here
+						OC.search.customResults[typeid](row,type[i]);
 					}
 					$('#searchresults tbody').append(row);
 				}
 			}
 		}
+		$('#searchresults').on('click', 'result', function () {
+			if ($(this).data('type') === 'Files') {
+				//FIXME use ajax to navigate to folder & highlight file
+			}
+		});
 	}
-}
+};
 OC.search.showResults.loaded=false;
 
 OC.search.renderCurrent=function(){
@@ -71,4 +104,4 @@ OC.search.renderCurrent=function(){
 		$('#searchresults tr.result').removeClass('current');
 		$(result).addClass('current');
 	}
-}
+};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list