UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

257 lines (256 loc) 10.8 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; import moment from 'moment'; import uuid from 'uuid'; import { observable, action, computed } from 'mobx'; import { Time } from '@qn-pandora/pandora-component'; import { ESearchFormat } from '@qn-pandora/app-sdk'; import bind from '../../utils/bind'; import Store from '../../stores/store'; import { defaultTimeRange, TimeShiftUnit, TimeShiftUnitOptions } from './constants'; import { transformToTime } from './transform'; var SearchConditionService = /** @class */ (function (_super) { __extends(SearchConditionService, _super); function SearchConditionService() { var _this = _super !== null && _super.apply(this, arguments) || this; // 排序字段,目前仅支持_time _this.sorts = []; // 多spl搜索时的spl数组 _this.queries = []; /** * setOriginQueryString时是否需要触发 datasetReaction */ _this.shouldDatasetReaction = true; /** * setOriginQueryString的唯一ID,用来触发dataSetReaction */ _this.uniqOriginQueryStringSetId = uuid(); _this._originQueryString = ''; _this.time = defaultTimeRange; return _this; } Object.defineProperty(SearchConditionService.prototype, "originQueryString", { get: function () { return this._originQueryString; }, enumerable: false, configurable: true }); SearchConditionService.prototype.setQueries = function (v) { this.queries = v; }; SearchConditionService.prototype.setOriginQueryString = function (queryString, shouldDatasetReaction) { if (shouldDatasetReaction === void 0) { shouldDatasetReaction = true; } this.shouldDatasetReaction = shouldDatasetReaction; this._originQueryString = queryString; this.uniqOriginQueryStringSetId = uuid(); }; SearchConditionService.prototype.setTime = function (time) { this.time = time; }; SearchConditionService.prototype.setSorts = function (v) { this.sorts = v; }; Object.defineProperty(SearchConditionService.prototype, "timeShift", { get: function () { return this.time.timeShift || '0seconds'; }, enumerable: false, configurable: true }); Object.defineProperty(SearchConditionService.prototype, "timeShiftValue", { get: function () { return parseFloat(this.timeShift) || 0; }, enumerable: false, configurable: true }); Object.defineProperty(SearchConditionService.prototype, "timeShiftUnit", { get: function () { var e_1, _a; try { for (var TimeShiftUnitOptions_1 = __values(TimeShiftUnitOptions), TimeShiftUnitOptions_1_1 = TimeShiftUnitOptions_1.next(); !TimeShiftUnitOptions_1_1.done; TimeShiftUnitOptions_1_1 = TimeShiftUnitOptions_1.next()) { var item = TimeShiftUnitOptions_1_1.value; if (this.timeShift.endsWith(item.value)) { return item.value; } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (TimeShiftUnitOptions_1_1 && !TimeShiftUnitOptions_1_1.done && (_a = TimeShiftUnitOptions_1.return)) _a.call(TimeShiftUnitOptions_1); } finally { if (e_1) throw e_1.error; } } return TimeShiftUnit.Second; }, enumerable: false, configurable: true }); Object.defineProperty(SearchConditionService.prototype, "isGlobalTime", { get: function () { return Boolean(this.time.global); }, enumerable: false, configurable: true }); SearchConditionService.prototype.getRelativeTime = function (time) { if (time) { return moment(time).subtract(this.timeShiftValue, this.timeShiftUnit); } }; SearchConditionService.prototype.calcTime = function () { var _a = new Time(transformToTime(this.time)).toDate(), start = _a.start, end = _a.end; var relativeStart = this.getRelativeTime(start && start.valueOf()); var relativeEnd = this.getRelativeTime(end && end.valueOf()); return { start: relativeStart && relativeStart.valueOf(), end: relativeEnd && relativeEnd.valueOf() }; }; SearchConditionService.prototype.setFormat = function (format) { this.format = format; }; // search 整体变更的时候,time 跟 queryString 作为一个整体变更,否则使用reaction 单独监听queryString 和time ,会认为是两次变更。导致两次查询。 SearchConditionService.prototype.setTimeAndOriginqueryString = function (time, queryString, shouldDatasetReaction) { if (shouldDatasetReaction === void 0) { shouldDatasetReaction = true; } this.setOriginQueryString(queryString, shouldDatasetReaction); this.setTime(time); }; __decorate([ observable.ref, __metadata("design:type", Object) ], SearchConditionService.prototype, "sorts", void 0); __decorate([ observable.ref, __metadata("design:type", Array) ], SearchConditionService.prototype, "queries", void 0); __decorate([ observable, __metadata("design:type", String) ], SearchConditionService.prototype, "uniqOriginQueryStringSetId", void 0); __decorate([ observable, __metadata("design:type", Object) ], SearchConditionService.prototype, "_originQueryString", void 0); __decorate([ observable, __metadata("design:type", String) ], SearchConditionService.prototype, "format", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], SearchConditionService.prototype, "originQueryString", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setQueries", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String, Boolean]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setOriginQueryString", null); __decorate([ observable.ref, __metadata("design:type", Object) ], SearchConditionService.prototype, "time", void 0); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setTime", null); __decorate([ action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setSorts", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], SearchConditionService.prototype, "timeShift", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], SearchConditionService.prototype, "timeShiftValue", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], SearchConditionService.prototype, "timeShiftUnit", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], SearchConditionService.prototype, "isGlobalTime", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "getRelativeTime", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "calcTime", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setFormat", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String, Boolean]), __metadata("design:returntype", void 0) ], SearchConditionService.prototype, "setTimeAndOriginqueryString", null); return SearchConditionService; }(Store)); export default SearchConditionService;