You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by an...@apache.org on 2015/08/20 05:41:08 UTC

incubator-ignite git commit: # IGNITE-843 Rename rest.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 8a4334838 -> a9af67435


# IGNITE-843 Rename rest.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/a9af6743
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a9af6743
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a9af6743

Branch: refs/heads/ignite-843
Commit: a9af6743599e04ea7b5fac6c70f3f5ccdd55cfaa
Parents: 8a43348
Author: Andrey <an...@gridgain.com>
Authored: Thu Aug 20 10:41:07 2015 +0700
Committer: Andrey <an...@gridgain.com>
Committed: Thu Aug 20 10:41:07 2015 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/common-module.js    | 51 +++++++++++---------
 .../main/js/controllers/profile-controller.js   |  4 +-
 .../src/main/js/controllers/sql-controller.js   | 34 +++++++++++--
 .../src/main/js/public/stylesheets/style.scss   |  8 +++
 .../src/main/js/routes/agent.js                 |  4 +-
 .../src/main/js/routes/notebooks.js             | 39 +++++++++++++--
 .../src/main/js/routes/profile.js               | 13 +----
 .../src/main/js/routes/public.js                | 10 ++--
 .../src/main/js/views/includes/header.jade      |  6 +--
 .../src/main/js/views/login.jade                | 14 +++---
 .../src/main/js/views/sql/sql.jade              | 10 ++--
 11 files changed, 128 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/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 d30292f..674940f 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
@@ -1100,7 +1100,7 @@ controlCenterModule.controller('auth', [
                     if (status == 403) {
                         loginModal.hide();
 
-                        $window.location = '/reset';
+                        $window.location = '/password/reset';
                     }
                     else
                         $common.showError(data, 'top', '#errors-container');
@@ -1109,7 +1109,7 @@ controlCenterModule.controller('auth', [
 
         // Try to reset user password for provided token.
         $scope.resetPassword = function (reset_info) {
-            $http.post('/reset_password', reset_info)
+            $http.post('/password/reset', reset_info)
                 .success(function (data) {
                     $scope.user_info = {email: data};
                     $scope.login();
@@ -1129,7 +1129,7 @@ controlCenterModule.controller('auth', [
 controlCenterModule.controller('agent-download', [
     '$scope', '$modal', function ($scope, $modal) {
         // Pre-fetch modal dialogs.
-        var _agentDownloadModal = $modal({scope: $scope, templateUrl: '/agent/agent-download', show: false});
+        var _agentDownloadModal = $modal({scope: $scope, templateUrl: '/agent/download', show: false});
 
         $scope.downloadAgent = function () {
             _agentDownloadModal.hide();
@@ -1152,31 +1152,36 @@ controlCenterModule.controller('agent-download', [
 }]);
 
 // Navigation bar controller.
-controlCenterModule.controller('notebooks', [
-    '$scope', '$http', '$common', function ($scope, $http, $common) {
-        $scope.notebooks = [];
+controlCenterModule.controller('notebooks', ['$scope', '$http', '$common', function ($scope, $http, $common) {
+    $scope.$root.notebooks = [];
 
+    $scope.$root.rebuildDropdown = function () {
+        $scope.notebookDropdown = [
+            {text: 'Create new notebook', href: '/notebooks/new', target: '_self'},
+            {divider: true}
+        ];
+
+        _.forEach($scope.$root.notebooks, function (notebook) {
+            $scope.notebookDropdown.push({
+                text: notebook.name,
+                href: '/sql/' + notebook._id,
+                target: '_self'
+            });
+        });
+    };
+
+    $scope.$root.reloadNotebooks = function () {
         // When landing on the page, get clusters and show them.
         $http.post('/notebooks/list')
             .success(function (data) {
-                $scope.notebooks = data;
-
-                if ($scope.notebooks.length > 0) {
-                    $scope.notebookDropdown = [
-                        {text: 'Create new notebook', href: '/notebooks/new', target: '_self'},
-                        {divider: true}
-                    ];
-
-                    _.forEach($scope.notebooks, function (notebook) {
-                        $scope.notebookDropdown.push({
-                            text: notebook.name,
-                            href: '/sql/' + notebook._id,
-                            target: '_self'
-                        });
-                    });
-                }
+                $scope.$root.notebooks = data;
+
+                $scope.$root.rebuildDropdown();
             })
             .error(function (errMsg) {
                 $common.showError(errMsg);
             });
-    }]);
+    };
+
+    $scope.$root.reloadNotebooks();
+}]);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/controllers/profile-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/profile-controller.js b/modules/control-center-web/src/main/js/controllers/profile-controller.js
index a67df63..6b4c9ed 100644
--- a/modules/control-center-web/src/main/js/controllers/profile-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/profile-controller.js
@@ -29,7 +29,7 @@ controlCenterModule.controller('profileController', ['$scope', '$http', '$common
             var changeEmail = email != $scope.user.email;
 
             if (changeUsername || changeEmail || profile.changePassword) {
-                $http.post('/profile/saveUser', {
+                $http.post('/profile/save', {
                     _id: profile._id,
                     userName: changeUsername ? userName : undefined,
                     email: changeEmail ? email : undefined,
@@ -48,4 +48,4 @@ controlCenterModule.controller('profileController', ['$scope', '$http', '$common
             }
         }
     };
-}]);
\ No newline at end of file
+}]);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/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 8ef5bff..9687b01 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
@@ -18,7 +18,6 @@
 controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http', '$common',
     function ($scope, $controller, $http, $common) {
     // Initialize the super class and extend it.
-    angular.extend(this, $controller('notebooks', {$scope: $scope}));
     angular.extend(this, $controller('agent-download', {$scope: $scope}));
 
     $scope.joinTip = $common.joinTip;
@@ -32,7 +31,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http
     ];
 
     var loadNotebook = function() {
-        $http.post('/notebooks/get', {nodeId: $scope.nodeId})
+        $http.post('/notebooks/get', {noteId: $scope.noteId})
             .success(function (notebook) {
                 $scope.notebook = notebook;
             })
@@ -43,6 +42,28 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http
 
     loadNotebook();
 
+    $scope.saveNotebook = function(notebook) {
+        $scope.notebook_edit = false;
+
+        $http.post('/notebooks/save', notebook)
+            .success(function () {
+                var idx = _.findIndex($scope.$root.notebooks, function (item) {
+                    return item._id == notebook._id;
+                });
+
+                if (idx >= 0) {
+                    $scope.$root.notebooks[idx].name = $scope.notebook.name;
+
+                    $scope.$root.rebuildDropdown();
+                }
+            })
+            .error(function (errMsg) {
+                $common.showError(errMsg);
+
+                loadNotebook();
+            });
+    };
+
     $scope.addParagraph = function(notebook) {
         notebook.paragraphs.push({});
     };
@@ -82,10 +103,13 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http
             if ($scope.tabs.length == 0)
                 $scope.addTab();
         })
-        .error(function (errMsg) {
+        .error(function (err, status) {
             $scope.caches = undefined;
 
-            $scope.showDownloadAgent();
+            if (status == 503)
+                $scope.showDownloadAgent();
+            else
+                $common.showError('Receive agent error: ' + err);
         });
 
     $scope.execute = function(tab) {
@@ -131,7 +155,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$controller', '$http
     };
 
     $scope.nextPage = function(tab) {
-        $http.post('/agent/query_fetch', {queryId: tab.queryId, pageSize: tab.pageSize, cacheName: tab.selectedItem.name})
+        $http.post('/agent/query/fetch', {queryId: tab.queryId, pageSize: tab.pageSize, cacheName: tab.selectedItem.name})
             .success(function (res) {
                 tab.page++;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/public/stylesheets/style.scss
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/public/stylesheets/style.scss b/modules/control-center-web/src/main/js/public/stylesheets/style.scss
index 8447a9a..89f1667 100644
--- a/modules/control-center-web/src/main/js/public/stylesheets/style.scss
+++ b/modules/control-center-web/src/main/js/public/stylesheets/style.scss
@@ -685,6 +685,14 @@ button .caret, .btn .caret {
     }
 }
 
+.form-control-h1 {
+    @extend .form-control;
+
+    width: auto;
+    font-size: 22px;
+    height: 44px;
+}
+
 .line-control {
     width: auto;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/routes/agent.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/agent.js b/modules/control-center-web/src/main/js/routes/agent.js
index 342675d..2796625 100644
--- a/modules/control-center-web/src/main/js/routes/agent.js
+++ b/modules/control-center-web/src/main/js/routes/agent.js
@@ -34,7 +34,7 @@ function _client(req, res) {
 }
 
 /* Get grid topology. */
-router.get('/agent-download', function (req, res) {
+router.get('/download', function (req, res) {
     res.render('templates/agent-download');
 });
 
@@ -78,7 +78,7 @@ router.post('/query', function (req, res) {
 });
 
 /* Get next query page. */
-router.post('/query_fetch', function (req, res) {
+router.post('/query/fetch', function (req, res) {
     var client = _client(req, res);
 
     if (client) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/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 0c37d85..ed6fef1 100644
--- a/modules/control-center-web/src/main/js/routes/notebooks.js
+++ b/modules/control-center-web/src/main/js/routes/notebooks.js
@@ -16,7 +16,6 @@
  */
 
 var router = require('express').Router();
-var crypto = require('crypto');
 var db = require('../db');
 
 /**
@@ -66,7 +65,7 @@ router.post('/get', function (req, res) {
         });
 
         // Get all metadata for spaces.
-        db.Notebook.findOne({$or: [{space: {$in: space_ids}}, {_id: req.body.noteId}]}).exec(function (err, notebook) {
+        db.Notebook.findOne({space: {$in: space_ids}, _id: req.body.noteId}).exec(function (err, notebook) {
             if (err)
                 return res.status(500).send(err.message);
 
@@ -75,8 +74,42 @@ router.post('/get', function (req, res) {
     });
 });
 
+/**
+ * Save notebook accessed for user account.
+ *
+ * @param req Request.
+ * @param res Response.
+ */
+router.post('/save', function (req, res) {
+    var note = req.body;
+    var noteId = note._id;
+
+    if (noteId)
+        db.Notebook.update({_id: noteId}, note, {upsert: true}, function (err) {
+            if (err)
+                return res.status(500).send(err.message);
+
+            res.send(noteId);
+        });
+    else
+        db.Notebook.findOne({space: note.space, name: note.name}, function (err, note) {
+            if (err)
+                return res.status(500).send(err.message);
+
+            if (note)
+                return res.status(500).send('Notebook with name: "' + note.name + '" already exist.');
+
+            (new db.Notebook(req.body)).save(function (err, note) {
+                if (err)
+                    return res.status(500).send(err.message);
+
+                res.send(note._id);
+            });
+        });
+});
+
 function _randomValueHex(len) {
-    return crypto.randomBytes(Math.ceil(len / 2))
+    return require('crypto').randomBytes(Math.ceil(len / 2))
         .toString('hex') // convert to hexadecimal format
         .slice(0, len);  // return required number of characters
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/profile.js b/modules/control-center-web/src/main/js/routes/profile.js
index 0269e7d..bc73671 100644
--- a/modules/control-center-web/src/main/js/routes/profile.js
+++ b/modules/control-center-web/src/main/js/routes/profile.js
@@ -18,15 +18,6 @@
 var router = require('express').Router();
 var db = require('../db');
 
-router.all('/profile/*', function (req, res, next) {
-    var userId = req.body._id;
-
-    if (userId != req.currentUserId() && userId != req.user._id)
-        return res.sendStatus(403);
-    else
-        next();
-});
-
 /**
  * Get user profile page.
  */
@@ -44,7 +35,7 @@ router.get('/', function (req, res) {
 /**
  * Save user profile.
  */
-router.post('/saveUser', function (req, res) {
+router.post('/save', function (req, res) {
     var params = req.body;
 
     if (params.newPassword) {
@@ -94,4 +85,4 @@ router.post('/saveUser', function (req, res) {
     }
 });
 
-module.exports = router;
\ No newline at end of file
+module.exports = router;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/routes/public.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/public.js b/modules/control-center-web/src/main/js/routes/public.js
index e29c7e6..7f4fb8a 100644
--- a/modules/control-center-web/src/main/js/routes/public.js
+++ b/modules/control-center-web/src/main/js/routes/public.js
@@ -114,7 +114,7 @@ router.get('/logout', function (req, res) {
 /**
  * Send e-mail to user with reset token.
  */
-router.post('/forgot_password', function(req, res) {
+router.post('/password/forgot', function(req, res) {
     var transporter = {
         service: config.get('smtp:service'),
         auth: {
@@ -169,7 +169,7 @@ router.post('/forgot_password', function(req, res) {
 /**
  * Change password with given token.
  */
-router.post('/reset_password', function(req, res) {
+router.post('/password/reset', function(req, res) {
     db.Account.findOne({ resetPasswordToken: req.body.token }, function(err, user) {
         if (!user)
             return res.status(500).send('Invalid token for password reset!');
@@ -219,12 +219,12 @@ router.post('/reset_password', function(req, res) {
     });
 });
 
-router.get('/reset', function (req, res) {
-    res.render('reset', {});
+router.get('/password/reset', function (req, res) {
+    res.render('reset');
 });
 
 /* GET reset password page. */
-router.get('/reset/:token', function (req, res) {
+router.get('/password/reset/:token', function (req, res) {
     var token = req.params.token;
 
     var data = {token: token};

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/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 1e200f3..35b946f 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
@@ -30,13 +30,13 @@ header#header.header
                 +header-item('/configuration', '/configuration/clusters', 'Configuration')
                 //+header-item('/monitoring', '/monitoring', 'Monitoring')
                 li(ng-controller='notebooks')
-                    a.dropdown-toggle(ng-hide='notebooks.length == 0' ng-class='{active: isActive("/sql")}' data-toggle='dropdown' bs-dropdown='notebookDropdown' data-placement='bottom-right') SQL
+                    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='notebooks.length > 0' href='/notebooks/new') SQL
+                    a(ng-hide='$root.notebooks.length > 0' href='/notebooks/new') SQL
                 //+header-item('/deploy', '/deploy', 'Deploy')
             ul.nav.navbar-nav.pull-right
                 li(ng-if='user')
-                    a.dropdown-toggle(data-toggle='dropdown' bs-dropdown='userDropdown' data-placement='bottom-right') {{::user.username}}
+                    a.dropdown-toggle(data-toggle='dropdown' bs-dropdown='userDropdown' data-placement='bottom-right') {{user.username}}
                         span.caret
                 li.nav-login(ng-if='!user')
                     a(ng-click='login()') Log In

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/modules/control-center-web/src/main/js/views/login.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/login.jade b/modules/control-center-web/src/main/js/views/login.jade
index ddc5c05..175e03e 100644
--- a/modules/control-center-web/src/main/js/views/login.jade
+++ b/modules/control-center-web/src/main/js/views/login.jade
@@ -29,7 +29,7 @@ mixin lbl(txt)
             form.form-horizontal(name='loginForm' ng-init='action == "login"')
                 .modal-body.row
                     .col-sm-10.col-sm-offset-1
-                        p(ng-show='action == "forgot_password"')
+                        p(ng-show='action == "password/forgot"')
                             | That's ok! Simply enter your email below and a reset password link will be sent to you via email. You can then follow that link and select a new password.
                         .details-row(ng-show='action == "register"')
                             +lbl('Full Name:')
@@ -38,25 +38,25 @@ mixin lbl(txt)
                         .details-row
                             +lbl('Email:')
                             .col-sm-9
-                                input#user_email.form-control(enter-focus-next='user_password' type='email' ng-model='user_info.email' placeholder='you@domain.com' required on-enter='action == "forgot_password" && loginForm.$valid && auth(action, user_info)')
-                        .details-row(ng-show='action != "forgot_password"')
+                                input#user_email.form-control(enter-focus-next='user_password' type='email' ng-model='user_info.email' placeholder='you@domain.com' required on-enter='action == "password/forgot" && loginForm.$valid && auth(action, user_info)')
+                        .details-row(ng-show='action != "password/forgot"')
                             +lbl('Password:')
                             .col-sm-9
-                                input#user_password.form-control(enter-focus-next='user_confirm' type='password' ng-model='user_info.password' placeholder='Password' ng-required='action != "forgot_password"' on-enter='action == "login" && loginForm.$valid && auth(action, user_info)')
+                                input#user_password.form-control(enter-focus-next='user_confirm' type='password' ng-model='user_info.password' placeholder='Password' ng-required='action != "password/forgot"' on-enter='action == "login" && loginForm.$valid && auth(action, user_info)')
                         .details-row(ng-if='action == "register"')
                             +lbl('Confirm:')
                             .col-sm-9
                                 input#user_confirm.form-control(type='password' ng-model='user_info.confirm' match='user_info.password' placeholder='Confirm password' ng-required='action == "register"' on-enter='loginForm.$valid && auth(action, user_info)')
             .modal-footer(ng-show='action == "register"')
-                a.labelField(ng-click='action = "forgot_password"' on-click-focus='user_email') Forgot password?
+                a.labelField(ng-click='action = "password/forgot"' on-click-focus='user_email') Forgot password?
                 a.labelLogin(ng-click='action = "login"' on-click-focus='user_email') Log In
                 button.btn.btn-primary(ng-click='auth(action, user_info)' ng-disabled='loginForm.$invalid') Sign Up
 
-            .modal-footer(ng-show='action == "forgot_password"')
+            .modal-footer(ng-show='action == "password/forgot"')
                 a.labelField(ng-click='action = "login"' on-click-focus='user_email') Log In
                 button.btn.btn-primary(ng-click='auth(action, user_info)' ng-disabled='loginForm.$invalid') Send it to me
 
             .modal-footer(ng-show='action == "login"')
-                a.labelField(ng-click='action = "forgot_password"' on-click-focus='user_email') Forgot password?
+                a.labelField(ng-click='action = "password/forgot"' on-click-focus='user_email') Forgot password?
                 a.labelLogin(ng-click='action = "register"' on-click-focus='user_name') Sign Up
                 button.btn.btn-primary(ng-click='auth(action, user_info)' ng-disabled='loginForm.$invalid') Log In

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a9af6743/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 c214ef5..b4f59c5 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
@@ -23,12 +23,14 @@ append scripts
 
 block container
     .row
-        .col-sm-12
-            .docs-content
+        .col-sm-12(ng-init='noteId = "#{noteId}";')
+            .docs-content(ng-controller='sqlController' )
                 .docs-header
-                    h1 Connect to Ignite and Execute SQL Queries
+                    h1
+                        a(ng-hide='notebook_edit' ng-click='notebook_edit = true;' style='line-height: 44px;') {{notebook.name}}
+                        input.form-control-h1(ng-show='notebook_edit' on-enter='saveNotebook(notebook)' ng-model='notebook.name')
                     hr
-                .docs-body(ng-controller='sqlController' ng-init='noteId = #{JSON.stringify(noteId)};')
+                .docs-body
                     div(ng-if='!caches')
                         .block-callout-right.margin-bottom-dflt(style='width: 100%')
                             p(ng-bind-html='joinTip(missingClientTip)')