From 7de5b0e327e1b37630ab89ee5a9fe948e356f295 Mon Sep 17 00:00:00 2001 From: Liza Katz Date: Sat, 29 Jun 2019 12:18:44 +0300 Subject: [PATCH] Graph - move custom views out of top_nav (#39706) (#39795) * Stop using template feature of kbn top nav * Combined css --- x-pack/legacy/plugins/graph/public/app.js | 36 ++++- .../graph/public/directives/graph_load.js | 17 +++ .../graph/public/directives/graph_save.js | 17 +++ .../graph/public/directives/graph_settings.js | 17 +++ .../graph/public/templates/_graph.scss | 4 + .../plugins/graph/public/templates/index.html | 126 +++++++++--------- .../public/templates/load_workspace.html | 27 ++-- .../graph/public/templates/settings.html | 5 +- 8 files changed, 172 insertions(+), 77 deletions(-) create mode 100644 x-pack/legacy/plugins/graph/public/directives/graph_load.js create mode 100644 x-pack/legacy/plugins/graph/public/directives/graph_save.js create mode 100644 x-pack/legacy/plugins/graph/public/directives/graph_settings.js diff --git a/x-pack/legacy/plugins/graph/public/app.js b/x-pack/legacy/plugins/graph/public/app.js index eccac38b19744..be14de4863c16 100644 --- a/x-pack/legacy/plugins/graph/public/app.js +++ b/x-pack/legacy/plugins/graph/public/app.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import _ from 'lodash'; import d3 from 'd3'; import { i18n } from '@kbn/i18n'; import 'ace'; @@ -56,6 +57,10 @@ import saveTemplate from './templates/save_workspace.html'; import loadTemplate from './templates/load_workspace.html'; import settingsTemplate from './templates/settings.html'; +import './directives/graph_load'; +import './directives/graph_save'; +import './directives/graph_settings'; + const app = uiModules.get('app/graph'); function checkLicense(Promise, kbnBaseUrl) { @@ -836,7 +841,11 @@ app.controller('graphuiPlugin', function ( defaultMessage: 'Save this workspace', }), disableButton: function () {return $scope.selectedFields.length === 0;}, - template: saveTemplate, + run: () => { + const curState = $scope.menus.showSave; + $scope.closeMenus(); + $scope.menus.showSave = !curState; + }, testId: 'graphSaveButton', }); } else { @@ -867,7 +876,11 @@ app.controller('graphuiPlugin', function ( tooltip: i18n.translate('xpack.graph.topNavMenu.loadWorkspaceTooltip', { defaultMessage: 'Load a saved workspace', }), - template: loadTemplate, + run: () => { + const curState = $scope.menus.showLoad; + $scope.closeMenus(); + $scope.menus.showLoad = !curState; + }, testId: 'graphOpenButton', }); // if deleting is disabled using uiCapabilities, we don't want to render the delete @@ -919,7 +932,7 @@ app.controller('graphuiPlugin', function ( ); } }); - }else { + } else { $scope.topNavMenu.push({ key: 'delete', disableButton: true, @@ -945,9 +958,24 @@ app.controller('graphuiPlugin', function ( description: i18n.translate('xpack.graph.topNavMenu.settingsAriaLabel', { defaultMessage: 'Settings', }), - template: settingsTemplate + run: () => { + const curState = $scope.menus.showSettings; + $scope.closeMenus(); + $scope.menus.showSettings = !curState; + }, }); + $scope.menus = { + showSave: false, + showLoad: false, + showSettings: false, + }; + + $scope.closeMenus = () => { + _.forOwn($scope.menus, function (value, key) { + $scope.menus[key] = false; + }); + }; // Deal with situation of request to open saved workspace if ($route.current.locals.savedWorkspace) { diff --git a/x-pack/legacy/plugins/graph/public/directives/graph_load.js b/x-pack/legacy/plugins/graph/public/directives/graph_load.js new file mode 100644 index 0000000000000..369243fff7487 --- /dev/null +++ b/x-pack/legacy/plugins/graph/public/directives/graph_load.js @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { uiModules } from 'ui/modules'; +import template from '../templates/load_workspace.html'; +const app = uiModules.get('app/graph'); + +app.directive('graphLoad', function () { + return { + replace: true, + restrict: 'E', + template, + }; +}); diff --git a/x-pack/legacy/plugins/graph/public/directives/graph_save.js b/x-pack/legacy/plugins/graph/public/directives/graph_save.js new file mode 100644 index 0000000000000..e8a2889feda24 --- /dev/null +++ b/x-pack/legacy/plugins/graph/public/directives/graph_save.js @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { uiModules } from 'ui/modules'; +import template from '../templates/save_workspace.html'; +const app = uiModules.get('app/graph'); + +app.directive('graphSave', function () { + return { + replace: true, + restrict: 'E', + template, + }; +}); diff --git a/x-pack/legacy/plugins/graph/public/directives/graph_settings.js b/x-pack/legacy/plugins/graph/public/directives/graph_settings.js new file mode 100644 index 0000000000000..28bb7019735ee --- /dev/null +++ b/x-pack/legacy/plugins/graph/public/directives/graph_settings.js @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { uiModules } from 'ui/modules'; +import template from '../templates/settings.html'; +const app = uiModules.get('app/graph'); + +app.directive('graphSettings', function () { + return { + replace: true, + restrict: 'E', + template, + }; +}); diff --git a/x-pack/legacy/plugins/graph/public/templates/_graph.scss b/x-pack/legacy/plugins/graph/public/templates/_graph.scss index 5768ddb96b6b5..b8a6213aef746 100644 --- a/x-pack/legacy/plugins/graph/public/templates/_graph.scss +++ b/x-pack/legacy/plugins/graph/public/templates/_graph.scss @@ -71,6 +71,10 @@ fill: $euiColorEmptyShade; } +.gphGraph__menus, .gphGraph__bar { + margin: $euiSizeM; +} + .gphGraph__flexGroup { display: flex; width: 100%; diff --git a/x-pack/legacy/plugins/graph/public/templates/index.html b/x-pack/legacy/plugins/graph/public/templates/index.html index 502d92b4abc98..b65dadbf54bc1 100644 --- a/x-pack/legacy/plugins/graph/public/templates/index.html +++ b/x-pack/legacy/plugins/graph/public/templates/index.html @@ -1,72 +1,78 @@
- -
-
- - - - - - - - - {{f.icon.code}} - - - + - - + + + +
+ +
+
+ + + + + + + + + {{f.icon.code}} + + + + + + + + + + +
+
+ - - - - -
- - -
- -
+
+
- +
diff --git a/x-pack/legacy/plugins/graph/public/templates/load_workspace.html b/x-pack/legacy/plugins/graph/public/templates/load_workspace.html index bf1ea0729deb2..5f8948caf1e97 100644 --- a/x-pack/legacy/plugins/graph/public/templates/load_workspace.html +++ b/x-pack/legacy/plugins/graph/public/templates/load_workspace.html @@ -1,12 +1,15 @@ -
- - +
+
+ + + +
\ No newline at end of file diff --git a/x-pack/legacy/plugins/graph/public/templates/settings.html b/x-pack/legacy/plugins/graph/public/templates/settings.html index d187567fb9085..c31474ca917f7 100644 --- a/x-pack/legacy/plugins/graph/public/templates/settings.html +++ b/x-pack/legacy/plugins/graph/public/templates/settings.html @@ -1,4 +1,5 @@ -
+
+ +
\ No newline at end of file