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


TypeScript chrome.addBasePath函數代碼示例

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


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

示例1: requestFile

export async function requestFile(
  payload: FetchFilePayload,
  line?: string
): Promise<FetchFileResponse> {
  const { uri, revision, path } = payload;
  const url = `/api/code/repo/${uri}/blob/${encodeURIComponent(revision)}/${path}`;
  const query: any = {};
  if (line) {
    query.line = line;
  }
  const response: Response = await fetch(chrome.addBasePath(Url.format({ pathname: url, query })));

  if (response.status >= 200 && response.status < 300) {
    const contentType = response.headers.get('Content-Type');

    if (contentType && contentType.startsWith('text/')) {
      const lang = contentType.split(';')[0].substring('text/'.length);
      if (lang === 'big') {
        return {
          payload,
          content: '',
          isOversize: true,
        };
      }
      return {
        payload,
        lang,
        content: await response.text(),
        isUnsupported: false,
      };
    } else if (contentType && contentType.startsWith('image/')) {
      return {
        payload,
        isImage: true,
        content: '',
        url,
        isUnsupported: false,
      };
    } else {
      return {
        payload,
        isImage: false,
        content: '',
        url,
        isUnsupported: true,
      };
    }
  } else if (response.status === 404) {
    return {
      payload,
      isNotFound: true,
    };
  }
  throw new Error('invalid file type');
}
開發者ID:elastic,項目名稱:kibana,代碼行數:55,代碼來源:file.ts

示例2: get

  (uiCapabilities: UICapabilities, kbnBaseUrl: string, $route: any, kbnUrl: any) => {
    const route = get($route, 'current.$$route') as any;
    if (!route.requireUICapability) {
      return;
    }

    if (!get(uiCapabilities, route.requireUICapability)) {
      const url = chrome.addBasePath(`${kbnBaseUrl}#/home`);
      kbnUrl.redirect(url);
      throw uiRoutes.WAIT_FOR_URL_CHANGE_TOKEN;
    }
  }
開發者ID:elastic,項目名稱:kibana,代碼行數:12,代碼來源:route_setup.ts

示例3: moveToDiscover

export function moveToDiscover(indexPatternId: string, kbnBaseUrl: string) {
  const _g = rison.encode({});

  // Add the index pattern ID to the appState part of the URL.
  const _a = rison.encode({
    index: indexPatternId,
  });

  const baseUrl = chrome.addBasePath(kbnBaseUrl);
  const hash = `#/discover?_g=${_g}&_a=${_a}`;

  window.location.href = `${baseUrl}${hash}`;
}
開發者ID:elastic,項目名稱:kibana,代碼行數:13,代碼來源:navigation.ts

示例4: getKibanaHref

export function getKibanaHref({
  location,
  pathname = '',
  hash,
  query = {}
}: KibanaHrefArgs): string {
  const search = getSearchString(location, pathname, query);
  const href = url.format({
    pathname: chrome.addBasePath(pathname),
    hash: `${hash}?${search}`
  });
  return href;
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:13,代碼來源:url_helpers.ts

示例5: getKibanaHref

export function getKibanaHref({
  location,
  pathname = '',
  hash,
  query = {}
}: KibanaHrefArgs): string {
  const queryWithRisonParams = getQueryWithRisonParams(location, query);
  const search = stringifyWithoutEncoding(queryWithRisonParams);
  const href = url.format({
    pathname: chrome.addBasePath(pathname),
    hash: `${hash}?${search}`
  });
  return href;
}
開發者ID:liuyepiaoxiang,項目名稱:kibana,代碼行數:14,代碼來源:url_helpers.ts

示例6: trackUiMetric

export function trackUiMetric(appName: string, metricType: string | string[]) {
  if (!getCanTrackUiMetrics()) {
    return;
  }

  if (appName.includes(':')) {
    throw createErrorMessage(`app name '${appName}'`);
  }

  if (metricType.includes(':')) {
    throw createErrorMessage(`metric type ${metricType}`);
  }

  const metricTypes = Array.isArray(metricType) ? metricType.join(',') : metricType;
  const uri = chrome.addBasePath(`${API_BASE_PATH}/${appName}/${metricTypes}`);
  _http.post(uri);
}
開發者ID:elastic,項目名稱:kibana,代碼行數:17,代碼來源:index.ts

示例7: fetchText

  private async fetchText(resource: Uri) {
    const repo = `${resource.authority}${resource.path}`;
    const revision = resource.query;
    const file = resource.fragment;
    const response = await fetch(
      chrome.addBasePath(`/api/code/repo/${repo}/blob/${revision}/${file}`)
    );
    if (response.status === 200) {
      const contentType = response.headers.get('Content-Type');

      if (contentType && contentType.startsWith('text/')) {
        const lang = contentType.split(';')[0].substring('text/'.length);
        const text = await response.text();
        return { text, lang };
      }
    } else {
      return null;
    }
  }
開發者ID:elastic,項目名稱:kibana,代碼行數:19,代碼來源:textmodel_resolver.ts

示例8: getRisonHref

export function getRisonHref({
  location,
  pathname,
  hash,
  query = {}
}: RisonHrefArgs) {
  const currentQuery = toQuery(location.search);
  const nextQuery = {
    ...TIMEPICKER_DEFAULTS,
    ...pick(currentQuery, PERSISTENT_APM_PARAMS),
    ...query
  };

  // Create _g value for non-apm links
  const g = createG(nextQuery);
  const encodedG = rison.encode(g);
  const encodedA = query._a ? rison.encode(query._a) : ''; // TODO: Do we need to url-encode the _a values before rison encoding _a?
  const risonQuery: RisonEncoded = {
    _g: encodedG
  };

  if (encodedA) {
    risonQuery._a = encodedA;
  }

  // don't URI-encode the already-encoded rison
  const search = qs.stringify(risonQuery, undefined, undefined, {
    encodeURIComponent: (v: string) => v
  });

  const href = url.format({
    pathname: chrome.addBasePath(pathname),
    hash: `${hash}?${search}`
  });

  return href;
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:37,代碼來源:rison_helpers.ts

示例9: saveRole

/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License;
 * you may not use this file except in compliance with the Elastic License.
 */
import { omit } from 'lodash';
import chrome from 'ui/chrome';
import { Role } from '../../../common/model/role';

const apiBase = chrome.addBasePath(`/api/security/role`);

export async function saveRole($http: any, role: Role) {
  const data = omit(role, 'name', 'transient_metadata', '_unrecognized_applications');
  return await $http.put(`${apiBase}/${role.name}`, data);
}

export async function deleteRole($http: any, name: string) {
  return await $http.delete(`${apiBase}/${name}`);
}
開發者ID:gingerwizard,項目名稱:kibana,代碼行數:19,代碼來源:roles.ts

示例10: createUserActionUri

export function createUserActionUri(appName: string, actionType: string): string {
  return chrome.addBasePath(`/api/user_action/${appName}/${actionType}`);
}
開發者ID:njd5475,項目名稱:kibana,代碼行數:3,代碼來源:user_action.ts


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