diff options
Diffstat (limited to 'ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/custom/visualsearch/models/search_facets.js')
-rw-r--r-- | ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/custom/visualsearch/models/search_facets.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/custom/visualsearch/models/search_facets.js b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/custom/visualsearch/models/search_facets.js new file mode 100644 index 0000000000..394cecdf4d --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-portal/src/main/webapp/libs/other/custom/visualsearch/models/search_facets.js @@ -0,0 +1,67 @@ +(function() { + +var $ = jQuery; // Handle namespaced jQuery + +// The model that holds individual search facets and their categories. +// Held in a collection by `VS.app.searchQuery`. +VS.model.SearchFacet = Backbone.Model.extend({ + + // Extract the category and value and serialize it in preparation for + // turning the entire searchBox into a search query that can be sent + // to the server for parsing and searching. + serialize : function() { + var category = this.quoteCategory(this.get('category')); + var value = VS.utils.inflector.trim(this.get('value')); + var remainder = this.get("app").options.remainder; + + if (!value) return ''; + + if (!_.contains(this.get("app").options.unquotable || [], category) && category != remainder) { + value = this.quoteValue(value); + } + + if (category != remainder) { + category = category + ': '; + } else { + category = ""; + } + return category + value; + }, + + // Wrap categories that have spaces or any kind of quote with opposite matching + // quotes to preserve the complex category during serialization. + quoteCategory : function(category) { + var hasDoubleQuote = (/"/).test(category); + var hasSingleQuote = (/'/).test(category); + var hasSpace = (/\s/).test(category); + + if (hasDoubleQuote && !hasSingleQuote) { + return "'" + category + "'"; + } else if (hasSpace || (hasSingleQuote && !hasDoubleQuote)) { + return '"' + category + '"'; + } else { + return category; + } + }, + + // Wrap values that have quotes in opposite matching quotes. If a value has + // both single and double quotes, just use the double quotes. + quoteValue : function(value) { + var hasDoubleQuote = (/"/).test(value); + var hasSingleQuote = (/'/).test(value); + + if (hasDoubleQuote && !hasSingleQuote) { + return "'" + value + "'"; + } else { + return '"' + value + '"'; + } + }, + + // If provided, use a custom label instead of the raw value. + label : function() { + return this.get('label') || this.get('value'); + } + +}); + +})();
\ No newline at end of file |