diff --git a/core/ajax/preview.php b/core/ajax/preview.php index 56ef5ea847..03dfb48306 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 57ce1ab695..9d62b7cac1 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 331fdaa383..13f1a62fbc 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 8bcf2348df..78b60e65e4 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 147377aff0..3d3cbd56ae 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 4a5cdd1b3e..451df7b143 100644 --- a/search/templates/part.results.php +++ b/search/templates/part.results.php @@ -1,13 +1,12 @@
+ - - +
- -
-
-
+
+ +