Merge branch 'master' into walmartlabs-master

This commit is contained in:
Torkel Ödegaard
2017-06-05 13:43:00 +02:00
151 changed files with 1967 additions and 3331 deletions

View File

@@ -1,16 +1,18 @@
define([
'jquery',
'angular',
'../core_module',
],
function ($, coreModule) {
function ($, angular, coreModule) {
'use strict';
var editViewMap = {
'settings': { src: 'public/app/features/dashboard/partials/settings.html'},
'annotations': { src: 'public/app/features/annotations/partials/editor.html'},
'history': { src: 'public/app/features/dashboard/history/partials/history.html'},
'templating': { src: 'public/app/features/templating/partials/editor.html'},
'import': { src: '<dash-import></dash-import>' }
'history': { html: '<gf-dashboard-history dashboard="dashboard"></gf-dashboard-history>'},
'timepicker': { src: 'public/app/features/dashboard/timepicker/dropdown.html' },
'import': { html: '<dash-import></dash-import>' }
};
coreModule.default.directive('dashEditorView', function($compile, $location, $rootScope) {
@@ -18,47 +20,53 @@ function ($, coreModule) {
restrict: 'A',
link: function(scope, elem) {
var editorScope;
var lastEditor;
var lastEditView;
function hideEditorPane() {
function hideEditorPane(hideToShowOtherView) {
if (editorScope) {
scope.appEvent('dash-editor-hidden', lastEditor);
editorScope.dismiss();
editorScope.dismiss(hideToShowOtherView);
scope.appEvent('dash-editor-hidden');
}
}
function showEditorPane(evt, payload, editview) {
if (editview) {
scope.contextSrv.editview = editViewMap[editview];
payload.src = scope.contextSrv.editview.src;
function showEditorPane(evt, options) {
if (options.editview) {
options.src = editViewMap[options.editview].src;
options.html = editViewMap[options.editview].html;
}
if (lastEditor === payload.src) {
hideEditorPane();
if (lastEditView === options.editview) {
hideEditorPane(false);
return;
}
hideEditorPane();
hideEditorPane(true);
lastEditor = payload.src;
editorScope = payload.scope ? payload.scope.$new() : scope.$new();
lastEditView = options.editview;
editorScope = options.scope ? options.scope.$new() : scope.$new();
editorScope.dismiss = function() {
editorScope.dismiss = function(hideToShowOtherView) {
editorScope.$destroy();
elem.empty();
lastEditor = null;
lastEditView = null;
editorScope = null;
elem.removeClass('dash-edit-view--open');
if (editview) {
if (!hideToShowOtherView) {
setTimeout(function() {
elem.empty();
}, 250);
}
if (options.editview) {
var urlParams = $location.search();
if (editview === urlParams.editview) {
if (options.editview === urlParams.editview) {
delete urlParams.editview;
$location.search(urlParams);
}
}
};
if (editview === 'import') {
if (options.editview === 'import') {
var modalScope = $rootScope.$new();
modalScope.$on("$destroy", function() {
editorScope.dismiss();
@@ -73,29 +81,42 @@ function ($, coreModule) {
return;
}
var view = payload.src;
if (view.indexOf('.html') > 0) {
view = $('<div class="tabbed-view" ng-include="' + "'" + view + "'" + '"></div>');
var view;
if (options.src) {
view = angular.element(document.createElement('div'));
view.html('<div class="tabbed-view" ng-include="' + "'" + options.src + "'" + '"></div>');
} else {
view = angular.element(document.createElement('div'));
view.addClass('tabbed-view');
view.html(options.html);
}
elem.append(view);
$compile(elem.contents())(editorScope);
$compile(view)(editorScope);
setTimeout(function() {
elem.empty();
elem.append(view);
setTimeout(function() {
elem.addClass('dash-edit-view--open');
}, 10);
}, 10);
}
scope.$watch("dashboardViewState.state.editview", function(newValue, oldValue) {
if (newValue) {
showEditorPane(null, {}, newValue);
showEditorPane(null, {editview: newValue});
} else if (oldValue) {
scope.contextSrv.editview = null;
if (lastEditor === editViewMap[oldValue]) {
if (lastEditView === oldValue) {
hideEditorPane();
}
}
});
scope.contextSrv.editview = null;
scope.$on("$destroy", hideEditorPane);
scope.onAppEvent('hide-dash-editor', hideEditorPane);
scope.onAppEvent('hide-dash-editor', function() {
hideEditorPane(false);
});
scope.onAppEvent('show-dash-editor', showEditorPane);
}
};