|
|
@@ -1073,24 +1073,6 @@ from desktop.views import _ko
|
|
|
})();
|
|
|
</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>
|
|
|
@@ -1110,124 +1092,4 @@ from desktop.views import _ko
|
|
|
<div>${ _('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 (!facetMatch && typeof data.results !== 'undefined' && data.results.length > 0) {
|
|
|
- if (values.length > 0) {
|
|
|
- values.push({ divider: true });
|
|
|
- }
|
|
|
- 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.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>
|