mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* noImplicitAny playlist approx 200 * Add AngularPanelMenuItem interface * Roughly 100 noImplicitAny
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import angular from 'angular';
|
|
import _ from 'lodash';
|
|
import './link_srv';
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
function panelLinksEditor() {
|
|
return {
|
|
scope: {
|
|
panel: '=',
|
|
},
|
|
restrict: 'E',
|
|
controller: 'PanelLinksEditorCtrl',
|
|
templateUrl: 'public/app/features/panel/panellinks/module.html',
|
|
link: () => {},
|
|
};
|
|
}
|
|
|
|
export class PanelLinksEditorCtrl {
|
|
/** @ngInject */
|
|
constructor($scope: any, backendSrv: BackendSrv) {
|
|
$scope.panel.links = $scope.panel.links || [];
|
|
|
|
$scope.addLink = () => {
|
|
$scope.panel.links.push({
|
|
type: 'dashboard',
|
|
});
|
|
};
|
|
|
|
$scope.searchDashboards = (queryStr: string, callback: Function) => {
|
|
backendSrv.search({ query: queryStr }).then(hits => {
|
|
const dashboards = _.map(hits, dash => {
|
|
return dash.title;
|
|
});
|
|
|
|
callback(dashboards);
|
|
});
|
|
};
|
|
|
|
$scope.dashboardChanged = (link: any) => {
|
|
backendSrv.search({ query: link.dashboard }).then(hits => {
|
|
const dashboard: any = _.find(hits, { title: link.dashboard });
|
|
if (dashboard) {
|
|
if (dashboard.url) {
|
|
link.url = dashboard.url;
|
|
} else {
|
|
// To support legacy url's
|
|
link.dashUri = dashboard.uri;
|
|
}
|
|
link.title = dashboard.title;
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.deleteLink = (link: any) => {
|
|
$scope.panel.links = _.without($scope.panel.links, link);
|
|
};
|
|
}
|
|
}
|
|
|
|
angular
|
|
.module('grafana.directives')
|
|
.directive('panelLinksEditor', panelLinksEditor)
|
|
.controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);
|