2014-11-11 04:48:27 -06:00
|
|
|
define([
|
|
|
|
'angular',
|
|
|
|
'lodash',
|
|
|
|
],
|
|
|
|
function (angular, _) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('grafana.directives')
|
2015-05-05 12:56:49 -05:00
|
|
|
.directive('dashLinksEditor', function() {
|
2014-11-11 04:48:27 -06:00
|
|
|
return {
|
|
|
|
scope: {
|
2015-05-05 12:56:49 -05:00
|
|
|
dashboard: "="
|
2014-11-11 04:48:27 -06:00
|
|
|
},
|
|
|
|
restrict: 'E',
|
2015-05-05 13:33:06 -05:00
|
|
|
controller: 'DashLinkEditorCtrl',
|
2015-05-05 12:56:49 -05:00
|
|
|
templateUrl: 'app/features/dashlinks/editor.html',
|
2014-11-11 04:48:27 -06:00
|
|
|
link: function() {
|
|
|
|
}
|
|
|
|
};
|
2015-05-05 13:33:06 -05:00
|
|
|
}).directive('dashLink', function(linkSrv) {
|
2015-05-05 12:56:49 -05:00
|
|
|
return {
|
|
|
|
scope: {
|
2015-05-05 13:33:06 -05:00
|
|
|
link: "="
|
2015-05-05 12:56:49 -05:00
|
|
|
},
|
|
|
|
restrict: 'E',
|
|
|
|
controller: 'DashLinkCtrl',
|
|
|
|
templateUrl: 'app/features/dashlinks/module.html',
|
2015-05-05 13:33:06 -05:00
|
|
|
link: function(scope, elem) {
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
var linkInfo = linkSrv.getPanelLinkAnchorInfo(scope.link);
|
|
|
|
elem.find("span").text(linkInfo.title);
|
|
|
|
elem.find("a").attr("href", linkInfo.href);
|
2015-05-06 02:41:30 -05:00
|
|
|
|
|
|
|
if (scope.link.type === 'dashboard') {
|
|
|
|
scope.tooltip = 'Go to dashboard';
|
|
|
|
}
|
2015-05-05 13:33:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
scope.$on('refresh', update);
|
2015-05-05 12:56:49 -05:00
|
|
|
}
|
|
|
|
};
|
2015-05-05 13:33:06 -05:00
|
|
|
})
|
|
|
|
.controller("DashLinkCtrl", function($scope) {
|
|
|
|
|
|
|
|
})
|
|
|
|
.controller('DashLinkEditorCtrl', function($scope, backendSrv) {
|
2014-11-11 04:48:27 -06:00
|
|
|
|
2015-05-05 12:56:49 -05:00
|
|
|
$scope.dashboard.links = $scope.dashboard.links || [];
|
2014-11-11 04:48:27 -06:00
|
|
|
|
|
|
|
$scope.addLink = function() {
|
2015-05-05 12:56:49 -05:00
|
|
|
$scope.dashboard.links.push({
|
2014-11-11 04:48:27 -06:00
|
|
|
type: 'dashboard',
|
2015-05-05 12:56:49 -05:00
|
|
|
name: 'Related dashboard'
|
2014-11-11 04:48:27 -06:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-10 07:52:53 -05:00
|
|
|
$scope.searchDashboards = function(queryStr, callback) {
|
|
|
|
var query = {query: queryStr};
|
2014-11-11 06:38:27 -06:00
|
|
|
|
2015-03-10 07:52:53 -05:00
|
|
|
backendSrv.search(query).then(function(result) {
|
2014-11-11 06:38:27 -06:00
|
|
|
var dashboards = _.map(result.dashboards, function(dash) {
|
|
|
|
return dash.title;
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(dashboards);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-11-11 04:48:27 -06:00
|
|
|
$scope.deleteLink = function(link) {
|
2015-05-05 12:56:49 -05:00
|
|
|
$scope.dashboard.links = _.without($scope.dashboard.links, link);
|
2014-11-11 04:48:27 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|