grafana/public/app/features/dashboard/history/history_srv.ts
Tobias Skarhed 3a9a36d6cf Karma to Jest: history_srv (#12341)
* Karma to Jest: history_srv

* Fix TS errors

* Remove q, as it is not needed
2018-06-19 08:05:49 -07:00

55 lines
1.4 KiB
TypeScript

import _ from 'lodash';
import coreModule from 'app/core/core_module';
import { DashboardModel } from '../dashboard_model';
export interface HistoryListOpts {
limit: number;
start: number;
}
export interface RevisionsModel {
id: number;
checked: boolean;
dashboardId: number;
parentVersion: number;
version: number;
created: Date;
createdBy: string;
message: string;
}
export interface CalculateDiffOptions {
new: DiffTarget;
base: DiffTarget;
diffType: string;
}
export interface DiffTarget {
dashboardId: number;
version: number;
unsavedDashboard?: DashboardModel; // when doing diffs against unsaved dashboard version
}
export class HistorySrv {
/** @ngInject */
constructor(private backendSrv) {}
getHistoryList(dashboard: DashboardModel, options: HistoryListOpts) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
return id ? this.backendSrv.get(`api/dashboards/id/${id}/versions`, options) : Promise.resolve([]);
}
calculateDiff(options: CalculateDiffOptions) {
return this.backendSrv.post('api/dashboards/calculate-diff', options);
}
restoreDashboard(dashboard: DashboardModel, version: number) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
const url = `api/dashboards/id/${id}/restore`;
return id && _.isNumber(version) ? this.backendSrv.post(url, { version }) : Promise.resolve({});
}
}
coreModule.service('historySrv', HistorySrv);