DashboardSrv/NavModelSrv: Remove legacy angularjs (#36810)

* DashboardSrv: Remove ngInject + promiseToDigest wrapper

* NavModelSrv: Remove ngInject that is doing nothing

* DashboardSrv: Use getBackendSrv instead of just importing the backendSrv directly
This commit is contained in:
Ashley Harrison 2021-07-19 11:38:12 +01:00 committed by GitHub
parent 4cadbba686
commit 9c6085ee0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 16 deletions

View File

@ -6,7 +6,6 @@ import { NavModel } from '@grafana/data';
export class NavModelSrv { export class NavModelSrv {
navItems: any; navItems: any;
/** @ngInject */
constructor() { constructor() {
this.navItems = config.bootData.navTree; this.navItems = config.bootData.navTree;
} }

View File

@ -3,17 +3,14 @@ import { appEvents } from 'app/core/app_events';
import { DashboardModel } from '../state/DashboardModel'; import { DashboardModel } from '../state/DashboardModel';
import { removePanel } from '../utils/panel'; import { removePanel } from '../utils/panel';
import { DashboardMeta } from 'app/types'; import { DashboardMeta } from 'app/types';
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; import { getBackendSrv } from 'app/core/services/backend_srv';
import { backendSrv } from 'app/core/services/backend_srv';
import { promiseToDigest } from '../../../core/utils/promiseToDigest';
import { saveDashboard } from 'app/features/manage-dashboards/state/actions'; import { saveDashboard } from 'app/features/manage-dashboards/state/actions';
import { RemovePanelEvent } from '../../../types/events'; import { RemovePanelEvent } from '../../../types/events';
export class DashboardSrv { export class DashboardSrv {
dashboard?: DashboardModel; dashboard?: DashboardModel;
/** @ngInject */ constructor() {
constructor(private $rootScope: GrafanaRootScope) {
appEvents.subscribe(RemovePanelEvent, (e) => this.onRemovePanel(e.payload)); appEvents.subscribe(RemovePanelEvent, (e) => this.onRemovePanel(e.payload));
} }
@ -48,20 +45,17 @@ export class DashboardSrv {
} }
starDashboard(dashboardId: string, isStarred: any) { starDashboard(dashboardId: string, isStarred: any) {
const backendSrv = getBackendSrv();
let promise; let promise;
if (isStarred) { if (isStarred) {
promise = promiseToDigest(this.$rootScope)( promise = backendSrv.delete('/api/user/stars/dashboard/' + dashboardId).then(() => {
backendSrv.delete('/api/user/stars/dashboard/' + dashboardId).then(() => { return false;
return false; });
})
);
} else { } else {
promise = promiseToDigest(this.$rootScope)( promise = backendSrv.post('/api/user/stars/dashboard/' + dashboardId).then(() => {
backendSrv.post('/api/user/stars/dashboard/' + dashboardId).then(() => { return true;
return true; });
})
);
} }
return promise.then((res: boolean) => { return promise.then((res: boolean) => {