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


TypeScript location_util.stripBaseFromUrl函數代碼示例

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


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

示例1: fetchDashboard

async function fetchDashboard(
  args: InitDashboardArgs,
  dispatch: ThunkDispatch,
  getState: () => StoreState
): Promise<DashboardDTO | null> {
  try {
    switch (args.routeInfo) {
      case DashboardRouteInfo.Home: {
        // load home dash
        const dashDTO: DashboardDTO = await getBackendSrv().get('/api/dashboards/home');

        // if user specified a custom home dashboard redirect to that
        if (dashDTO.redirectUri) {
          const newUrl = locationUtil.stripBaseFromUrl(dashDTO.redirectUri);
          dispatch(updateLocation({ path: newUrl, replace: true }));
          return null;
        }

        // disable some actions on the default home dashboard
        dashDTO.meta.canSave = false;
        dashDTO.meta.canShare = false;
        dashDTO.meta.canStar = false;
        return dashDTO;
      }
      case DashboardRouteInfo.Normal: {
        // for old db routes we redirect
        if (args.urlType === 'db') {
          redirectToNewUrl(args.urlSlug, dispatch, getState().location.path);
          return null;
        }

        const loaderSrv: DashboardLoaderSrv = args.$injector.get('dashboardLoaderSrv');
        const dashDTO: DashboardDTO = await loaderSrv.loadDashboard(args.urlType, args.urlSlug, args.urlUid);

        if (args.fixUrl && dashDTO.meta.url) {
          // check if the current url is correct (might be old slug)
          const dashboardUrl = locationUtil.stripBaseFromUrl(dashDTO.meta.url);
          const currentPath = getState().location.path;

          if (dashboardUrl !== currentPath) {
            // replace url to not create additional history items and then return so that initDashboard below isn't executed multiple times.
            dispatch(updateLocation({ path: dashboardUrl, partial: true, replace: true }));
            return null;
          }
        }
        return dashDTO;
      }
      case DashboardRouteInfo.New: {
        return getNewDashboardModelData(args.urlFolderId);
      }
      default:
        throw { message: 'Unknown route ' + args.routeInfo };
    }
  } catch (err) {
    dispatch(dashboardInitFailed({ message: 'Failed to fetch dashboard', error: err }));
    console.log(err);
    return null;
  }
}
開發者ID:CorpGlory,項目名稱:grafana,代碼行數:59,代碼來源:initDashboard.ts

示例2:

      loader.load(this, this.uid, 'manage-folder-dashboards').then(folder => {
        const url = locationUtil.stripBaseFromUrl(folder.url);

        if (url !== $location.path()) {
          $location.path(url).replace();
        }
      });
開發者ID:CorpGlory,項目名稱:grafana,代碼行數:7,代碼來源:FolderDashboardsCtrl.ts

示例3:

 backendSrv.get('/api/dashboards/home').then(homeDash => {
   if (homeDash.redirectUri) {
     const newUrl = locationUtil.stripBaseFromUrl(homeDash.redirectUri);
     $location.path(newUrl);
   } else {
     const meta = homeDash.meta;
     meta.canSave = meta.canShare = meta.canStar = false;
     $scope.initDashboard(homeDash, $scope);
   }
 });
開發者ID:ArcticSnowman,項目名稱:grafana,代碼行數:10,代碼來源:dashboard_loaders.ts

示例4:

    appEvents.on('location-change', (payload: any) => {
      const urlWithoutBase = locationUtil.stripBaseFromUrl(payload.href);
      if (this.fullPageReloadRoutes.indexOf(urlWithoutBase) > -1) {
        this.$window.location.href = payload.href;
        return;
      }

      this.$timeout(() => {
        // A hack to use timeout when we're changing things (in this case the url) from outside of Angular.
        this.$location.url(urlWithoutBase);
      });
    });
開發者ID:grafana,項目名稱:grafana,代碼行數:12,代碼來源:bridge_srv.ts

示例5:

    dashboardLoaderSrv.loadDashboard($routeParams.type, $routeParams.slug, $routeParams.uid).then(function(result) {
      if (result.meta.url) {
        const url = locationUtil.stripBaseFromUrl(result.meta.url);

        if (url !== $location.path()) {
          $location.path(url).replace();
        }
      }

      if ($routeParams.keepRows) {
        result.meta.keepRows = true;
      }
      $scope.initDashboard(result, $scope);
    });
開發者ID:Othyus,項目名稱:grafana,代碼行數:14,代碼來源:dashboard_loaders.ts

示例6: postSave

  postSave(clone, data) {
    this.dash.version = data.version;

    const newUrl = locationUtil.stripBaseFromUrl(data.url);
    const currentPath = this.$location.path();

    if (newUrl !== currentPath) {
      this.$location.url(newUrl).replace();
    }

    this.$rootScope.appEvent('dashboard-saved', this.dash);
    this.$rootScope.appEvent('alert-success', ['Dashboard saved']);

    return this.dash;
  }
開發者ID:InvariantIO,項目名稱:grafana,代碼行數:15,代碼來源:dashboard_srv.ts

示例7: redirectToNewUrl

async function redirectToNewUrl(slug: string, dispatch: ThunkDispatch, currentPath: string) {
  const res = await getBackendSrv().getDashboardBySlug(slug);

  if (res) {
    let newUrl = res.meta.url;

    // fix solo route urls
    if (currentPath.indexOf('dashboard-solo') !== -1) {
      newUrl = newUrl.replace('/d/', '/d-solo/');
    }

    const url = locationUtil.stripBaseFromUrl(newUrl);
    dispatch(updateLocation({ path: url, partial: true, replace: true }));
  }
}
開發者ID:CorpGlory,項目名稱:grafana,代碼行數:15,代碼來源:initDashboard.ts

示例8: postSave

  postSave(clone, data) {
    this.dash.version = data.version;

    // important that these happens before location redirect below
    this.$rootScope.appEvent('dashboard-saved', this.dash);
    this.$rootScope.appEvent('alert-success', ['Dashboard saved']);

    const newUrl = locationUtil.stripBaseFromUrl(data.url);
    const currentPath = this.$location.path();

    if (newUrl !== currentPath) {
      this.$location.url(newUrl).replace();
    }

    return this.dash;
  }
開發者ID:gnydick,項目名稱:grafana,代碼行數:16,代碼來源:DashboardSrv.ts


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