ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject incubator-ignite git commit: # 843 WIP Login page.
Date Wed, 27 May 2015 04:47:37 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 c92da1671 -> 2a8445dee


# 843 WIP Login page.


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

Branch: refs/heads/ignite-843
Commit: 2a8445dee324ab274ee7492a493b742a22d179e7
Parents: c92da16
Author: Andrey <anovikov@gridgain.com>
Authored: Wed May 27 11:19:42 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Wed May 27 11:19:42 2015 +0700

----------------------------------------------------------------------
 modules/webconfig/nodejs/db.js                  |  16 +-
 .../public/javascripts/controllers/clusters.js  | 217 +++++++++----------
 .../public/javascripts/controllers/common.js    |   8 +-
 modules/webconfig/nodejs/routes/auth.js         |  52 +++--
 modules/webconfig/nodejs/routes/clusters.js     |  80 +++----
 modules/webconfig/nodejs/views/clusters.jade    |   2 +-
 6 files changed, 203 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/db.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/db.js b/modules/webconfig/nodejs/db.js
index b6cbf43..89ced0f 100644
--- a/modules/webconfig/nodejs/db.js
+++ b/modules/webconfig/nodejs/db.js
@@ -6,10 +6,10 @@ var mongoose = require('mongoose'),
     ObjectId = mongoose.Schema.Types.ObjectId,
     passportLocalMongoose = require('passport-local-mongoose');
 
-// Connect to mongoDB database on modulus.io.
+// Connect to mongoDB database.
 mongoose.connect(config.get('mongoDB:url'), {server: {poolSize: 4}});
 
-// Define user model.
+// Define account model.
 var AccountSchema = new Schema({
     username: String
 });
@@ -44,3 +44,15 @@ exports.Cache =  mongoose.model('Cache', new Schema({
     backups: Number,
     clusters: [{ type: ObjectId, ref: 'Cluster' }]
 }));
+
+exports.upsert = function(model, data, cb){
+    if (data._id) {
+        var id = data._id;
+
+        delete data._id;
+
+        model.findOneAndUpdate({_id: id}, data, cb);
+    }
+    else
+        model.create(data, cb);
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
index 36a04e4..0884109 100644
--- a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js
@@ -1,130 +1,129 @@
-configuratorModule.controller('clustersController',
-    ['$scope', '$modal', '$http', '$filter', 'ngTableParams',
-        function ($scope, $modal, $http, $filter, ngTableParams) {
-            $scope.edit = {};
-            $scope.editRow = {};
-            $scope.editIdx = false;
-
-            $scope.discoveries = [
-                {value: 'TcpDiscoveryVmIpFinder', label: 'Static IPs'},
-                {value: 'TcpDiscoveryMulticastIpFinder', label: 'Multicast'}
-            ];
-
-            $scope.discoveryAsString = function (value) {
-                for (var i in $scope.discoveries) {
-                    if ($scope.discoveries[i].value == value)
-                        return $scope.discoveries[i].label;
-                }
-
-                return 'Wrong discovery';
-            };
-
-            // When landing on the page, get clusters and show them.
-            $http.get('/rest/clusters')
-                .success(function (data) {
-                    $scope.clusters = data;
-
-                    $scope.clustersTable = new ngTableParams({
-                        page: 1,                    // Show first page.
-                        count: Number.MAX_VALUE,    // Count per page.
-                        sorting: {name: 'asc'}      // Initial sorting.
-                    }, {
-                        total: $scope.clusters.length, // Length of data.
-                        counts: [],
-                        getData: function ($defer, params) {
-                            // Use build-in angular filter.
-                            var orderedData = params.sorting() ?
-                                $filter('orderBy')($scope.clusters, params.orderBy()) :
-                                $scope.clusters;
-
-                            var page = params.page();
-                            var cnt = params.count();
-                            $defer.resolve(orderedData.slice(page - 1 * cnt, page * cnt));
-                        }
-                    });
-                })
-                .error(function (data) {
-                    $scope.text = data;
-                });
+configuratorModule.controller('clustersController', [ '$scope', '$modal', '$http', '$filter',
'ngTableParams',
+    function ($scope, $modal, $http, $filter, ngTableParams) {
+        $scope.edit = {};
+        $scope.editRow = {};
+        $scope.editIdx = false;
+
+        $scope.discoveries = [
+            {value: 'TcpDiscoveryVmIpFinder', label: 'Static IPs'},
+            {value: 'TcpDiscoveryMulticastIpFinder', label: 'Multicast'}
+        ];
+
+        $scope.discoveryAsString = function (value) {
+            for (var i in $scope.discoveries) {
+                if ($scope.discoveries[i].value == value)
+                    return $scope.discoveries[i].label;
+            }
 
-            // Create popup for discovery advanced settings.
-            var discoveryModal = $modal({scope: $scope, template: '/discovery', show: false});
+            return 'Wrong discovery';
+        };
+
+        // When landing on the page, get clusters and show them.
+        $http.get('/rest/clusters')
+            .success(function (data) {
+                $scope.spaces = data.spaces;
+                $scope.clusters = data.clusters;
+
+                $scope.clustersTable = new ngTableParams({
+                    page: 1,                    // Show first page.
+                    count: Number.MAX_VALUE,    // Count per page.
+                    sorting: {name: 'asc'}     // Initial sorting.
+                }, {
+                    total: $scope.clusters.length, // Length of data.
+                    counts: [],
+                    getData: function ($defer, params) {
+                        // Use build-in angular filter.
+                        var orderedData = params.sorting() ?
+                            $filter('orderBy')($scope.clusters, params.orderBy()) :
+                            $scope.clusters;
+
+                        var page = params.page();
+                        var cnt = params.count();
+
+                        $defer.resolve(orderedData.slice(page - 1 * cnt, page * cnt));
+                    }
+                });
+            });
 
-            $scope.editDiscovery = function (cluster) {
-                console.log('>>> editDiscovery');
+        // Create popup for discovery advanced settings.
+        var discoveryModal = $modal({scope: $scope, template: '/discovery', show: false});
 
-                discoveryModal.$promise.then(discoveryModal.show);
-            }
+        $scope.editDiscovery = function (cluster) {
+            discoveryModal.$promise.then(discoveryModal.show);
+        };
 
-            $scope.submit = function () {
-                if ($scope.editIdx !== false) {
-                    var cluster = $scope.clusters[$scope.editIdx];
+        $scope.submit = function () {
+            if ($scope.editIdx !== false) {
+                console.log($scope.$data);
 
-                    var data = {
-                        _id: cluster._id,
-                        name: cluster.name,
-                        discovery: cluster.discovery,
-                        addresses: ['127.0.0.1', '192.168.1.1']
-                    };
+                var cluster = $scope.clusters[$scope.editIdx];
 
-                    $scope.editIdx = false;
+                var data = {
+                    _id: cluster._id,
+                    space: cluster.space,
+                    name: cluster.name,
+                    discovery: cluster.discovery,
+                    addresses: ['127.0.0.1', '192.168.1.1']
+                };
 
-                    $http.post('/rest/clusters/save', data)
-                        .success(function (data) {
-                            myOtherModal.hide();
+                $scope.editIdx = false;
 
-                            $scope.clusters = data;
+                $http.post('/rest/clusters/save', data)
+                    .success(function (data) {
+                        myOtherModal.hide();
 
-                            $scope.clustersTable.reload();
-                        })
-                        .error(function (data) {
-                            console.log('Error: ' + data);
-                        });
-                }
-            };
+                        $scope.spaces = data.spaces;
+                        $scope.clusters = data.clusters;
 
-            // Add new cluster.
-            $scope.add = function () {
-//                $scope.clusters.push({name: 'Cluster', discovery: 'TcpDiscoveryVmIpFinder'});
-                $scope.clusters.push({});
+                        $scope.clustersTable.reload();
+                    })
+                    .error(function (errorMessage) {
+                        console.log('Error: ' + errorMessage);
+                    });
+            }
+        };
 
-                $scope.clustersTable.reload();
+        // Add new cluster.
+        $scope.add = function () {
+            // $scope.clusters.push({name: 'Cluster', discovery: 'TcpDiscoveryVmIpFinder'});
+            $scope.clusters.push({space: $scope.spaces[0]._id});
 
-                // Show when some event occurs (use $promise property to ensure the template
has been loaded)
-                //myOtherModal.$promise.then(myOtherModal.show);
-            };
+            $scope.clustersTable.reload();
+        };
 
-            $scope.beginEdit = function (cluster) {
-                $scope.editIdx = $scope.clusters.indexOf(cluster);
+        $scope.beginEdit = function (cluster) {
+            $scope.editIdx = $scope.clusters.indexOf(cluster);
 
-                $scope.editRow = angular.copy(cluster);
+            $scope.editRow = angular.copy(cluster);
 
-                //// Show when some event occurs (use $promise property to ensure the template
has been loaded)
-                //myOtherModal.$promise.then(myOtherModal.show);
-            };
+            //// Show when some event occurs (use $promise property to ensure the template
has been loaded)
+            //myOtherModal.$promise.then(myOtherModal.show);
+        };
 
-            $scope.revert = function () {
-                if ($scope.editIdx !== false) {
-                    $scope.clusters[$scope.editIdx] = $scope.editRow;
+        $scope.revert = function () {
+            if ($scope.editIdx !== false) {
+                $scope.clusters[$scope.editIdx] = $scope.editRow;
 
-                    $scope.editIdx = false;
+                $scope.editIdx = false;
 
-                    $scope.clustersTable.reload();
-                }
+                $scope.clustersTable.reload();
+            }
 
-                //// Show when some event occurs (use $promise property to ensure the template
has been loaded)
-                //myOtherModal.$promise.then(myOtherModal.show);
-            };
+            //// Show when some event occurs (use $promise property to ensure the template
has been loaded)
+            //myOtherModal.$promise.then(myOtherModal.show);
+        };
 
-            $scope.delete = function (cluster) {
-                $http.post('/rest/clusters/remove', {_id: cluster._id})
-                    .success(function (data) {
-                        $scope.clusters = data;
+        $scope.delete = function (cluster) {
+            $http.post('/rest/clusters/remove', {_id: cluster._id})
+                .success(function (data) {
+                    $scope.spaces = data.spaces;
+                    $scope.clusters = data.clusters;
 
-                        $scope.clustersTable.reload();
-                    })
-                    .error(function (data) {
-                        console.log('Error: ' + data);
-                    });
-            };
-        }]);
\ No newline at end of file
+                    $scope.clustersTable.reload();
+                })
+                .error(function (errorMessage) {
+                    console.log('Error: ' + errorMessage);
+                });
+        };
+    }]
+);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/public/javascripts/controllers/common.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/common.js b/modules/webconfig/nodejs/public/javascripts/controllers/common.js
index 5f91d7e..3a9ef07 100644
--- a/modules/webconfig/nodejs/public/javascripts/controllers/common.js
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/common.js
@@ -6,7 +6,7 @@ configuratorModule.controller('activeLink', ['$scope', function($scope) {
     };
 }]);
 
-configuratorModule.controller('auth', ['$scope', '$modal', '$http', function($scope, $modal,
$http) {
+configuratorModule.controller('auth', ['$scope', '$modal', '$http', '$window', function($scope,
$modal, $http, $window) {
     $scope.action = 'login';
 
     $scope.errorMessage = '';
@@ -24,13 +24,11 @@ configuratorModule.controller('auth', ['$scope', '$modal', '$http', function($sc
     $scope.auth = function(action, user_info) {
         $http.post('/rest/auth/' + action, user_info)
             .success(function(data) {
-                console.log(data);
-
                 authModal.hide();
+
+                $window.location = '/clusters';
             })
             .error(function (data) {
-                console.log(data);
-
                 $scope.errorMessage = data;
             });
     };

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/routes/auth.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/routes/auth.js b/modules/webconfig/nodejs/routes/auth.js
index 9efa48a..41be291 100644
--- a/modules/webconfig/nodejs/routes/auth.js
+++ b/modules/webconfig/nodejs/routes/auth.js
@@ -3,37 +3,53 @@ var router = require('express').Router();
 
 var db = require('../db');
 
-var loginCallback = function(req, res, next) {
-    return function(err, user) {
+/**
+ * Register new account.
+ */
+router.post('/register', function(req, res, next) {
+    db.Account.register(new db.Account(req.body), req.body.password, function(err, account)
{
         if (err)
-            return res.status(400).send(err.message);
+            return res.status(401).send(err.message);
 
-        if (!user)
-            return res.status(400).send('Account with this email not exist.');
+        if (!account)
+            return res.status(500).send('Failed to create account.');
 
-        req.logIn(user, {}, function(err) {
+        new db.Space({name: 'Personal space', owner: account._id}).create();
+
+        req.logIn(account, {}, function(err) {
             if (err)
-                return res.status(400).send(err.message);
+                return res.status(401).send(err.message);
 
-            res.redirect('/clusters');
+            return res.redirect('/clusters');
         });
-    };
-};
-
-router.post('/register', function(req, res, next) {
-    var account = new db.Account(req.body);
-
-    db.Account.register(account, req.body.password, loginCallback(req, res, next));
+    });
 });
 
+/**
+ * Login in exist account.
+ */
 router.post('/login', function(req, res, next) {
-    passport.authenticate('local', loginCallback(req, res, next))(req, res, next);
+    passport.authenticate('local', function(err, user) {
+        if (err)
+            return res.status(401).send(err.message);
+
+        if (!user)
+            return res.status(401).send('Account with this email not exist.');
+
+        req.logIn(user, {}, function(err) {
+            if (err)
+                return res.status(401).send(err.message);
+
+            res.redirect('/clusters');
+        });
+    })(req, res, next);
 });
 
+/**
+ * Logout.
+ */
 router.get('/logout', function(req, res) {
     req.logout();
-
-    res.redirect('/');
 });
 
 module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/routes/clusters.js b/modules/webconfig/nodejs/routes/clusters.js
index ea85232..d82fbea 100644
--- a/modules/webconfig/nodejs/routes/clusters.js
+++ b/modules/webconfig/nodejs/routes/clusters.js
@@ -1,56 +1,62 @@
-var express = require('express');
-
-var router = express.Router();
-
+var router = require('express').Router();
 var db = require('../db');
 
-function selectAll(user_id, res) {
-    db.Cluster.find(function(err, clusters) {
-        // if there is an error retrieving, send the error. nothing after res.send(err) will
execute
+/**
+ * Send spaces and clusters accessed for user account.
+ *
+ * @param req Request.
+ * @param res Response.
+ */
+function selectAll(req, res) {
+    var user_id = req.user._id;
+
+    // Get owned space and all accessed space.
+    db.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]},
function (err, spaces) {
         if (err)
-            res.send(err);
-        else
-            res.json(clusters); // return all clusters in JSON format
+            return res.status(500).send(err);
+
+        var space_ids = spaces.map(function(value, index) {
+            return value._id;
+        });
+
+        // Get all clusters for spaces.
+        db.Cluster.find({space: {$in: space_ids}}, function (err, clusters) {
+            if (err)
+                return res.status(500).send(err);
+
+            res.json({spaces: spaces, clusters: clusters});
+        });
     });
 }
 
+/**
+ * Get spaces and clusters accessed for user account.
+ */
 router.get('/', function(req, res) {
-    var user = req.session.user;
-
-    selectAll(user, res);
+    selectAll(req, res);
 });
 
+/**
+ * Save cluster.
+ */
 router.post('/save', function(req, res) {
-    if (req.body._id) {
-        var clusterId = req.body._id;
-
-        delete req.body._id;
-
-        db.Cluster.findByIdAndUpdate(clusterId, req.body, null, function(err) {
-            if (err)
-                res.send(err);
-            else
-                selectAll(res);
-        });
-    }
-    else {
-        var cluster = new db.Cluster(req.body);
+    db.upsert(db.Cluster, req.body, function(err) {
+        if (err)
+            return res.status(500).send(err);
 
-        cluster.save(function (err) {
-            if (err)
-                res.send(err);
-            else
-                selectAll(res);
-        });
-    }
+        selectAll(req, res);
+    });
 });
 
+/**
+ * Remove cluster by ._id.
+ */
 router.post('/remove', function(req, res) {
     db.Cluster.remove(req.body, function (err) {
         if (err)
-            res.send(err);
-        else
-            selectAll(res);
+            return res.send(err);
+
+        selectAll(req, res);
     })
 });
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/2a8445de/modules/webconfig/nodejs/views/clusters.jade
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/views/clusters.jade b/modules/webconfig/nodejs/views/clusters.jade
index 883ac0d..0960624 100644
--- a/modules/webconfig/nodejs/views/clusters.jade
+++ b/modules/webconfig/nodejs/views/clusters.jade
@@ -44,4 +44,4 @@ block content
                 td(data-title="'Delete'" class=['col-sm-1'])
                     center
                         span(type='button' ng-click='delete(cluster)')
-                            i(class=['fa', 'fa-remove'])
+                            i(class=['fa', 'fa-remove'])
\ No newline at end of file


Mime
View raw message