mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: load dashboards from a data source (#36366)
This commit is contained in:
parent
4632b070e4
commit
3a6ec01c05
@ -37,6 +37,8 @@ export class DashboardLoaderSrv {
|
||||
promise = backendSrv.get('/api/snapshots/' + slug).catch(() => {
|
||||
return this._dashboardLoadFailed('Snapshot not found', true);
|
||||
});
|
||||
} else if (type === 'ds') {
|
||||
promise = this._loadFromDatasource(slug); // explore dashboards as code
|
||||
} else {
|
||||
promise = backendSrv
|
||||
.getDashboardByUid(uid)
|
||||
@ -92,6 +94,38 @@ export class DashboardLoaderSrv {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a temporary solution to load dashboards dynamically from a datasource
|
||||
* Eventually this should become a plugin type or a special handler in the dashboard
|
||||
* loading code
|
||||
*/
|
||||
async _loadFromDatasource(dsid: string) {
|
||||
const ds = await getDatasourceSrv().get(dsid);
|
||||
if (!ds) {
|
||||
return Promise.reject('can not find datasource: ' + dsid);
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const path = params.get('path');
|
||||
if (!path) {
|
||||
return Promise.reject('expecting path parameter');
|
||||
}
|
||||
|
||||
return getBackendSrv()
|
||||
.get(`/api/datasources/${ds.id}/resources/${path}`, {})
|
||||
.then((data) => {
|
||||
return {
|
||||
meta: {
|
||||
fromScript: true,
|
||||
canDelete: false,
|
||||
canSave: false,
|
||||
canStar: false,
|
||||
},
|
||||
dashboard: data,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
_executeScript(result: any) {
|
||||
const services = {
|
||||
dashboardSrv: getDashboardSrv(),
|
||||
|
Loading…
Reference in New Issue
Block a user