ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [10/17] ignite git commit: IGNITE-3262 Exported api for list entites.
Date Fri, 08 Jul 2016 06:27:56 GMT
IGNITE-3262 Exported api for list entites.


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

Branch: refs/heads/ignite-3262
Commit: fd77da69ac4aab9b2e8e4b0f3c415acf67e7cb76
Parents: bfdbfd0
Author: Maxim Afanasiev <mafkus@gmail.com>
Authored: Thu Jul 7 15:54:54 2016 +0700
Committer: Maxim Afanasiev <mafkus@gmail.com>
Committed: Thu Jul 7 15:54:54 2016 +0700

----------------------------------------------------------------------
 .../configuration/summary/summary.resource.js   | 10 ++--
 .../main/js/controllers/caches-controller.js    |  2 +-
 .../main/js/controllers/clusters-controller.js  |  2 +-
 .../main/js/controllers/domains-controller.js   |  4 +-
 .../src/main/js/controllers/igfs-controller.js  |  2 +-
 .../src/main/js/serve/routes/caches.js          | 11 +---
 .../src/main/js/serve/routes/clusters.js        | 51 +-----------------
 .../src/main/js/serve/routes/configuration.js   | 57 ++++++++++++++++++++
 .../src/main/js/serve/routes/demo.js            | 11 ++--
 .../src/main/js/serve/routes/domains.js         | 35 ------------
 .../src/main/js/serve/routes/igfs.js            | 33 +-----------
 .../src/main/js/serve/routes/routes.js          |  4 +-
 .../src/main/js/serve/services/cache.js         | 22 ++------
 .../src/main/js/serve/services/space.js         |  9 ++++
 14 files changed, 96 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/app/modules/states/configuration/summary/summary.resource.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/app/modules/states/configuration/summary/summary.resource.js
b/modules/web-console/src/main/js/app/modules/states/configuration/summary/summary.resource.js
index 0ef53ac..f9880e4 100644
--- a/modules/web-console/src/main/js/app/modules/states/configuration/summary/summary.resource.js
+++ b/modules/web-console/src/main/js/app/modules/states/configuration/summary/summary.resource.js
@@ -16,17 +16,21 @@
  */
 
 export default ['ConfigurationSummaryResource', ['$q', '$http', ($q, $http) => {
-    const api = '/api/v1/configuration/clusters/list';
+    const api = '/api/v1/configuration/list';
 
     return {
         read() {
             return $http
-                .post(api)
+                .get(api)
                 .then(({data}) => data)
-                .then(({clusters, caches, igfss}) => {
+                .then(({clusters, caches, igfss, domains}) => {
                     if (!clusters || !clusters.length)
                         return {};
 
+                    _.forEach(caches, (cache) => {
+                        cache.domains = _.filter(domains, ({_id}) => _.includes(cache.domains,
_id));
+                    });
+
                     _.forEach(clusters, (cluster) => {
                         cluster.igfss = _.filter(igfss, ({_id}) => _.includes(cluster.igfss,
_id));
                         cluster.caches = _.filter(caches, ({_id}) => _.includes(cluster.caches,
_id));

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/controllers/caches-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/caches-controller.js b/modules/web-console/src/main/js/controllers/caches-controller.js
index acd65a2..72dcf75 100644
--- a/modules/web-console/src/main/js/controllers/caches-controller.js
+++ b/modules/web-console/src/main/js/controllers/caches-controller.js
@@ -80,7 +80,7 @@ export default ['cachesController', [
         Loading.start('loadingCachesScreen');
 
         // When landing on the page, get caches and show them.
-        $http.post('/api/v1/configuration/caches/list')
+        $http.get('/api/v1/configuration/list')
             .success(function(data) {
                 const validFilter = $filter('domainsValidation');
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/controllers/clusters-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/clusters-controller.js b/modules/web-console/src/main/js/controllers/clusters-controller.js
index 5f86d08..9c9fcc9 100644
--- a/modules/web-console/src/main/js/controllers/clusters-controller.js
+++ b/modules/web-console/src/main/js/controllers/clusters-controller.js
@@ -194,7 +194,7 @@ export default ['clustersController', [
         Loading.start('loadingClustersScreen');
 
         // When landing on the page, get clusters and show them.
-        $http.post('/api/v1/configuration/clusters/list')
+        $http.get('/api/v1/configuration/list')
             .success(function(data) {
                 $scope.spaces = data.spaces;
                 $scope.clusters = data.clusters;

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/controllers/domains-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/domains-controller.js b/modules/web-console/src/main/js/controllers/domains-controller.js
index eb2f9d0..6c4bd93 100644
--- a/modules/web-console/src/main/js/controllers/domains-controller.js
+++ b/modules/web-console/src/main/js/controllers/domains-controller.js
@@ -1057,7 +1057,7 @@ export default ['domainsController', [
         // When landing on the page, get domain models and show them.
         Loading.start('loadingDomainModelsScreen');
 
-        $http.post('/api/v1/configuration/domains/list')
+        $http.get('/api/v1/configuration/list')
             .success(function(data) {
                 $scope.spaces = data.spaces;
                 $scope.clusters = _.map(data.clusters, function(cluster) {
@@ -1067,7 +1067,7 @@ export default ['domainsController', [
                     };
                 });
                 $scope.caches = _mapCaches(data.caches);
-                $scope.domains = data.domains;
+                $scope.domains = _.sortBy(data.domains, 'valueType');
 
                 _.forEach($scope.clusters, function(cluster) {
                     $scope.ui.generatedCachesClusters.push(cluster.value);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/controllers/igfs-controller.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/controllers/igfs-controller.js b/modules/web-console/src/main/js/controllers/igfs-controller.js
index 5f5f0bb..a601012 100644
--- a/modules/web-console/src/main/js/controllers/igfs-controller.js
+++ b/modules/web-console/src/main/js/controllers/igfs-controller.js
@@ -135,7 +135,7 @@ export default ['igfsController', [
         Loading.start('loadingIgfsScreen');
 
         // When landing on the page, get IGFSs and show them.
-        $http.post('/api/v1/configuration/igfs/list')
+        $http.get('/api/v1/configuration/list')
             .success(function(data) {
                 $scope.spaces = data.spaces;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/caches.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/caches.js b/modules/web-console/src/main/js/serve/routes/caches.js
index 334b7f2..ca04716 100644
--- a/modules/web-console/src/main/js/serve/routes/caches.js
+++ b/modules/web-console/src/main/js/serve/routes/caches.js
@@ -27,16 +27,7 @@ module.exports = {
 module.exports.factory = function(_, express, mongo, cacheService) {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
-
-        /**
-         * Get spaces and caches accessed for user account.
-         */
-        router.post('/list', (req, res) => {
-            cacheService.listByUser(req.currentUserId(), req.header('IgniteDemoMode'))
-                .then(res.api.ok)
-                .catch(res.api.error);
-        });
-
+        
         /**
          * Save cache.
          */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/clusters.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/clusters.js b/modules/web-console/src/main/js/serve/routes/clusters.js
index 6cb5385..22aeef8 100644
--- a/modules/web-console/src/main/js/serve/routes/clusters.js
+++ b/modules/web-console/src/main/js/serve/routes/clusters.js
@@ -27,56 +27,7 @@ module.exports = {
 module.exports.factory = function(_, express, mongo, spaceService) {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
-
-        /**
-         * Get spaces and clusters accessed for user account.
-         *
-         * @param req Request.
-         * @param res Response.
-         */
-        router.post('/list', (req, res) => {
-            const result = {};
-            let spaceIds = [];
-            let domains = {};
-
-            spaceService.spaces(req.currentUserId(), req.header('IgniteDemoMode'))
-                .then((spaces) => {
-                    result.spaces = spaces;
-                    spaceIds = spaces.map((space) => space._id);
-
-                    return mongo.DomainModel.find({space: {$in: spaceIds}}).lean().exec();
-                })
-                .then((_domains) => {
-                    domains = _domains.reduce((map, obj) => {
-                        map[obj._id] = obj;
-
-                        return map;
-                    }, {});
-
-                    return mongo.Cache.find({space: {$in: spaceIds}}).sort('name').lean().exec();
-                })
-                .then((caches) => {
-                    _.forEach(caches, (cache) => {
-                        cache.domains = _.map(cache.domains, (domainId) => domains[domainId]);
-                    });
-
-                    result.caches = caches;
-
-                    return mongo.Igfs.find({space: {$in: spaceIds}}).sort('name').lean().exec();
-                })
-                .then((igfss) => {
-                    result.igfss = igfss;
-
-                    return mongo.Cluster.find({space: {$in: spaceIds}}).sort('name').deepPopulate(mongo.ClusterDefaultPopulate).lean().exec();
-                })
-                .then((clusters) => {
-                    result.clusters = clusters;
-
-                    res.json(result);
-                })
-                .catch((err) => mongo.handleError(res, err));
-        });
-
+        
         /**
          * Save cluster.
          */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/configuration.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/configuration.js b/modules/web-console/src/main/js/serve/routes/configuration.js
new file mode 100644
index 0000000..e881d4a
--- /dev/null
+++ b/modules/web-console/src/main/js/serve/routes/configuration.js
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+'use strict';
+
+// Fire me up!
+
+module.exports = {
+    implements: 'configuration-routes',
+    inject: ['require(lodash)', 'require(express)', 'mongo', 'services/space', 'services/cache']
+};
+
+module.exports.factory = function(_, express, mongo, spaceService, cacheService) {
+
+    return new Promise((factoryResolve) => {
+        const router = new express.Router();
+
+        /**
+         * Get spaces and caches accessed for user account.
+         */
+
+        router.get('/list', (req, res) => {
+            let spaces;
+
+            spaceService.spaces(req.currentUserId(), req.header('IgniteDemoMode'))
+                .then((_spaces) => {
+                    spaces = _spaces;
+                    return spaces.map((space) => space._id);
+                })
+                .then((spacesIds) => Promise.all([
+                    cacheService.listBySpaces(spacesIds),
+                    mongo.DomainModel.find({space: {$in: spacesIds}}).sort('name').lean().exec(),
+                    mongo.Igfs.find({space: {$in: spacesIds}}).sort('name').lean().exec(),
+                    mongo.Cluster.find({space: {$in: spacesIds}}).sort('name').deepPopulate(mongo.ClusterDefaultPopulate).lean().exec()
+                ]))
+                .then(([caches, domains, igfss, clusters]) => ({caches, domains, igfss,
clusters, spaces}))
+                .then(res.api.ok)
+                .catch(res.api.error);
+        });
+
+        factoryResolve(router);
+    });
+};

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/demo.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/demo.js b/modules/web-console/src/main/js/serve/routes/demo.js
index e49c2f9..31174b8 100644
--- a/modules/web-console/src/main/js/serve/routes/demo.js
+++ b/modules/web-console/src/main/js/serve/routes/demo.js
@@ -30,11 +30,12 @@ module.exports = {
         'require(./demo/caches.json)',
         'require(./demo/igfss.json)',
         'require(./demo/clusters.json)',
-        'services/space'
+        'services/space',
+        'errors'
     ]
 };
 
-module.exports.factory = (_, express, settings, mongo, domains, caches, igfss, clusters,
spaceService) => {
+module.exports.factory = (_, express, settings, mongo, domains, caches, igfss, clusters,
spaceService, errors) => {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
 
@@ -54,8 +55,10 @@ module.exports.factory = (_, express, settings, mongo, domains, caches,
igfss, c
                             mongo.Igfs.remove({space: {$in: spaceIds}}).exec()
                         ]).then(() => spaces[0]);
                     }
-
-                    return new mongo.Space({name: 'Demo space', owner: req.user._id, demo:
true}).save();
+                })
+                .catch((err) => {
+                    if (err instanceof errors.NotFoundException)
+                        return spaceService.createDemoSpace(req.user._id);
                 })
                 .then((space) => {
                     return Promise.all(_.map(clusters, (cluster) => {

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/domains.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/domains.js b/modules/web-console/src/main/js/serve/routes/domains.js
index d1d402f..b6e0a50 100644
--- a/modules/web-console/src/main/js/serve/routes/domains.js
+++ b/modules/web-console/src/main/js/serve/routes/domains.js
@@ -28,41 +28,6 @@ module.exports.factory = (_, express, mongo, spaceService) => {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
 
-        /**
-         * Get spaces and domain models accessed for user account.
-         *
-         * @param req Request.
-         * @param res Response.
-         */
-        router.post('/list', (req, res) => {
-            const result = {};
-            let spacesIds = [];
-
-            spaceService.spaces(req.currentUserId(), req.header('IgniteDemoMode'))
-                .then((spaces) => {
-                    result.spaces = spaces;
-                    spacesIds = spaces.map((space) => space._id);
-
-                    return mongo.Cluster.find({space: {$in: spacesIds}}, '_id name').sort('name').lean().exec();
-                })
-                .then((clusters) => {
-                    result.clusters = clusters;
-
-                    return mongo.Cache.find({space: {$in: spacesIds}}).sort('name').lean().exec();
-                })
-                .then((caches) => {
-                    result.caches = caches;
-
-                    return mongo.DomainModel.find({space: {$in: spacesIds}}).sort('valueType').lean().exec();
-                })
-                .then((domains) => {
-                    result.domains = domains;
-
-                    res.json(result);
-                })
-                .catch((err) => mongo.handleError(res, err));
-        });
-
         function _updateCacheStore(cacheStoreChanges) {
             const promises = [];
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/igfs.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/igfs.js b/modules/web-console/src/main/js/serve/routes/igfs.js
index e44d8c2..892951a 100644
--- a/modules/web-console/src/main/js/serve/routes/igfs.js
+++ b/modules/web-console/src/main/js/serve/routes/igfs.js
@@ -27,38 +27,7 @@ module.exports = {
 module.exports.factory = function(_, express, mongo, spaceService) {
     return new Promise((factoryResolve) => {
         const router = new express.Router();
-
-        /**
-         * Get spaces and IGFSs accessed for user account.
-         *
-         * @param req Request.
-         * @param res Response.
-         */
-        router.post('/list', (req, res) => {
-            const result = {};
-            let spaceIds = [];
-
-            // Get owned space and all accessed space.
-            spaceService.spaces(req.currentUserId(), req.header('IgniteDemoMode'))
-                .then((spaces) => {
-                    result.spaces = spaces;
-                    spaceIds = spaces.map((space) => space._id);
-
-                    return mongo.Cluster.find({space: {$in: spaceIds}}, '_id name').sort('name').lean().exec();
-                })
-                .then((clusters) => {
-                    result.clusters = clusters;
-
-                    return mongo.Igfs.find({space: {$in: spaceIds}}).sort('name').lean().exec();
-                })
-                .then((igfss) => {
-                    result.igfss = igfss;
-
-                    res.json(result);
-                })
-                .catch((err) => mongo.handleError(res, err));
-        });
-
+        
         /**
          * Save IGFS.
          */

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/routes/routes.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/routes/routes.js b/modules/web-console/src/main/js/serve/routes/routes.js
index a6fb188..32642d51 100644
--- a/modules/web-console/src/main/js/serve/routes/routes.js
+++ b/modules/web-console/src/main/js/serve/routes/routes.js
@@ -32,12 +32,13 @@ module.exports = {
         'igfs-routes',
         'notebooks-routes',
         'agent-routes',
+        'configuration-routes',
         'ignite_modules/routes:*' // Loads all routes modules of all plugins
     ]
 };
 
 module.exports.factory = function(publicRoutes, adminRoutes, profileRoutes, demoRoutes,
-    clusterRoutes, domainRoutes, cacheRoutes, igfsRoutes, notebookRoutes, agentRoutes, pluginRoutes)
{
+    clusterRoutes, domainRoutes, cacheRoutes, igfsRoutes, notebookRoutes, agentRoutes, configurationRoutes,
pluginRoutes) {
     return {
         register: (app) => {
             // TODO Extract this to separate middleware.
@@ -67,6 +68,7 @@ module.exports.factory = function(publicRoutes, adminRoutes, profileRoutes,
demo
 
             app.all('/configuration/*', _mustAuthenticated);
 
+            app.use('/configuration', _mustAuthenticated, configurationRoutes);
             app.use('/configuration/clusters', clusterRoutes);
             app.use('/configuration/domains', domainRoutes);
             app.use('/configuration/caches', cacheRoutes);

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/services/cache.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/services/cache.js b/modules/web-console/src/main/js/serve/services/cache.js
index c5c882c..a4118c6 100644
--- a/modules/web-console/src/main/js/serve/services/cache.js
+++ b/modules/web-console/src/main/js/serve/services/cache.js
@@ -93,24 +93,12 @@ module.exports.factory = (_, mongo, spaceService, errors) => {
         }
 
         /**
-         * Get caches and linked objects by user.
-         * @param {mongo.ObjectId|String} userId - The user id that own caches.
-         * @param {Boolean} demo - The flag indicates that need lookup in demo space.
-         * @returns {Promise.<[mongo.Cache[], mongo.Cluster[], mongo.DomainModel[], mongo.Space[]]>}
- contains requested caches and array of linked objects: clusters, domains, spaces.
+         * Get caches by spaces.
+         * @param {mongo.ObjectId|String} spaceIds - The spaces ids that own caches.
+         * @returns {Promise.<mongo.Cache[]>} - contains requested caches.
          */
-        static listByUser(userId, demo) {
-            // Get owned space and all accessed space.
-            return spaceService.spaces(userId, demo)
-                .then((spaces) => {
-                    const spaceIds = spaces.map((space) => space._id);
-
-                    return Promise.all([
-                        mongo.Cluster.find({space: {$in: spaceIds}}).sort('name').lean().exec(),
-                        mongo.DomainModel.find({space: {$in: spaceIds}}).sort('name').lean().exec(),
-                        mongo.Cache.find({space: {$in: spaceIds}}).sort('name').lean().exec()
-                    ])
-                        .then(([clusters, domains, caches]) => ({caches, clusters, domains,
spaces}));
-                });
+        static listBySpaces(spaceIds) {
+            return mongo.Cache.find({space: {$in: spaceIds}}).sort('name').lean().exec();
         }
 
         /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/fd77da69/modules/web-console/src/main/js/serve/services/space.js
----------------------------------------------------------------------
diff --git a/modules/web-console/src/main/js/serve/services/space.js b/modules/web-console/src/main/js/serve/services/space.js
index 28a8897..0daebc4 100644
--- a/modules/web-console/src/main/js/serve/services/space.js
+++ b/modules/web-console/src/main/js/serve/services/space.js
@@ -54,6 +54,15 @@ module.exports.factory = (mongo, errors) => {
             return this.spaces(userId, demo)
                 .then((spaces) => spaces.map((space) => space._id));
         }
+
+        /**
+         * Create demo space for user
+         * @param userId - user id
+         * @returns {Promise<mongo.Space>} that resolves created demo space for user
+         */
+        static createDemoSpace(userId) {
+            return new mongo.Space({name: 'Demo space', owner: userId, demo: true}).save();
+        }
     }
 
     return SpaceService;


Mime
View raw message