diff options
-rw-r--r-- | js/fulltextsearch.v1.api.js | 15 | ||||
-rw-r--r-- | js/fulltextsearch.v1.navigation.js | 10 | ||||
-rw-r--r-- | js/fulltextsearch.v1.result.js | 4 | ||||
-rw-r--r-- | js/fulltextsearch.v1.searchbox.js | 2 | ||||
-rw-r--r-- | js/fulltextsearch.v1.settings.js | 6 | ||||
-rw-r--r-- | js/navigate.js | 11 | ||||
-rw-r--r-- | lib/Service/SearchService.php | 7 |
7 files changed, 43 insertions, 12 deletions
diff --git a/js/fulltextsearch.v1.api.js b/js/fulltextsearch.v1.api.js index 778ae10..394bf4c 100644 --- a/js/fulltextsearch.v1.api.js +++ b/js/fulltextsearch.v1.api.js @@ -34,8 +34,8 @@ var api = { - search: function (request, callback) { - var res = {status: -1}; + search: function (request, callback, callbackError) { + var res = {status: -1, error: 'failed to connect to Nextcloud'}; nav.onSearchRequest(request); @@ -46,12 +46,19 @@ var api = { request: JSON.stringify(request) } }).done(function (res) { + if (_.has(res, 'error')) { + result.displayError(res); + nav.onError(res.error); + api.onCallback(callbackError, res); + return; + } result.displayResult(res); nav.onResultDisplayed(res); api.onCallback(callback, res); }).fail(function () { - nav.failedToAjax(); - api.onCallback(callback, res); + nav.failedToAjax(res); + nav.onError(res.error); + api.onCallback(callbackError, res); }); }, diff --git a/js/fulltextsearch.v1.navigation.js b/js/fulltextsearch.v1.navigation.js index 90544bf..d81c032 100644 --- a/js/fulltextsearch.v1.navigation.js +++ b/js/fulltextsearch.v1.navigation.js @@ -268,9 +268,15 @@ var nav = { } }, - onResultDisplayed: function () { + onResultDisplayed: function (data) { if (settings.parentHasMethod('onResultDisplayed')) { - settings.parent.onResultDisplayed(); + settings.parent.onResultDisplayed(data); + } + }, + + onError: function (data) { + if (settings.parentHasMethod('onError')) { + settings.parent.onError(data); } }, diff --git a/js/fulltextsearch.v1.result.js b/js/fulltextsearch.v1.result.js index b6bcd88..daa5f83 100644 --- a/js/fulltextsearch.v1.result.js +++ b/js/fulltextsearch.v1.result.js @@ -50,6 +50,10 @@ var result = { }, + displayError: function (res) { + }, + + displayNoResult: function () { settings.divNoResult.fadeTo(settings.delay_result, 1); settings.resultContainer.find('.provider_header').each(function () { diff --git a/js/fulltextsearch.v1.searchbox.js b/js/fulltextsearch.v1.searchbox.js index 215ea71..8f0a9e8 100644 --- a/js/fulltextsearch.v1.searchbox.js +++ b/js/fulltextsearch.v1.searchbox.js @@ -149,7 +149,7 @@ var searchbox = { force = false; } - if (search.length < 3) { + if (search.length < 1) { return; } diff --git a/js/fulltextsearch.v1.settings.js b/js/fulltextsearch.v1.settings.js index 32d260a..b103b4d 100644 --- a/js/fulltextsearch.v1.settings.js +++ b/js/fulltextsearch.v1.settings.js @@ -77,9 +77,13 @@ var settings = { * used to set the template to display search result entries * * @param template + * @param parent */ - setEntryTemplate: function (template) { + setEntryTemplate: function (template, parent) { settings.entryTemplate = template; + if (parent !== null) { + settings.parent = parent; + } }, /** diff --git a/js/navigate.js b/js/navigate.js index 428dd97..e16287a 100644 --- a/js/navigate.js +++ b/js/navigate.js @@ -27,7 +27,7 @@ /** global: OCA */ /** global: _ */ -const fullTextSearch = OCA.FullTextSearch.api; +var fullTextSearch = OCA.FullTextSearch.api; var elements = { @@ -38,7 +38,7 @@ var elements = { search_json: null }; -const Navigate = function () { +var Navigate = function () { this.init(); }; @@ -209,7 +209,7 @@ Navigate.prototype = { initSearch: function () { var search = elements.search_input.val(); - if (search.length < 3) { + if (search.length < 1) { return false; } @@ -261,6 +261,11 @@ Navigate.prototype = { }, + onError: function (message) { + console.log('!' + message); + }, + + onEntryGenerated: function (entry) { this.deleteEmptyDiv(entry, '#line1'); this.deleteEmptyDiv(entry, '#line2'); diff --git a/lib/Service/SearchService.php b/lib/Service/SearchService.php index 78b207b..663b7a7 100644 --- a/lib/Service/SearchService.php +++ b/lib/Service/SearchService.php @@ -28,6 +28,7 @@ namespace OCA\FullTextSearch\Service; use Exception; use OC\App\AppManager; +use OC\User\NoUserException; use OCA\Circles\Api\v1\Circles; use OCA\FullTextSearch\Exceptions\EmptySearchException; use OCA\FullTextSearch\Exceptions\ProviderDoesNotExistException; @@ -115,6 +116,10 @@ class SearchService { } $user = $this->userManager->get($userId); + if ($user === null) { + throw new NoUserException('User does not exist'); + } + $request->setAuthor($user->getUID()); $request->cleanSearch(); @@ -139,7 +144,7 @@ class SearchService { * @throws EmptySearchException */ private function searchRequestCannotBeEmpty(SearchRequest $request) { - if ($request === null || strlen($request->getSearch()) < 2) { + if ($request === null || strlen($request->getSearch()) < 1) { throw new EmptySearchException('search cannot be empty'); } } |