From 0ba3093196fee7079583847b40ef3a8e00df47a7 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 4 Dec 2014 13:43:38 +0100 Subject: full page search results --- search/css/results.css | 40 +++++++++++++++++++-------------------- search/js/result.js | 32 ++++++++++++++++++++++++------- search/templates/part.results.php | 3 ++- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/search/css/results.css b/search/css/results.css index 6aa73f55c33..8bcf2348df2 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -4,26 +4,16 @@ #searchresults { background-color:#fff; - border-bottom-left-radius:11px; - box-shadow:0 0 10px #000; - list-style:none; - max-height:80%; overflow-x:hidden; overflow-y: auto; - padding-bottom:6px; position:fixed; - right:0; text-overflow:ellipsis; - top:45px; - width:380px; - max-width: 95%; + top:0; + padding-top: 45px; + height: 100%; z-index:75; } -.ie8 #searchresults { - border: 1px solid #666 !important; -} - #searchresults li.resultHeader { background-color:#eee; border-bottom:solid 1px #CCC; @@ -44,22 +34,34 @@ } #searchresults td { - padding:0 .3em; - height: 44px; + border-top: 20px solid white; + border-bottom: none; } #searchresults tr.template { display: none; } #searchresults .name, -#searchresults .text { +#searchresults .text, +#searchresults .path { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } +#searchresults .name { + font-size: larger; +} #searchresults .text { - padding-left: 16px; - color: #999; + white-space: normal; + color: #545454; +} +#searchresults .path { + color: green; +} +#searchresults .text em { + color: #545454; + font-weight: bold; + opacity: 1; } #searchresults td.result * { @@ -79,8 +81,6 @@ } #searchresults td.type { - border-bottom:none; - border-right:1px solid #aaa; font-weight:700; text-align:right; width:3.5em; diff --git a/search/js/result.js b/search/js/result.js index fe84aecde3e..147377aff0c 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -45,8 +45,8 @@ OC.search.showResults=function(results){ return; } if(!OC.search.showResults.loaded){ - var parent=$('
'); - $('body').append(parent); + var parent=$('
'); + $('#app-content').append(parent); parent.load(OC.filePath('search','templates','part.results.php'),function(){ OC.search.showResults.loaded=true; $('#searchresults').click(function(event){ @@ -74,19 +74,37 @@ OC.search.showResults=function(results){ var row=$('#searchresults tr.template').clone(); row.removeClass('template'); row.addClass('result'); - + row.data('type', typeid); row.data('name', type[i].name); + row.data('path', type[i].path); row.data('text', type[i].text); row.data('index',index); - + if (i === 0){ var typeName = OC.search.resultTypes[typeid]; row.children('td.type').text(t('lib', typeName)); } + + if (type[i].path) { + OCA.Files.App.fileList.lazyLoadPreview({ + path: type[i].path, + mime: type[i].mime_type, + callback: function (url) { + row.find('td.type').css('background-image', 'url(' + url + ')'); + } + }); + } + row.find('td.result div.name').text(type[i].name); - row.find('td.result div.text').text(type[i].text); - + row.find('td.result div.path').text(type[i].path); + if (typeof type[i].highlights === 'object') { + var highlights = type[i].highlights.join(' … '); + row.find('td.result div.text').html(highlights); + } else { + row.find('td.result div.text').text(type[i].text); + } + if (type[i].path) { var parent = OC.dirname(type[i].path); if (parent === '') { @@ -105,7 +123,7 @@ OC.search.showResults=function(results){ } else { row.find('td.result a').attr('href', type[i].link); } - + index++; /** * Give plugins the ability to customize the search results. For example: diff --git a/search/templates/part.results.php b/search/templates/part.results.php index b6e7bad4a2f..4a5cdd1b3eb 100644 --- a/search/templates/part.results.php +++ b/search/templates/part.results.php @@ -5,7 +5,8 @@ -
+
+
-- cgit v1.2.3 From d3662722f66eb5b97593922a11e5357eff0fb042 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Sat, 6 Dec 2014 00:53:06 +0100 Subject: new OC.Search, add search result formatters and handlers, use full content width for results --- core/ajax/preview.php | 2 +- core/js/js.js | 77 ++++++++++---- lib/private/search/result/file.php | 2 +- search/css/results.css | 34 ++---- search/js/result.js | 211 ++++++++++++++++++++----------------- search/templates/part.results.php | 11 +- 6 files changed, 187 insertions(+), 150 deletions(-) diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 56ef5ea847b..03dfb483062 100644 --- a/core/ajax/preview.php +++ b/core/ajax/preview.php @@ -40,9 +40,9 @@ try { $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); $preview->setKeepAspect($keepAspect); + $preview->showPreview(); } - $preview->showPreview(); } catch (\Exception $e) { \OC_Response::setStatus(500); \OC_Log::write('core', $e->getmessage(), \OC_Log::DEBUG); diff --git a/core/js/js.js b/core/js/js.js index 57ce1ab6955..9d62b7cac1e 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -319,8 +319,8 @@ var OC={ } } $.getJSON(OC.generateUrl('search/ajax/search.php'), {inApps:inApps, query:query}, function(results){ - OC.search.lastResults=results; - OC.search.showResults(results); + OC.Search.lastResults=results; + OC.Search.showResults(results); }); } }, 500), @@ -608,10 +608,47 @@ OC.Plugins = { /** * @namespace OC.search */ -OC.search.customResults={}; -OC.search.currentResult=-1; -OC.search.lastQuery=''; -OC.search.lastResults={}; +OC.search.customResults = {}; +/** + * @deprecated use get/setFormatter() instead + */ +OC.search.resultTypes = {}; + +/** + * @namespace OC.Search + */ +OC.Search = { + /** + * contains closures that are called to format search results + */ + formatter:{}, + setFormatter: function(type, formatter) { + this.formatter[type] = formatter; + }, + hasFormatter: function(type) { + return typeof this.formatter[type] !== 'undefined'; + }, + getFormatter: function(type) { + return this.formatter[type]; + }, + /** + * contains closures that are called when a search result has been clicked + */ + handler:{}, + setHandler: function(type, handler) { + this.handler[type] = handler; + }, + hasHandler: function(type) { + return typeof this.handler[type] !== 'undefined'; + }, + getHandler: function(type) { + return this.handler[type]; + }, + currentResult:-1, + lastQuery:'', + lastResults:{} +}; + OC.addStyle.loaded=[]; OC.addScript.loaded=[]; @@ -1043,38 +1080,38 @@ function initCore() { }); $('#searchbox').keyup(function(event){ if(event.keyCode===13){//enter - if(OC.search.currentResult>-1){ - var result=$('#searchresults tr.result a')[OC.search.currentResult]; + if(OC.Search.currentResult>-1){ + var result=$('#searchresults tr.result a')[OC.Search.currentResult]; window.location = $(result).attr('href'); } }else if(event.keyCode===38){//up - if(OC.search.currentResult>0){ - OC.search.currentResult--; - OC.search.renderCurrent(); + if(OC.Search.currentResult>0){ + OC.Search.currentResult--; + OC.Search.renderCurrent(); } }else if(event.keyCode===40){//down - if(OC.search.lastResults.length>OC.search.currentResult+1){ - OC.search.currentResult++; - OC.search.renderCurrent(); + if(OC.Search.lastResults.length>OC.Search.currentResult+1){ + OC.Search.currentResult++; + OC.Search.renderCurrent(); } }else if(event.keyCode===27){//esc - OC.search.hide(); + 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(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{ - if(OC.search.hide){ - OC.search.hide(); + if(OC.Search.hide){ + OC.Search.hide(); } } } diff --git a/lib/private/search/result/file.php b/lib/private/search/result/file.php index 331fdaa383a..13f1a62fbc0 100644 --- a/lib/private/search/result/file.php +++ b/lib/private/search/result/file.php @@ -83,7 +83,7 @@ class File extends \OCP\Search\Result { $this->path = $path; $this->size = $data->getSize(); $this->modified = $data->getMtime(); - $this->mime_type = $data->getMimetype(); + $this->mime = $data->getMimetype(); } /** diff --git a/search/css/results.css b/search/css/results.css index 8bcf2348df2..78b60e65e45 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -11,21 +11,10 @@ top:0; padding-top: 45px; height: 100%; + box-sizing: border-box; z-index:75; } -#searchresults li.resultHeader { - background-color:#eee; - border-bottom:solid 1px #CCC; - font-size:1.2em; - font-weight:700; - padding:.2em; -} - -#searchresults li.result { - margin-left:2em; -} - #searchresults table { border-spacing:0; table-layout:fixed; @@ -64,26 +53,17 @@ opacity: 1; } -#searchresults td.result * { +#searchresults tr.result * { cursor:pointer; } -#searchresults td.container { - width:20px; -} - -#searchresults td.container img { - vertical-align: middle; - display:none; -} -#searchresults tr:hover td.container img { - display:inline; -} - -#searchresults td.type { +#searchresults td.icon { font-weight:700; text-align:right; - width:3.5em; + width:32px; + height: 40px; + background-position: 30px 4px; + background-repeat: no-repeat; } #searchresults tr.current { diff --git a/search/js/result.js b/search/js/result.js index 147377aff0c..3d3cbd56aea 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -9,24 +9,13 @@ */ //translations for result type ids, can be extended by apps -OC.search.resultTypes={ +OC.Search.resultTypes={ file: t('core','File'), folder: t('core','Folder'), image: t('core','Image'), audio: t('core','Audio') }; -OC.search.catagorizeResults=function(results){ - var types={}; - for(var i=0;i2){ $('#searchbox').val(''); @@ -40,117 +29,149 @@ OC.search.hide=function(){ } } }; -OC.search.showResults=function(results){ +OC.Search.showResults=function(results){ if(results.length === 0){ return; } - if(!OC.search.showResults.loaded){ + if(!OC.Search.showResults.loaded){ var parent=$('
'); $('#app-content').append(parent); parent.load(OC.filePath('search','templates','part.results.php'),function(){ - OC.search.showResults.loaded=true; + OC.Search.showResults.loaded=true; $('#searchresults').click(function(event){ - OC.search.hide(); + OC.Search.hide(); event.stopPropagation(); }); $(document).click(function(event){ - OC.search.hide(); + OC.Search.hide(); if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system FileList.unfilter(); } }); - OC.search.lastResults=results; - OC.search.showResults(results); + OC.Search.lastResults=results; + OC.Search.showResults(results); }); - }else{ - var types=OC.search.catagorizeResults(results); - $('#searchresults').show(); + } else { $('#searchresults tr.result').remove(); - var index=0; - for(var typeid in types){ - var type=types[typeid]; - if(type.length>0){ - for(var i=0;i= 0) ... - * }; - */ - if(OC.search.customResults[typeid]){ - OC.search.customResults[typeid](row, type[i]); - } - $('#searchresults tbody').append(row); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'places/link') + ')'); + /** + * Give plugins the ability to customize the search results. For example: + * OC.search.customResults.file = function (row, item){ + * if(item.name.search('.json') >= 0) ... + * }; + */ + if(OC.Search.hasFormatter(result.type)){ + OC.Search.getFormatter(result.type)($row, result); + } else + { + // for backward compatibility add text div + $row.find('td.info div.name').addClass('result') + $row.find('td.result div.name').after('
'); + $row.find('td.result div.text').text(result.name); + if(OC.search.customResults[result.type]){ + OC.search.customResults[result.type]($row, result); } } - } - $('#searchresults').on('click', 'result', function () { - if ($(this).data('type') === 'Files') { - //FIXME use ajax to navigate to folder & highlight file + $('#searchresults tbody').append($row); + }); + + $('#searchresults').on('click', 'tr.result', function (event) { + var $row = $(this); + var result = $row.data('result'); + if(OC.Search.hasHandler(result.type)){ + var result = OC.Search.getHandler(result.type)($row, result, event); + OC.Search.hide(); + event.stopPropagation(); + return result; } }); } }; -OC.search.showResults.loaded=false; +OC.Search.showResults.loaded=false; -OC.search.renderCurrent=function(){ +OC.Search.renderCurrent=function(){ if($('#searchresults tr.result')[OC.search.currentResult]){ var result=$('#searchresults tr.result')[OC.search.currentResult]; $('#searchresults tr.result').removeClass('current'); $(result).addClass('current'); } }; + +OC.Search.setFormatter('file', function ($row, result) { + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } + + $pathDiv = $('
').text(result.path) + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + + if (OCA.Files) { + OCA.Files.App.fileList.lazyLoadPreview({ + path: result.path, + mime: result.mime, + callback: function (url) { + $row.find('td.icon').css('background-image', 'url(' + url + ')'); + } + }); + } else { + // FIXME how to get mime icon if not in files app + var mimeicon = result.mime.replace('/','-'); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/'+mimeicon) + ')'); + var dir = OC.dirname(result.path); + if (dir === '') { + dir = '/'; + } + $row.find('td.info a').attr('href', + OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir:dir, scrollto:result.name}) + ); + } +}); +OC.Search.setHandler('file', function ($row, result, event) { + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); + OCA.Files.App.fileList.scrollTo(result.name); + return false; + } else { + return true; + } +}); + +OC.Search.setFormatter('folder', function ($row, result) { + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } + + var $pathDiv = $('
').text(result.path) + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); +}); +OC.Search.setHandler('folder', function ($row, result, event) { + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(result.path); + return false; + } else { + return true; + } +}); diff --git a/search/templates/part.results.php b/search/templates/part.results.php index 4a5cdd1b3eb..451df7b143f 100644 --- a/search/templates/part.results.php +++ b/search/templates/part.results.php @@ -1,13 +1,12 @@
+ - - + -- cgit v1.2.3 From 088323aad5de7b2fadd3c26a10cf4bdf51b5ae73 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 10 Dec 2014 17:11:02 +0100 Subject: move code from js.js to search.js in the search app --- core/js/js.js | 61 ++------------------------- lib/base.php | 1 + search/js/result.js | 49 +++++++++++----------- search/js/search.js | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 82 deletions(-) create mode 100644 search/js/search.js diff --git a/core/js/js.js b/core/js/js.js index 9d62b7cac1e..60237a7fe83 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -308,22 +308,9 @@ var OC={ * Do a search query and display the results * @param {string} query the search query */ - search: _.debounce(function(query){ - if(query){ - OC.addStyle('search','results'); - var classList = document.getElementById('content').className.split(/\s+/); - var inApps = []; - for (var i = 0; i < classList.length; i++) { - if (classList[i].indexOf('app-') === 0) { - var inApps = [classList[i].substr(4)]; - } - } - $.getJSON(OC.generateUrl('search/ajax/search.php'), {inApps:inApps, query:query}, function(results){ - OC.Search.lastResults=results; - OC.Search.showResults(results); - }); - } - }, 500), + search: function (query) { + OC.Search.search(query) + }, /** * Dialog helper for jquery dialogs. * @@ -1075,48 +1062,6 @@ function initCore() { }else{ SVGSupport.checkMimeType(); } - $('form.searchbox').submit(function(event){ - event.preventDefault(); - }); - $('#searchbox').keyup(function(event){ - if(event.keyCode===13){//enter - if(OC.Search.currentResult>-1){ - var result=$('#searchresults tr.result a')[OC.Search.currentResult]; - window.location = $(result).attr('href'); - } - }else if(event.keyCode===38){//up - if(OC.Search.currentResult>0){ - OC.Search.currentResult--; - OC.Search.renderCurrent(); - } - }else if(event.keyCode===40){//down - if(OC.Search.lastResults.length>OC.Search.currentResult+1){ - OC.Search.currentResult++; - OC.Search.renderCurrent(); - } - }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{ - if(OC.Search.hide){ - OC.Search.hide(); - } - } - } - } - }); // user menu $('#settings #expand').keydown(function(event) { diff --git a/lib/base.php b/lib/base.php index 009732ead7b..551d0afbd78 100644 --- a/lib/base.php +++ b/lib/base.php @@ -362,6 +362,7 @@ class OC { OC_Util::addScript("eventsource"); OC_Util::addScript("config"); //OC_Util::addScript( "multiselect" ); + OC_Util::addScript('search', 'search'); OC_Util::addScript('search', 'result'); OC_Util::addScript("oc-requesttoken"); OC_Util::addScript("apps"); diff --git a/search/js/result.js b/search/js/result.js index 3d3cbd56aea..95526749c53 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -8,14 +8,7 @@ * */ -//translations for result type ids, can be extended by apps -OC.Search.resultTypes={ - file: t('core','File'), - folder: t('core','Folder'), - image: t('core','Image'), - audio: t('core','Audio') -}; -OC.Search.hide=function(){ +OC.Search.hide = function(){ $('#searchresults').hide(); if($('#searchbox').val().length>2){ $('#searchbox').val(''); @@ -29,15 +22,15 @@ OC.Search.hide=function(){ } } }; -OC.Search.showResults=function(results){ +OC.Search.showResults = function(results){ if(results.length === 0){ return; } - if(!OC.Search.showResults.loaded){ - var parent=$('
'); + if (!OC.Search.showResults.loaded){ + var parent = $('
'); $('#app-content').append(parent); parent.load(OC.filePath('search','templates','part.results.php'),function(){ - OC.Search.showResults.loaded=true; + OC.Search.showResults.loaded = true; $('#searchresults').click(function(event){ OC.Search.hide(); event.stopPropagation(); @@ -68,19 +61,18 @@ OC.Search.showResults=function(results){ $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'places/link') + ')'); /** * Give plugins the ability to customize the search results. For example: - * OC.search.customResults.file = function (row, item){ + * OC.search.customResults.file = function (row, item){ FIXME * if(item.name.search('.json') >= 0) ... * }; */ - if(OC.Search.hasFormatter(result.type)){ + if (OC.Search.hasFormatter(result.type)) { OC.Search.getFormatter(result.type)($row, result); - } else - { + } else { // for backward compatibility add text div $row.find('td.info div.name').addClass('result') $row.find('td.result div.name').after('
'); $row.find('td.result div.text').text(result.name); - if(OC.search.customResults[result.type]){ + if(OC.search.customResults && OC.search.customResults[result.type]) { OC.search.customResults[result.type]($row, result); } } @@ -99,13 +91,22 @@ OC.Search.showResults=function(results){ }); } }; -OC.Search.showResults.loaded=false; +OC.Search.showResults.loaded = false; -OC.Search.renderCurrent=function(){ - if($('#searchresults tr.result')[OC.search.currentResult]){ - var result=$('#searchresults tr.result')[OC.search.currentResult]; - $('#searchresults tr.result').removeClass('current'); - $(result).addClass('current'); +OC.Search.renderCurrent = function(){ + var $resultsContainer = $('#searchresults'); + var result = $resultsContainer.find('tr.result')[OC.Search.currentResult] + if (result) { + var $result = $(result); + var currentOffset = $resultsContainer.scrollTop(); + $resultsContainer.animate({ + // Scrolling to the top of the new result + scrollTop: currentOffset + $result.offset().top - $result.height() * 2 + }, { + duration: 100 + }); + $resultsContainer.find('tr.result.current').removeClass('current'); + $result.addClass('current'); } }; @@ -117,7 +118,7 @@ OC.Search.setFormatter('file', function ($row, result) { result.mime = result.mime_type; } - $pathDiv = $('
').text(result.path) + $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); $row.find('td.result a').attr('href', result.link); diff --git a/search/js/search.js b/search/js/search.js new file mode 100644 index 00000000000..372d1d7a055 --- /dev/null +++ b/search/js/search.js @@ -0,0 +1,116 @@ +/** + * ownCloud - core + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Bernhard Posselt + * @copyright Bernhard Posselt 2014 + */ + +(function (exports) { + + 'use strict'; + + exports.Search = { + /** + * contains closures that are called to format search results + */ + formatter:{}, + setFormatter: function(type, formatter) { + this.formatter[type] = formatter; + }, + hasFormatter: function(type) { + return typeof this.formatter[type] !== 'undefined'; + }, + getFormatter: function(type) { + return this.formatter[type]; + }, + /** + * contains closures that are called when a search result has been clicked + */ + handler:{}, + setHandler: function(type, handler) { + this.handler[type] = handler; + }, + hasHandler: function(type) { + return typeof this.handler[type] !== 'undefined'; + }, + getHandler: function(type) { + return this.handler[type]; + }, + currentResult:-1, + lastQuery:'', + lastResults:{}, + /** + * Do a search query and display the results + * @param {string} query the search query + */ + search: _.debounce(function(query) { + if(query) { + exports.addStyle('search','results'); + $.getJSON(exports.filePath('search','ajax','search.php')+'?query=' + encodeURIComponent(query), function(results) { + exports.Search.lastResults = results; + exports.Search.showResults(results); + }); + } + }, 500) + }; + + + $(document).ready(function () { + $('form.searchbox').submit(function(event) { + event.preventDefault(); + }); + $('#searchbox').keyup(function(event) { + if (event.keyCode === 13) { //enter + if(exports.Search.currentResult > -1) { + var result = $('#searchresults tr.result a')[exports.Search.currentResult]; + window.location = $(result).attr('href'); + } + } else if(event.keyCode === 38) { //up + if(exports.Search.currentResult > 0) { + exports.Search.currentResult--; + exports.Search.renderCurrent(); + + } + } else if(event.keyCode === 40) { //down + if(exports.Search.lastResults.length > exports.Search.currentResult + 1){ + exports.Search.currentResult++; + exports.Search.renderCurrent(); + } + } else if(event.keyCode === 27) { //esc + exports.Search.hide(); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } + } else { + var query = $('#searchbox').val(); + if (exports.Search.lastQuery !== query) { + exports.Search.lastQuery = query; + exports.Search.currentResult = -1; + if (FileList && typeof FileList.filter === 'function') { //TODO add hook system + FileList.filter(query); + } + if (query.length > 2) { + exports.Search.search(query); + } else { + if (exports.Search.hide) { + exports.Search.hide(); + } + } + } + } + }); + }); + +}(OC)); + +/** + * @deprecated use get/setFormatter() instead + */ +OC.search.customResults = {}; +/** + * @deprecated use get/setFormatter() instead + */ +OC.search.resultTypes = {}; \ No newline at end of file -- cgit v1.2.3 From c738359a111445aac90518db39b5d5883e44892d Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 11 Dec 2014 12:58:22 +0100 Subject: add paged provider --- core/js/js.js | 2 +- lib/private/files/storage/common.php | 1 + lib/private/search.php | 27 +++++++++++++++-- lib/public/isearch.php | 10 +++++++ lib/public/search/pagedprovider.php | 58 ++++++++++++++++++++++++++++++++++++ search/ajax/search.php | 12 +++++++- search/js/search.js | 10 +++++-- 7 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 lib/public/search/pagedprovider.php diff --git a/core/js/js.js b/core/js/js.js index 60237a7fe83..9d38a8c77fe 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -309,7 +309,7 @@ var OC={ * @param {string} query the search query */ search: function (query) { - OC.Search.search(query) + OC.Search.search(query, 0, 30); }, /** * Dialog helper for jquery dialogs. diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php index fe6aefbb42e..b2bf41f751c 100644 --- a/lib/private/files/storage/common.php +++ b/lib/private/files/storage/common.php @@ -278,6 +278,7 @@ abstract class Common implements \OC\Files\Storage\Storage { } } } + closedir($dh); return $files; } diff --git a/lib/private/search.php b/lib/private/search.php index 8f04aa8360b..4629d52b40e 100644 --- a/lib/private/search.php +++ b/lib/private/search.php @@ -21,6 +21,7 @@ */ namespace OC; +use OCP\Search\PagedProvider; use OCP\Search\Provider; use OCP\ISearch; @@ -39,12 +40,34 @@ class Search implements ISearch { * @return array An array of OC\Search\Result's */ public function search($query, array $inApps = array()) { + return $this->searchPaged($query, $inApps, 0, 0); + } + + /** + * Search all providers for $query + * @param string $query + * @param int $page + * @param int $size, 0 = all + * @return array An array of OC\Search\Result's + */ + public function searchPaged($query, $page = 0, $size = 30) { $this->initProviders(); $results = array(); foreach($this->providers as $provider) { /** @var $provider Provider */ - if ($provider->providesResultsFor($inApps)) { - $results = array_merge($results, $provider->search($query)); + if ( ! $provider->providesResultsFor($inApps) ) { + continue; + } + if ($provider instanceof PagedProvider) { + $results = array_merge($results, $provider->searchPaged($query, $page, $size)); + } else if ($provider instanceof Provider) { + $providerResults = $provider->search($query); + if ($size > 0) { + $slicedResults = array_slice($providerResults, $page * $size, $size); + } + $results = array_merge($results, $slicedResults); + } else { + \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); } } return $results; diff --git a/lib/public/isearch.php b/lib/public/isearch.php index 229376ed3ae..84e450afe6f 100644 --- a/lib/public/isearch.php +++ b/lib/public/isearch.php @@ -34,9 +34,19 @@ interface ISearch { * @param string $query * @param string[] $inApps optionally limit results to the given apps * @return array An array of OCP\Search\Result's + * @deprecated use searchPaged() with page and size */ public function search($query, array $inApps = array()); + /** + * Search all providers for $query + * @param string $query + * @param int $page + * @param int $size + * @return array An array of OCP\Search\Result's + */ + public function searchPaged($query, $page = 0, $size = 30); + /** * Register a new search provider to search with * @param string $class class name of a OCP\Search\Provider diff --git a/lib/public/search/pagedprovider.php b/lib/public/search/pagedprovider.php new file mode 100644 index 00000000000..97da1dd2c85 --- /dev/null +++ b/lib/public/search/pagedprovider.php @@ -0,0 +1,58 @@ +. + * + */ + +namespace OCP\Search; + +/** + * Provides a template for search functionality throughout ownCloud; + */ +abstract class PagedProvider extends Provider { + + /** + * List of options (currently unused) + * @var array + */ + private $options; + + /** + * Constructor + * @param array $options + */ + public function __construct($options) { + $this->options = $options; + } + + /** + * Search for $query + * @param string $query + * @return array An array of OCP\Search\Result's + */ + public function search($query) { + $this->searchPaged($query, 0, 0); + } + + /** + * Search for $query + * @param string $query + * @param int $limit, 0 = unlimited + * @param int $offset + * @return array An array of OCP\Search\Result's + */ + abstract public function searchPaged($query, $limit, $offset); +} diff --git a/search/ajax/search.php b/search/ajax/search.php index 21e127e72b1..90771084659 100644 --- a/search/ajax/search.php +++ b/search/ajax/search.php @@ -38,8 +38,18 @@ if (isset($_GET['inApps'])) { } else { $inApps = array(); } +if (isset($_GET['page'])) { + $page = (int)$_GET['page']; +} else { + $page = 0; +} +if (isset($_GET['size'])) { + $size = (int)$_GET['size']; +} else { + $size = 0; +} if($query) { - $result = \OC::$server->getSearch()->search($query, $inApps); + $result = \OC::$server->getSearch()->search($query, $inApps, $page, $size); OC_JSON::encodedPrint($result); } else { diff --git a/search/js/search.js b/search/js/search.js index 372d1d7a055..06a96fd582b 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -46,10 +46,16 @@ * Do a search query and display the results * @param {string} query the search query */ - search: _.debounce(function(query) { + search: _.debounce(function(query, page, size) { if(query) { exports.addStyle('search','results'); - $.getJSON(exports.filePath('search','ajax','search.php')+'?query=' + encodeURIComponent(query), function(results) { + if (typeof page !== 'number') { + page = 0; + } + if (typeof size !== 'number') { + size = 30; + } + $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, page:page, size:size }, function(results) { exports.Search.lastResults = results; exports.Search.showResults(results); }); -- cgit v1.2.3 From 0e9b05b7012844e348d36b5b35e1c50487a3bbc4 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 11 Dec 2014 16:23:39 +0100 Subject: ajax paging, some js cleanups --- lib/private/search.php | 4 +- search/ajax/search.php | 2 +- search/css/results.css | 6 + search/js/result.js | 211 +++++++----------------- search/js/search.js | 320 +++++++++++++++++++++++++++---------- search/templates/part.results.html | 15 ++ search/templates/part.results.php | 15 -- 7 files changed, 315 insertions(+), 258 deletions(-) create mode 100644 search/templates/part.results.html delete mode 100644 search/templates/part.results.php diff --git a/lib/private/search.php b/lib/private/search.php index 4629d52b40e..22f92534cbd 100644 --- a/lib/private/search.php +++ b/lib/private/search.php @@ -64,8 +64,10 @@ class Search implements ISearch { $providerResults = $provider->search($query); if ($size > 0) { $slicedResults = array_slice($providerResults, $page * $size, $size); + $results = array_merge($results, $slicedResults); + } else { + $results = array_merge($results, $providerResults); } - $results = array_merge($results, $slicedResults); } else { \OC::$server->getLogger()->warning('Ignoring Unknown search provider', array('provider' => $provider)); } diff --git a/search/ajax/search.php b/search/ajax/search.php index 90771084659..e26432d1eb2 100644 --- a/search/ajax/search.php +++ b/search/ajax/search.php @@ -46,7 +46,7 @@ if (isset($_GET['page'])) { if (isset($_GET['size'])) { $size = (int)$_GET['size']; } else { - $size = 0; + $size = 30; } if($query) { $result = \OC::$server->getSearch()->search($query, $inApps, $page, $size); diff --git a/search/css/results.css b/search/css/results.css index 78b60e65e45..5dbfa2bd50e 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -14,6 +14,9 @@ box-sizing: border-box; z-index:75; } +#searchresults * { + box-sizing: content-box; +} #searchresults table { border-spacing:0; @@ -23,6 +26,9 @@ } #searchresults td { + padding: 0 15px; + font-style: normal; + vertical-align: middle; border-top: 20px solid white; border-bottom: none; } diff --git a/search/js/result.js b/search/js/result.js index 95526749c53..217d66dc1e3 100644 --- a/search/js/result.js +++ b/search/js/result.js @@ -8,171 +8,76 @@ * */ -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){ - return; - } - if (!OC.Search.showResults.loaded){ - var parent = $('
'); - $('#app-content').append(parent); - parent.load(OC.filePath('search','templates','part.results.php'),function(){ - OC.Search.showResults.loaded = true; - $('#searchresults').click(function(event){ - OC.Search.hide(); - event.stopPropagation(); - }); - $(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); - }); - } else { - $('#searchresults tr.result').remove(); - $('#searchresults').show(); - jQuery.each(results, function(i, result) { - var $row = $('#searchresults tr.template').clone(); - $row.removeClass('template'); - $row.addClass('result'); +//FIXME move to files? +$(document).ready(function() { + // wait for other apps/extensions to register their event handlers and file actions + // in the "ready" clause + _.defer(function() { + OC.Search.setFormatter('file', function ($row, result) { + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } - $row.data('result', result); + $pathDiv = $('
').text(result.path); + $row.find('td.info div.name').after($pathDiv).text(result.name); - // generic results only have four attributes - $row.find('td.info div.name').text(result.name); - $row.find('td.info a').attr('href', result.link); + $row.find('td.result a').attr('href', result.link); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'places/link') + ')'); - /** - * Give plugins the ability to customize the search results. For example: - * OC.search.customResults.file = function (row, item){ FIXME - * if(item.name.search('.json') >= 0) ... - * }; - */ - if (OC.Search.hasFormatter(result.type)) { - OC.Search.getFormatter(result.type)($row, result); + if (OCA.Files) { + OCA.Files.App.fileList.lazyLoadPreview({ + path: result.path, + mime: result.mime, + callback: function (url) { + $row.find('td.icon').css('background-image', 'url(' + url + ')'); + } + }); } else { - // for backward compatibility add text div - $row.find('td.info div.name').addClass('result') - $row.find('td.result div.name').after('
'); - $row.find('td.result div.text').text(result.name); - if(OC.search.customResults && OC.search.customResults[result.type]) { - OC.search.customResults[result.type]($row, result); + // FIXME how to get mime icon if not in files app + var mimeicon = result.mime.replace('/', '-'); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')'); + var dir = OC.dirname(result.path); + if (dir === '') { + dir = '/'; } + $row.find('td.info a').attr('href', + OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) + ); } - $('#searchresults tbody').append($row); }); - - $('#searchresults').on('click', 'tr.result', function (event) { - var $row = $(this); - var result = $row.data('result'); - if(OC.Search.hasHandler(result.type)){ - var result = OC.Search.getHandler(result.type)($row, result, event); - OC.Search.hide(); - event.stopPropagation(); - return result; + OC.Search.setHandler('file', function ($row, result, event) { + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); + OCA.Files.App.fileList.scrollTo(result.name); + return false; + } else { + return true; } }); - } -}; -OC.Search.showResults.loaded = false; -OC.Search.renderCurrent = function(){ - var $resultsContainer = $('#searchresults'); - var result = $resultsContainer.find('tr.result')[OC.Search.currentResult] - if (result) { - var $result = $(result); - var currentOffset = $resultsContainer.scrollTop(); - $resultsContainer.animate({ - // Scrolling to the top of the new result - scrollTop: currentOffset + $result.offset().top - $result.height() * 2 - }, { - duration: 100 - }); - $resultsContainer.find('tr.result.current').removeClass('current'); - $result.addClass('current'); - } -}; - -OC.Search.setFormatter('file', function ($row, result) { - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } - - $pathDiv = $('
').text(result.path); - $row.find('td.info div.name').after($pathDiv).text(result.name); + OC.Search.setFormatter('folder', function ($row, result) { + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } - $row.find('td.result a').attr('href', result.link); + var $pathDiv = $('
').text(result.path) + $row.find('td.info div.name').after($pathDiv).text(result.name); - if (OCA.Files) { - OCA.Files.App.fileList.lazyLoadPreview({ - path: result.path, - mime: result.mime, - callback: function (url) { - $row.find('td.icon').css('background-image', 'url(' + url + ')'); + $row.find('td.result a').attr('href', result.link); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); + }); + OC.Search.setHandler('folder', function ($row, result, event) { + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(result.path); + return false; + } else { + return true; } }); - } else { - // FIXME how to get mime icon if not in files app - var mimeicon = result.mime.replace('/','-'); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/'+mimeicon) + ')'); - var dir = OC.dirname(result.path); - if (dir === '') { - dir = '/'; - } - $row.find('td.info a').attr('href', - OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir:dir, scrollto:result.name}) - ); - } -}); -OC.Search.setHandler('file', function ($row, result, event) { - if (OCA.Files) { - OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); - OCA.Files.App.fileList.scrollTo(result.name); - return false; - } else { - return true; - } -}); - -OC.Search.setFormatter('folder', function ($row, result) { - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } - - var $pathDiv = $('
').text(result.path) - $row.find('td.info div.name').after($pathDiv).text(result.name); - - $row.find('td.result a').attr('href', result.link); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); -}); -OC.Search.setHandler('folder', function ($row, result, event) { - if (OCA.Files) { - OCA.Files.App.fileList.changeDirectory(result.path); - return false; - } else { - return true; - } + }); }); diff --git a/search/js/search.js b/search/js/search.js index 06a96fd582b..7a6428bce33 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -4,113 +4,257 @@ * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * - * @author Bernhard Posselt - * @copyright Bernhard Posselt 2014 + * @author Jörn Friedrich Dreyer + * @copyright Jörn Friedrich Dreyer 2014 */ -(function (exports) { - - 'use strict'; +(function () { + /** + * @class OCA.Search + * @classdesc + * + * The Search class manages a search queries and their results + * + * @param $searchBox container element with existing markup for the #searchbox form + */ + var Search = function($searchBox) { + this.initialize($searchBox); + }; + /** + * @memberof OC + */ + Search.prototype = { - exports.Search = { - /** - * contains closures that are called to format search results - */ - formatter:{}, - setFormatter: function(type, formatter) { - this.formatter[type] = formatter; - }, - hasFormatter: function(type) { - return typeof this.formatter[type] !== 'undefined'; - }, - getFormatter: function(type) { - return this.formatter[type]; - }, - /** - * contains closures that are called when a search result has been clicked - */ - handler:{}, - setHandler: function(type, handler) { - this.handler[type] = handler; - }, - hasHandler: function(type) { - return typeof this.handler[type] !== 'undefined'; - }, - getHandler: function(type) { - return this.handler[type]; - }, - currentResult:-1, - lastQuery:'', - lastResults:{}, /** - * Do a search query and display the results - * @param {string} query the search query + * Initialize the search box and results + * + * @param $searchBox container element with existing markup for the #searchbox form + * @private */ - search: _.debounce(function(query, page, size) { - if(query) { - exports.addStyle('search','results'); - if (typeof page !== 'number') { - page = 0; + initialize: function($searchBox) { + + var that = this; + + /** + * contains closures that are called to format search results + */ + var formatters = {}; + this.setFormatter = function(type, formatter) { + formatters[type] = formatter; + }; + this.hasFormatter = function(type) { + return typeof formatters[type] !== 'undefined'; + }; + this.getFormatter = function(type) { + return formatters[type]; + }; + + /** + * contains closures that are called when a search result has been clicked + */ + var handlers = {}; + this.setHandler = function(type, handler) { + handlers[type] = handler; + }; + this.hasHandler = function(type) { + return typeof handlers[type] !== 'undefined'; + }; + this.getHandler = function(type) { + return handlers[type]; + }; + + var currentResult = -1; + var lastQuery = ''; + var lastPage = 0; + var lastSize = 30; + var lastResults = {}; + + /** + * Do a search query and display the results + * @param {string} query the search query + */ + this.search = _.debounce(function(query, page, size) { + if(query) { + OC.addStyle('search','results'); + if (typeof page !== 'number') { + page = 0; + } + if (typeof size !== 'number') { + size = 30; + } + // prevent double pages + if (query === lastPage && page === lastPage && currentResult !== -1) { + return; + } + $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, page:page, size:size }, function(results) { + lastQuery = query; + lastPage = page; + lastSize = size; + lastResults = results; + if (page === 0) { + showResults(results); + } else { + addResults(results); + } + }); + } + }, 500); + var $searchResults = false; + + function showResults(results) { + if (results.length === 0) { + return; } - if (typeof size !== 'number') { - size = 30; + if (!$searchResults) { + var $parent = $('
'); + $('#app-content').append($parent); + $parent.load(OC.webroot + '/search/templates/part.results.html', function () { + $searchResults = $parent.find('#searchresults'); + $searchResults.click(function (event) { + that.hideResults(); + event.stopPropagation(); + }); + $(document).click(function (event) { + that.hideResults(); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } + }); + $searchResults.on('scroll', _.bind(onScroll, this)); + lastResults = results; + showResults(results); + }); + } else { + $searchResults.find('tr.result').remove(); + $searchResults.show(); + addResults(results); } - $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, page:page, size:size }, function(results) { - exports.Search.lastResults = results; - exports.Search.showResults(results); - }); } - }, 500) - }; + function addResults(results) { + var $template = $searchResults.find('tr.template'); + jQuery.each(results, function (i, result) { + var $row = $template.clone(); + $row.removeClass('template'); + $row.addClass('result'); + $row.data('result', result); - $(document).ready(function () { - $('form.searchbox').submit(function(event) { - event.preventDefault(); - }); - $('#searchbox').keyup(function(event) { - if (event.keyCode === 13) { //enter - if(exports.Search.currentResult > -1) { - var result = $('#searchresults tr.result a')[exports.Search.currentResult]; - window.location = $(result).attr('href'); - } - } else if(event.keyCode === 38) { //up - if(exports.Search.currentResult > 0) { - exports.Search.currentResult--; - exports.Search.renderCurrent(); + // generic results only have four attributes + $row.find('td.info div.name').text(result.name); + $row.find('td.info a').attr('href', result.link); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'places/link') + ')'); + /** + * Give plugins the ability to customize the search results. see result.js for examples + */ + if (that.hasFormatter(result.type)) { + that.getFormatter(result.type)($row, result); + } else { + // for backward compatibility add text div + $row.find('td.info div.name').addClass('result'); + $row.find('td.result div.name').after('
'); + $row.find('td.result div.text').text(result.name); + if (OC.search.customResults && OC.search.customResults[result.type]) { + OC.search.customResults[result.type]($row, result); + } + } + $searchResults.find('tbody').append($row); + }); + } + function renderCurrent() { + var result = $searchResults.find('tr.result')[currentResult]; + if (result) { + var $result = $(result); + var currentOffset = $searchResults.scrollTop(); + $searchResults.animate({ + // Scrolling to the top of the new result + scrollTop: currentOffset + $result.offset().top - $result.height() * 2 + }, { + duration: 100 + }); + $searchResults.find('tr.result.current').removeClass('current'); + $result.addClass('current'); } - } else if(event.keyCode === 40) { //down - if(exports.Search.lastResults.length > exports.Search.currentResult + 1){ - exports.Search.currentResult++; - exports.Search.renderCurrent(); - } - } else if(event.keyCode === 27) { //esc - exports.Search.hide(); - if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system - FileList.unfilter(); + } + this.hideResults = function() { + if ($searchResults) { + $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(); + } + } } - } else { - var query = $('#searchbox').val(); - if (exports.Search.lastQuery !== query) { - exports.Search.lastQuery = query; - exports.Search.currentResult = -1; - if (FileList && typeof FileList.filter === 'function') { //TODO add hook system - FileList.filter(query); + }; + + $searchBox.keyup(function(event) { + if (event.keyCode === 13) { //enter + if(currentResult > -1) { + var result = $searchResults.find('tr.result a')[currentResult]; + window.location = $(result).attr('href'); } - if (query.length > 2) { - exports.Search.search(query); - } else { - if (exports.Search.hide) { - exports.Search.hide(); + } else if(event.keyCode === 38) { //up + if(currentResult > 0) { + currentResult--; + renderCurrent(); + + } + } else if(event.keyCode === 40) { //down + if(lastResults.length > currentResult + 1){ + currentResult++; + renderCurrent(); + } + } else if(event.keyCode === 27) { //esc + that.hideResults(); + if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system + FileList.unfilter(); + } + } else { + var query = $searchBox.val(); + if (lastQuery !== query) { + lastQuery = query; + currentResult = -1; + if (FileList && typeof FileList.filter === 'function') { //TODO add hook system + FileList.filter(query); + } + if (query.length > 2) { + that.search(query); + } else { + if (that.hideResults) { + that.hideResults(); + } } } } + }); + + /** + * Event handler for when scrolling the list container. + * This appends/renders the next page of entries when reaching the bottom. + */ + function onScroll(e) { + if ( $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { + that.search(lastQuery, lastPage + 1); + } } - }); - }); -}(OC)); + $('form.searchbox').submit(function(event) { + event.preventDefault(); + }); + } + }; + OCA.Search = Search; +})(); + +$(document).ready(function() { + OC.Search = new OCA.Search($('#searchbox')); +}); /** * @deprecated use get/setFormatter() instead diff --git a/search/templates/part.results.html b/search/templates/part.results.html new file mode 100644 index 00000000000..451df7b143f --- /dev/null +++ b/search/templates/part.results.html @@ -0,0 +1,15 @@ +
+ +
- -
-
-
+
+ +
+ + + + + + +
+ +
+
+
+
diff --git a/search/templates/part.results.php b/search/templates/part.results.php deleted file mode 100644 index 451df7b143f..00000000000 --- a/search/templates/part.results.php +++ /dev/null @@ -1,15 +0,0 @@ -
- - - - - - - - -
- -
-
-
-
-- cgit v1.2.3 From 606f802b7be0cb6f2f6d99c547e432bb8cd27994 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 17 Dec 2014 18:49:39 +0100 Subject: move search results below filelist, show hint when results are off screen, use js plugin mechanism --- apps/files/css/files.css | 4 +- apps/files/index.php | 1 + apps/files/js/filelist.js | 15 +--- apps/files/js/search.js | 118 ++++++++++++++++++++++++ core/js/js.js | 37 +------- lib/base.php | 1 - lib/private/search.php | 10 ++- lib/public/isearch.php | 5 +- lib/public/search/pagedprovider.php | 9 +- search/ajax/search.php | 4 +- search/css/results.css | 14 ++- search/js/result.js | 83 ----------------- search/js/search.js | 175 ++++++++++++++++++++++++++---------- search/templates/part.results.html | 2 +- 14 files changed, 280 insertions(+), 198 deletions(-) create mode 100644 apps/files/js/search.js delete mode 100644 search/js/result.js diff --git a/apps/files/css/files.css b/apps/files/css/files.css index 6f31715499b..a75ad57c833 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -540,7 +540,7 @@ a.action>img { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; filter: alpha(opacity=30); opacity: .3; - height: 70px; + height: 60px; } .summary:hover, @@ -551,8 +551,6 @@ table tr.summary td { } .summary td { - padding-top: 20px; - padding-bottom: 150px; border-bottom: none; } .summary .info { diff --git a/apps/files/index.php b/apps/files/index.php index 64b49c3bf1f..767cb156ca2 100644 --- a/apps/files/index.php +++ b/apps/files/index.php @@ -38,6 +38,7 @@ OCP\Util::addscript('files', 'jquery-visibility'); OCP\Util::addscript('files', 'filesummary'); OCP\Util::addscript('files', 'breadcrumb'); OCP\Util::addscript('files', 'filelist'); +OCP\Util::addscript('files', 'search'); \OCP\Util::addScript('files', 'favoritesfilelist'); \OCP\Util::addScript('files', 'tagsplugin'); diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 09cb3d3287d..08017e3fef1 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1640,21 +1640,14 @@ }, filter:function(query) { this.$fileList.find('tr').each(function(i,e) { - if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) !== -1) { - $(e).addClass("searchresult"); - } else { - $(e).removeClass("searchresult"); + if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) === -1) { + $(e).hide(); } }); - //do not use scrollto to prevent removing searchresult css class - var first = this.$fileList.find('tr.searchresult').first(); - if (first.exists()) { - $(window).scrollTop(first.position().top); - } }, unfilter:function() { - this.$fileList.find('tr.searchresult').each(function(i,e) { - $(e).removeClass("searchresult"); + this.$fileList.find('tr:hidden').each(function(i,e) { + $(e).show(); }); }, /** diff --git a/apps/files/js/search.js b/apps/files/js/search.js new file mode 100644 index 00000000000..a2d3a261259 --- /dev/null +++ b/apps/files/js/search.js @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2014 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ +(function() { + if (!OCA.Files) { + OCA.Files = {}; + } + OCA.Files.Search = { + attach: function(search) { + search.setFilter('files', function (query) { + if (query) { + if (OCA.Files) { + OCA.Files.App.fileList.filter(query); + } + } else { + if (OCA.Files) { + OCA.Files.App.fileList.unfilter(); + } + } + }); + + search.setRenderer('folder', OCA.Files.Search.renderFolderResult); + search.setRenderer('file', OCA.Files.Search.renderFileResult); + search.setRenderer('audio', OCA.Files.Search.renderAudioResult); + search.setRenderer('image', OCA.Files.Search.renderImageResult); + + search.setHandler('folder', OCA.Files.Search.handleFolderClick); + search.setHandler(['file', 'audio', 'image'], OCA.Files.Search.handleFileClick); + }, + renderFolderResult: function($row, result) { + /*render folder icon, show path beneath filename, + show size and last modified date on the right */ + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } + + var $pathDiv = $('
').text(result.path) + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); + }, + renderFileResult: function($row, result) { + /*render preview icon, show path beneath filename, + show size and last modified date on the right */ + // backward compatibility: + if (typeof result.mime !== 'undefined') { + result.mime_type = result.mime; + } else if (typeof result.mime_type !== 'undefined') { + result.mime = result.mime_type; + } + + $pathDiv = $('
').text(result.path); + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + + if (OCA.Files) { + OCA.Files.App.fileList.lazyLoadPreview({ + path: result.path, + mime: result.mime, + callback: function (url) { + $row.find('td.icon').css('background-image', 'url(' + url + ')'); + } + }); + } else { + // FIXME how to get mime icon if not in files app + var mimeicon = result.mime.replace('/', '-'); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')'); + var dir = OC.dirname(result.path); + if (dir === '') { + dir = '/'; + } + $row.find('td.info a').attr('href', + OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) + ); + } + }, + renderAudioResult: function($row, result) { + /*render preview icon, show path beneath filename, + show size and last modified date on the right + show Artist and Album */ + }, + renderImageResult: function($row, result) { + /*render preview icon, show path beneath filename, + show size and last modified date on the right + show width and height */ + }, + handleFolderClick: function($row, result, event) { + // open folder + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(result.path); + return false; + } else { + return true; + } + }, + handleFileClick: function($row, result, event) { + if (OCA.Files) { + OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); + OCA.Files.App.fileList.scrollTo(result.name); + return false; + } else { + return true; + } + } + }; +})(); +OC.Plugins.register('OCA.Search', OCA.Files.Search); diff --git a/core/js/js.js b/core/js/js.js index 9d38a8c77fe..8bcd546b420 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -309,7 +309,7 @@ var OC={ * @param {string} query the search query */ search: function (query) { - OC.Search.search(query, 0, 30); + OC.Search.search(query, null, 0, 30); }, /** * Dialog helper for jquery dialogs. @@ -601,41 +601,6 @@ OC.search.customResults = {}; */ OC.search.resultTypes = {}; -/** - * @namespace OC.Search - */ -OC.Search = { - /** - * contains closures that are called to format search results - */ - formatter:{}, - setFormatter: function(type, formatter) { - this.formatter[type] = formatter; - }, - hasFormatter: function(type) { - return typeof this.formatter[type] !== 'undefined'; - }, - getFormatter: function(type) { - return this.formatter[type]; - }, - /** - * contains closures that are called when a search result has been clicked - */ - handler:{}, - setHandler: function(type, handler) { - this.handler[type] = handler; - }, - hasHandler: function(type) { - return typeof this.handler[type] !== 'undefined'; - }, - getHandler: function(type) { - return this.handler[type]; - }, - currentResult:-1, - lastQuery:'', - lastResults:{} -}; - OC.addStyle.loaded=[]; OC.addScript.loaded=[]; diff --git a/lib/base.php b/lib/base.php index 551d0afbd78..34fa178ebf7 100644 --- a/lib/base.php +++ b/lib/base.php @@ -363,7 +363,6 @@ class OC { OC_Util::addScript("config"); //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'search'); - OC_Util::addScript('search', 'result'); OC_Util::addScript("oc-requesttoken"); OC_Util::addScript("apps"); OC_Util::addVendorScript('snapjs/dist/latest/snap'); diff --git a/lib/private/search.php b/lib/private/search.php index 22f92534cbd..a29a4762b68 100644 --- a/lib/private/search.php +++ b/lib/private/search.php @@ -40,17 +40,19 @@ class Search implements ISearch { * @return array An array of OC\Search\Result's */ public function search($query, array $inApps = array()) { - return $this->searchPaged($query, $inApps, 0, 0); + // old apps might assume they get all results, so we set size 0 + return $this->searchPaged($query, $inApps, 1, 0); } /** * Search all providers for $query * @param string $query - * @param int $page + * @param string[] $inApps optionally limit results to the given apps + * @param int $page pages start at page 1 * @param int $size, 0 = all * @return array An array of OC\Search\Result's */ - public function searchPaged($query, $page = 0, $size = 30) { + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30) { $this->initProviders(); $results = array(); foreach($this->providers as $provider) { @@ -63,7 +65,7 @@ class Search implements ISearch { } else if ($provider instanceof Provider) { $providerResults = $provider->search($query); if ($size > 0) { - $slicedResults = array_slice($providerResults, $page * $size, $size); + $slicedResults = array_slice($providerResults, ($page - 1) * $size, $size); $results = array_merge($results, $slicedResults); } else { $results = array_merge($results, $providerResults); diff --git a/lib/public/isearch.php b/lib/public/isearch.php index 84e450afe6f..fe58f202d66 100644 --- a/lib/public/isearch.php +++ b/lib/public/isearch.php @@ -41,11 +41,12 @@ interface ISearch { /** * Search all providers for $query * @param string $query - * @param int $page + * @param string[] $inApps optionally limit results to the given apps + * @param int $page pages start at page 1 * @param int $size * @return array An array of OCP\Search\Result's */ - public function searchPaged($query, $page = 0, $size = 30); + public function searchPaged($query, array $inApps = array(), $page = 1, $size = 30); /** * Register a new search provider to search with diff --git a/lib/public/search/pagedprovider.php b/lib/public/search/pagedprovider.php index 97da1dd2c85..10c36cfc483 100644 --- a/lib/public/search/pagedprovider.php +++ b/lib/public/search/pagedprovider.php @@ -44,15 +44,16 @@ abstract class PagedProvider extends Provider { * @return array An array of OCP\Search\Result's */ public function search($query) { - $this->searchPaged($query, 0, 0); + // old apps might assume they get all results, so we set size 0 + $this->searchPaged($query, 1, 0); } /** * Search for $query * @param string $query - * @param int $limit, 0 = unlimited - * @param int $offset + * @param int $page pages start at page 1 + * @param int $size, 0 = all * @return array An array of OCP\Search\Result's */ - abstract public function searchPaged($query, $limit, $offset); + abstract public function searchPaged($query, $page, $size); } diff --git a/search/ajax/search.php b/search/ajax/search.php index e26432d1eb2..5bd810aacfd 100644 --- a/search/ajax/search.php +++ b/search/ajax/search.php @@ -41,7 +41,7 @@ if (isset($_GET['inApps'])) { if (isset($_GET['page'])) { $page = (int)$_GET['page']; } else { - $page = 0; + $page = 1; } if (isset($_GET['size'])) { $size = (int)$_GET['size']; @@ -49,7 +49,7 @@ if (isset($_GET['size'])) { $size = 30; } if($query) { - $result = \OC::$server->getSearch()->search($query, $inApps, $page, $size); + $result = \OC::$server->getSearch()->searchPaged($query, $inApps, $page, $size); OC_JSON::encodedPrint($result); } else { diff --git a/search/css/results.css b/search/css/results.css index 5dbfa2bd50e..bf9a7871d17 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -6,9 +6,7 @@ background-color:#fff; overflow-x:hidden; overflow-y: auto; - position:fixed; text-overflow:ellipsis; - top:0; padding-top: 45px; height: 100%; box-sizing: border-box; @@ -18,6 +16,18 @@ box-sizing: content-box; } +#searchresults #status { + background-color:#ccc; + height: 24px; + padding: 17px 15px; +} +#searchresults #status.fixed { + position: fixed; + bottom: 0; + width: 100%; + z-index: 10; +} + #searchresults table { border-spacing:0; table-layout:fixed; diff --git a/search/js/result.js b/search/js/result.js deleted file mode 100644 index 217d66dc1e3..00000000000 --- a/search/js/result.js +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2014 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ - -//FIXME move to files? -$(document).ready(function() { - // wait for other apps/extensions to register their event handlers and file actions - // in the "ready" clause - _.defer(function() { - OC.Search.setFormatter('file', function ($row, result) { - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } - - $pathDiv = $('
').text(result.path); - $row.find('td.info div.name').after($pathDiv).text(result.name); - - $row.find('td.result a').attr('href', result.link); - - if (OCA.Files) { - OCA.Files.App.fileList.lazyLoadPreview({ - path: result.path, - mime: result.mime, - callback: function (url) { - $row.find('td.icon').css('background-image', 'url(' + url + ')'); - } - }); - } else { - // FIXME how to get mime icon if not in files app - var mimeicon = result.mime.replace('/', '-'); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')'); - var dir = OC.dirname(result.path); - if (dir === '') { - dir = '/'; - } - $row.find('td.info a').attr('href', - OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) - ); - } - }); - OC.Search.setHandler('file', function ($row, result, event) { - if (OCA.Files) { - OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); - OCA.Files.App.fileList.scrollTo(result.name); - return false; - } else { - return true; - } - }); - - OC.Search.setFormatter('folder', function ($row, result) { - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } - - var $pathDiv = $('
').text(result.path) - $row.find('td.info div.name').after($pathDiv).text(result.name); - - $row.find('td.result a').attr('href', result.link); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); - }); - OC.Search.setHandler('folder', function ($row, result, event) { - if (OCA.Files) { - OCA.Files.App.fileList.changeDirectory(result.path); - return false; - } else { - return true; - } - }); - }); -}); diff --git a/search/js/search.js b/search/js/search.js index 7a6428bce33..8791b98cfdd 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -36,17 +36,31 @@ var that = this; /** - * contains closures that are called to format search results + * contains closures that are called to filter the current content */ - var formatters = {}; - this.setFormatter = function(type, formatter) { - formatters[type] = formatter; + var filters = {}; + this.setFilter = function(type, filter) { + filters[type] = filter; }; - this.hasFormatter = function(type) { - return typeof formatters[type] !== 'undefined'; + this.hasFilter = function(type) { + return typeof filters[type] !== 'undefined'; }; - this.getFormatter = function(type) { - return formatters[type]; + this.getFilter = function(type) { + return filters[type]; + }; + + /** + * contains closures that are called to render search results + */ + var renderers = {}; + this.setRenderer = function(type, renderer) { + renderers[type] = renderer; + }; + this.hasRenderer = function(type) { + return typeof renderers[type] !== 'undefined'; + }; + this.getRenderer = function(type) { + return renderers[type]; }; /** @@ -73,25 +87,33 @@ * Do a search query and display the results * @param {string} query the search query */ - this.search = _.debounce(function(query, page, size) { + this.search = _.debounce(function(query, inApps, page, size) { if(query) { OC.addStyle('search','results'); if (typeof page !== 'number') { - page = 0; + page = 1; } if (typeof size !== 'number') { size = 30; } + if (typeof inApps !== 'object') { + var currentApp = getCurrentApp(); + if(currentApp) { + inApps = [currentApp]; + } else { + inApps = []; + } + } // prevent double pages - if (query === lastPage && page === lastPage && currentResult !== -1) { + if ($searchResults && query === lastQuery && page === lastPage&& size === lastSize) { return; } - $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, page:page, size:size }, function(results) { - lastQuery = query; - lastPage = page; - lastSize = size; + lastQuery = query; + lastPage = page; + lastSize = size; + $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) { lastResults = results; - if (page === 0) { + if (page === 1) { showResults(results); } else { addResults(results); @@ -99,29 +121,69 @@ }); } }, 500); + + function getCurrentApp() { + var classList = document.getElementById('content').className.split(/\s+/); + for (var i = 0; i < classList.length; i++) { + if (classList[i].indexOf('app-') === 0) { + return classList[i].substr(4); + } + } + return false; + } + var $searchResults = false; + var $wrapper = false; + var $status = false; + const summaryAndStatusHeight = 118; + function isStatusOffScreen() { + return $searchResults.position().top + summaryAndStatusHeight > window.innerHeight; + } + + function placeStatus() { + if (isStatusOffScreen()) { + $status.addClass('fixed'); + } else { + $status.removeClass('fixed'); + } + } function showResults(results) { if (results.length === 0) { return; } if (!$searchResults) { - var $parent = $('
'); - $('#app-content').append($parent); - $parent.load(OC.webroot + '/search/templates/part.results.html', function () { - $searchResults = $parent.find('#searchresults'); - $searchResults.click(function (event) { - that.hideResults(); - event.stopPropagation(); + $wrapper = $('
'); + $('#app-content') + .append($wrapper) + .find('.viewcontainer').css('min-height', 'initial'); + $wrapper.load(OC.webroot + '/search/templates/part.results.html', function () { + $searchResults = $wrapper.find('#searchresults'); + $searchResults.on('click', 'tr.result', function (event) { + var $row = $(this); + var item = $row.data('result'); + if(that.hasHandler(item.type)){ + var result = that.getHandler(item.type)($row, result, event); + that.hideResults(); + return result; + } + }); + $searchResults.on('click', '#status', function (event) { + event.preventDefault(); + scrollToResults(); + return false; }); $(document).click(function (event) { that.hideResults(); - if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system - FileList.unfilter(); + if(that.hasFilter(getCurrentApp())) { + that.getFilter(getCurrentApp())(''); } }); - $searchResults.on('scroll', _.bind(onScroll, this)); + $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; + $status = $searchResults.find('#status') + .text(t('search', '{count} Search results', {count:results.length}, results.length)); + placeStatus(); showResults(results); }); } else { @@ -147,8 +209,8 @@ /** * Give plugins the ability to customize the search results. see result.js for examples */ - if (that.hasFormatter(result.type)) { - that.getFormatter(result.type)($row, result); + if (that.hasRenderer(result.type)) { + that.getRenderer(result.type)($row, result); } else { // for backward compatibility add text div $row.find('td.info div.name').addClass('result'); @@ -166,7 +228,7 @@ if (result) { var $result = $(result); var currentOffset = $searchResults.scrollTop(); - $searchResults.animate({ + $('#app-content').animate({ // Scrolling to the top of the new result scrollTop: currentOffset + $result.offset().top - $result.height() * 2 }, { @@ -179,17 +241,10 @@ this.hideResults = function() { if ($searchResults) { $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(); - } - } + $searchBox.val(''); + $wrapper.remove(); + $searchResults = false; + $wrapper = false; } }; @@ -212,16 +267,13 @@ } } else if(event.keyCode === 27) { //esc that.hideResults(); - if (FileList && typeof FileList.unfilter === 'function') { //TODO add hook system - FileList.unfilter(); - } } else { var query = $searchBox.val(); if (lastQuery !== query) { lastQuery = query; currentResult = -1; - if (FileList && typeof FileList.filter === 'function') { //TODO add hook system - FileList.filter(query); + if(that.hasFilter(getCurrentApp())) { + that.getFilter(getCurrentApp())(query); } if (query.length > 2) { that.search(query); @@ -239,14 +291,39 @@ * This appends/renders the next page of entries when reaching the bottom. */ function onScroll(e) { - if ( $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { - that.search(lastQuery, lastPage + 1); + if ($searchResults) { + //if ( $searchResults && $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { + // that.search(lastQuery, lastPage + 1); + //} + placeStatus(); } } + /** + * scrolls the search results to the top + */ + function scrollToResults() { + setTimeout(function() { + if (isStatusOffScreen()) { + var newScrollTop = $('#app-content').prop('scrollHeight') - $searchResults.height(); + console.log('scrolling to ' + newScrollTop); + $('#app-content').animate({ + scrollTop: newScrollTop + }, { + duration: 100, + complete: function () { + scrollToResults(); + } + }); + } + }, 150); + } + $('form.searchbox').submit(function(event) { event.preventDefault(); }); + + OC.Plugins.attach('OCA.Search', this); } }; OCA.Search = Search; @@ -257,10 +334,10 @@ $(document).ready(function() { }); /** - * @deprecated use get/setFormatter() instead + * @deprecated use get/setRenderer() instead */ OC.search.customResults = {}; /** - * @deprecated use get/setFormatter() instead + * @deprecated use get/setRenderer() instead */ OC.search.resultTypes = {}; \ No newline at end of file diff --git a/search/templates/part.results.html b/search/templates/part.results.html index 451df7b143f..d82a72c1199 100644 --- a/search/templates/part.results.html +++ b/search/templates/part.results.html @@ -1,5 +1,5 @@
- +
{message}
-- cgit v1.2.3 From 423a3047d7cb26c53674530fb99d7b381a3853ef Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 17 Dec 2014 22:28:37 +0100 Subject: first style fixes to search results --- search/css/results.css | 23 +++++++++++------------ search/js/search.js | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/search/css/results.css b/search/css/results.css index bf9a7871d17..d361090a374 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -17,9 +17,11 @@ } #searchresults #status { - background-color:#ccc; - height: 24px; - padding: 17px 15px; + background-color: rgba(255, 255, 255, .85); + height: 12px; + padding: 28px 0; + font-size: 18px; + text-align: center; } #searchresults #status.fixed { position: fixed; @@ -36,10 +38,9 @@ } #searchresults td { - padding: 0 15px; + padding: 5px 15px; font-style: normal; vertical-align: middle; - border-top: 20px solid white; border-bottom: none; } #searchresults tr.template { @@ -53,15 +54,14 @@ overflow: hidden; text-overflow: ellipsis; } -#searchresults .name { - font-size: larger; -} #searchresults .text { white-space: normal; color: #545454; } #searchresults .path { - color: green; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; + filter: alpha(opacity=50); + opacity: .5; } #searchresults .text em { color: #545454; @@ -74,11 +74,10 @@ } #searchresults td.icon { - font-weight:700; text-align:right; - width:32px; + width: 32px; height: 40px; - background-position: 30px 4px; + background-position: 30px 8px; background-repeat: no-repeat; } diff --git a/search/js/search.js b/search/js/search.js index 8791b98cfdd..2da5dd5c3d2 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -182,7 +182,7 @@ $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; $status = $searchResults.find('#status') - .text(t('search', '{count} Search results', {count:results.length}, results.length)); + .text(t('search', '{count} search results in other folders', {count:results.length}, results.length)); placeStatus(); showResults(results); }); -- cgit v1.2.3 From d063c8e0429b680c9998f91075b18297f55ae62d Mon Sep 17 00:00:00 2001 From: Jan-Christoph Borchardt Date: Wed, 17 Dec 2014 23:28:29 +0100 Subject: adjust search result alignment depending on if the layout has favorites or not --- search/css/results.css | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/search/css/results.css b/search/css/results.css index d361090a374..4e3fade68d2 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -19,9 +19,11 @@ #searchresults #status { background-color: rgba(255, 255, 255, .85); height: 12px; - padding: 28px 0; + padding: 28px 0 28px 56px; font-size: 18px; - text-align: center; +} +.has-favorites:not(.hidden) ~ .searchresults-wrapper #searchresults #status { + padding-left: 102px; } #searchresults #status.fixed { position: fixed; @@ -38,11 +40,23 @@ } #searchresults td { - padding: 5px 15px; + padding: 5px 19px; font-style: normal; vertical-align: middle; border-bottom: none; } +#searchresults td.icon { + text-align: right; + width: 40px; + height: 40px; + padding: 5px 0; + background-position: right center; + background-repeat: no-repeat; +} +.has-favorites:not(.hidden) ~ .searchresults-wrapper #searchresults td.icon { + width: 86px; +} + #searchresults tr.template { display: none; } @@ -73,14 +87,6 @@ cursor:pointer; } -#searchresults td.icon { - text-align:right; - width: 32px; - height: 40px; - background-position: 30px 8px; - background-repeat: no-repeat; -} - #searchresults tr.current { background-color:#ddd; } -- cgit v1.2.3 From 7e6c660b008d158de92a664b56359ed0750b82a8 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 18 Dec 2014 10:26:41 +0100 Subject: filter new rows --- apps/files/js/filelist.js | 50 ++++++++++++++++++++++++++++++++++++++++------- apps/files/js/search.js | 44 +++++++++++++++++++++++++++++++---------- search/js/search.js | 14 ++++++++++--- 3 files changed, 88 insertions(+), 20 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 08017e3fef1..88c81fb43af 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -111,6 +111,12 @@ */ _selectionSummary: null, + /** + * If not empty, only files containing this string will be shown + * @type String + */ + _filter: '', + /** * Sort attribute * @type String @@ -551,6 +557,7 @@ _nextPage: function(animate) { var index = this.$fileList.children().length, count = this.pageSize(), + hidden, tr, fileData, newTrs = [], @@ -562,7 +569,12 @@ while (count > 0 && index < this.files.length) { fileData = this.files[index]; - tr = this._renderRow(fileData, {updateSummary: false, silent: true}); + if (this._filter) { + hidden = fileData.name.toLowerCase().indexOf(this._filter.toLowerCase()) === -1; + } else { + hidden = false; + } + tr = this._renderRow(fileData, {updateSummary: false, silent: true, hidden: hidden}); this.$fileList.append(tr); if (isAllSelected || this._selectedFiles[fileData.id]) { tr.addClass('selected'); @@ -1638,17 +1650,41 @@ }); }); }, + /** + * @deprecated use setFilter(filter) + */ filter:function(query) { + this.setFilter(''); + }, + /** + * @deprecated use setFilter('') + */ + unfilter:function() { + this.setFilter(''); + }, + /** + * hide files matching the given filter + * @param filter + */ + setFilter:function(filter) { + this._filter = filter; + var that = this; this.$fileList.find('tr').each(function(i,e) { - if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) === -1) { - $(e).hide(); + var $e = $(e); + if ($e.data('file').toString().toLowerCase().indexOf(filter.toLowerCase()) === -1) { + $e.addClass('hidden'); + that.$container.trigger('scroll'); + } else { + $e.removeClass('hidden'); } }); }, - unfilter:function() { - this.$fileList.find('tr:hidden').each(function(i,e) { - $(e).show(); - }); + /** + * get the current filter + * @param filter + */ + getFilter:function(filter) { + return this._filter; }, /** * Update UI based on the current selection diff --git a/apps/files/js/search.js b/apps/files/js/search.js index a2d3a261259..e6d71cf0f60 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -14,12 +14,10 @@ OCA.Files.Search = { attach: function(search) { search.setFilter('files', function (query) { - if (query) { - if (OCA.Files) { - OCA.Files.App.fileList.filter(query); - } - } else { - if (OCA.Files) { + if (OCA.Files.Search.fileAppLoaded()) { + if (query) { + OCA.Files.App.fileList.setFilter(query); + } else { OCA.Files.App.fileList.unfilter(); } } @@ -34,6 +32,9 @@ search.setHandler(['file', 'audio', 'image'], OCA.Files.Search.handleFileClick); }, renderFolderResult: function($row, result) { + if (OCA.Files.Search.inFileList($row, result)) { + return null; + } /*render folder icon, show path beneath filename, show size and last modified date on the right */ // backward compatibility: @@ -43,13 +44,17 @@ result.mime = result.mime_type; } - var $pathDiv = $('
').text(result.path) + var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); $row.find('td.result a').attr('href', result.link); $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); + return $row; }, renderFileResult: function($row, result) { + if (OCA.Files.Search.inFileList($row, result)) { + return null; + } /*render preview icon, show path beneath filename, show size and last modified date on the right */ // backward compatibility: @@ -64,7 +69,7 @@ $row.find('td.result a').attr('href', result.link); - if (OCA.Files) { + if (OCA.Files.Search.fileAppLoaded()) { OCA.Files.App.fileList.lazyLoadPreview({ path: result.path, mime: result.mime, @@ -84,20 +89,36 @@ OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) ); } + return $row; }, renderAudioResult: function($row, result) { + if (OCA.Files.Search.inFileList($row, result)) { + return null; + } /*render preview icon, show path beneath filename, show size and last modified date on the right show Artist and Album */ + return $row; }, renderImageResult: function($row, result) { + if (OCA.Files.Search.inFileList($row, result)) { + return null; + } /*render preview icon, show path beneath filename, show size and last modified date on the right show width and height */ + return $row; + }, + inFileList: function($row, result){ + if (OCA.Files.Search.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) { + return true; + } else { + return false; + } }, handleFolderClick: function($row, result, event) { // open folder - if (OCA.Files) { + if (OCA.Files.Search.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(result.path); return false; } else { @@ -105,13 +126,16 @@ } }, handleFileClick: function($row, result, event) { - if (OCA.Files) { + if (OCA.Files.Search.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); OCA.Files.App.fileList.scrollTo(result.name); return false; } else { return true; } + }, + fileAppLoaded: function() { + return OCA.Files && OCA.Files.App; } }; })(); diff --git a/search/js/search.js b/search/js/search.js index 2da5dd5c3d2..28e6fa999a0 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -26,7 +26,7 @@ Search.prototype = { /** - * Initialize the search box and results + * Initialize the search box * * @param $searchBox container element with existing markup for the #searchbox form * @private @@ -182,6 +182,7 @@ $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; $status = $searchResults.find('#status') + .data('count', results.length) .text(t('search', '{count} search results in other folders', {count:results.length}, results.length)); placeStatus(); showResults(results); @@ -210,7 +211,7 @@ * Give plugins the ability to customize the search results. see result.js for examples */ if (that.hasRenderer(result.type)) { - that.getRenderer(result.type)($row, result); + $row = that.getRenderer(result.type)($row, result); } else { // for backward compatibility add text div $row.find('td.info div.name').addClass('result'); @@ -220,7 +221,14 @@ OC.search.customResults[result.type]($row, result); } } - $searchResults.find('tbody').append($row); + if ($row) { + $searchResults.find('tbody').append($row); + } else { + // not showing result, decrease counter + var count = $status.data('count') - 1; + $status.data('count', count) + .text(t('search', '{count} search results in other folders', {count:count}, count)); + } }); } function renderCurrent() { -- cgit v1.2.3 From b93f2ddcb577a262d170163f4bc7117b70ffa3f7 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 18 Dec 2014 23:11:42 +0100 Subject: hide header when no files in list match --- apps/files/js/filelist.js | 9 +++++++++ apps/files/js/filesummary.js | 32 +++++++++++++++++++++++++++++--- apps/files/js/search.js | 7 ++----- search/js/search.js | 2 +- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 88c81fb43af..910441bf267 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1668,6 +1668,8 @@ */ setFilter:function(filter) { this._filter = filter; + this.fileSummary.setFilter(filter, this.files); + this.hideHeaderWhenNoFilesMatch(); var that = this; this.$fileList.find('tr').each(function(i,e) { var $e = $(e); @@ -1679,6 +1681,13 @@ } }); }, + hideHeaderWhenNoFilesMatch:function() { + if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) { + this.$el.find('#filestable thead th').addClass('hidden'); + } else { + this.$el.find('#filestable thead th').removeClass('hidden'); + } + }, /** * get the current filter * @param filter diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index f83eb54678b..d73fd59cb81 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -39,7 +39,8 @@ summary: { totalFiles: 0, totalDirs: 0, - totalSize: 0 + totalSize: 0, + filter:'' }, /** @@ -48,6 +49,9 @@ * @param update whether to update the display */ add: function(file, update) { + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + return; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { this.summary.totalDirs++; } @@ -65,6 +69,9 @@ * @param update whether to update the display */ remove: function(file, update) { + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + return; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { this.summary.totalDirs--; } @@ -76,6 +83,10 @@ this.update(); } }, + setFilter: function(filter, files){ + this.summary.filter = filter.toLowerCase(); + this.calculate(files); + }, /** * Returns the total of files and directories */ @@ -91,11 +102,15 @@ var summary = { totalDirs: 0, totalFiles: 0, - totalSize: 0 + totalSize: 0, + filter: this.summary.filter }; for (var i = 0; i < files.length; i++) { file = files[i]; + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + continue; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { summary.totalDirs++; } @@ -137,10 +152,12 @@ var $dirInfo = this.$el.find('.dirinfo'); var $fileInfo = this.$el.find('.fileinfo'); var $connector = this.$el.find('.connector'); + var $filterInfo = this.$el.find('.filter'); // Substitute old content with new translations $dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs)); $fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles)); + $filterInfo.html(n('files', 'matches \'{filter}\'', 'match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); this.$el.find('.filesize').html(OC.Util.humanFileSize(this.summary.totalSize)); // Show only what's necessary (may be hidden) @@ -159,6 +176,11 @@ if (this.summary.totalDirs > 0 && this.summary.totalFiles > 0) { $connector.removeClass('hidden'); } + if (this.summary.filter === '') { + $filterInfo.addClass('hidden'); + } else { + $filterInfo.removeClass('hidden'); + } }, render: function() { if (!this.$el) { @@ -168,6 +190,7 @@ var summary = this.summary; var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs); var fileInfo = n('files', '%n file', '%n files', summary.totalFiles); + var filterInfo = n('files', 'matches \'{filter}\'', 'match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}) var infoVars = { dirs: ''+directoryInfo+'', @@ -182,11 +205,14 @@ var info = t('files', '{dirs} and {files}', infoVars); - var $summary = $('
'+fileSize+''); + var $summary = $(''+fileSize+''); if (!this.summary.totalFiles && !this.summary.totalDirs) { this.$el.addClass('hidden'); } + if (!summary.filter) { + $summary.find('.filter').addClass('hidden'); + } this.$el.append($summary); } diff --git a/apps/files/js/search.js b/apps/files/js/search.js index e6d71cf0f60..1f155b0e9b7 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -15,11 +15,8 @@ attach: function(search) { search.setFilter('files', function (query) { if (OCA.Files.Search.fileAppLoaded()) { - if (query) { - OCA.Files.App.fileList.setFilter(query); - } else { - OCA.Files.App.fileList.unfilter(); - } + OCA.Files.App.fileList.setFilter(query); + } }); diff --git a/search/js/search.js b/search/js/search.js index 28e6fa999a0..afd3fca7b1b 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -227,7 +227,7 @@ // not showing result, decrease counter var count = $status.data('count') - 1; $status.data('count', count) - .text(t('search', '{count} search results in other folders', {count:count}, count)); + .text(t('search', '{count} search results in other places', {count:count}, count)); } }); } -- cgit v1.2.3 From a6204efa0d1422a6840372db2caed677a5c1c80d Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 00:24:46 +0100 Subject: show audio icon & image previews --- apps/files/js/search.js | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 1f155b0e9b7..cd66bca4986 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -34,12 +34,7 @@ } /*render folder icon, show path beneath filename, show size and last modified date on the right */ - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } + OCA.Files.Search.updateLegacyMimetype(result); var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); @@ -54,12 +49,7 @@ } /*render preview icon, show path beneath filename, show size and last modified date on the right */ - // backward compatibility: - if (typeof result.mime !== 'undefined') { - result.mime_type = result.mime; - } else if (typeof result.mime_type !== 'undefined') { - result.mime = result.mime_type; - } + OCA.Files.Search.updateLegacyMimetype(result); $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); @@ -89,21 +79,23 @@ return $row; }, renderAudioResult: function($row, result) { - if (OCA.Files.Search.inFileList($row, result)) { - return null; - } /*render preview icon, show path beneath filename, show size and last modified date on the right show Artist and Album */ + $row = OCA.Files.Search.renderFileResult($row, result); + if ($row) { + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')'); + } return $row; }, renderImageResult: function($row, result) { - if (OCA.Files.Search.inFileList($row, result)) { - return null; - } /*render preview icon, show path beneath filename, show size and last modified date on the right show width and height */ + $row = OCA.Files.Search.renderFileResult($row, result); + if ($row && !OCA.Files.Search.fileAppLoaded()) { + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')'); + } return $row; }, inFileList: function($row, result){ @@ -113,6 +105,12 @@ return false; } }, + updateLegacyMimetype: function(result){ + // backward compatibility: + if (!result.mime && result.mime_type) { + result.mime = result.mime_type; + } + }, handleFolderClick: function($row, result, event) { // open folder if (OCA.Files.Search.fileAppLoaded()) { -- cgit v1.2.3 From 980f88c9b51ef90151836cfa59d9fda5de4c6890 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 00:25:25 +0100 Subject: remove globe fallback icon --- search/js/search.js | 1 - 1 file changed, 1 deletion(-) diff --git a/search/js/search.js b/search/js/search.js index afd3fca7b1b..4933bbec625 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -206,7 +206,6 @@ $row.find('td.info div.name').text(result.name); $row.find('td.info a').attr('href', result.link); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'places/link') + ')'); /** * Give plugins the ability to customize the search results. see result.js for examples */ -- cgit v1.2.3 From 74fd31d9bfaf2793290594d6eccf707cdcad9d02 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 00:30:55 +0100 Subject: set empty filter when hiding results / esc --- search/js/search.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/search/js/search.js b/search/js/search.js index 4933bbec625..f2ed58a8436 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -246,6 +246,9 @@ } } this.hideResults = function() { + if(that.hasFilter(getCurrentApp())) { + that.getFilter(getCurrentApp())(''); + } if ($searchResults) { $searchResults.hide(); $searchBox.val(''); -- cgit v1.2.3 From 80ded08ec46d56476f20f3e71d5bb115e070f228 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 00:49:05 +0100 Subject: hide irrelevant stuff in empty filelist --- apps/files/js/filelist.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 910441bf267..e01a029bc97 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1669,7 +1669,7 @@ setFilter:function(filter) { this._filter = filter; this.fileSummary.setFilter(filter, this.files); - this.hideHeaderWhenNoFilesMatch(); + this.hideIrrelevantUIWhenNoFilesMatch(); var that = this; this.$fileList.find('tr').each(function(i,e) { var $e = $(e); @@ -1681,11 +1681,13 @@ } }); }, - hideHeaderWhenNoFilesMatch:function() { + hideIrrelevantUIWhenNoFilesMatch:function() { if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) { this.$el.find('#filestable thead th').addClass('hidden'); + this.$el.find('#emptycontent').addClass('hidden'); } else { - this.$el.find('#filestable thead th').removeClass('hidden'); + this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty); + this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty); } }, /** -- cgit v1.2.3 From 8bf048376ce91f960c0df5d8807455f19a214a07 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 16:37:44 +0100 Subject: allow getting the last query --- apps/files/js/search.js | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index cd66bca4986..669def85d85 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -8,33 +8,30 @@ * */ (function() { - if (!OCA.Files) { - OCA.Files = {}; - } - OCA.Files.Search = { + OCA.Search.Files = { attach: function(search) { search.setFilter('files', function (query) { - if (OCA.Files.Search.fileAppLoaded()) { + if (OCA.Search.Files.fileAppLoaded()) { OCA.Files.App.fileList.setFilter(query); } }); - search.setRenderer('folder', OCA.Files.Search.renderFolderResult); - search.setRenderer('file', OCA.Files.Search.renderFileResult); - search.setRenderer('audio', OCA.Files.Search.renderAudioResult); - search.setRenderer('image', OCA.Files.Search.renderImageResult); + search.setRenderer('folder', OCA.Search.Files.renderFolderResult); + search.setRenderer('file', OCA.Search.Files.renderFileResult); + search.setRenderer('audio', OCA.Search.Files.renderAudioResult); + search.setRenderer('image', OCA.Search.Files.renderImageResult); - search.setHandler('folder', OCA.Files.Search.handleFolderClick); - search.setHandler(['file', 'audio', 'image'], OCA.Files.Search.handleFileClick); + search.setHandler('folder', OCA.Search.Files.handleFolderClick); + search.setHandler(['file', 'audio', 'image'], OCA.Search.Files.handleFileClick); }, renderFolderResult: function($row, result) { - if (OCA.Files.Search.inFileList($row, result)) { + if (OCA.Search.Files.inFileList($row, result)) { return null; } /*render folder icon, show path beneath filename, show size and last modified date on the right */ - OCA.Files.Search.updateLegacyMimetype(result); + OCA.Search.Files.updateLegacyMimetype(result); var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); @@ -44,19 +41,19 @@ return $row; }, renderFileResult: function($row, result) { - if (OCA.Files.Search.inFileList($row, result)) { + if (OCA.Search.Files.inFileList($row, result)) { return null; } /*render preview icon, show path beneath filename, show size and last modified date on the right */ - OCA.Files.Search.updateLegacyMimetype(result); + OCA.Search.Files.updateLegacyMimetype(result); $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); $row.find('td.result a').attr('href', result.link); - if (OCA.Files.Search.fileAppLoaded()) { + if (OCA.Search.Files.fileAppLoaded()) { OCA.Files.App.fileList.lazyLoadPreview({ path: result.path, mime: result.mime, @@ -82,7 +79,7 @@ /*render preview icon, show path beneath filename, show size and last modified date on the right show Artist and Album */ - $row = OCA.Files.Search.renderFileResult($row, result); + $row = OCA.Search.Files.renderFileResult($row, result); if ($row) { $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')'); } @@ -92,14 +89,14 @@ /*render preview icon, show path beneath filename, show size and last modified date on the right show width and height */ - $row = OCA.Files.Search.renderFileResult($row, result); - if ($row && !OCA.Files.Search.fileAppLoaded()) { + $row = OCA.Search.Files.renderFileResult($row, result); + if ($row && !OCA.Search.Files.fileAppLoaded()) { $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')'); } return $row; }, inFileList: function($row, result){ - if (OCA.Files.Search.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) { + if (OCA.Search.Files.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) { return true; } else { return false; @@ -113,7 +110,7 @@ }, handleFolderClick: function($row, result, event) { // open folder - if (OCA.Files.Search.fileAppLoaded()) { + if (OCA.Search.Files.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(result.path); return false; } else { @@ -121,7 +118,7 @@ } }, handleFileClick: function($row, result, event) { - if (OCA.Files.Search.fileAppLoaded()) { + if (OCA.Search.Files.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); OCA.Files.App.fileList.scrollTo(result.name); return false; @@ -130,8 +127,9 @@ } }, fileAppLoaded: function() { - return OCA.Files && OCA.Files.App; + return !!OCA.Files && !!OCA.Files.App; } }; })(); -OC.Plugins.register('OCA.Search', OCA.Files.Search); + +OC.Plugins.register('OCA.Search', OCA.Search.Files); -- cgit v1.2.3 From a8edb2124d24018f95733c88d840ff9a0708f3d0 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 16:39:03 +0100 Subject: fix visibility --- lib/public/search/pagedprovider.php | 6 ------ lib/public/search/provider.php | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/public/search/pagedprovider.php b/lib/public/search/pagedprovider.php index 10c36cfc483..10125d4a887 100644 --- a/lib/public/search/pagedprovider.php +++ b/lib/public/search/pagedprovider.php @@ -24,12 +24,6 @@ namespace OCP\Search; */ abstract class PagedProvider extends Provider { - /** - * List of options (currently unused) - * @var array - */ - private $options; - /** * Constructor * @param array $options diff --git a/lib/public/search/provider.php b/lib/public/search/provider.php index d6cd1fb025e..c9ef173d363 100644 --- a/lib/public/search/provider.php +++ b/lib/public/search/provider.php @@ -27,10 +27,10 @@ abstract class Provider { const OPTION_APPS = 'apps'; /** - * List of options (currently unused) + * List of options * @var array */ - private $options; + protected $options; /** * Constructor -- cgit v1.2.3 From 63f86340429b34039abebe12efe87c45d30cc3a0 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 16:39:49 +0100 Subject: allow getting the last query --- search/js/search.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/search/js/search.js b/search/js/search.js index f2ed58a8436..82d3c2c6691 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -83,6 +83,10 @@ var lastSize = 30; var lastResults = {}; + this.getLastQuery = function() { + return lastQuery; + }; + /** * Do a search query and display the results * @param {string} query the search query -- cgit v1.2.3 From ff1c581dcbdeafd9dc7f0c0cbf1b698e817adc9f Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 19 Dec 2014 22:36:00 +0100 Subject: hide, esc, and backspace fixes --- search/js/search.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/search/js/search.js b/search/js/search.js index 82d3c2c6691..e1da92b84ef 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -168,6 +168,10 @@ var item = $row.data('result'); if(that.hasHandler(item.type)){ var result = that.getHandler(item.type)($row, result, event); + $searchBox.val(''); + if(that.hasFilter(getCurrentApp())) { + that.getFilter(getCurrentApp())(''); + } that.hideResults(); return result; } @@ -178,10 +182,11 @@ return false; }); $(document).click(function (event) { - that.hideResults(); + $searchBox.val(''); if(that.hasFilter(getCurrentApp())) { that.getFilter(getCurrentApp())(''); } + that.hideResults(); }); $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; @@ -250,12 +255,8 @@ } } this.hideResults = function() { - if(that.hasFilter(getCurrentApp())) { - that.getFilter(getCurrentApp())(''); - } if ($searchResults) { $searchResults.hide(); - $searchBox.val(''); $wrapper.remove(); $searchResults = false; $wrapper = false; @@ -272,7 +273,6 @@ if(currentResult > 0) { currentResult--; renderCurrent(); - } } else if(event.keyCode === 40) { //down if(lastResults.length > currentResult + 1){ @@ -280,11 +280,14 @@ renderCurrent(); } } else if(event.keyCode === 27) { //esc + $searchBox.val(''); + if(that.hasFilter(getCurrentApp())) { + that.getFilter(getCurrentApp())(''); + } that.hideResults(); } else { var query = $searchBox.val(); if (lastQuery !== query) { - lastQuery = query; currentResult = -1; if(that.hasFilter(getCurrentApp())) { that.getFilter(getCurrentApp())(query); @@ -292,9 +295,7 @@ if (query.length > 2) { that.search(query); } else { - if (that.hideResults) { - that.hideResults(); - } + that.hideResults(); } } } -- cgit v1.2.3 From 79e790c55dd5780f63a84b481f6a2c75838c28af Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 00:11:58 +0100 Subject: add SIZE_ALL const --- lib/public/search/pagedprovider.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/public/search/pagedprovider.php b/lib/public/search/pagedprovider.php index 10125d4a887..55771762e68 100644 --- a/lib/public/search/pagedprovider.php +++ b/lib/public/search/pagedprovider.php @@ -24,6 +24,11 @@ namespace OCP\Search; */ abstract class PagedProvider extends Provider { + /** + * show all results + */ + const SIZE_ALL = 0; + /** * Constructor * @param array $options @@ -38,15 +43,15 @@ abstract class PagedProvider extends Provider { * @return array An array of OCP\Search\Result's */ public function search($query) { - // old apps might assume they get all results, so we set size 0 - $this->searchPaged($query, 1, 0); + // old apps might assume they get all results, so we use SIZE_ALL + $this->searchPaged($query, 1, self::SIZE_ALL); } /** * Search for $query * @param string $query * @param int $page pages start at page 1 - * @param int $size, 0 = all + * @param int $size, 0 = SIZE_ALL * @return array An array of OCP\Search\Result's */ abstract public function searchPaged($query, $page, $size); -- cgit v1.2.3 From 0c55ef1a3015dae625b34a239c1a0cdba9aece93 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 00:13:09 +0100 Subject: that -> self, add missing var --- search/js/search.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/search/js/search.js b/search/js/search.js index e1da92b84ef..b19a420cee8 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -33,7 +33,7 @@ */ initialize: function($searchBox) { - var that = this; + var self = this; /** * contains closures that are called to filter the current content @@ -166,13 +166,13 @@ $searchResults.on('click', 'tr.result', function (event) { var $row = $(this); var item = $row.data('result'); - if(that.hasHandler(item.type)){ - var result = that.getHandler(item.type)($row, result, event); + if(self.hasHandler(item.type)){ + var result = self.getHandler(item.type)($row, result, event); $searchBox.val(''); - if(that.hasFilter(getCurrentApp())) { - that.getFilter(getCurrentApp())(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); } - that.hideResults(); + self.hideResults(); return result; } }); @@ -183,10 +183,10 @@ }); $(document).click(function (event) { $searchBox.val(''); - if(that.hasFilter(getCurrentApp())) { - that.getFilter(getCurrentApp())(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); } - that.hideResults(); + self.hideResults(); }); $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; @@ -218,8 +218,8 @@ /** * Give plugins the ability to customize the search results. see result.js for examples */ - if (that.hasRenderer(result.type)) { - $row = that.getRenderer(result.type)($row, result); + if (self.hasRenderer(result.type)) { + $row = self.getRenderer(result.type)($row, result); } else { // for backward compatibility add text div $row.find('td.info div.name').addClass('result'); @@ -281,21 +281,21 @@ } } else if(event.keyCode === 27) { //esc $searchBox.val(''); - if(that.hasFilter(getCurrentApp())) { - that.getFilter(getCurrentApp())(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); } - that.hideResults(); + self.hideResults(); } else { var query = $searchBox.val(); if (lastQuery !== query) { currentResult = -1; - if(that.hasFilter(getCurrentApp())) { - that.getFilter(getCurrentApp())(query); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(query); } if (query.length > 2) { - that.search(query); + self.search(query); } else { - that.hideResults(); + self.hideResults(); } } } @@ -308,7 +308,7 @@ function onScroll(e) { if ($searchResults) { //if ( $searchResults && $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { - // that.search(lastQuery, lastPage + 1); + // self.search(lastQuery, lastPage + 1); //} placeStatus(); } -- cgit v1.2.3 From 66cf17b32bd10bdaacc2bd3ae383c0100cdf73bd Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 00:14:02 +0100 Subject: don't use full class name to register plugin --- apps/files/js/search.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 669def85d85..15a4649de81 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -8,7 +8,25 @@ * */ (function() { - OCA.Search.Files = { + + /** + * Construct a new FileActions instance + * @constructs Files + */ + var Files = function() { + this.initialize(); + }; + /** + * @memberof OCA.Search + */ + Files.prototype = { + + /** + * Initialize the file search + */ + initialize: function() { + OC.Plugins.register('OCA.Search', this); + }, attach: function(search) { search.setFilter('files', function (query) { if (OCA.Search.Files.fileAppLoaded()) { @@ -48,7 +66,7 @@ show size and last modified date on the right */ OCA.Search.Files.updateLegacyMimetype(result); - $pathDiv = $('
').text(result.path); + var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); $row.find('td.result a').attr('href', result.link); @@ -96,11 +114,7 @@ return $row; }, inFileList: function($row, result){ - if (OCA.Search.Files.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) { - return true; - } else { - return false; - } + return OCA.Search.Files.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); }, updateLegacyMimetype: function(result){ // backward compatibility: @@ -132,4 +146,3 @@ }; })(); -OC.Plugins.register('OCA.Search', OCA.Search.Files); -- cgit v1.2.3 From 8abd954d9a361b4fad3bbd2e7c8ef67ba03c57b5 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 14:28:01 +0100 Subject: instantiate file search --- apps/files/js/search.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 15a4649de81..75c5f22cab9 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -28,28 +28,29 @@ OC.Plugins.register('OCA.Search', this); }, attach: function(search) { + var self = this; search.setFilter('files', function (query) { - if (OCA.Search.Files.fileAppLoaded()) { + if (self.fileAppLoaded()) { OCA.Files.App.fileList.setFilter(query); } }); - search.setRenderer('folder', OCA.Search.Files.renderFolderResult); - search.setRenderer('file', OCA.Search.Files.renderFileResult); - search.setRenderer('audio', OCA.Search.Files.renderAudioResult); - search.setRenderer('image', OCA.Search.Files.renderImageResult); + search.setRenderer('folder', this.renderFolderResult); + search.setRenderer('file', this.renderFileResult); + search.setRenderer('audio', this.renderAudioResult); + search.setRenderer('image', this.renderImageResult); - search.setHandler('folder', OCA.Search.Files.handleFolderClick); - search.setHandler(['file', 'audio', 'image'], OCA.Search.Files.handleFileClick); + search.setHandler('folder', this.handleFolderClick); + search.setHandler(['file', 'audio', 'image'], this.handleFileClick); }, renderFolderResult: function($row, result) { - if (OCA.Search.Files.inFileList($row, result)) { + if (this.inFileList($row, result)) { return null; } /*render folder icon, show path beneath filename, show size and last modified date on the right */ - OCA.Search.Files.updateLegacyMimetype(result); + this.updateLegacyMimetype(result); var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); @@ -59,19 +60,19 @@ return $row; }, renderFileResult: function($row, result) { - if (OCA.Search.Files.inFileList($row, result)) { + if (this.inFileList($row, result)) { return null; } /*render preview icon, show path beneath filename, show size and last modified date on the right */ - OCA.Search.Files.updateLegacyMimetype(result); + this.updateLegacyMimetype(result); var $pathDiv = $('
').text(result.path); $row.find('td.info div.name').after($pathDiv).text(result.name); $row.find('td.result a').attr('href', result.link); - if (OCA.Search.Files.fileAppLoaded()) { + if (this.fileAppLoaded()) { OCA.Files.App.fileList.lazyLoadPreview({ path: result.path, mime: result.mime, @@ -97,7 +98,7 @@ /*render preview icon, show path beneath filename, show size and last modified date on the right show Artist and Album */ - $row = OCA.Search.Files.renderFileResult($row, result); + $row = this.renderFileResult($row, result); if ($row) { $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')'); } @@ -107,14 +108,14 @@ /*render preview icon, show path beneath filename, show size and last modified date on the right show width and height */ - $row = OCA.Search.Files.renderFileResult($row, result); - if ($row && !OCA.Search.Files.fileAppLoaded()) { + $row = this.renderFileResult($row, result); + if ($row && !this.fileAppLoaded()) { $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')'); } return $row; }, inFileList: function($row, result){ - return OCA.Search.Files.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); + return this.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); }, updateLegacyMimetype: function(result){ // backward compatibility: @@ -124,7 +125,7 @@ }, handleFolderClick: function($row, result, event) { // open folder - if (OCA.Search.Files.fileAppLoaded()) { + if (this.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(result.path); return false; } else { @@ -132,7 +133,7 @@ } }, handleFileClick: function($row, result, event) { - if (OCA.Search.Files.fileAppLoaded()) { + if (this.fileAppLoaded()) { OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); OCA.Files.App.fileList.scrollTo(result.name); return false; @@ -144,5 +145,5 @@ return !!OCA.Files && !!OCA.Files.App; } }; + new Files(); })(); - -- cgit v1.2.3 From b45d0f03fc57c861ddaec0e293d537eefab4c7d1 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 14:36:48 +0100 Subject: fix js tests --- apps/files/js/filesummary.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index d73fd59cb81..46880272cdc 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -49,7 +49,7 @@ * @param update whether to update the display */ add: function(file, update) { - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { return; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { @@ -69,7 +69,7 @@ * @param update whether to update the display */ remove: function(file, update) { - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { return; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { @@ -133,6 +133,9 @@ */ setSummary: function(summary) { this.summary = summary; + if (typeof this.summary.filter === 'undefined') { + this.summary.filter = ''; + } this.update(); }, @@ -157,7 +160,6 @@ // Substitute old content with new translations $dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs)); $fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles)); - $filterInfo.html(n('files', 'matches \'{filter}\'', 'match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); this.$el.find('.filesize').html(OC.Util.humanFileSize(this.summary.totalSize)); // Show only what's necessary (may be hidden) @@ -177,8 +179,10 @@ $connector.removeClass('hidden'); } if (this.summary.filter === '') { + $filterInfo.html(''); $filterInfo.addClass('hidden'); } else { + $filterInfo.html(n('files', ' matches \'{filter}\'', ' match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); $filterInfo.removeClass('hidden'); } }, @@ -190,7 +194,11 @@ var summary = this.summary; var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs); var fileInfo = n('files', '%n file', '%n files', summary.totalFiles); - var filterInfo = n('files', 'matches \'{filter}\'', 'match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}) + if (this.summary.filter === '') { + var filterInfo = ''; + } else { + var filterInfo = n('files', ' matches \'{filter}\'', ' match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}); + } var infoVars = { dirs: ''+directoryInfo+'', @@ -205,14 +213,11 @@ var info = t('files', '{dirs} and {files}', infoVars); - var $summary = $('
'+fileSize+''); + var $summary = $(''+fileSize+''); if (!this.summary.totalFiles && !this.summary.totalDirs) { this.$el.addClass('hidden'); } - if (!summary.filter) { - $summary.find('.filter').addClass('hidden'); - } this.$el.append($summary); } -- cgit v1.2.3 From 4fdd626f0a4b6667e3fd4c376399617df5866315 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 16:02:58 +0100 Subject: use correct visibilities --- apps/files/js/search.js | 212 +++++++++++++++++++++++++----------------------- 1 file changed, 111 insertions(+), 101 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 75c5f22cab9..6f034f79f60 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -25,6 +25,117 @@ * Initialize the file search */ initialize: function() { + + var self = this; + + this.fileAppLoaded = function() { + return !!OCA.Files && !!OCA.Files.App; + }; + function inFileList($row, result) { + return self.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); + } + function updateLegacyMimetype(result){ + // backward compatibility: + if (!result.mime && result.mime_type) { + result.mime = result.mime_type; + } + } + + this.renderFolderResult = function($row, result) { + if (inFileList($row, result)) { + return null; + } + /*render folder icon, show path beneath filename, + show size and last modified date on the right */ + this.updateLegacyMimetype(result); + + var $pathDiv = $('
').text(result.path); + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); + return $row; + }; + + this.renderFileResult = function($row, result) { + if (inFileList($row, result)) { + return null; + } + /*render preview icon, show path beneath filename, + show size and last modified date on the right */ + this.updateLegacyMimetype(result); + + var $pathDiv = $('
').text(result.path); + $row.find('td.info div.name').after($pathDiv).text(result.name); + + $row.find('td.result a').attr('href', result.link); + + if (self.fileAppLoaded()) { + OCA.Files.App.fileList.lazyLoadPreview({ + path: result.path, + mime: result.mime, + callback: function (url) { + $row.find('td.icon').css('background-image', 'url(' + url + ')'); + } + }); + } else { + // FIXME how to get mime icon if not in files app + var mimeicon = result.mime.replace('/', '-'); + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')'); + var dir = OC.dirname(result.path); + if (dir === '') { + dir = '/'; + } + $row.find('td.info a').attr('href', + OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) + ); + } + return $row; + }; + + this.renderAudioResult = function($row, result) { + /*render preview icon, show path beneath filename, + show size and last modified date on the right + show Artist and Album */ + $row = this.renderFileResult($row, result); + if ($row) { + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')'); + } + return $row; + }; + + this.renderImageResult = function($row, result) { + /*render preview icon, show path beneath filename, + show size and last modified date on the right + show width and height */ + $row = this.renderFileResult($row, result); + if ($row && !self.fileAppLoaded()) { + $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')'); + } + return $row; + }; + + + this.handleFolderClick = function($row, result, event) { + // open folder + if (self.fileAppLoaded()) { + OCA.Files.App.fileList.changeDirectory(result.path); + return false; + } else { + return true; + } + }; + + this.handleFileClick = function($row, result, event) { + if (self.fileAppLoaded()) { + OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); + OCA.Files.App.fileList.scrollTo(result.name); + return false; + } else { + return true; + } + }; + OC.Plugins.register('OCA.Search', this); }, attach: function(search) { @@ -32,7 +143,6 @@ search.setFilter('files', function (query) { if (self.fileAppLoaded()) { OCA.Files.App.fileList.setFilter(query); - } }); @@ -43,106 +153,6 @@ search.setHandler('folder', this.handleFolderClick); search.setHandler(['file', 'audio', 'image'], this.handleFileClick); - }, - renderFolderResult: function($row, result) { - if (this.inFileList($row, result)) { - return null; - } - /*render folder icon, show path beneath filename, - show size and last modified date on the right */ - this.updateLegacyMimetype(result); - - var $pathDiv = $('
').text(result.path); - $row.find('td.info div.name').after($pathDiv).text(result.name); - - $row.find('td.result a').attr('href', result.link); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')'); - return $row; - }, - renderFileResult: function($row, result) { - if (this.inFileList($row, result)) { - return null; - } - /*render preview icon, show path beneath filename, - show size and last modified date on the right */ - this.updateLegacyMimetype(result); - - var $pathDiv = $('
').text(result.path); - $row.find('td.info div.name').after($pathDiv).text(result.name); - - $row.find('td.result a').attr('href', result.link); - - if (this.fileAppLoaded()) { - OCA.Files.App.fileList.lazyLoadPreview({ - path: result.path, - mime: result.mime, - callback: function (url) { - $row.find('td.icon').css('background-image', 'url(' + url + ')'); - } - }); - } else { - // FIXME how to get mime icon if not in files app - var mimeicon = result.mime.replace('/', '-'); - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')'); - var dir = OC.dirname(result.path); - if (dir === '') { - dir = '/'; - } - $row.find('td.info a').attr('href', - OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name}) - ); - } - return $row; - }, - renderAudioResult: function($row, result) { - /*render preview icon, show path beneath filename, - show size and last modified date on the right - show Artist and Album */ - $row = this.renderFileResult($row, result); - if ($row) { - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/audio') + ')'); - } - return $row; - }, - renderImageResult: function($row, result) { - /*render preview icon, show path beneath filename, - show size and last modified date on the right - show width and height */ - $row = this.renderFileResult($row, result); - if ($row && !this.fileAppLoaded()) { - $row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/image') + ')'); - } - return $row; - }, - inFileList: function($row, result){ - return this.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); - }, - updateLegacyMimetype: function(result){ - // backward compatibility: - if (!result.mime && result.mime_type) { - result.mime = result.mime_type; - } - }, - handleFolderClick: function($row, result, event) { - // open folder - if (this.fileAppLoaded()) { - OCA.Files.App.fileList.changeDirectory(result.path); - return false; - } else { - return true; - } - }, - handleFileClick: function($row, result, event) { - if (this.fileAppLoaded()) { - OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); - OCA.Files.App.fileList.scrollTo(result.name); - return false; - } else { - return true; - } - }, - fileAppLoaded: function() { - return !!OCA.Files && !!OCA.Files.App; } }; new Files(); -- cgit v1.2.3 From 457f5abf6cc611064b30bdc0d70a8d42a73c9706 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 16:15:57 +0100 Subject: fix count --- apps/files/js/filesummary.js | 2 +- search/js/search.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index 46880272cdc..d69c5f1b53a 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -108,7 +108,7 @@ for (var i = 0; i < files.length; i++) { file = files[i]; - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { continue; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { diff --git a/search/js/search.js b/search/js/search.js index b19a420cee8..b090a4ec4a8 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -234,6 +234,9 @@ } else { // not showing result, decrease counter var count = $status.data('count') - 1; + if (count < 0) { + count = 0; + } $status.data('count', count) .text(t('search', '{count} search results in other places', {count:count}, count)); } -- cgit v1.2.3 From f8700ec6492ef9be32e75fc56adb4fb836b9bd9b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 31 Dec 2014 16:36:00 +0100 Subject: Fix rendering search results --- apps/files/js/search.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 6f034f79f60..050f5f259ba 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -136,6 +136,13 @@ } }; + this.updateLegacyMimetype = function (result) { + // backward compatibility: + if (!result.mime && result.mime_type) { + result.mime = result.mime_type; + } + }; + OC.Plugins.register('OCA.Search', this); }, attach: function(search) { @@ -146,13 +153,13 @@ } }); - search.setRenderer('folder', this.renderFolderResult); - search.setRenderer('file', this.renderFileResult); - search.setRenderer('audio', this.renderAudioResult); - search.setRenderer('image', this.renderImageResult); + search.setRenderer('folder', this.renderFolderResult.bind(this)); + search.setRenderer('file', this.renderFileResult.bind(this)); + search.setRenderer('audio', this.renderAudioResult.bind(this)); + search.setRenderer('image', this.renderImageResult.bind(this)); - search.setHandler('folder', this.handleFolderClick); - search.setHandler(['file', 'audio', 'image'], this.handleFileClick); + search.setHandler('folder', this.handleFolderClick.bind(this)); + search.setHandler(['file', 'audio', 'image'], this.handleFileClick.bind(this)); } }; new Files(); -- cgit v1.2.3 From 6ba888134318878161eec0c40d26645d9e8190ac Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 10:28:23 +0100 Subject: add file summary filter spec tests --- apps/files/tests/js/filesummarySpec.js | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/apps/files/tests/js/filesummarySpec.js b/apps/files/tests/js/filesummarySpec.js index 5e39dd1d232..4c53b7d8b3a 100644 --- a/apps/files/tests/js/filesummarySpec.js +++ b/apps/files/tests/js/filesummarySpec.js @@ -85,4 +85,67 @@ describe('OCA.Files.FileSummary tests', function() { expect(s.summary.totalFiles).toEqual(1); expect(s.summary.totalSize).toEqual(127900); }); + + it('renders filtered summary as text', function() { + var s = new FileSummary($container); + s.setSummary({ + totalDirs: 5, + totalFiles: 2, + totalSize: 256000, + filter: 'foo' + }); + expect($container.hasClass('hidden')).toEqual(false); + expect($container.find('.info').text()).toEqual('5 folders and 2 files match \'foo\''); + expect($container.find('.filesize').text()).toEqual('250 kB'); + }); + it('hides filtered summary when no files or folders', function() { + var s = new FileSummary($container); + s.setSummary({ + totalDirs: 0, + totalFiles: 0, + totalSize: 0, + filter: 'foo' + }); + expect($container.hasClass('hidden')).toEqual(true); + }); + it('increases filtered summary when adding files', function() { + var s = new FileSummary($container); + s.setSummary({ + totalDirs: 5, + totalFiles: 2, + totalSize: 256000, + filter: 'foo' + }); + s.add({name: 'bar.txt', type: 'file', size: 256000}); + s.add({name: 'foo.txt', type: 'file', size: 256001}); + s.add({name: 'bar', type: 'dir', size: 100}); + s.add({name: 'foo', type: 'dir', size: 102}); + s.update(); + expect($container.hasClass('hidden')).toEqual(false); + expect($container.find('.info').text()).toEqual('6 folders and 3 files match \'foo\''); + expect($container.find('.filesize').text()).toEqual('500 kB'); + expect(s.summary.totalDirs).toEqual(6); + expect(s.summary.totalFiles).toEqual(3); + expect(s.summary.totalSize).toEqual(512103); + }); + it('decreases filtered summary when removing files', function() { + var s = new FileSummary($container); + s.setSummary({ + totalDirs: 5, + totalFiles: 2, + totalSize: 256000, + filter: 'foo' + }); + s.remove({name: 'bar.txt', type: 'file', size: 128000}); + s.remove({name: 'foo.txt', type: 'file', size: 127999}); + s.remove({name: 'bar', type: 'dir', size: 100}); + s.remove({name: 'foo', type: 'dir', size: 98}); + s.update(); + expect($container.hasClass('hidden')).toEqual(false); + expect($container.find('.info').text()).toEqual('4 folders and 1 file match \'foo\''); + expect($container.find('.filesize').text()).toEqual('125 kB'); + expect(s.summary.totalDirs).toEqual(4); + expect(s.summary.totalFiles).toEqual(1); + expect(s.summary.totalSize).toEqual(127903); + }); }); -- cgit v1.2.3 From 9e3f4e043f6204a336a6efc4a9c39f23723d0522 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 10:57:25 +0100 Subject: make OCA.Search.Files available in tests and for other apps --- apps/files/js/search.js | 1 + core/js/core.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 050f5f259ba..73eccd06dcf 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -163,4 +163,5 @@ } }; new Files(); + OCA.Search.Files = Files; })(); diff --git a/core/js/core.json b/core/js/core.json index d3a9e2404e8..101a88cd4f0 100644 --- a/core/js/core.json +++ b/core/js/core.json @@ -22,6 +22,7 @@ "eventsource.js", "config.js", "multiselect.js", - "oc-requesttoken.js" + "oc-requesttoken.js", + "../../search/js/search.js" ] } -- cgit v1.2.3 From 0cca9e26c41a1957b3a574d33b3835ea76c63e13 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 12:50:21 +0100 Subject: show no files found message --- apps/files/css/files.css | 23 +++++++++++++++++++++++ apps/files/js/filelist.js | 5 +++++ apps/files/js/search.js | 8 ++++++++ apps/files/templates/list.php | 6 ++++++ search/js/search.js | 27 +++++++++------------------ 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index a75ad57c833..a6a28b594ae 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -599,3 +599,26 @@ table.dragshadow td.size { .mask.transparent{ opacity: 0; } + +#nofilterresults { + font-size: 16px; + color: #888; + position: absolute; + text-align: center; + top: 30%; + width: 100%; +} +#nofilterresults h2 { + font-size: 22px; + margin-bottom: 10px; +} +#nofilterresults [class^="icon-"], +#nofilterresults [class*=" icon-"] { + background-size: 64px; + height: 64px; + width: 64px; + margin: 0 auto 15px; + -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; + filter: alpha(opacity=50); + opacity: .5; +} \ No newline at end of file diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index e01a029bc97..48c990872d1 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1685,9 +1685,14 @@ if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) { this.$el.find('#filestable thead th').addClass('hidden'); this.$el.find('#emptycontent').addClass('hidden'); + if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden')) { + this.$el.find('#nofilterresults').removeClass('hidden'). + find('p').text(t('files', 'No entries in this folder match \'{filter}\'', {filter:this._filter})); + } } else { this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty); this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty); + this.$el.find('#nofilterresults').addClass('hidden'); } }, /** diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 73eccd06dcf..ec93b937690 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -40,11 +40,18 @@ result.mime = result.mime_type; } } + function hideNoFilterResults (){ + var $nofilterresults = $('#nofilterresults'); + if ( ! $nofilterresults.hasClass('hidden') ) { + $nofilterresults.addClass('hidden'); + } + } this.renderFolderResult = function($row, result) { if (inFileList($row, result)) { return null; } + hideNoFilterResults(); /*render folder icon, show path beneath filename, show size and last modified date on the right */ this.updateLegacyMimetype(result); @@ -61,6 +68,7 @@ if (inFileList($row, result)) { return null; } + hideNoFilterResults(); /*render preview icon, show path beneath filename, show size and last modified date on the right */ this.updateLegacyMimetype(result); diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 4224d9bc100..5b90e629ddd 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -60,6 +60,12 @@

t('Upload some content or sync with your devices!')); ?>

+ +
'+info+''+info+' '+filterInfo+''+info+' '+filterInfo+''+info+''+filterInfo+'
diff --git a/search/js/search.js b/search/js/search.js index b090a4ec4a8..8e576e6e8f0 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -109,7 +109,7 @@ } } // prevent double pages - if ($searchResults && query === lastQuery && page === lastPage&& size === lastSize) { + if ($searchResults && query === lastQuery && page === lastPage && size === lastSize) { return; } lastQuery = query; @@ -153,9 +153,6 @@ } } function showResults(results) { - if (results.length === 0) { - return; - } if (!$searchResults) { $wrapper = $('
'); $('#app-content') @@ -190,9 +187,7 @@ }); $('#app-content').on('scroll', _.bind(onScroll, this)); lastResults = results; - $status = $searchResults.find('#status') - .data('count', results.length) - .text(t('search', '{count} search results in other folders', {count:results.length}, results.length)); + $status = $searchResults.find('#status'); placeStatus(); showResults(results); }); @@ -231,16 +226,11 @@ } if ($row) { $searchResults.find('tbody').append($row); - } else { - // not showing result, decrease counter - var count = $status.data('count') - 1; - if (count < 0) { - count = 0; - } - $status.data('count', count) - .text(t('search', '{count} search results in other places', {count:count}, count)); } }); + var count = $searchResults.find('tr.result').length; + $status.data('count', count) + .text(t('search', '{count} search results in other places', {count:count}, count)); } function renderCurrent() { var result = $searchResults.find('tr.result')[currentResult]; @@ -263,6 +253,7 @@ $wrapper.remove(); $searchResults = false; $wrapper = false; + lastQuery = false; } }; @@ -292,14 +283,14 @@ var query = $searchBox.val(); if (lastQuery !== query) { currentResult = -1; - if(self.hasFilter(getCurrentApp())) { - self.getFilter(getCurrentApp())(query); - } if (query.length > 2) { self.search(query); } else { self.hideResults(); } + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(query); + } } } }); -- cgit v1.2.3 From 2eec8dc156d6bbeb8a40fa9547fbc266bd881437 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 14:22:48 +0100 Subject: correctly update search results when query is changed, show spinner when searching --- apps/files/js/search.js | 7 +- search/css/results.css | 10 +- search/js/search.js | 187 ++++++++++++++++++------------------- search/templates/part.results.html | 28 +++--- 4 files changed, 119 insertions(+), 113 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index ec93b937690..dd8d3a6e502 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -34,13 +34,13 @@ function inFileList($row, result) { return self.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); } - function updateLegacyMimetype(result){ + function updateLegacyMimetype(result) { // backward compatibility: if (!result.mime && result.mime_type) { result.mime = result.mime_type; } } - function hideNoFilterResults (){ + function hideNoFilterResults() { var $nofilterresults = $('#nofilterresults'); if ( ! $nofilterresults.hasClass('hidden') ) { $nofilterresults.addClass('hidden'); @@ -158,6 +158,9 @@ search.setFilter('files', function (query) { if (self.fileAppLoaded()) { OCA.Files.App.fileList.setFilter(query); + if (query.length > 2) { + $('#nofilterresults').addClass('hidden'); + } } }); diff --git a/search/css/results.css b/search/css/results.css index 4e3fade68d2..dd746391387 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -22,7 +22,7 @@ padding: 28px 0 28px 56px; font-size: 18px; } -.has-favorites:not(.hidden) ~ .searchresults-wrapper #searchresults #status { +.has-favorites:not(.hidden) ~ #searchresults #status { padding-left: 102px; } #searchresults #status.fixed { @@ -32,6 +32,12 @@ z-index: 10; } +#searchresults #status .spinner { + height: 16px; + width: 16px; + vertical-align: middle; + margin-left: 10px; +} #searchresults table { border-spacing:0; table-layout:fixed; @@ -53,7 +59,7 @@ background-position: right center; background-repeat: no-repeat; } -.has-favorites:not(.hidden) ~ .searchresults-wrapper #searchresults td.icon { +.has-favorites:not(.hidden) ~ #searchresults td.icon { width: 86px; } diff --git a/search/js/search.js b/search/js/search.js index 8e576e6e8f0..b74674d5aa7 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -16,9 +16,10 @@ * The Search class manages a search queries and their results * * @param $searchBox container element with existing markup for the #searchbox form + * @param $searchResults container element for results und status message */ - var Search = function($searchBox) { - this.initialize($searchBox); + var Search = function($searchBox, $searchResults) { + this.initialize($searchBox, $searchResults); }; /** * @memberof OC @@ -31,7 +32,7 @@ * @param $searchBox container element with existing markup for the #searchbox form * @private */ - initialize: function($searchBox) { + initialize: function($searchBox, $searchResults) { var self = this; @@ -115,6 +116,10 @@ lastQuery = query; lastPage = page; lastSize = size; + + $searchResults.removeClass('hidden'); + $status.html(t('core', 'Searching other places')+'search in progress'); + // do the actual search query $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) { lastResults = results; if (page === 1) { @@ -126,23 +131,25 @@ } }, 500); + //TODO should be a core method, see https://github.com/owncloud/core/issues/12557 function getCurrentApp() { - var classList = document.getElementById('content').className.split(/\s+/); - for (var i = 0; i < classList.length; i++) { - if (classList[i].indexOf('app-') === 0) { - return classList[i].substr(4); + var content = document.getElementById('content'); + if (content) { + var classList = document.getElementById('content').className.split(/\s+/); + for (var i = 0; i < classList.length; i++) { + if (classList[i].indexOf('app-') === 0) { + return classList[i].substr(4); + } } } return false; } - var $searchResults = false; - var $wrapper = false; - var $status = false; + var $status = $searchResults.find('#status'); const summaryAndStatusHeight = 118; function isStatusOffScreen() { - return $searchResults.position().top + summaryAndStatusHeight > window.innerHeight; + return $searchResults.position() && ($searchResults.position().top + summaryAndStatusHeight > window.innerHeight); } function placeStatus() { @@ -153,49 +160,10 @@ } } function showResults(results) { - if (!$searchResults) { - $wrapper = $('
'); - $('#app-content') - .append($wrapper) - .find('.viewcontainer').css('min-height', 'initial'); - $wrapper.load(OC.webroot + '/search/templates/part.results.html', function () { - $searchResults = $wrapper.find('#searchresults'); - $searchResults.on('click', 'tr.result', function (event) { - var $row = $(this); - var item = $row.data('result'); - if(self.hasHandler(item.type)){ - var result = self.getHandler(item.type)($row, result, event); - $searchBox.val(''); - if(self.hasFilter(getCurrentApp())) { - self.getFilter(getCurrentApp())(''); - } - self.hideResults(); - return result; - } - }); - $searchResults.on('click', '#status', function (event) { - event.preventDefault(); - scrollToResults(); - return false; - }); - $(document).click(function (event) { - $searchBox.val(''); - if(self.hasFilter(getCurrentApp())) { - self.getFilter(getCurrentApp())(''); - } - self.hideResults(); - }); - $('#app-content').on('scroll', _.bind(onScroll, this)); - lastResults = results; - $status = $searchResults.find('#status'); - placeStatus(); - showResults(results); - }); - } else { - $searchResults.find('tr.result').remove(); - $searchResults.show(); - addResults(results); - } + lastResults = results; + $searchResults.find('tr.result').remove(); + $searchResults.show(); + addResults(results); } function addResults(results) { var $template = $searchResults.find('tr.template'); @@ -248,14 +216,49 @@ } } this.hideResults = function() { + $searchResults.addClass('hidden'); + $searchResults.find('tr.result').remove(); + lastQuery = false; + }; + + /** + * Event handler for when scrolling the list container. + * This appends/renders the next page of entries when reaching the bottom. + */ + function onScroll(e) { if ($searchResults) { - $searchResults.hide(); - $wrapper.remove(); - $searchResults = false; - $wrapper = false; - lastQuery = false; + //if ( $searchResults && $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { + // self.search(lastQuery, lastPage + 1); + //} + placeStatus(); } - }; + } + + $('#app-content').on('scroll', _.bind(onScroll, this)); + + /** + * scrolls the search results to the top + */ + function scrollToResults() { + setTimeout(function() { + if (isStatusOffScreen()) { + var newScrollTop = $('#app-content').prop('scrollHeight') - $searchResults.height(); + console.log('scrolling to ' + newScrollTop); + $('#app-content').animate({ + scrollTop: newScrollTop + }, { + duration: 100, + complete: function () { + scrollToResults(); + } + }); + } + }, 150); + } + + $('form.searchbox').submit(function(event) { + event.preventDefault(); + }); $searchBox.keyup(function(event) { if (event.keyCode === 13) { //enter @@ -295,42 +298,32 @@ } }); - /** - * Event handler for when scrolling the list container. - * This appends/renders the next page of entries when reaching the bottom. - */ - function onScroll(e) { - if ($searchResults) { - //if ( $searchResults && $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { - // self.search(lastQuery, lastPage + 1); - //} - placeStatus(); - } - } - - /** - * scrolls the search results to the top - */ - function scrollToResults() { - setTimeout(function() { - if (isStatusOffScreen()) { - var newScrollTop = $('#app-content').prop('scrollHeight') - $searchResults.height(); - console.log('scrolling to ' + newScrollTop); - $('#app-content').animate({ - scrollTop: newScrollTop - }, { - duration: 100, - complete: function () { - scrollToResults(); - } - }); + $searchResults.on('click', 'tr.result', function (event) { + var $row = $(this); + var item = $row.data('result'); + if(self.hasHandler(item.type)){ + var result = self.getHandler(item.type)($row, result, event); + $searchBox.val(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); } - }, 150); - } - - $('form.searchbox').submit(function(event) { + self.hideResults(); + return result; + } + }); + $searchResults.on('click', '#status', function (event) { event.preventDefault(); + scrollToResults(); + return false; + }); + $(document).click(function (event) { + $searchBox.val(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); + } + self.hideResults(); }); + placeStatus(); OC.Plugins.attach('OCA.Search', this); } @@ -339,7 +332,13 @@ })(); $(document).ready(function() { - OC.Search = new OCA.Search($('#searchbox')); + var $searchResults = $('
- - - - - - -
- -
-
-
-
+
+ + + + + + + +
+ +
+
+
-- cgit v1.2.3 From 6c9d9d26bb19a22eca1cf17cf23a715320be62ba Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 14:46:35 +0100 Subject: do not hide search results when clicking, but hide on ESC --- search/css/results.css | 6 +++++- search/js/search.js | 22 +++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/search/css/results.css b/search/css/results.css index dd746391387..f2e6e475483 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -7,11 +7,15 @@ overflow-x:hidden; overflow-y: auto; text-overflow:ellipsis; - padding-top: 45px; + padding-top: 65px; height: 100%; box-sizing: border-box; z-index:75; } + +#searchresults.hidden { + display: none; +} #searchresults * { box-sizing: content-box; } diff --git a/search/js/search.js b/search/js/search.js index b74674d5aa7..87b8908aa0a 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -276,12 +276,6 @@ currentResult++; renderCurrent(); } - } else if(event.keyCode === 27) { //esc - $searchBox.val(''); - if(self.hasFilter(getCurrentApp())) { - self.getFilter(getCurrentApp())(''); - } - self.hideResults(); } else { var query = $searchBox.val(); if (lastQuery !== query) { @@ -297,6 +291,15 @@ } } }); + $(document).keyup(function(event) { + if(event.keyCode === 27) { //esc + $searchBox.val(''); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); + } + self.hideResults(); + } + }); $searchResults.on('click', 'tr.result', function (event) { var $row = $(this); @@ -316,13 +319,6 @@ scrollToResults(); return false; }); - $(document).click(function (event) { - $searchBox.val(''); - if(self.hasFilter(getCurrentApp())) { - self.getFilter(getCurrentApp())(''); - } - self.hideResults(); - }); placeStatus(); OC.Plugins.attach('OCA.Search', this); -- cgit v1.2.3 From 152c8b3969e38eccf5204c8f7b436676e7168413 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 14:58:39 +0100 Subject: text and icon fixes --- apps/files/templates/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 5b90e629ddd..55754fd0c6b 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -61,8 +61,8 @@
-- cgit v1.2.3 From 6f820b02094eaba3191124a7a17e56f302be202d Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 14:59:55 +0100 Subject: use " to avoid escaping ' --- apps/files/js/filelist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 48c990872d1..84b537fbdfe 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1687,7 +1687,7 @@ this.$el.find('#emptycontent').addClass('hidden'); if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden')) { this.$el.find('#nofilterresults').removeClass('hidden'). - find('p').text(t('files', 'No entries in this folder match \'{filter}\'', {filter:this._filter})); + find('p').text(t('files', "No entries in this folder match '{filter}'", {filter:this._filter})); } } else { this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty); -- cgit v1.2.3 From d89733c85914e12c456b8425dfdfd3f69f337a19 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 15:44:41 +0100 Subject: clear search results when clicking the x in type=search input field --- search/js/search.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/search/js/search.js b/search/js/search.js index 87b8908aa0a..10949cec0b0 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -30,6 +30,7 @@ * Initialize the search box * * @param $searchBox container element with existing markup for the #searchbox form + * @param $searchResults container element for results und status message * @private */ initialize: function($searchBox, $searchResults) { @@ -117,8 +118,10 @@ lastPage = page; lastSize = size; + //show spinner $searchResults.removeClass('hidden'); $status.html(t('core', 'Searching other places')+'search in progress'); + // do the actual search query $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) { lastResults = results; @@ -260,6 +263,14 @@ event.preventDefault(); }); + $searchBox.on('search', function (event) { + if($searchBox.val() === '') { + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); + } + self.hideResults(); + } + }); $searchBox.keyup(function(event) { if (event.keyCode === 13) { //enter if(currentResult > -1) { -- cgit v1.2.3 From 818e7388c435bb64530ef642345304c369805fd1 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 16:12:37 +0100 Subject: use correct spinner --- search/js/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/js/search.js b/search/js/search.js index 10949cec0b0..b17b175d70d 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -120,7 +120,7 @@ //show spinner $searchResults.removeClass('hidden'); - $status.html(t('core', 'Searching other places')+'search in progress'); + $status.html(t('core', 'Searching other places')+'search in progress'); // do the actual search query $.getJSON(OC.generateUrl('search/ajax/search.php'), {query:query, inApps:inApps, page:page, size:size }, function(results) { -- cgit v1.2.3 From ba235eb51de074670b04f25993d6ed2051ffbebf Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 16:13:15 +0100 Subject: delay hiding no results message until search is triggered --- apps/files/js/search.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index dd8d3a6e502..2c3c42cf496 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -159,7 +159,10 @@ if (self.fileAppLoaded()) { OCA.Files.App.fileList.setFilter(query); if (query.length > 2) { - $('#nofilterresults').addClass('hidden'); + //search is not started until 500msec have passed + window.setTimeout(function() { + $('#nofilterresults').addClass('hidden'); + }, 500); } } }); -- cgit v1.2.3 From 73e17dc7e8f06d9855b9a1c99133fd7f1c6a1a67 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Fri, 2 Jan 2015 16:22:23 +0100 Subject: pluralize translation --- search/js/search.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/search/js/search.js b/search/js/search.js index b17b175d70d..078fe4f82ba 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -200,8 +200,12 @@ } }); var count = $searchResults.find('tr.result').length; - $status.data('count', count) - .text(t('search', '{count} search results in other places', {count:count}, count)); + $status.data('count', count); + if (count === 0) { + $status.text(t('core', 'No search result in other places')); + } else { + $status.text(n('core', '{count} search result in other places', '{count} search results in other places', count, {count:count})); + } } function renderCurrent() { var result = $searchResults.find('tr.result')[currentResult]; -- cgit v1.2.3 From 23900a5a39c45cff90e0056d3d58736ea11553c4 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 5 Jan 2015 13:11:50 +0100 Subject: filter trashbin and share views --- apps/files/js/filelist.js | 12 ++++++++++++ apps/files/js/search.js | 19 ++++++++++++------- apps/files/templates/simplelist.php | 6 ++++++ apps/files_sharing/templates/list.php | 6 ++++++ apps/files_trashbin/templates/index.php | 6 ++++++ search/js/search.js | 2 +- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 84b537fbdfe..768fc77df24 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -214,6 +214,8 @@ this.$el.on('show', this._onResize); + this.updateSearch(); + this.$fileList.on('click','td.filename>a.name', _.bind(this._onClickFile, this)); this.$fileList.on('change', 'td.filename>.selectCheckBox', _.bind(this._onClickFileCheckbox, this)); this.$el.on('urlChanged', _.bind(this._onUrlChanged, this)); @@ -274,6 +276,8 @@ containerWidth -= $('#app-navigation-toggle').width(); this.breadcrumb.setMaxWidth(containerWidth - actionsWidth - 10); + + this.updateSearch(); }, /** @@ -1702,6 +1706,14 @@ getFilter:function(filter) { return this._filter; }, + /** + * update the search object to use this filelist when filtering + */ + updateSearch:function() { + if (OCA.Search.files) { + OCA.Search.files.setFileList(this); + } + }, /** * Update UI based on the current selection */ diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 2c3c42cf496..5fb10ef34cd 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -21,6 +21,8 @@ */ Files.prototype = { + fileList: null, + /** * Initialize the file search */ @@ -32,7 +34,7 @@ return !!OCA.Files && !!OCA.Files.App; }; function inFileList($row, result) { - return self.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name); + return self.fileAppLoaded() && self.fileList.inList(result.name); } function updateLegacyMimetype(result) { // backward compatibility: @@ -79,7 +81,7 @@ $row.find('td.result a').attr('href', result.link); if (self.fileAppLoaded()) { - OCA.Files.App.fileList.lazyLoadPreview({ + self.fileList.lazyLoadPreview({ path: result.path, mime: result.mime, callback: function (url) { @@ -127,7 +129,7 @@ this.handleFolderClick = function($row, result, event) { // open folder if (self.fileAppLoaded()) { - OCA.Files.App.fileList.changeDirectory(result.path); + self.fileList.changeDirectory(result.path); return false; } else { return true; @@ -136,8 +138,8 @@ this.handleFileClick = function($row, result, event) { if (self.fileAppLoaded()) { - OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path)); - OCA.Files.App.fileList.scrollTo(result.name); + self.fileList.changeDirectory(OC.dirname(result.path)); + self.fileList.scrollTo(result.name); return false; } else { return true; @@ -150,6 +152,9 @@ result.mime = result.mime_type; } }; + this.setFileList = function (fileList) { + this.fileList = fileList; + }; OC.Plugins.register('OCA.Search', this); }, @@ -157,7 +162,7 @@ var self = this; search.setFilter('files', function (query) { if (self.fileAppLoaded()) { - OCA.Files.App.fileList.setFilter(query); + self.fileList.setFilter(query); if (query.length > 2) { //search is not started until 500msec have passed window.setTimeout(function() { @@ -176,6 +181,6 @@ search.setHandler(['file', 'audio', 'image'], this.handleFileClick.bind(this)); } }; - new Files(); OCA.Search.Files = Files; + OCA.Search.files = new Files(); })(); diff --git a/apps/files/templates/simplelist.php b/apps/files/templates/simplelist.php index d806a220ac0..15bbfbb2921 100644 --- a/apps/files/templates/simplelist.php +++ b/apps/files/templates/simplelist.php @@ -11,6 +11,12 @@ + + diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php index a1d95ebc1f1..f9a6257dff2 100644 --- a/apps/files_sharing/templates/list.php +++ b/apps/files_sharing/templates/list.php @@ -8,6 +8,12 @@ + +
diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index fe1311340c7..b89ec66b15a 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -12,6 +12,12 @@ + +
diff --git a/search/js/search.js b/search/js/search.js index 078fe4f82ba..d8922cf167b 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -165,7 +165,7 @@ function showResults(results) { lastResults = results; $searchResults.find('tr.result').remove(); - $searchResults.show(); + $searchResults.removeClass('hidden'); addResults(results); } function addResults(results) { -- cgit v1.2.3 From ba931d2124a915233d99edabdac730f3a9abdd54 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 5 Jan 2015 13:53:56 +0100 Subject: search with endless scrolling --- search/css/results.css | 2 -- search/js/search.js | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/search/css/results.css b/search/css/results.css index f2e6e475483..04f7b6dcb99 100644 --- a/search/css/results.css +++ b/search/css/results.css @@ -5,10 +5,8 @@ #searchresults { background-color:#fff; overflow-x:hidden; - overflow-y: auto; text-overflow:ellipsis; padding-top: 65px; - height: 100%; box-sizing: border-box; z-index:75; } diff --git a/search/js/search.js b/search/js/search.js index d8922cf167b..d1e25913e37 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -81,6 +81,7 @@ var currentResult = -1; var lastQuery = ''; + var lastInApps = []; var lastPage = 0; var lastSize = 30; var lastResults = {}; @@ -115,6 +116,7 @@ return; } lastQuery = query; + lastInApps = inApps; lastPage = page; lastSize = size; @@ -234,9 +236,11 @@ */ function onScroll(e) { if ($searchResults) { - //if ( $searchResults && $searchResults.scrollTop() + $searchResults.height() > $searchResults.find('table').height() - 300 ) { - // self.search(lastQuery, lastPage + 1); - //} + var resultsBottom = $searchResults.offset().top + $searchResults.height(); + var containerBottom = $searchResults.offsetParent().offset().top + $searchResults.offsetParent().height(); + if ( resultsBottom < containerBottom * 1.2 ) { + self.search(lastQuery, lastInApps, lastPage + 1); + } placeStatus(); } } -- cgit v1.2.3 From 10038640aeab6b156c15cac9fe8da438dad31d7b Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 5 Jan 2015 14:28:09 +0100 Subject: fix onScroll breaking search, fix keyboard navigation, fix filter for files in other dirs --- apps/files/js/search.js | 7 ++++++- search/js/search.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 5fb10ef34cd..496c210232a 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -34,7 +34,12 @@ return !!OCA.Files && !!OCA.Files.App; }; function inFileList($row, result) { - return self.fileAppLoaded() && self.fileList.inList(result.name); + if (! self.fileAppLoaded()) { + return false; + } + var dir = self.fileList.getCurrentDirectory().replace(/\/+$/,''); + var resultDir = OC.dirname(result.path); + return dir === resultDir && self.fileList.inList(result.name); } function updateLegacyMimetype(result) { // backward compatibility: diff --git a/search/js/search.js b/search/js/search.js index d1e25913e37..58778900a69 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -213,7 +213,7 @@ var result = $searchResults.find('tr.result')[currentResult]; if (result) { var $result = $(result); - var currentOffset = $searchResults.scrollTop(); + var currentOffset = $('#app-content').scrollTop(); $('#app-content').animate({ // Scrolling to the top of the new result scrollTop: currentOffset + $result.offset().top - $result.height() * 2 @@ -235,7 +235,7 @@ * This appends/renders the next page of entries when reaching the bottom. */ function onScroll(e) { - if ($searchResults) { + if ($searchResults && lastQuery !== false) { var resultsBottom = $searchResults.offset().top + $searchResults.height(); var containerBottom = $searchResults.offsetParent().offset().top + $searchResults.offsetParent().height(); if ( resultsBottom < containerBottom * 1.2 ) { -- cgit v1.2.3 From 7a812801db6cc2cddf4e176dc893b07c7c486d76 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Mon, 5 Jan 2015 17:53:14 +0100 Subject: correctly clear searchbox when switching filelists --- apps/files/js/filelist.js | 3 +++ search/js/search.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 768fc77df24..3e61e50f75d 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1713,6 +1713,9 @@ if (OCA.Search.files) { OCA.Search.files.setFileList(this); } + if (OC.Search) { + OC.Search.clear(); + } }, /** * Update UI based on the current selection diff --git a/search/js/search.js b/search/js/search.js index 58778900a69..c595ae25092 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -229,6 +229,14 @@ $searchResults.find('tr.result').remove(); lastQuery = false; }; + this.clear = function() { + self.hideResults(); + if(self.hasFilter(getCurrentApp())) { + self.getFilter(getCurrentApp())(''); + } + $searchBox.val(''); + $searchBox.blur(); + }; /** * Event handler for when scrolling the list container. -- cgit v1.2.3 From 926737fdb780d7c32a6ecf95445a4d17ddc222f2 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 6 Jan 2015 13:55:51 +0100 Subject: clear search when navigating via breadcrumbs --- apps/files/js/filelist.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 3e61e50f75d..2ab9f2d43b5 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -468,6 +468,7 @@ e.preventDefault(); this.changeDirectory($targetDir); } + this.updateSearch(); }, /** -- cgit v1.2.3 From 357fbd88bead4aecb5a4f24d5d1087cf96da730f Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Tue, 6 Jan 2015 14:34:35 +0100 Subject: use class for no results div instead of id. the elements are not unique. --- apps/files/css/files.css | 8 ++++---- apps/files/js/filelist.js | 4 ++-- apps/files/js/search.js | 4 ++-- apps/files/templates/list.php | 2 +- apps/files/templates/simplelist.php | 2 +- apps/files_sharing/templates/list.php | 2 +- apps/files_trashbin/templates/index.php | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/files/css/files.css b/apps/files/css/files.css index a6a28b594ae..1e7b1d45f71 100644 --- a/apps/files/css/files.css +++ b/apps/files/css/files.css @@ -600,7 +600,7 @@ table.dragshadow td.size { opacity: 0; } -#nofilterresults { +.nofilterresults { font-size: 16px; color: #888; position: absolute; @@ -608,12 +608,12 @@ table.dragshadow td.size { top: 30%; width: 100%; } -#nofilterresults h2 { +.nofilterresults h2 { font-size: 22px; margin-bottom: 10px; } -#nofilterresults [class^="icon-"], -#nofilterresults [class*=" icon-"] { +.nofilterresults [class^="icon-"], +.nofilterresults [class*=" icon-"] { background-size: 64px; height: 64px; width: 64px; diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 2ab9f2d43b5..e680ef4b3ed 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1691,13 +1691,13 @@ this.$el.find('#filestable thead th').addClass('hidden'); this.$el.find('#emptycontent').addClass('hidden'); if ( $('#searchresults').length === 0 || $('#searchresults').hasClass('hidden')) { - this.$el.find('#nofilterresults').removeClass('hidden'). + this.$el.find('.nofilterresults').removeClass('hidden'). find('p').text(t('files', "No entries in this folder match '{filter}'", {filter:this._filter})); } } else { this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty); this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty); - this.$el.find('#nofilterresults').addClass('hidden'); + this.$el.find('.nofilterresults').addClass('hidden'); } }, /** diff --git a/apps/files/js/search.js b/apps/files/js/search.js index 496c210232a..394bcb48603 100644 --- a/apps/files/js/search.js +++ b/apps/files/js/search.js @@ -48,7 +48,7 @@ } } function hideNoFilterResults() { - var $nofilterresults = $('#nofilterresults'); + var $nofilterresults = $('.nofilterresults'); if ( ! $nofilterresults.hasClass('hidden') ) { $nofilterresults.addClass('hidden'); } @@ -171,7 +171,7 @@ if (query.length > 2) { //search is not started until 500msec have passed window.setTimeout(function() { - $('#nofilterresults').addClass('hidden'); + $('.nofilterresults').addClass('hidden'); }, 500); } } diff --git a/apps/files/templates/list.php b/apps/files/templates/list.php index 55754fd0c6b..aa879002baa 100644 --- a/apps/files/templates/list.php +++ b/apps/files/templates/list.php @@ -60,7 +60,7 @@

t('Upload some content or sync with your devices!')); ?>

-