|
@@ -592,23 +592,6 @@ from desktop.views import _ko
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
<script type="text/javascript">
|
|
|
(function () {
|
|
(function () {
|
|
|
- var SEARCH_FACET_ICON = 'fa-tags';
|
|
|
|
|
- var SEARCH_TYPE_ICONS = {
|
|
|
|
|
- 'DATABASE': 'fa-database',
|
|
|
|
|
- 'TABLE': 'fa-table',
|
|
|
|
|
- 'VIEW': 'fa-eye',
|
|
|
|
|
- 'FIELD': 'fa-columns',
|
|
|
|
|
- 'PARTITION': 'fa-th',
|
|
|
|
|
- 'SOURCE': 'fa-server',
|
|
|
|
|
- 'OPERATION': 'fa-cogs',
|
|
|
|
|
- 'OPERATION_EXECUTION': 'fa-cog',
|
|
|
|
|
- 'DIRECTORY': 'fa-folder-o',
|
|
|
|
|
- 'FILE': 'fa-file-o',
|
|
|
|
|
- 'SUB_OPERATION': 'fa-code-fork',
|
|
|
|
|
- 'COLLECTION': 'fa-search',
|
|
|
|
|
- 'HBASE': 'fa-th-large',
|
|
|
|
|
- 'HUE': 'fa-file-o'
|
|
|
|
|
- };
|
|
|
|
|
|
|
|
|
|
var FACETS = [
|
|
var FACETS = [
|
|
|
'type', 'tags'
|
|
'type', 'tags'
|
|
@@ -898,4 +881,164 @@ from desktop.views import _ko
|
|
|
});
|
|
});
|
|
|
})();
|
|
})();
|
|
|
</script>
|
|
</script>
|
|
|
|
|
+
|
|
|
|
|
+ <script type="text/html" id="hue-global-search-old-template">
|
|
|
|
|
+ <input placeholder="${ _('Search data and saved documents...') }" type="text"
|
|
|
|
|
+ data-bind="autocomplete: {
|
|
|
|
|
+ source: searchAutocompleteSource,
|
|
|
|
|
+ itemTemplate: 'top-search-autocomp-item',
|
|
|
|
|
+ noMatchTemplate: 'top-search-autocomp-no-match',
|
|
|
|
|
+ classPrefix: 'nav-',
|
|
|
|
|
+ showOnFocus: true,
|
|
|
|
|
+ closeOnEnter: false,
|
|
|
|
|
+ onSelect: mainSearchSelect,
|
|
|
|
|
+ reopenPattern: /.*:$/
|
|
|
|
|
+ },
|
|
|
|
|
+ hasFocus: searchHasFocus,
|
|
|
|
|
+ clearable: { value: searchInput, onClear: function () { searchActive(false); huePubSub.publish('autocomplete.close'); } },
|
|
|
|
|
+ textInput: searchInput,
|
|
|
|
|
+ valueUpdate: 'afterkeydown'">
|
|
|
|
|
+ </script>
|
|
|
|
|
+
|
|
|
|
|
+ <script type="text/html" id="top-search-autocomp-item">
|
|
|
|
|
+ <a href="javascript:void(0);">
|
|
|
|
|
+ <div class="nav-autocomplete-item-link">
|
|
|
|
|
+ <div class="nav-search-result-icon"><i class="fa fa-fw" data-bind="css: icon"></i></div>
|
|
|
|
|
+ <div class="nav-search-result-text">
|
|
|
|
|
+ <div class="nav-search-result-header" data-bind="html: label, style: { 'padding-top': description ? 0 : '9px' }"></div>
|
|
|
|
|
+ <!-- ko if: description -->
|
|
|
|
|
+ <div class="nav-search-result-description" data-bind="html: description"></div>
|
|
|
|
|
+ <!-- /ko -->
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </a>
|
|
|
|
|
+ </script>
|
|
|
|
|
+
|
|
|
|
|
+ <script type="text/html" id="top-search-autocomp-no-match">
|
|
|
|
|
+ <div class="nav-autocomplete-item-link" style="height: 30px;">
|
|
|
|
|
+ <div class="nav-autocomplete-empty">${ _('No match found') }</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </script>
|
|
|
|
|
+
|
|
|
|
|
+ <script type="text/javascript">
|
|
|
|
|
+ (function () {
|
|
|
|
|
+
|
|
|
|
|
+ var SEARCH_FACET_ICON = 'fa-tags';
|
|
|
|
|
+ var SEARCH_TYPE_ICONS = {
|
|
|
|
|
+ 'DATABASE': 'fa-database',
|
|
|
|
|
+ 'TABLE': 'fa-table',
|
|
|
|
|
+ 'VIEW': 'fa-eye',
|
|
|
|
|
+ 'FIELD': 'fa-columns',
|
|
|
|
|
+ 'PARTITION': 'fa-th',
|
|
|
|
|
+ 'SOURCE': 'fa-server',
|
|
|
|
|
+ 'OPERATION': 'fa-cogs',
|
|
|
|
|
+ 'OPERATION_EXECUTION': 'fa-cog',
|
|
|
|
|
+ 'DIRECTORY': 'fa-folder-o',
|
|
|
|
|
+ 'FILE': 'fa-file-o',
|
|
|
|
|
+ 'SUB_OPERATION': 'fa-code-fork',
|
|
|
|
|
+ 'COLLECTION': 'fa-search',
|
|
|
|
|
+ 'HBASE': 'fa-th-large',
|
|
|
|
|
+ 'HUE': 'fa-file-o'
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ var GlobalSearchOld = function (params) {
|
|
|
|
|
+ var self = this;
|
|
|
|
|
+ self.apiHelper = ApiHelper.getInstance();
|
|
|
|
|
+ self.searchHasFocus = ko.observable(false);
|
|
|
|
|
+ self.searchInput = ko.observable();
|
|
|
|
|
+ self.searchActive = ko.observable(false);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ GlobalSearchOld.prototype.mainSearchSelect = function (entry) {
|
|
|
|
|
+ if (entry.data && entry.data.link) {
|
|
|
|
|
+ huePubSub.publish('open.link', entry.data.link);
|
|
|
|
|
+ } else if (!/:\s*$/.test(entry.value)) {
|
|
|
|
|
+ huePubSub.publish('assist.show.sql');
|
|
|
|
|
+ huePubSub.publish('assist.db.search', entry.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ GlobalSearchOld.prototype.searchAutocompleteSource = function (request, callback) {
|
|
|
|
|
+ var apiHelper = ApiHelper.getInstance();
|
|
|
|
|
+ // TODO: Extract complete contents to common module (shared with nav search autocomplete)
|
|
|
|
|
+ var facetMatch = request.term.match(/([a-z]+):\s*(\S+)?$/i);
|
|
|
|
|
+ var isFacet = facetMatch !== null;
|
|
|
|
|
+ var partialMatch = isFacet ? null : request.term.match(/\S+$/);
|
|
|
|
|
+ var partial = isFacet && facetMatch[2] ? facetMatch[2] : (partialMatch ? partialMatch[0] : '');
|
|
|
|
|
+ var beforePartial = request.term.substring(0, request.term.length - partial.length);
|
|
|
|
|
+
|
|
|
|
|
+ apiHelper.globalSearchAutocomplete({
|
|
|
|
|
+ query: request.term,
|
|
|
|
|
+ successCallback: function (data) {
|
|
|
|
|
+ var values = [];
|
|
|
|
|
+ var facetPartialRe = new RegExp(partial.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i'); // Protect for 'tags:*axe'
|
|
|
|
|
+
|
|
|
|
|
+ if (typeof data.resultsHuedocuments !== 'undefined') {
|
|
|
|
|
+ data.resultsHuedocuments.forEach(function (result) {
|
|
|
|
|
+ values.push({ data: { label: result.hue_name, icon: SEARCH_TYPE_ICONS[result.type], description: result.hue_description, link: result.link }, value: beforePartial + result.originalName });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (values.length > 0) {
|
|
|
|
|
+ values.push({ divider: true });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (isFacet && typeof data.facets !== 'undefined') { // Is typed facet, e.g. type: type:bla
|
|
|
|
|
+ var facetInQuery = facetMatch[1];
|
|
|
|
|
+ if (typeof data.facets[facetInQuery] !== 'undefined') {
|
|
|
|
|
+ $.map(data.facets[facetInQuery], function (count, value) {
|
|
|
|
|
+ if (facetPartialRe.test(value)) {
|
|
|
|
|
+ values.push({ data: { label: facetInQuery + ':' + value, icon: SEARCH_FACET_ICON, description: count }, value: beforePartial + value})
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (typeof data.facets !== 'undefined') {
|
|
|
|
|
+ Object.keys(data.facets).forEach(function (facet) {
|
|
|
|
|
+ if (facetPartialRe.test(facet)) {
|
|
|
|
|
+ if (Object.keys(data.facets[facet]).length > 0) {
|
|
|
|
|
+ values.push({ data: { label: facet + ':', icon: SEARCH_FACET_ICON, description: $.map(data.facets[facet], function (key, value) { return value + ' (' + key + ')'; }).join(', ') }, value: beforePartial + facet + ':'});
|
|
|
|
|
+ } else { // Potential facet from the list
|
|
|
|
|
+ values.push({ data: { label: facet + ':', icon: SEARCH_FACET_ICON, description: '' }, value: beforePartial + facet + ':'});
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (partial.length > 0) {
|
|
|
|
|
+ Object.keys(data.facets[facet]).forEach(function (facetValue) {
|
|
|
|
|
+ if (facetValue.indexOf(partial) !== -1) {
|
|
|
|
|
+ values.push({ data: { label: facet + ':' + facetValue, icon: SEARCH_FACET_ICON, description: facetValue }, value: beforePartial + facet + ':' + facetValue });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (values.length > 0) {
|
|
|
|
|
+ values.push({ divider: true });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof data.results !== 'undefined') {
|
|
|
|
|
+ data.results.forEach(function (result) {
|
|
|
|
|
+ values.push({ data: { label: result.hue_name, icon: SEARCH_TYPE_ICONS[result.type], description: result.hue_description }, value: beforePartial + result.originalName });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (values.length > 0 && values[values.length - 1].divider) {
|
|
|
|
|
+ values.pop();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (values.length === 0) {
|
|
|
|
|
+ values.push({ noMatch: true });
|
|
|
|
|
+ }
|
|
|
|
|
+ callback(values);
|
|
|
|
|
+ },
|
|
|
|
|
+ silenceErrors: true,
|
|
|
|
|
+ errorCallback: function () {
|
|
|
|
|
+ callback([]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ ko.components.register('hue-global-search-old', {
|
|
|
|
|
+ viewModel: GlobalSearchOld,
|
|
|
|
|
+ template: {element: 'hue-global-search-old-template'}
|
|
|
|
|
+ });
|
|
|
|
|
+ })();
|
|
|
|
|
+ </script>
|
|
|
</%def>
|
|
</%def>
|