mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Began work on dashboard links and nav feature, #1944
This commit is contained in:
39
public/app/features/panellinks/linkSrv.js
Normal file
39
public/app/features/panellinks/linkSrv.js
Normal file
@@ -0,0 +1,39 @@
|
||||
define([
|
||||
'angular',
|
||||
'kbn',
|
||||
],
|
||||
function (angular, kbn) {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('grafana.services')
|
||||
.service('linkSrv', function(templateSrv, timeSrv) {
|
||||
|
||||
this.getPanelLinkAnchorInfo = function(link) {
|
||||
var info = {};
|
||||
if (link.type === 'absolute') {
|
||||
info.target = '_blank';
|
||||
info.href = templateSrv.replace(link.url || '');
|
||||
info.title = templateSrv.replace(link.title || '');
|
||||
info.href += '?';
|
||||
|
||||
}
|
||||
else {
|
||||
info.title = templateSrv.replace(link.title || '');
|
||||
var slug = kbn.slugifyForUrl(link.dashboard || '');
|
||||
info.href = 'dashboard/db/' + slug + '?';
|
||||
}
|
||||
|
||||
var range = timeSrv.timeRangeForUrl();
|
||||
info.href += 'from=' + range.from;
|
||||
info.href += '&to=' + range.to;
|
||||
|
||||
if (link.params) {
|
||||
info.href += "&" + templateSrv.replace(link.params);
|
||||
}
|
||||
|
||||
return info;
|
||||
};
|
||||
|
||||
});
|
||||
});
|
||||
60
public/app/features/panellinks/module.html
Normal file
60
public/app/features/panellinks/module.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<div class="editor-row">
|
||||
<div class="section">
|
||||
<h5>Drilldown / detail link<tip>These links appear in the dropdown menu in the panel menu. </tip></h5>
|
||||
|
||||
<div ng-repeat="link in panel.links">
|
||||
<div class="tight-form" >
|
||||
<ul class="tight-form-list">
|
||||
<li class="tight-form-item">
|
||||
<i class="fa fa-remove pointer" ng-click="deleteLink(link)"></i>
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item" style="width: 80px;">Link title</li>
|
||||
<li>
|
||||
<input type="text" ng-model="link.title" class="input-medium tight-form-input">
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item">Type</li>
|
||||
<li>
|
||||
<select class="input-medium tight-form-input" style="width: 101px;" ng-model="link.type" ng-options="f for f in ['dashboard','absolute']"></select>
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item" ng-show="link.type === 'dashboard'">Dashboard</li>
|
||||
<li ng-show="link.type === 'dashboard'">
|
||||
<input type="text"
|
||||
ng-model="link.dashboard"
|
||||
bs-typeahead="searchDashboards"
|
||||
class="input-large tight-form-input">
|
||||
</li>
|
||||
|
||||
<li class="tight-form-item" ng-show="link.type === 'absolute'">Url</li>
|
||||
<li ng-show="link.type === 'absolute'">
|
||||
<input type="text" ng-model="link.url" class="input-xlarge tight-form-input">
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="tight-form">
|
||||
<ul class="tight-form-list" role="menu">
|
||||
<li class="tight-form-item">
|
||||
<i class="fa fa-remove invisible"></i>
|
||||
</li>
|
||||
<li class="tight-form-item" style="width: 80px;">
|
||||
Params
|
||||
<tip>Use var-variableName=value to pass templating variables.</tip>
|
||||
</li>
|
||||
<li>
|
||||
<input type="text" ng-model="link.params" class="input-xxlarge tight-form-input">
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="editor-row">
|
||||
<br>
|
||||
<button class="btn btn-inverse" ng-click="addLink()"><i class="fa fa-plus"></i> Add link</button>
|
||||
</div>
|
||||
50
public/app/features/panellinks/module.js
Normal file
50
public/app/features/panellinks/module.js
Normal file
@@ -0,0 +1,50 @@
|
||||
define([
|
||||
'angular',
|
||||
'lodash',
|
||||
'./linkSrv',
|
||||
],
|
||||
function (angular, _) {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('grafana.directives')
|
||||
.directive('panelLinksEditor', function() {
|
||||
return {
|
||||
scope: {
|
||||
panel: "="
|
||||
},
|
||||
restrict: 'E',
|
||||
controller: 'PanelLinksEditorCtrl',
|
||||
templateUrl: 'app/features/panellinkeditor/module.html',
|
||||
link: function() {
|
||||
}
|
||||
};
|
||||
}).controller('PanelLinksEditorCtrl', function($scope, backendSrv) {
|
||||
|
||||
$scope.panel.links = $scope.panel.links || [];
|
||||
|
||||
$scope.addLink = function() {
|
||||
$scope.panel.links.push({
|
||||
type: 'dashboard',
|
||||
name: 'Drilldown dashboard'
|
||||
});
|
||||
};
|
||||
|
||||
$scope.searchDashboards = function(queryStr, callback) {
|
||||
var query = {query: queryStr};
|
||||
|
||||
backendSrv.search(query).then(function(result) {
|
||||
var dashboards = _.map(result.dashboards, function(dash) {
|
||||
return dash.title;
|
||||
});
|
||||
|
||||
callback(dashboards);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteLink = function(link) {
|
||||
$scope.panel.links = _.without($scope.panel.links, link);
|
||||
};
|
||||
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user