| 1 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 2 | import type { Dashboard, Org, Panel, PanelLink } from "@/types/reporting.d" |
| 3 | import { HttpClient } from "../httpClient" |
| 4 | |
| 5 | export type PanelsLinksTimeUnit = "minutes" | "hours" | "days" |
| 6 | |
| 7 | export interface PanelsLinksPayload { |
| 8 | org_id: string | number |
| 9 | dashboard_title: string |
| 10 | dashboard_uid: string |
| 11 | panel_ids: number[] |
| 12 | time_range: { |
| 13 | value: number |
| 14 | unit: PanelsLinksTimeUnit |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | export type RowPanelTimeUnit = "m" | "h" | "d" |
| 19 | |
| 20 | export interface RowPanelPayload { |
| 21 | org_id: number |
| 22 | dashboard_title: string |
| 23 | dashboard_uid: string |
| 24 | panel_id: number |
| 25 | panel_width: number |
| 26 | panel_height: number |
| 27 | theme: "light" | "dark" |
| 28 | } |
| 29 | |
| 30 | export interface RowPayload { |
| 31 | id: string | number |
| 32 | panels: RowPanelPayload[] |
| 33 | } |
| 34 | |
| 35 | export interface GenerateReportPayload { |
| 36 | timerange: ReportTimeRange |
| 37 | timerange_text: string |
| 38 | logo_base64: string |
| 39 | company_name: string |
| 40 | rows: RowPayload[] |
| 41 | } |
| 42 | |
| 43 | export type ReportTimeRange = `${number}${RowPanelTimeUnit}` |
| 44 | |
| 45 | export default { |
| 46 | getOrgs() { |
| 47 | return HttpClient.get<FlaskBaseResponse & { orgs: Org[] }>(`/reporting/orgs`) |
| 48 | }, |
| 49 | getDashboards(orgId: string) { |
| 50 | return HttpClient.get<FlaskBaseResponse & { dashboards: Dashboard[] }>(`/reporting/dashboards/${orgId}`) |
| 51 | }, |
| 52 | getPanels(dashboardUID: string) { |
| 53 | return HttpClient.get<FlaskBaseResponse & { panels: Panel[] }>(`/reporting/dashboard_panels/${dashboardUID}`) |
| 54 | }, |
| 55 | generatePanelsLinks(payload: PanelsLinksPayload) { |
| 56 | return HttpClient.post<FlaskBaseResponse & { links: PanelLink[] }>(`/reporting/generate_iframe_links`, payload) |
| 57 | }, |
| 58 | generateReport({ timerange, timerange_text, logo_base64, company_name, rows }: GenerateReportPayload) { |
| 59 | return HttpClient.post<FlaskBaseResponse & { base64_result: string }>( |
| 60 | `/reporting/generate-report`, |
| 61 | { timerange, timerange_text, logo_base64, company_name, rows }, |
| 62 | { timeout: 0 } |
| 63 | ) |
| 64 | } |
| 65 | } |