當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript rangeutil.describeTextRange函數代碼示例

本文整理匯總了TypeScript中app/core/utils/rangeutil.describeTextRange函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript describeTextRange函數的具體用法?TypeScript describeTextRange怎麽用?TypeScript describeTextRange使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了describeTextRange函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: applyPanelTimeOverrides

export function applyPanelTimeOverrides(panel: PanelModel, timeRange: TimeRange): TimeOverrideResult {
  const newTimeData = {
    timeInfo: '',
    timeRange: timeRange,
  };

  if (panel.timeFrom) {
    const timeFromInterpolated = templateSrv.replace(panel.timeFrom, panel.scopedVars);
    const timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated);
    if (timeFromInfo.invalid) {
      newTimeData.timeInfo = 'invalid time override';
      return newTimeData;
    }

    if (_isString(timeRange.raw.from)) {
      const timeFromDate = dateMath.parse(timeFromInfo.from);
      newTimeData.timeInfo = timeFromInfo.display;
      newTimeData.timeRange = {
        from: timeFromDate,
        to: dateMath.parse(timeFromInfo.to),
        raw: {
          from: timeFromInfo.from,
          to: timeFromInfo.to,
        },
      };
    }
  }

  if (panel.timeShift) {
    const timeShiftInterpolated = templateSrv.replace(panel.timeShift, panel.scopedVars);
    const timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated);
    if (timeShiftInfo.invalid) {
      newTimeData.timeInfo = 'invalid timeshift';
      return newTimeData;
    }

    const timeShift = '-' + timeShiftInterpolated;
    newTimeData.timeInfo += ' timeshift ' + timeShift;
    const from = dateMath.parseDateMath(timeShift, newTimeData.timeRange.from, false);
    const to = dateMath.parseDateMath(timeShift, newTimeData.timeRange.to, true);

    newTimeData.timeRange = {
      from,
      to,
      raw: {
        from,
        to,
      },
    };
  }

  if (panel.hideTimeOverride) {
    newTimeData.timeInfo = '';
  }

  return newTimeData;
}
開發者ID:gnydick,項目名稱:grafana,代碼行數:57,代碼來源:panel.ts

示例2:

 ctrl.$validators.integer = (modelValue, viewValue) => {
   if (ctrl.$isEmpty(modelValue)) {
     return true;
   }
   if (viewValue.indexOf('$') === 0 || viewValue.indexOf('+$') === 0) {
     return true; // allow template variable
   }
   const info = rangeUtil.describeTextRange(viewValue);
   return info.invalid !== true;
 };
開發者ID:ArcticSnowman,項目名稱:grafana,代碼行數:10,代碼來源:ng_model_on_blur.ts

示例3: applyPanelTimeOverrides

  applyPanelTimeOverrides() {
    this.timeInfo = '';

    // check panel time overrrides
    if (this.panel.timeFrom) {
      var timeFromInterpolated = this.templateSrv.replace(this.panel.timeFrom, this.panel.scopedVars);
      var timeFromInfo = rangeUtil.describeTextRange(timeFromInterpolated);
      if (timeFromInfo.invalid) {
        this.timeInfo = 'invalid time override';
        return;
      }

      if (_.isString(this.rangeRaw.from)) {
        var timeFromDate = dateMath.parse(timeFromInfo.from);
        this.timeInfo = timeFromInfo.display;
        this.rangeRaw.from = timeFromInfo.from;
        this.rangeRaw.to = timeFromInfo.to;
        this.range.from = timeFromDate;
        this.range.to = dateMath.parse(timeFromInfo.to);
      }
    }

    if (this.panel.timeShift) {
      var timeShiftInterpolated = this.templateSrv.replace(this.panel.timeShift, this.panel.scopedVars);
      var timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated);
      if (timeShiftInfo.invalid) {
        this.timeInfo = 'invalid timeshift';
        return;
      }

      var timeShift = '-' + timeShiftInterpolated;
      this.timeInfo += ' timeshift ' + timeShift;
      this.range.from = dateMath.parseDateMath(timeShift, this.range.from, false);
      this.range.to = dateMath.parseDateMath(timeShift, this.range.to, true);

      this.rangeRaw = this.range;
    }

    if (this.panel.hideTimeOverride) {
      this.timeInfo = '';
    }
  };
開發者ID:1tylermitchell,項目名稱:grafana,代碼行數:42,代碼來源:metrics_panel_ctrl.ts

示例4: it

 it('should handle now/w', () => {
   var info = rangeUtil.describeTextRange('now/w');
   expect(info.display).to.be('This week so far');
 });
開發者ID:Sensetif,項目名稱:grafana,代碼行數:4,代碼來源:rangeutil_specs.ts

示例5: it

 it('should handle now/y', () => {
   var info = rangeUtil.describeTextRange('now/y');
   expect(info.display).toBe('This year so far');
 });
開發者ID:connection-reset,項目名稱:grafana,代碼行數:4,代碼來源:rangeutil.jest.ts

示例6: it

 it('should handle now/M', () => {
   const info = rangeUtil.describeTextRange('now/M');
   expect(info.display).toBe('This month so far');
 });
開發者ID:ArcticSnowman,項目名稱:grafana,代碼行數:4,代碼來源:rangeutil.test.ts


注:本文中的app/core/utils/rangeutil.describeTextRange函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。