Repository: ignite Updated Branches: refs/heads/ignite-843 c073338a0 -> 8398a233d
# IGNITE-843 Updated sql page. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/43360182 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/43360182 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/43360182 Branch: refs/heads/ignite-843 Commit: 433601822c3eb1641fba8fdf16652a430945d33a Parents: 9588e26 Author: Andrey <[email protected]> Authored: Wed Sep 2 13:05:04 2015 +0700 Committer: Andrey <[email protected]> Committed: Wed Sep 2 13:05:04 2015 +0700 ---------------------------------------------------------------------- .../src/main/js/controllers/common-module.js | 30 ++++++++++-- .../src/main/js/controllers/sql-controller.js | 50 +++++++++++++------- .../src/main/js/routes/notebooks.js | 27 +++++++++-- .../src/main/js/views/includes/header.jade | 2 +- .../src/main/js/views/sql/sql.jade | 15 +++--- .../src/main/js/views/templates/copy.jade | 2 +- .../main/js/views/templates/notebook-new.jade | 31 ++++++++++++ 7 files changed, 121 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/controllers/common-module.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js index c9c1d23..f5ef51d 100644 --- a/modules/control-center-web/src/main/js/controllers/common-module.js +++ b/modules/control-center-web/src/main/js/controllers/common-module.js @@ -671,7 +671,7 @@ controlCenterModule.service('$common', [ }) }, initPreview: function () { - MutationObserver = window.MutationObserver || window.WebKitMutationObserver; + MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; $('.panel-collapse').each(function (ix, el) { var observer = new MutationObserver(function(mutations, observer) { @@ -1358,12 +1358,16 @@ controlCenterModule.controller('agent-download', [ }]); // Navigation bar controller. -controlCenterModule.controller('notebooks', ['$scope', '$http', '$common', function ($scope, $http, $common) { +controlCenterModule.controller('notebooks', ['$scope', '$modal', '$window', '$http', '$common', + function ($scope, $modal, $window, $http, $common) { $scope.$root.notebooks = []; - $scope.$root.rebuildDropdown = function () { + // Pre-fetch modal dialogs. + var _notebookNewModal = $modal({scope: $scope, templateUrl: '/notebooks/new', show: false}); + + $scope.$root.rebuildDropdown = function() { $scope.notebookDropdown = [ - {text: 'Create new notebook', href: '/notebooks/new', target: '_self'}, + {text: 'Create new notebook', click: 'inputNotebookName()'}, {divider: true} ]; @@ -1376,7 +1380,7 @@ controlCenterModule.controller('notebooks', ['$scope', '$http', '$common', funct }); }; - $scope.$root.reloadNotebooks = function () { + $scope.$root.reloadNotebooks = function() { // When landing on the page, get clusters and show them. $http.post('/notebooks/list') .success(function (data) { @@ -1389,6 +1393,22 @@ controlCenterModule.controller('notebooks', ['$scope', '$http', '$common', funct }); }; + $scope.$root.inputNotebookName = function() { + _notebookNewModal.$promise.then(_notebookNewModal.show); + }; + + $scope.$root.createNewNotebook = function(name) { + $http.post('/notebooks/new', {name: name}) + .success(function (id) { + _notebookNewModal.hide(); + + $window.location = '/sql/' + id; + }) + .error(function (message, state) { + $common.showError(message); + }); + }; + $scope.$root.reloadNotebooks(); }]); http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/controllers/sql-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/sql-controller.js b/modules/control-center-web/src/main/js/controllers/sql-controller.js index 80fffd9..e6447bf 100644 --- a/modules/control-center-web/src/main/js/controllers/sql-controller.js +++ b/modules/control-center-web/src/main/js/controllers/sql-controller.js @@ -16,8 +16,8 @@ */ // Controller for SQL notebook screen. -controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http', '$common', - function ($scope, $controller, $http, $common) { +controlCenterModule.controller('sqlController', ['$scope', '$window','$controller', '$http', '$common', + function ($scope, $window, $controller, $http, $common) { // Initialize the super class and extend it. angular.extend(this, $controller('agent-download', {$scope: $scope})); $scope.agentGoal = 'execute sql statements'; @@ -53,6 +53,9 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http loadNotebook(); $scope.renameNotebook = function (name) { + if (!name) + return; + if ($scope.notebook.name != name) { $scope.notebook.name = name; @@ -91,9 +94,21 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http }; $scope.removeNotebook = function () { - $http.post('/notebooks/remove', $scope.notebook) + $http.post('/notebooks/remove', {_id: $scope.notebook._id}) .success(function () { - $common.showInfo("Notebook successfully removed."); + var idx = _.findIndex($scope.$root.notebooks, function (item) { + return item._id == $scope.notebook._id; + }); + + if (idx >= 0) { + $scope.$root.notebooks.splice(idx, 1); + + if ($scope.$root.notebooks.length > 0) + $window.location = "/sql/" + + $scope.$root.notebooks[Math.min(idx, $scope.$root.notebooks.length - 1)]._id; + else + $scope.inputNotebookName(); + } }) .error(function (errMsg) { $common.showError(errMsg); @@ -101,6 +116,9 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http }; $scope.renameParagraph = function (paragraph, newName) { + if (!newName) + return; + if (paragraph.name != newName) { paragraph.name = newName; @@ -132,7 +150,15 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http $scope.notebook.paragraphs.push(paragraph); }; - $scope.removeParagraph = function (paragraph) { + $scope.setResult = function (paragraph, new_result) { + paragraph.result = paragraph.result === new_result ? '' : new_result; + }; + + $scope.resultEq = function(paragraph, result) { + return (paragraph.result === result); + }; + + $scope.removeParagraph = function(paragraph) { var paragraph_idx = _.findIndex($scope.notebook.paragraphs, function (item) { return paragraph == item; }); @@ -216,11 +242,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http $scope.explain = function (item) { _appendOnLast(item); - $http.post('/agent/query', { - query: 'EXPLAIN ' + item.query, - pageSize: item.pageSize, - cacheName: item.cache.name - }) + $http.post('/agent/query', {query: 'EXPLAIN ' + item.query, pageSize: item.pageSize, cacheName: item.cache.name}) .success(_processQueryResult(item)) .error(function (errMsg) { $common.showError(errMsg); @@ -237,12 +259,8 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http }); }; - $scope.nextPage = function (item) { - $http.post('/agent/query/fetch', { - queryId: item.queryId, - pageSize: item.pageSize, - cacheName: item.cache.name - }) + $scope.nextPage = function(item) { + $http.post('/agent/query/fetch', {queryId: item.queryId, pageSize: item.pageSize, cacheName: item.cache.name}) .success(function (res) { item.page++; http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/routes/notebooks.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/notebooks.js b/modules/control-center-web/src/main/js/routes/notebooks.js index f929821..9f5a5a8 100644 --- a/modules/control-center-web/src/main/js/routes/notebooks.js +++ b/modules/control-center-web/src/main/js/routes/notebooks.js @@ -20,6 +20,10 @@ var router = require('express').Router(); var db = require('../db'); var utils = require('./../helpers/common-utils'); +router.get('/new', function (req, res) { + res.render('templates/notebook-new', {}); +}); + /** * Get notebooks names accessed for user account. * @@ -111,12 +115,27 @@ router.post('/save', function (req, res) { }); /** + * Remove notebook by ._id. + * + * @param req Request. + * @param res Response. + */ +router.post('/remove', function (req, res) { + db.Notebook.remove(req.body, function (err) { + if (err) + return res.status(500).send(err.message); + + res.sendStatus(200); + }); +}); + +/** * Create new notebook for user account. * * @param req Request. * @param res Response. */ -router.get('/new', function (req, res) { +router.post('/new', function (req, res) { var user_id = req.currentUserId(); // Get owned space and all accessed space. @@ -124,13 +143,11 @@ router.get('/new', function (req, res) { if (err) return res.status(500).send(err.message); - var name = 'Notebook' + ' ' + utils.randomValueHex(8); - - (new db.Notebook({space: space.id, name: name, paragraphs: []})).save(function (err, notebook) { + (new db.Notebook({space: space.id, name: req.body.name, paragraphs: []})).save(function (err, note) { if (err) return res.status(500).send(err.message); - return res.redirect('/sql/' + notebook._id); + return res.send(note._id); }); }); }); http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/views/includes/header.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/includes/header.jade b/modules/control-center-web/src/main/js/views/includes/header.jade index 6e7b5ca..2c78d8f 100644 --- a/modules/control-center-web/src/main/js/views/includes/header.jade +++ b/modules/control-center-web/src/main/js/views/includes/header.jade @@ -32,7 +32,7 @@ header#header.header li(ng-controller='notebooks') a.dropdown-toggle(ng-hide='$root.notebooks.length == 0' ng-class='{active: isActive("/sql")}' data-toggle='dropdown' bs-dropdown='notebookDropdown' data-placement='bottom-right') SQL span.caret - a(ng-hide='$root.notebooks.length > 0' href='/notebooks/new') SQL + a(ng-hide='$root.notebooks.length > 0' ng-click='inputNotebookName()') SQL //+header-item('/deploy', '/deploy', 'Deploy') ul.nav.navbar-nav.pull-right li(ng-if='user') http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/views/sql/sql.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/sql/sql.jade b/modules/control-center-web/src/main/js/views/sql/sql.jade index 51dba89..a1fc76a 100644 --- a/modules/control-center-web/src/main/js/views/sql/sql.jade +++ b/modules/control-center-web/src/main/js/views/sql/sql.jade @@ -36,8 +36,8 @@ block container i.btn.btn-default.fa.fa-floppy-o(ng-click='saveNotebook()' bs-tooltip data-title='Save notebook' data-trigger='hover') i.btn.btn-default.fa.fa-remove(ng-click='removeNotebook()' bs-tooltip data-title='Remove notebook' data-trigger='hover') h1.col-sm-6(ng-show='notebook.edit') - input.sql-name-input(ng-model='notebook.edit_name' on-enter='renameNotebook(notebook.edit_name)' on-escape='notebook.edit = false;') - i.tipLabel.fa.fa-floppy-o(ng-click='renameNotebook(notebook.edit_name)' bs-tooltip data-title='Save notebook name' data-trigger='hover') + input.sql-name-input(ng-model='notebook.edit_name' required on-enter='renameNotebook(notebook.edit_name)' on-escape='notebook.edit = false;') + i.tipLabel.fa.fa-floppy-o(ng-show='notebook.edit_name' ng-click='renameNotebook(notebook.edit_name)' bs-tooltip data-title='Save notebook name' data-trigger='hover') h1.col-sm-6 i.tipField.fa.fa-plus(ng-click='addParagraph()' bs-tooltip data-title='Add new paragraph' data-trigger='hover') .docs-body(style='margin-top: 20px;') @@ -53,11 +53,11 @@ block container i.btn.btn-default.fa.fa-remove(ng-click='removeParagraph(paragraph)' bs-tooltip data-title='Remove paragraph' data-trigger='hover') .btn-group(ng-model='paragraph.result' ng-click='$event.stopPropagation();' style='float: right' ) - i.btn.btn-default.fa.fa-table(ng-click='paragraph.result="table"' ng-class="{'active': resultMode(paragraph, 'table')}" bs-tooltip data-title='Show table' data-trigger='hover') - i.btn.btn-default.fa.fa-bar-chart(ng-click='showBarChart(paragraph)' ng-class="{'active': resultMode(paragraph, 'bar')}" bs-tooltip data-title='Show bar chart' data-trigger='hover') + i.btn.btn-default.fa.fa-table(ng-click='setResult(paragraph, "table")' ng-class="{'active': resultEq(paragraph, 'table')}" bs-tooltip data-title='Show table' data-trigger='hover') + i.btn.btn-default.fa.fa-bar-chart(ng-click='showBarChart(paragraph)' ng-class="{'active': resultEq(paragraph, 'bar')}" bs-tooltip data-title='Show bar chart' data-trigger='hover') div(ng-show='paragraph.edit') - input.sql-name-input(ng-model='paragraph.edit_name' ng-click='$event.stopPropagation();' on-enter='renameParagraph(paragraph, paragraph.edit_name)' on-escape='renameParagraph(paragraph, paragraph.name)') - i.tipLabel.fa.fa-floppy-o(ng-click='renameParagraph(paragraph, paragraph.edit_name); $event.stopPropagation();' bs-tooltip data-title='Save paragraph name' data-trigger='hover') + input.sql-name-input(ng-model='paragraph.edit_name' required ng-click='$event.stopPropagation();' on-enter='renameParagraph(paragraph, paragraph.edit_name)' on-escape='paragraph.edit = false') + i.tipLabel.fa.fa-floppy-o(ng-show='paragraph.edit_name' ng-click='renameParagraph(paragraph, paragraph.edit_name); $event.stopPropagation();' bs-tooltip data-title='Save paragraph name' data-trigger='hover') .panel-collapse(role='tabpanel' bs-collapse-target) .panel-body(ng-show='paragraph.editor') .row @@ -83,7 +83,7 @@ block container .pull-right label Page Size: button.btn.btn-default.base-control(ng-model='paragraph.pageSize' bs-options='item for item in pageSizes' bs-select) - .panel-body(ng-show='paragraph.result === "table"') + .panel-body(ng-show='paragraph.result === "table" && !paragraph.rows') .row .col-sm-8 lable Page #: @@ -111,4 +111,3 @@ block container label Bar chart #chart svg - http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/views/templates/copy.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/templates/copy.jade b/modules/control-center-web/src/main/js/views/templates/copy.jade index 8e21ded..9ccd3b6 100644 --- a/modules/control-center-web/src/main/js/views/templates/copy.jade +++ b/modules/control-center-web/src/main/js/views/templates/copy.jade @@ -23,7 +23,7 @@ form.form-horizontal(name='ui.inputForm' novalidate) .modal-body.row .col-sm-9.login.col-sm-offset-1 - label.required.labelFormField() New name: + label.required.labelFormField New name: .col-sm-9 input.form-control(id='copy-new-name' type='text' ng-model='newName' required) .modal-footer http://git-wip-us.apache.org/repos/asf/ignite/blob/43360182/modules/control-center-web/src/main/js/views/templates/notebook-new.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/templates/notebook-new.jade b/modules/control-center-web/src/main/js/views/templates/notebook-new.jade new file mode 100644 index 0000000..368998d --- /dev/null +++ b/modules/control-center-web/src/main/js/views/templates/notebook-new.jade @@ -0,0 +1,31 @@ +//- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +.modal(tabindex='-1' role='dialog') + .modal-dialog + .modal-content + .modal-header + button.close(type='button' ng-click='$hide()') × + h4.modal-title New notebook + form.form-horizontal(name='ui.inputForm' novalidate) + .modal-body.row + .col-sm-9.login.col-sm-offset-1 + label.required.labelFormField Name: + .col-sm-9 + input.form-control(id='create-notebook' type='text' ng-model='name' required) + .modal-footer + button.btn.btn-default(id='copy-btn-cancel' type='button' ng-click='$hide()') Cancel + button.btn.btn-primary(id='copy-btn-confirm' type='button' ng-disabled='ui.inputForm.$invalid' ng-click='createNewNotebook(name)') Create
