UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

113 lines (87 loc) 3.88 kB
'use strict'; exports.__esModule = true; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Details for a single value for a particular facet. */ var SearchFacetBucket = function () { SearchFacetBucket.fromJson = function fromJson(json) { var children = void 0; if (json.children && json.children.buckets && Array.isArray(json.children.buckets)) { children = json.children.buckets.map(function (jsonChild) { return SearchFacetBucket.fromJson(jsonChild); }); } else { children = []; } var label = json.label; if (!label && json.range) { label = json.range.label; } return new SearchFacetBucket(json.value, label, json.count, json.filter, json.min, json.max, children, json.range); }; function SearchFacetBucket(value, label, count, filter) { var min = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var max = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; var children = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : []; var range = arguments[7]; _classCallCheck(this, SearchFacetBucket); this.value = value; this.label = label; this.count = count; this.filter = filter; this.min = min; this.max = max; this.children = children; this.range = range; } /** Get the label to display for this bucket */ SearchFacetBucket.prototype.displayLabel = function displayLabel() { var result = 'Unknown'; if (this.label) { result = this.label; } else if (this.value) { if (typeof this.value === 'string') { result = this.value; } else if (_typeof(this.value) === 'object') { // If it's a position, with either y and y coordinate or // longitude and latitude values, show it within parentheses if (Object.prototype.hasOwnProperty.call(this.value, 'x') && Object.prototype.hasOwnProperty.call(this.value, 'y')) { result = '(' + this.value.x + ', ' + this.value.y + ')'; } else if (Object.prototype.hasOwnProperty.call(this.value, 'longitude') && Object.prototype.hasOwnProperty.call(this.value, 'latitude')) { result = '(' + this.value.longitude + ', ' + this.value.latitude + ')'; } else { // Always convert to a string in any case... result = this.value.toString(); } } else { result = this.value; } } else if (this.min) { if (this.max) { result = this.min + ' - ' + this.max; } result = '' + this.min; } return result; }; /** Get a key to use for this bucket */ SearchFacetBucket.prototype.bucketKey = function bucketKey() { return this.displayLabel() + ':' + this.filter; }; /** The value of the bucket */ /** * If present (generally for filter facet requests or range facets), the label to display * as the facet bucket's value instead of the value field */ /** The number of occurrences of this value in the facet */ /** The filter that can be used to limit the original query to only show documents matching this value */ /** The minimum, or "from," value for the bucket's range (for range facets only) */ /** The maximum, or "to," value for the bucket's range (for range facets only) */ /** Any child buckets */ /** The range if this is a range facet */ return SearchFacetBucket; }(); exports.default = SearchFacetBucket; module.exports = exports['default'];