2017-12-19 09:06:54 -06:00
|
|
|
import angular from "angular";
|
|
|
|
import _ from "lodash";
|
|
|
|
import "./link_srv";
|
2017-11-23 07:53:23 -06:00
|
|
|
|
|
|
|
function panelLinksEditor() {
|
|
|
|
return {
|
|
|
|
scope: {
|
|
|
|
panel: "="
|
|
|
|
},
|
2017-12-19 09:06:54 -06:00
|
|
|
restrict: "E",
|
|
|
|
controller: "PanelLinksEditorCtrl",
|
|
|
|
templateUrl: "public/app/features/panellinks/module.html",
|
|
|
|
link: function() {}
|
2017-11-23 07:53:23 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export class PanelLinksEditorCtrl {
|
|
|
|
/** @ngInject */
|
|
|
|
constructor($scope, backendSrv) {
|
|
|
|
$scope.panel.links = $scope.panel.links || [];
|
|
|
|
|
|
|
|
$scope.addLink = function() {
|
|
|
|
$scope.panel.links.push({
|
2017-12-19 09:06:54 -06:00
|
|
|
type: "dashboard"
|
2017-11-23 07:53:23 -06:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.searchDashboards = function(queryStr, callback) {
|
2017-12-19 09:06:54 -06:00
|
|
|
backendSrv.search({ query: queryStr }).then(function(hits) {
|
2017-11-23 07:53:23 -06:00
|
|
|
var dashboards = _.map(hits, function(dash) {
|
|
|
|
return dash.title;
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(dashboards);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.dashboardChanged = function(link) {
|
2017-12-19 09:06:54 -06:00
|
|
|
backendSrv.search({ query: link.dashboard }).then(function(hits) {
|
|
|
|
var dashboard = _.find(hits, { title: link.dashboard });
|
2017-11-23 07:53:23 -06:00
|
|
|
if (dashboard) {
|
|
|
|
link.dashUri = dashboard.uri;
|
|
|
|
link.title = dashboard.title;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteLink = function(link) {
|
|
|
|
$scope.panel.links = _.without($scope.panel.links, link);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
angular
|
|
|
|
.module("grafana.directives")
|
|
|
|
.directive("panelLinksEditor", panelLinksEditor)
|
|
|
|
.controller("PanelLinksEditorCtrl", PanelLinksEditorCtrl);
|