mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Stackdriver: Refactored api call to google resource manager
This commit is contained in:
parent
a4ef4792bc
commit
5bee38ed69
@ -7,7 +7,7 @@ export class StackdriverConfigCtrl {
|
||||
inputDataValid: boolean;
|
||||
defaultProject: string;
|
||||
projectsError: string;
|
||||
projects: string[];
|
||||
projects: any[];
|
||||
loadingProjects: boolean;
|
||||
|
||||
/** @ngInject */
|
||||
@ -15,6 +15,7 @@ export class StackdriverConfigCtrl {
|
||||
this.datasourceSrv = datasourceSrv;
|
||||
this.current.jsonData = this.current.jsonData || {};
|
||||
this.current.secureJsonData = this.current.secureJsonData || {};
|
||||
this.defaultProject = this.current.jsonData.defaultProject;
|
||||
this.projects = [];
|
||||
}
|
||||
|
||||
@ -80,11 +81,12 @@ export class StackdriverConfigCtrl {
|
||||
try {
|
||||
this.loadingProjects = true;
|
||||
const ds = await this.datasourceSrv.loadDatasource(this.current.name);
|
||||
const response = await ds.doRequest(`/cloudresourcemanager/v1/projects`);
|
||||
this.projects = await ds.getProjects();
|
||||
this.$scope.$apply(() => {
|
||||
this.projects = response.data.projects.map(p => ({ id: p.projectId, name: p.name }));
|
||||
if (this.projects.length > 0) {
|
||||
this.current.jsonData.defaultProject = this.current.jsonData.defaultProject || this.projects[0].id;
|
||||
}
|
||||
});
|
||||
console.log(this.projects);
|
||||
} catch (error) {
|
||||
let message = 'Projects cannot be fetched: ';
|
||||
message += error.statusText ? error.statusText + ': ' : '';
|
||||
@ -100,10 +102,9 @@ export class StackdriverConfigCtrl {
|
||||
} else {
|
||||
message += 'Cannot connect to Stackdriver API';
|
||||
}
|
||||
this.$scope.$apply(() => {
|
||||
this.loadingProjects = false;
|
||||
this.projectsError = message;
|
||||
});
|
||||
this.$scope.$apply(() => (this.projectsError = message));
|
||||
} finally {
|
||||
this.$scope.$apply(() => (this.loadingProjects = false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,12 @@ export default class StackdriverDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
doRequest(url, maxRetries = 1) {
|
||||
async getProjects() {
|
||||
const response = await this.doRequest(`/cloudresourcemanager/v1/projects`);
|
||||
return response.data.projects.map(p => ({ id: p.projectId, name: p.name }));
|
||||
}
|
||||
|
||||
async doRequest(url, maxRetries = 1) {
|
||||
return this.backendSrv
|
||||
.datasourceRequest({
|
||||
url: this.url + url,
|
||||
|
@ -28,7 +28,8 @@
|
||||
<div class="gf-form" ng-if="ctrl.inputDataValid">
|
||||
<span class="gf-form-label width-10">Default Project</span>
|
||||
<div class="gf-form-select-wrapper max-width-23">
|
||||
<select class="gf-form-input" ng-model="ctrl.defaultProject" ng-options="p.id as p.name for p in ctrl.projects" ng-change="ctrl.userChangedDefaultProject()"></select>
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.defaultProject" ng-options="p.id as p.name for p in ctrl.projects"
|
||||
ng-change="ctrl.userChangedDefaultProject()"></select>
|
||||
</div>
|
||||
<div ng-if="ctrl.loadingProjects">
|
||||
<i class="fa fa-spinner fa-spin"></i>
|
||||
|
Loading…
Reference in New Issue
Block a user