ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject ignite git commit: IGNITE-843 Refactor serve to es6.
Date Wed, 17 Feb 2016 03:21:49 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 ddf268ca0 -> acf54cffd


IGNITE-843 Refactor serve to es6.


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

Branch: refs/heads/ignite-843-rc2
Commit: acf54cffdbb4b5b1bb48fbe87cb1cadb8478f2ab
Parents: ddf268c
Author: Andrey <anovikov@gridgain.com>
Authored: Wed Feb 17 10:22:14 2016 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Wed Feb 17 10:22:14 2016 +0700

----------------------------------------------------------------------
 .../src/main/js/controllers/common-module.js    |  1 +
 .../src/main/js/serve/mongo.js                  |  9 ++---
 .../src/main/js/serve/routes/admin.js           | 38 +++++++++-----------
 .../src/main/js/serve/routes/agent.js           |  6 ++--
 .../src/main/js/serve/routes/caches.js          | 32 ++++++++---------
 .../src/main/js/serve/routes/clusters.js        | 17 ++++-----
 .../src/main/js/serve/routes/domains.js         | 23 +++++-------
 .../src/main/js/serve/routes/igfs.js            | 24 ++++++-------
 .../src/main/js/serve/routes/notebooks.js       |  6 ++--
 9 files changed, 66 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/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 cf51fa3..1e06cee 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
@@ -2100,6 +2100,7 @@ consoleModule.service('$agentDownload', [
 
             lnk.setAttribute('href', '/api/v1/agent/download/zip');
             lnk.setAttribute('target', '_self');
+            lnk.setAttribute('download', null);
             lnk.style.display = 'none';
 
             document.body.appendChild(lnk);

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/mongo.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/mongo.js b/modules/control-center-web/src/main/js/serve/mongo.js
index 0ea72d9..5f7ef9e 100644
--- a/modules/control-center-web/src/main/js/serve/mongo.js
+++ b/modules/control-center-web/src/main/js/serve/mongo.js
@@ -547,11 +547,12 @@ module.exports.factory = function(deepPopulatePlugin, passportMongo,
settings, p
     /**
      * Extract IDs from user spaces.
      *
-     * @param spaces Array of user spaces.
-     * @returns {Array} of spaces ID.
+     * @param userId User ID.
+     * @returns {Promise}
      */
-    result.spacesIds = function(spaces) {
-        return spaces.map((value) => value._id);
+    result.spaceIds = function(userId) {
+        return result.Space.find({owner: userId}).lean().exec()
+            .then((spaces) => spaces.map((space) => space._id));
     };
 
     // Registering the routes of all plugin modules

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/admin.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/admin.js b/modules/control-center-web/src/main/js/serve/routes/admin.js
index 9b8cbee..bcf8321 100644
--- a/modules/control-center-web/src/main/js/serve/routes/admin.js
+++ b/modules/control-center-web/src/main/js/serve/routes/admin.js
@@ -24,7 +24,7 @@ module.exports = {
     inject: ['require(lodash)', 'require(express)', 'require(nodemailer)', 'settings', 'mail',
'mongo']
 };
 
-module.exports.factory = function(_, express, nodemailer, settings, mail, mongo) {
+module.exports.factory = function (_, express, nodemailer, settings, mail, mongo) {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
 
@@ -45,28 +45,22 @@ module.exports.factory = function(_, express, nodemailer, settings, mail,
mongo)
                 .then((user) => {
                     res.sendStatus(200);
 
-                    mongo.spaces(userId)
-                        .then((spaces) => {
-                            const spacesIds = mongo.spacesIds(spaces);
-
-                            return Promise.all([
-                                mongo.Cluster.remove({space: {$in: spacesIds}}).exec(),
-                                mongo.Cache.remove({space: {$in: spacesIds}}).exec(),
-                                mongo.DomainModel.remove({space: {$in: spacesIds}}).exec(),
-                                mongo.Notebook.remove({space: {$in: spacesIds}}).exec(),
-                                mongo.Space.remove({owner: userId}).exec()
-                            ]);
-                        })
-                        .catch((err) => {
-                            console.error(`Failed to cleanup spaces [user=${user.username},
err=${err}`);
-                        });
-
-                    return Promise.resolve(user);
+                    return mongo.spaceIds(userId)
+                        .then((spaceIds) => Promise.all([
+                            mongo.Cluster.remove({space: {$in: spaceIds}}).exec(),
+                            mongo.Cache.remove({space: {$in: spaceIds}}).exec(),
+                            mongo.DomainModel.remove({space: {$in: spaceIds}}).exec(),
+                            mongo.Notebook.remove({space: {$in: spaceIds}}).exec(),
+                            mongo.Space.remove({owner: userId}).exec()
+                        ]))
+                        .then(() => user)
+                        .catch((err) => console.error(`Failed to cleanup spaces [user=${user.username},
err=${err}`));
                 })
-                .then((user) => mail.send(user, 'Your account was deleted',
-                    `Hello ${user.username}!<br><br>` +
-                    `You are receiving this email because your account for ${settings.smtp.username}
was removed.`,
-                    'Account was removed, but failed to send email notification to user!')
+                .then((user) =>
+                    mail.send(user, 'Your account was deleted',
+                        `Hello ${user.username}!<br><br>` +
+                        `You are receiving this email because your account for <a href="http://${req.headers.host}">${settings.smtp.username}</a>
was removed.`,
+                        'Account was removed, but failed to send email notification to user!')
                 )
                 .catch((err) => mongo.handleError(res, err));
         });

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/agent.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/agent.js b/modules/control-center-web/src/main/js/serve/routes/agent.js
index 0451e52..7bb05e7 100644
--- a/modules/control-center-web/src/main/js/serve/routes/agent.js
+++ b/modules/control-center-web/src/main/js/serve/routes/agent.js
@@ -148,11 +148,9 @@ module.exports.factory = function(_, express, apacheIgnite, fs, JSZip,
settings,
                     // Get query cursor.
                     const cursor = client.ignite(req.body.demo).cache(req.body.cacheName).query(qry);
 
-                    return new Promise((resolve) => {
-                        cursor.getAll().then((rows) => resolve({meta: cursor.fieldsMetadata(),
rows}));
-                    });
+                    return cursor.getAll()
+                        .then((rows) => res.json({meta: cursor.fieldsMetadata(), rows}));
                 })
-                .then((response) => res.json(response))
                 .catch(_handleException(res));
         });
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/caches.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/caches.js b/modules/control-center-web/src/main/js/serve/routes/caches.js
index 0122864..855d2fc 100644
--- a/modules/control-center-web/src/main/js/serve/routes/caches.js
+++ b/modules/control-center-web/src/main/js/serve/routes/caches.js
@@ -36,25 +36,24 @@ module.exports.factory = function(_, express, mongo) {
          */
         router.post('/list', (req, res) => {
             const result = {};
-            let spacesIds = [];
+            let spaceIds = [];
 
             // Get owned space and all accessed space.
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => {
-                    result.spaces = spaces;
-                    spacesIds = mongo.spacesIds(spaces);
+            mongo.spaceIds(req.currentUserId())
+                .then((_spaceIds) => {
+                    spaceIds = _spaceIds;
 
-                    return mongo.Cluster.find({space: {$in: spacesIds}}).sort('name').lean().exec();
+                    mongo.Cluster.find({space: {$in: _spaceIds}}).sort('name').lean().exec()
                 })
                 .then((clusters) => {
                     result.clusters = clusters;
 
-                    return mongo.DomainModel.find({space: {$in: spacesIds}}).sort('name').lean().exec();
+                    return mongo.DomainModel.find({space: {$in: spaceIds}}).sort('name').lean().exec();
                 })
                 .then((domains) => {
                     result.domains = domains;
 
-                    return mongo.Cache.find({space: {$in: spacesIds}}).sort('name').lean().exec();
+                    return mongo.Cache.find({space: {$in: spaceIds}}).sort('name').lean().exec();
                 })
                 .then((caches) => {
                     result.caches = caches;
@@ -118,16 +117,13 @@ module.exports.factory = function(_, express, mongo) {
          * Remove all caches.
          */
         router.post('/remove/all', (req, res) => {
-            let spacesIds = [];
-
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => {
-                    spacesIds = mongo.spacesIds(spaces);
-
-                    return mongo.Cluster.update({space: {$in: spacesIds}}, {caches: []},
{multi: true}).exec();
-                })
-                .then(() => mongo.DomainModel.update({space: {$in: spacesIds}}, {caches:
[]}, {multi: true}).exec())
-                .then(() => mongo.Cache.remove({space: {$in: spacesIds}}).exec())
+            mongo.spaceIds(req.currentUserId())
+                .then((spaceIds) =>
+                    mongo.Cluster.update({space: {$in: spaceIds}}, {caches: []}, {multi:
true}).exec()
+                        .then(() => mongo.DomainModel.update({space: {$in: spaceIds}},
{caches: []}, {multi: true}).exec())
+                        .then(() => mongo.Cache.remove({space: {$in: spaceIds}}).exec())
+                )
+                .then(() => res.sendStatus(200))
                 .catch((err) => mongo.handleError(res, err));
         });
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/clusters.js b/modules/control-center-web/src/main/js/serve/routes/clusters.js
index aae7e42..469eae7 100644
--- a/modules/control-center-web/src/main/js/serve/routes/clusters.js
+++ b/modules/control-center-web/src/main/js/serve/routes/clusters.js
@@ -42,7 +42,7 @@ module.exports.factory = function(_, express, mongo) {
             mongo.spaces(req.currentUserId())
                 .then((spaces) => {
                     result.spaces = spaces;
-                    spacesIds = mongo.spacesIds(spaces);
+                    spacesIds = spaces.map((space) => space._id);
 
                     return mongo.DomainModel.find({space: {$in: spacesIds}}).sort('valueType').lean().exec();
                 })
@@ -133,17 +133,12 @@ module.exports.factory = function(_, express, mongo) {
          * Remove all clusters.
          */
         router.post('/remove/all', (req, res) => {
-            let spacesIds = [];
-
             // Get owned space and all accessed space.
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => {
-                    spacesIds = mongo.spacesIds(spaces);
-
-                    return mongo.Cache.update({space: {$in: spacesIds}}, {clusters: []},
{multi: true}).exec();
-                })
-                .then(() => mongo.Igfs.update({space: {$in: spacesIds}}, {clusters: []},
{multi: true}).exec())
-                .then(() => mongo.Cluster.remove({space: {$in: spacesIds}}).exec())
+            mongo.spaceIds(req.currentUserId())
+                .then((spaceIds) => mongo.Cache.update({space: {$in: spaceIds}}, {clusters:
[]}, {multi: true}).exec()
+                    .then(() => mongo.Igfs.update({space: {$in: spaceIds}}, {clusters:
[]}, {multi: true}).exec())
+                    .then(() => mongo.Cluster.remove({space: {$in: spaceIds}}).exec())
+                )
                 .then(() => res.sendStatus(200))
                 .catch((err) => mongo.handleError(res, err));
         });

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/domains.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/domains.js b/modules/control-center-web/src/main/js/serve/routes/domains.js
index d98398b..bd2dab5 100644
--- a/modules/control-center-web/src/main/js/serve/routes/domains.js
+++ b/modules/control-center-web/src/main/js/serve/routes/domains.js
@@ -41,7 +41,7 @@ module.exports.factory = (_, express, mongo) => {
             mongo.spaces(req.currentUserId())
                 .then((spaces) => {
                     result.spaces = spaces;
-                    spacesIds = mongo.spacesIds(spaces);
+                    spacesIds = spaces.map((space) => space._id);
 
                     return mongo.Cluster.find({space: {$in: spacesIds}}, '_id name').sort('name').lean().exec();
                 })
@@ -181,15 +181,9 @@ module.exports.factory = (_, express, mongo) => {
          * Remove all domain models.
          */
         router.post('/remove/all', (req, res) => {
-            let spacesIds = [];
-
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => {
-                    spacesIds = mongo.spacesIds(spaces);
-
-                    return mongo.Cache.update({space: {$in: spacesIds}}, {domains: []}, {multi:
true}).exec();
-                })
-                .then(() => mongo.DomainModel.remove({space: {$in: spacesIds}}).exec())
+            mongo.spaceIds(req.currentUserId())
+                .then((spaceIds) => mongo.Cache.update({space: {$in: spaceIds}}, {domains:
[]}, {multi: true}).exec()
+                        .then(() => mongo.DomainModel.remove({space: {$in: spaceIds}}).exec()))
                 .then(() => res.sendStatus(200))
                 .catch((err) => mongo.handleError(res, err));
         });
@@ -202,11 +196,12 @@ module.exports.factory = (_, express, mongo) => {
             let domainIds = [];
             let cacheIds = [];
 
-            // TODO IGNITE-843 also remove from links: Cache -> DomainModel ; DomainModel
-> Cache; Cluster -> Cache.
+            mongo.spaceIds(req.currentUserId())
+                .then((_spaceIds) => {
+                    spaceIds = _spaceIds;
 
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => spaceIds = mongo.spacesIds(spaces))
-                .then(() => mongo.DomainModel.find({$and: [{space: {$in: spaceIds}}, {demo:
true}]}).lean().exec())
+                    mongo.DomainModel.find({$and: [{space: {$in: spaceIds}}, {demo: true}]}).lean().exec()
+                })
                 .then((domains) => domainIds = _.map(domains, (domain) => domain._id))
                 .then(() => mongo.Cache.update({domains: {$in: domainIds}}, {$pull: {domains:
{$in: domainIds}}}, {multi: true}).exec())
                 .then(() => mongo.DomainModel.remove({_id: {$in: domainIds}}).exec())

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/igfs.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/igfs.js b/modules/control-center-web/src/main/js/serve/routes/igfs.js
index 255220a..c204079 100644
--- a/modules/control-center-web/src/main/js/serve/routes/igfs.js
+++ b/modules/control-center-web/src/main/js/serve/routes/igfs.js
@@ -36,20 +36,20 @@ module.exports.factory = function(_, express, mongo) {
          */
         router.post('/list', (req, res) => {
             const result = {};
-            let spacesIds = [];
+            let spaceIds = [];
 
             // Get owned space and all accessed space.
             mongo.spaces(req.currentUserId())
                 .then((spaces) => {
                     result.spaces = spaces;
-                    spacesIds = mongo.spacesIds(spaces);
+                    spaceIds = spaces.map((space) => space._id);
 
-                    return mongo.Cluster.find({space: {$in: spacesIds}}, '_id name').sort('name').lean().exec();
+                    return mongo.Cluster.find({space: {$in: spaceIds}}, '_id name').sort('name').lean().exec();
                 })
                 .then((clusters) => {
                     result.clusters = clusters;
 
-                    return mongo.Igfs.find({space: {$in: spacesIds}}).sort('name').lean().exec();
+                    return mongo.Igfs.find({space: {$in: spaceIds}}).sort('name').lean().exec();
                 })
                 .then((igfss) => {
                     result.igfss = igfss;
@@ -99,7 +99,7 @@ module.exports.factory = function(_, express, mongo) {
             const igfsId = params._id;
 
             mongo.Cluster.update({igfss: {$in: [igfsId]}}, {$pull: {igfss: igfsId}}, {multi:
true}).exec()
-                .then(mongo.Igfs.remove(params).exec())
+                .then(() => mongo.Igfs.remove(params).exec())
                 .then(() => res.sendStatus(200))
                 .catch((err) => mongo.handleError(res, err));
         });
@@ -108,16 +108,12 @@ module.exports.factory = function(_, express, mongo) {
          * Remove all IGFSs.
          */
         router.post('/remove/all', (req, res) => {
-            let spacesIds = [];
-
             // Get owned space and all accessed space.
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => {
-                    spacesIds = mongo.spacesIds(spaces);
-
-                    return mongo.Cluster.update({space: {$in: spacesIds}}, {igfss: []}, {multi:
true}).exec();
-                })
-                .then(() => mongo.Igfs.remove({space: {$in: spacesIds}}).exec())
+            mongo.spaceIds(req.currentUserId())
+                .then((spaceIds) =>
+                    mongo.Cluster.update({space: {$in: spaceIds}}, {igfss: []}, {multi: true}).exec()
+                        .then(() => mongo.Igfs.remove({space: {$in: spaceIds}}).exec())
+                )
                 .then(() => res.sendStatus(200))
                 .catch((err) => mongo.handleError(res, err));
         });

http://git-wip-us.apache.org/repos/asf/ignite/blob/acf54cff/modules/control-center-web/src/main/js/serve/routes/notebooks.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/serve/routes/notebooks.js b/modules/control-center-web/src/main/js/serve/routes/notebooks.js
index 8e79ec1..4055c27 100644
--- a/modules/control-center-web/src/main/js/serve/routes/notebooks.js
+++ b/modules/control-center-web/src/main/js/serve/routes/notebooks.js
@@ -50,7 +50,7 @@ module.exports.factory = function(express, mongo) {
          */
         router.post('/get', (req, res) => {
             mongo.spaces(req.currentUserId())
-                .then((spaces) => mongo.Notebook.findOne({space: {$in: spaces.map((value)
=> value._id)}, _id: req.body.noteId}).exec())
+                .then((spaces) => mongo.Notebook.findOne({space: {$in: spaces.map((value)
=> value._id)}, _id: req.body.noteId}).lean().exec())
                 .then((notebook) => res.json(notebook))
                 .catch((err) => mongo.handleError(res, err));
         });
@@ -102,8 +102,8 @@ module.exports.factory = function(express, mongo) {
          * @param res Response.
          */
         router.post('/new', (req, res) => {
-            mongo.spaces(req.currentUserId())
-                .then((spaces) => (new mongo.Notebook({space: spaces[0].id, name: req.body.name})).save())
+            mongo.spaceIds(req.currentUserId())
+                .then((spaceIds) => (new mongo.Notebook({space: spaceIds[0], name: req.body.name})).save())
                 .then((notebook) => res.send(notebook._id))
                 .catch((err) => mongo.handleError(res, err));
         });


Mime
View raw message