ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject incubator-ignite git commit: # IGNITE-843 WIP on percistence.
Date Thu, 25 Jun 2015 04:36:49 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 9005bd11a -> a78eee502


# IGNITE-843 WIP on percistence.


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

Branch: refs/heads/ignite-843
Commit: a78eee502743e19ea8f13e6fb384df633abfbc58
Parents: 9005bd1
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Thu Jun 25 11:36:43 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Thu Jun 25 11:36:43 2015 +0700

----------------------------------------------------------------------
 modules/webconfig/nodejs/app.js                 |  20 ++--
 .../nodejs/public/form-models/persistence.json  |  11 +-
 .../public/javascripts/controllers/caches.js    |  18 ++--
 .../javascripts/controllers/persistence.js      |  43 --------
 .../javascripts/controllers/persistences.js     | 107 +++++++++++++++++++
 modules/webconfig/nodejs/routes/persistence.js  |  91 ----------------
 modules/webconfig/nodejs/routes/persistences.js |  91 ++++++++++++++++
 modules/webconfig/nodejs/views/persistence.jade |   6 +-
 8 files changed, 230 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/app.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/app.js b/modules/webconfig/nodejs/app.js
index e2021f6..de3fd06 100644
--- a/modules/webconfig/nodejs/app.js
+++ b/modules/webconfig/nodejs/app.js
@@ -28,6 +28,7 @@ var mongoStore = require('connect-mongo')(session);
 var pageRoutes = require('./routes/pages');
 var clustersRouter = require('./routes/clusters');
 var cachesRouter = require('./routes/caches');
+var persistencesRouter = require('./routes/persistences');
 var authRouter = require('./routes/auth');
 var configGenerator = require('./routes/configGenerator');
 
@@ -37,11 +38,11 @@ var db = require('./db');
 
 var app = express();
 
-// view engine setup
+// Views engine setup.
 app.set('views', path.join(__dirname, 'views'));
 app.set('view engine', 'jade');
 
-// Site favicon
+// Site favicon.
 app.use(favicon(__dirname + '/public/favicon.ico'));
 
 app.use(logger('dev'));
@@ -88,22 +89,22 @@ app.all('/caches', mustAuthenticated);
 app.use('/', pageRoutes);
 app.use('/rest/clusters', clustersRouter);
 app.use('/rest/caches', cachesRouter);
+app.use('/rest/persistences', persistencesRouter);
 app.use('/rest/auth', authRouter);
 app.use('/rest/configGenerator', configGenerator);
 
-// catch 404 and forward to error handler
+// Catch 404 and forward to error handler.
 //app.use(function (req, res, next) {
 //    var err = new Error('Not Found');
 //    err.status = 404;
 //    next(err);
 //});
 
-// error handlers
+// Error handlers.
 
-// development error handler
-// will print stacktrace
+// Development error handler: will print stacktrace.
 if (app.get('env') === 'development') {
-    app.use(function (err, req, res, next) {
+    app.use(function (err, req, res) {
         res.status(err.status || 500);
         res.render('error', {
             message: err.message,
@@ -112,9 +113,8 @@ if (app.get('env') === 'development') {
     });
 }
 
-// production error handler
-// no stacktraces leaked to user
-app.use(function (err, req, res, next) {
+// Production error handler: no stacktraces leaked to user.
+app.use(function (err, req, res) {
     res.status(err.status || 500);
     res.render('error', {
         message: err.message,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/public/form-models/persistence.json
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/form-models/persistence.json b/modules/webconfig/nodejs/public/form-models/persistence.json
index 515aa6c..57a74d2 100644
--- a/modules/webconfig/nodejs/public/form-models/persistence.json
+++ b/modules/webconfig/nodejs/public/form-models/persistence.json
@@ -1,9 +1,16 @@
 {
   "connection": [
     {
+      "label": "Name",
+      "type": "text",
+      "model": "name",
+      "required": true,
+      "placeholder": "Input name"
+    },
+    {
       "label": "Database",
       "type": "dropdown",
-      "model": "db",
+      "model": "database",
       "placeholder": "Choose database",
       "items": "databases",
       "tip": [
@@ -22,7 +29,7 @@
     {
       "label": "Password",
       "type": "password",
-      "model": "user",
+      "model": "password",
       "placeholder": "",
       "tip": [
         "User name for connecting to database"

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/public/javascripts/controllers/caches.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/caches.js b/modules/webconfig/nodejs/public/javascripts/controllers/caches.js
index 9ca4729..0b9c330 100644
--- a/modules/webconfig/nodejs/public/javascripts/controllers/caches.js
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/caches.js
@@ -103,18 +103,18 @@ configuratorModule.controller('cachesController', ['$scope', '$alert',
'$http',
         };
 
         // Add new cache.
-        $scope.createItem = function() {
+        $scope.createItem = function () {
             $scope.backupItem = {mode: 'PARTITIONED', atomicityMode: 'ATOMIC'};
             $scope.backupItem.space = $scope.spaces[0]._id;
         };
 
         // Save cache in db.
-        $scope.saveItem = function() {
+        $scope.saveItem = function () {
             var item = $scope.backupItem;
 
             $http.post('/rest/caches/save', item)
-                .success(function(_id) {
-                    var i = _.findIndex($scope.caches, function(cache) {
+                .success(function (_id) {
+                    var i = _.findIndex($scope.caches, function (cache) {
                         return cache._id == _id;
                     });
 
@@ -128,17 +128,17 @@ configuratorModule.controller('cachesController', ['$scope', '$alert',
'$http',
 
                     $scope.selectItem(item);
                 })
-                .error(function(errorMessage) {
+                .error(function (errorMessage) {
                     $alert({title: errorMessage});
                 });
         };
 
-        $scope.removeItem = function() {
+        $scope.removeItem = function () {
             var _id = $scope.selectedItem._id;
 
             $http.post('/rest/caches/remove', {_id: _id})
-                .success(function() {
-                    var i = _.findIndex($scope.caches, function(cache) {
+                .success(function () {
+                    var i = _.findIndex($scope.caches, function (cache) {
                         return cache._id == _id;
                     });
 
@@ -149,7 +149,7 @@ configuratorModule.controller('cachesController', ['$scope', '$alert',
'$http',
                         $scope.backupItem = undefined;
                     }
                 })
-                .error(function(errorMessage) {
+                .error(function (errorMessage) {
                     $alert({title: errorMessage});
                 });
         };

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/public/javascripts/controllers/persistence.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/persistence.js b/modules/webconfig/nodejs/public/javascripts/controllers/persistence.js
deleted file mode 100644
index 88b4d31..0000000
--- a/modules/webconfig/nodejs/public/javascripts/controllers/persistence.js
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- */
-
-configuratorModule.controller('persistenceController', ['$scope', '$alert', '$http', function
($scope, $alert, $http) {
-        $scope.databases = [
-            {value: 'oracle', label: 'Oracle database'},
-            {value: 'db2', label: 'IBM DB2'},
-            {value: 'mssql', label: 'MS SQL Server'},
-            {value: 'postgre', label: 'PostgreSQL'},
-            {value: 'mysql', label: 'MySQL'},
-            {value: 'h2', label: 'H2 database'}
-        ];
-
-        $scope.connection = [];
-
-        $scope.persistences = [];
-
-        $http.get('/form-models/persistence.json')
-            .success(function (data) {
-                $scope.connection = data.connection;
-            });
-
-        // Add new persistence.
-        $scope.createItem = function() {
-            $scope.backupItem = {database: oracle};
-            $scope.backupItem.space = $scope.spaces[0]._id;
-        };
-    }]
-);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/public/javascripts/controllers/persistences.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/persistences.js b/modules/webconfig/nodejs/public/javascripts/controllers/persistences.js
new file mode 100644
index 0000000..d1857ecc
--- /dev/null
+++ b/modules/webconfig/nodejs/public/javascripts/controllers/persistences.js
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+
+configuratorModule.controller('persistenceController', ['$scope', '$alert', '$http', function
($scope, $alert, $http) {
+        $scope.databases = [
+            {value: 'oracle', label: 'Oracle database'},
+            {value: 'db2', label: 'IBM DB2'},
+            {value: 'mssql', label: 'MS SQL Server'},
+            {value: 'postgre', label: 'PostgreSQL'},
+            {value: 'mysql', label: 'MySQL'},
+            {value: 'h2', label: 'H2 database'}
+        ];
+
+        $scope.connection = [];
+
+        $http.get('/form-models/persistence.json')
+            .success(function (data) {
+                $scope.connection = data.connection;
+            });
+
+        $scope.persistences = [];
+
+        // When landing on the page, get persistences and show them.
+        $http.get('/rest/persistences')
+            .success(function (data) {
+                $scope.spaces = data.spaces;
+                $scope.persistences = data.persistences;
+
+                $scope.backupItem = angular.fromJson(sessionStorage.persistenceBackupItem);
+
+                $scope.$watch('backupItem', function (val) {
+                    sessionStorage.persistenceBackupItem = angular.toJson(val);
+                }, true);
+            });
+
+        $scope.selectItem = function (item) {
+            $scope.selectedItem = item;
+            $scope.backupItem = angular.copy(item);
+        };
+
+        // Add new persistence.
+        $scope.createItem = function () {
+            $scope.backupItem = {database: 'oracle'};
+            $scope.backupItem.space = $scope.spaces[0]._id;
+        };
+
+        // Save persistence in db.
+        $scope.saveItem = function () {
+            var item = $scope.backupItem;
+
+            $http.post('/rest/persistences/save', item)
+                .success(function (_id) {
+                    var i = _.findIndex($scope.persistences, function (persistence) {
+                        return persistence._id == _id;
+                    });
+
+                    if (i >= 0)
+                        angular.extend($scope.persistences[i], item);
+                    else {
+                        item._id = _id;
+
+                        $scope.persistences.push(item);
+                    }
+
+                    $scope.selectItem(item);
+                })
+                .error(function (errorMessage) {
+                    $alert({title: errorMessage});
+                });
+        };
+
+        $scope.removeItem = function () {
+            var _id = $scope.selectedItem._id;
+
+            $http.post('/rest/persistences/remove', {_id: _id})
+                .success(function () {
+                    var i = _.findIndex($scope.persistences, function (persistence) {
+                        return persistence._id == _id;
+                    });
+
+                    if (i >= 0) {
+                        $scope.persistences.splice(i, 1);
+
+                        $scope.selectedItem = undefined;
+                        $scope.backupItem = undefined;
+                    }
+                })
+                .error(function (errorMessage) {
+                    $alert({title: errorMessage});
+                });
+        };
+    }]
+);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/routes/persistence.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/routes/persistence.js b/modules/webconfig/nodejs/routes/persistence.js
deleted file mode 100644
index 3163fdd..0000000
--- a/modules/webconfig/nodejs/routes/persistence.js
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.
- */
-
-var router = require('express').Router();
-var db = require('../db');
-
-/**
- * Send spaces and persistences 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)
-            return res.status(500).send(err.message);
-
-        var space_ids = spaces.map(function(value) {
-            return value._id;
-        });
-
-        // Get all persistences for spaces.
-        db.Persistence.find({space: {$in: space_ids}}, function (err, persistences) {
-            if (err)
-                return res.status(500).send(err.message);
-
-            res.json({spaces: spaces, persistences: persistences});
-        });
-    });
-}
-
-/**
- * Get spaces and persistences accessed for user account.
- */
-router.get('/', function(req, res) {
-    selectAll(req, res);
-});
-
-/**
- * Save persistence.
- */
-router.post('/save', function(req, res) {
-    if (req.body._id)
-        db.Persistence.update({_id: req.body._id}, req.body, {upsert: true}, function(err,
persistence) {
-            if (err)
-                return res.status(500).send(err.message);
-
-            res.send(req.body._id);
-        });
-    else {
-        var persistence = new db.Persistence(req.body);
-
-        persistence.save(function(err, persistence) {
-            if (err)
-                return res.status(500).send(err.message);
-
-            res.send(persistence._id);
-        });
-    }
-});
-
-/**
- * Remove persistence by ._id.
- */
-router.post('/remove', function(req, res) {
-    db.Persistence.remove(req.body, function (err) {
-        if (err)
-            return res.status(500).send(err.message);
-
-        res.sendStatus(200);
-    })
-});
-
-module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/routes/persistences.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/routes/persistences.js b/modules/webconfig/nodejs/routes/persistences.js
new file mode 100644
index 0000000..787453f
--- /dev/null
+++ b/modules/webconfig/nodejs/routes/persistences.js
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+var router = require('express').Router();
+var db = require('../db');
+
+/**
+ * Send spaces and persistences 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)
+            return res.status(500).send(err.message);
+
+        var space_ids = spaces.map(function(value) {
+            return value._id;
+        });
+
+        // Get all persistences for spaces.
+        db.Persistence.find({space: {$in: space_ids}}, function (err, persistences) {
+            if (err)
+                return res.status(500).send(err.message);
+
+            res.json({spaces: spaces, persistences: persistences});
+        });
+    });
+}
+
+/**
+ * Get spaces and persistences accessed for user account.
+ */
+router.get('/', function(req, res) {
+    selectAll(req, res);
+});
+
+/**
+ * Save persistence.
+ */
+router.post('/save', function(req, res) {
+    if (req.body._id)
+        db.Persistence.update({_id: req.body._id}, req.body, {upsert: true}, function(err)
{
+            if (err)
+                return res.status(500).send(err.message);
+
+            res.send(req.body._id);
+        });
+    else {
+        var persistence = new db.Persistence(req.body);
+
+        persistence.save(function(err, persistence) {
+            if (err)
+                return res.status(500).send(err.message);
+
+            res.send(persistence._id);
+        });
+    }
+});
+
+/**
+ * Remove persistence by ._id.
+ */
+router.post('/remove', function(req, res) {
+    db.Persistence.remove(req.body, function (err) {
+        if (err)
+            return res.status(500).send(err.message);
+
+        res.sendStatus(200);
+    })
+});
+
+module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a78eee50/modules/webconfig/nodejs/views/persistence.jade
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/views/persistence.jade b/modules/webconfig/nodejs/views/persistence.jade
index 39cdd6e..f642dca 100644
--- a/modules/webconfig/nodejs/views/persistence.jade
+++ b/modules/webconfig/nodejs/views/persistence.jade
@@ -17,7 +17,7 @@
 extends layout-sidebar
 
 append scripts
-    script(src='/javascripts/controllers/persistence.js')
+    script(src='/javascripts/controllers/persistences.js')
 
 include includes/controls
 
@@ -35,7 +35,7 @@ block content
                             a(ng-click='selectItem(row)') {{$index + 1}}. {{row.name}}, {{row.database
| displayValue:databases:'Database not set'}}
         button.btn.btn-primary(ng-click='createItem()') Add
         hr
-        form.form-horizontal(name='inputForm')
+        form.form-horizontal(name='inputForm' ng-if='backupItem' novalidate)
             div(bs-collapse data-start-collapsed='false')
                 .panel.panel-default
                     .panel-heading
@@ -45,3 +45,5 @@ block content
                         .panel-body
                             .settings-row(ng-repeat='field in connection')
                                 +form-row
+            button.btn.btn-primary(ng-disabled='inputForm.$invalid' ng-click='saveItem()')
Save
+            button.btn.btn-primary.btn-second(ng-show='backupItem._id' ng-click='removeItem()')
Remove


Mime
View raw message