From 9694c4dec561948da3c8ea2094937534c68af679 Mon Sep 17 00:00:00 2001 From: Johan Ahlen Date: Mon, 27 Feb 2017 14:59:07 +0100 Subject: [PATCH] HUE-5952 [assist] Add error handling to assist search --- .../static/desktop/js/ko.hue-bindings.js | 8 ++++++- .../src/desktop/templates/assist_search.mako | 23 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js b/desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js index c878b7bd6ce..ded89d2ebe7 100644 --- a/desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js +++ b/desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js @@ -141,7 +141,13 @@ if (typeof $().hueAutocomplete === 'undefined') { $.widget('custom.hueAutocomplete', $.ui.autocomplete, { _renderItemData: function( ul, item ) { - if (item.noMatch && this.options.noMatchTemplate) { + if (item.error && this.options.errorTemplate) { + var $li = $('
  • ') + .addClass(this.options.classPrefix + 'autocomplete-item') + .appendTo(ul) + .data( "ui-autocomplete-item", item ); + ko.applyBindings(item.data, $li[0]); + } else if (item.noMatch && this.options.noMatchTemplate) { var $li = $('
  • ') .addClass(this.options.classPrefix + 'autocomplete-item') .appendTo(ul) diff --git a/desktop/core/src/desktop/templates/assist_search.mako b/desktop/core/src/desktop/templates/assist_search.mako index fd74835294f..27e9564bd5e 100644 --- a/desktop/core/src/desktop/templates/assist_search.mako +++ b/desktop/core/src/desktop/templates/assist_search.mako @@ -48,6 +48,12 @@ from notebook.conf import ENABLE_QUERY_BUILDER + + @@ -146,6 +158,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER self.searchInput = ko.observable('').extend({rateLimit: 500}); self.searchResult = ko.observableArray(); + self.hasErrors = ko.observable(false); self.searchHasFocus = ko.observable(false); self.searching = ko.observable(false); self.searchActive = ko.observable(false); @@ -182,6 +195,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER } lastQuery = self.searchInput(); self.searching(true); + self.hasErrors(false); var showInAssist = function (entry) { self.searchInput(''); @@ -240,7 +254,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER query_s: ko.mapping.toJSON(self.searchInput()), limit: 25, sources: ko.mapping.toJSON([self.assistPanel.visiblePanel().type]) - }, function (data) { + }).done(function (data) { data.entities.forEach(function (entity) { entity.statsVisible = ko.observable(false); entity.showNavContextPopoverDelayed = showNavContextPopoverDelayed; @@ -298,9 +312,10 @@ from notebook.conf import ENABLE_QUERY_BUILDER entity.hasDescription = typeof entity.originalDescription !== 'undefined' && entity.originalDescription !== null && entity.originalDescription.length > 0; }); self.searchResult(data.entities); - self.searching(false); }).fail(function (xhr, textStatus, errorThrown) { + self.hasErrors(true); $(document).trigger("error", xhr.responseText); + }).always(function () { self.searching(false); }); }; @@ -372,7 +387,7 @@ from notebook.conf import ENABLE_QUERY_BUILDER }, silenceErrors: true, errorCallback: function () { - callback([]); + callback([{ error: true }]); } }); };