2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import './link_srv';
|
2019-07-18 01:03:04 -05:00
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
2017-11-23 07:53:23 -06:00
|
|
|
|
|
|
|
function panelLinksEditor() {
|
|
|
|
return {
|
|
|
|
scope: {
|
2017-12-20 05:33:33 -06:00
|
|
|
panel: '=',
|
2017-11-23 07:53:23 -06:00
|
|
|
},
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
|
|
|
controller: 'PanelLinksEditorCtrl',
|
2019-01-29 02:47:41 -06:00
|
|
|
templateUrl: 'public/app/features/panel/panellinks/module.html',
|
2018-09-05 00:47:30 -05:00
|
|
|
link: () => {},
|
2017-11-23 07:53:23 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PanelLinksEditorCtrl {
|
|
|
|
/** @ngInject */
|
2019-07-18 01:03:04 -05:00
|
|
|
constructor($scope: any, backendSrv: BackendSrv) {
|
2017-11-23 07:53:23 -06:00
|
|
|
$scope.panel.links = $scope.panel.links || [];
|
|
|
|
|
2018-09-05 00:47:30 -05:00
|
|
|
$scope.addLink = () => {
|
2017-11-23 07:53:23 -06:00
|
|
|
$scope.panel.links.push({
|
2017-12-20 05:33:33 -06:00
|
|
|
type: 'dashboard',
|
2017-11-23 07:53:23 -06:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
$scope.searchDashboards = (queryStr: string, callback: Function) => {
|
2018-09-05 00:47:30 -05:00
|
|
|
backendSrv.search({ query: queryStr }).then(hits => {
|
|
|
|
const dashboards = _.map(hits, dash => {
|
2017-11-23 07:53:23 -06:00
|
|
|
return dash.title;
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(dashboards);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
$scope.dashboardChanged = (link: any) => {
|
2018-09-05 00:47:30 -05:00
|
|
|
backendSrv.search({ query: link.dashboard }).then(hits => {
|
2019-04-15 05:11:52 -05:00
|
|
|
const dashboard: any = _.find(hits, { title: link.dashboard });
|
2017-11-23 07:53:23 -06:00
|
|
|
if (dashboard) {
|
2018-08-08 09:01:01 -05:00
|
|
|
if (dashboard.url) {
|
|
|
|
link.url = dashboard.url;
|
|
|
|
} else {
|
|
|
|
// To support legacy url's
|
|
|
|
link.dashUri = dashboard.uri;
|
|
|
|
}
|
2017-11-23 07:53:23 -06:00
|
|
|
link.title = dashboard.title;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
$scope.deleteLink = (link: any) => {
|
2017-11-23 07:53:23 -06:00
|
|
|
$scope.panel.links = _.without($scope.panel.links, link);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
angular
|
2017-12-20 05:33:33 -06:00
|
|
|
.module('grafana.directives')
|
|
|
|
.directive('panelLinksEditor', panelLinksEditor)
|
|
|
|
.controller('PanelLinksEditorCtrl', PanelLinksEditorCtrl);
|