You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.1 KiB
33 lines
1.1 KiB
import { GrafanaPanelTemplate, GrafanaTemplateVariables } from '../models/grafana_panel_model'; |
|
import { exportPanel, importPanel } from '../services/grafana_service'; |
|
|
|
import * as Router from 'koa-router'; |
|
|
|
|
|
async function exportGrafanaPanelTemplate(ctx: Router.IRouterContext) { |
|
let panelId = ctx.request.query.panelId; |
|
if(panelId === undefined) { |
|
throw new Error('Cannot export analytic units with undefined panelId'); |
|
} |
|
|
|
const panelTemplate = await exportPanel(panelId); |
|
ctx.response.body = panelTemplate; |
|
} |
|
|
|
async function importGrafanaPanelTemplate(ctx: Router.IRouterContext) { |
|
const { panelTemplate, templateVariables } = ctx.request.body as { |
|
panelTemplate: GrafanaPanelTemplate, |
|
templateVariables: GrafanaTemplateVariables |
|
}; |
|
|
|
if(panelTemplate.analyticUnitTemplates === undefined) { |
|
throw new Error('Cannot import analytic units with undefined analyticUnitTemplates'); |
|
} |
|
await importPanel(panelTemplate, templateVariables); |
|
ctx.response.status = 200; |
|
} |
|
|
|
export var router = new Router(); |
|
|
|
router.get('/template', exportGrafanaPanelTemplate); |
|
router.post('/template', importGrafanaPanelTemplate);
|
|
|