本文整理汇总了TypeScript中app/core/services/backend_srv.BackendSrv类的典型用法代码示例。如果您正苦于以下问题:TypeScript BackendSrv类的具体用法?TypeScript BackendSrv怎么用?TypeScript BackendSrv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BackendSrv类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
/** @ngInject */
constructor($scope: any, backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
this.navModel = navModelSrv.getNav('admin', 'server-settings');
backendSrv.get('/api/admin/settings').then((settings: any) => {
$scope.settings = settings;
});
}
示例2: describe
describe('backend_srv', () => {
const _httpBackend = options => {
if (options.url === 'gateway-error') {
return Promise.reject({ status: 502 });
}
return Promise.resolve({});
};
const _backendSrv = new BackendSrv(
_httpBackend,
{} as angular.IQService,
{} as angular.ITimeoutService,
{} as ContextSrv
);
describe('when handling errors', () => {
it('should return the http status code', async () => {
try {
await _backendSrv.datasourceRequest({
url: 'gateway-error',
});
} catch (err) {
expect(err.status).toBe(502);
}
});
});
});
示例3:
$scope.getUser = (id: number) => {
backendSrv.get('/api/users/' + id).then((user: User) => {
$scope.user = user;
$scope.user_id = id;
$scope.permissions.isGrafanaAdmin = user.isGrafanaAdmin;
});
};
示例4: getDefaultProject
async getDefaultProject() {
try {
if (this.authenticationType === 'gce' || !this.projectName) {
const { data } = await this.backendSrv.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
data: {
queries: [
{
refId: 'ensureDefaultProjectQuery',
type: 'ensureDefaultProjectQuery',
datasourceId: this.id,
},
],
},
});
this.projectName = data.results.ensureDefaultProjectQuery.meta.defaultProject;
return this.projectName;
} else {
return this.projectName;
}
} catch (error) {
throw this.formatStackdriverError(error);
}
}
示例5: deleteNotification
deleteNotification(id: number) {
this.backendSrv.delete(`/api/alert-notifications/${id}`).then(() => {
this.notifications = this.notifications.filter((notification: any) => {
return notification.id !== id;
});
});
}
示例6:
$scope.update = () => {
if (!$scope.orgDetailsForm.$valid) {
return;
}
backendSrv.put('/api/orgs/' + $scope.org.id, $scope.org).then(() => {
$location.path('/admin/orgs');
});
};
示例7: it
it('should return the http status code', async () => {
try {
await _backendSrv.datasourceRequest({
url: 'gateway-error',
});
} catch (err) {
expect(err.status).toBe(502);
}
});