You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2016/02/16 16:14:26 UTC
[09/50] ignite git commit: IGNITE-843 Rework IGFS server side to
Promises.
IGNITE-843 Rework IGFS server side to Promises.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/055d2a9a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/055d2a9a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/055d2a9a
Branch: refs/heads/ignite-843-rc3
Commit: 055d2a9abaf4375dc3b6a6b0f3e3f4a463da89b1
Parents: 540acaa
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Mon Feb 15 15:42:28 2016 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Mon Feb 15 15:42:28 2016 +0700
----------------------------------------------------------------------
.../src/main/js/serve/routes/igfs.js | 56 ++++++++++----------
1 file changed, 29 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/055d2a9a/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 1a864d7..eb9b877 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
@@ -35,37 +35,39 @@ module.exports.factory = function(_, express, mongo) {
* @param res Response.
*/
router.post('/list', (req, res) => {
- const user_id = req.currentUserId();
+ const result = {};
// Get owned space and all accessed space.
- mongo.Space.find({$or: [{owner: user_id}, {usedBy: {$elemMatch: {account: user_id}}}]}, (errSpace, spaces) => {
- if (mongo.processed(errSpace, res)) {
- const space_ids = spaces.map((value) => value._id);
+ mongo.Space.find({$or: [{owner: req.currentUserId()}, {usedBy: {$elemMatch: {account: req.currentUserId()}}}]}).exec()
+ .then((spaces) => {
+ result.spaces = spaces;
+ result.spacesIds = spaces.map((value) => value._id);
+
+ return mongo.Cluster.find({space: {$in: result.spacesIds}}, '_id name').sort('name').exec();
+ })
+ .then(clusters => {
+ result.clusters = clusters;
+
+ return mongo.Igfs.find({space: {$in: result.spacesIds}}).sort('name').exec();
+ })
+ .then(igfss => {
+ _.forEach(igfss, (igfs) => {
+ // Remove deleted clusters.
+ igfs.clusters = _.filter(igfs.clusters, (clusterId) => {
+ return _.findIndex(result.clusters, (cluster) => cluster._id.equals(clusterId)) >= 0;
+ });
+ });
- // Get all clusters for spaces.
- mongo.Cluster.find({space: {$in: space_ids}}, '_id name').sort('name').exec((errCluster, clusters) => {
- if (mongo.processed(errCluster, res)) {
- // Get all IGFSs for spaces.
- mongo.Igfs.find({space: {$in: space_ids}}).sort('name').exec((errIgfs, igfss) => {
- if (mongo.processed(errIgfs, res)) {
- _.forEach(igfss, (igfs) => {
- // Remove deleted clusters.
- igfs.clusters = _.filter(igfs.clusters, (clusterId) => {
- return _.findIndex(clusters, (cluster) => cluster._id.equals(clusterId)) >= 0;
- });
- });
-
- res.json({
- spaces,
- clusters: clusters.map((cluster) => ({value: cluster._id, label: cluster.name})),
- igfss
- });
- }
- });
- }
+ res.json({
+ spaces: result.spaces,
+ clusters: result.clusters.map((cluster) => ({value: cluster._id, label: cluster.name})),
+ igfss
});
- }
- });
+ })
+ .catch((err) => {
+ // TODO IGNITE-843 Send error to admin
+ res.status(500).send(err.message);
+ });
});
/**