|
|
@@ -1,123 +1,11 @@
|
|
|
define([
|
|
|
'angular',
|
|
|
'jquery',
|
|
|
- 'lodash',
|
|
|
+ './panelMenu',
|
|
|
],
|
|
|
-function (angular, $, _) {
|
|
|
+function (angular, $) {
|
|
|
'use strict';
|
|
|
|
|
|
- angular
|
|
|
- .module('grafana.directives')
|
|
|
- .directive('panelTitle', function($compile) {
|
|
|
- var linkTemplate = '<a class="pointer panel-title">{{panel.title || interpolateTemplateVars}}</a>';
|
|
|
- var moveAttributes = ' data-drag=true data-jqyoui-options="kbnJqUiDraggableOptions"'+
|
|
|
- ' jqyoui-draggable="'+
|
|
|
- '{'+
|
|
|
- 'animate:false,'+
|
|
|
- 'mutate:false,'+
|
|
|
- 'index:{{$index}},'+
|
|
|
- 'onStart:\'panelMoveStart\','+
|
|
|
- 'onStop:\'panelMoveStop\''+
|
|
|
- '}" ng-model="panel" ';
|
|
|
-
|
|
|
- function createMenuTemplate($scope) {
|
|
|
- var template = '<div class="panel-menu small">';
|
|
|
- template += '<div class="panel-menu-inner">';
|
|
|
- template += '<div class="panel-menu-row">';
|
|
|
- template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(-1)"><i class="icon-minus"></i></a>';
|
|
|
- template += '<a class="panel-menu-icon pull-left" ng-click="updateColumnSpan(1)"><i class="icon-plus"></i></a>';
|
|
|
- template += '<a class="panel-menu-icon pull-right" ng-click="remove_panel_from_row(row, panel)"><i class="icon-remove"></i></a>';
|
|
|
- template += '<a class="panel-menu-icon pull-right" ' + moveAttributes + '><i class="icon-move"></i></a>';
|
|
|
- template += '<div class="clearfix"></div>';
|
|
|
- template += '</div>';
|
|
|
-
|
|
|
- template += '<div class="panel-menu-row">';
|
|
|
-
|
|
|
- _.each($scope.panelMeta.menu, function(item) {
|
|
|
- template += '<a class="panel-menu-link pull-left" ';
|
|
|
- if (item.click) { template += ' ng-click="' + item.click + '"'; }
|
|
|
- template += '>';
|
|
|
- template += item.text + '</a>';
|
|
|
- });
|
|
|
-
|
|
|
- template += '<a class="panel-menu-link pull-left">share</a>';
|
|
|
-
|
|
|
- template += '</div>';
|
|
|
- template += '</div>';
|
|
|
- template += '</div>';
|
|
|
- return template;
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- restrict: 'A',
|
|
|
- link: function($scope, elem) {
|
|
|
- var $link = $(linkTemplate);
|
|
|
- var $panelContainer = elem.parents(".panel-container");
|
|
|
- var menuTemplate = createMenuTemplate($scope);
|
|
|
- var menuWidth = 277;
|
|
|
- var menuScope = null;
|
|
|
- var timeout = null;
|
|
|
-
|
|
|
- elem.append($link);
|
|
|
-
|
|
|
- var dismiss = function() {
|
|
|
- $('.panel-menu').remove();
|
|
|
-
|
|
|
- if (menuScope) {
|
|
|
- menuScope.$destroy();
|
|
|
- menuScope = null;
|
|
|
- $panelContainer.removeClass('panel-highlight');
|
|
|
- }
|
|
|
- if (timeout) {
|
|
|
- clearTimeout(timeout);
|
|
|
- timeout = null;
|
|
|
- }
|
|
|
- return;
|
|
|
- };
|
|
|
-
|
|
|
- $link.click(function() {
|
|
|
- if (menuScope) {
|
|
|
- dismiss();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- dismiss();
|
|
|
-
|
|
|
- var windowWidth = $(window).width();
|
|
|
- var panelLeftPos = $(elem).offset().left;
|
|
|
- var panelWidth = $(elem).width();
|
|
|
- var menuLeftPos = (panelWidth / 2) - (menuWidth/2);
|
|
|
- var stickingOut = panelLeftPos + menuLeftPos + menuWidth - windowWidth;
|
|
|
- if (stickingOut > 0) {
|
|
|
- menuLeftPos -= stickingOut + 10;
|
|
|
- }
|
|
|
- if (panelLeftPos + menuLeftPos < 0) {
|
|
|
- menuLeftPos = 0;
|
|
|
- }
|
|
|
-
|
|
|
- var $menu = $(menuTemplate);
|
|
|
- $menu.css('left', menuLeftPos);
|
|
|
-
|
|
|
- menuScope = $scope.$new();
|
|
|
-
|
|
|
- elem.append($menu);
|
|
|
- $scope.$apply(function() {
|
|
|
- $compile($menu.contents())(menuScope);
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- $(".panel-container").removeClass('panel-highlight');
|
|
|
- $panelContainer.toggleClass('panel-highlight');
|
|
|
-
|
|
|
- //timeout = setTimeout(dismiss, 8000);
|
|
|
- });
|
|
|
-
|
|
|
- $compile(elem.contents())($scope);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
angular
|
|
|
.module('grafana.directives')
|
|
|
.directive('grafanaPanel', function($compile, $parse) {
|
|
|
@@ -138,7 +26,7 @@ function (angular, $, _) {
|
|
|
'<i class="icon-spinner icon-spin icon-large"></i>' +
|
|
|
'</span>' +
|
|
|
|
|
|
- '<div panel-title ' + '></div>' +
|
|
|
+ '<div panel-menu></div>' +
|
|
|
'</div>'+
|
|
|
'</div>';
|
|
|
|