- No article are currently in this folder.
create one?
+
+ No article are currently in this folder.
create articles
+
create folder
diff --git a/viDoc/modules/folders/server/controllers/folders.server.controller.js b/viDoc/modules/folders/server/controllers/folders.server.controller.js
index 57c2be4..81d1eae 100644
--- a/viDoc/modules/folders/server/controllers/folders.server.controller.js
+++ b/viDoc/modules/folders/server/controllers/folders.server.controller.js
@@ -17,7 +17,7 @@ var path = require('path'),
exports.create = function(req, res) {
var folder = new Folder(req.body);
folder.user = req.user;
- folder.project = req.project || req.user;
+ folder.project = req.project;
folder.save(function(err) {
if (err) {
@@ -25,33 +25,80 @@ exports.create = function(req, res) {
message: errorHandler.getErrorMessage(err)
});
} else {
- res.jsonp(folder);
+ var project = req.project;
+ project.folders.push(folder._id);
+ project.save(err => {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ }
+ res.jsonp(folder);
+ });
}
});
};
/**
- * Show the current Folder
+ * Create a subFolder
*/
-exports.read = function(req, res) {
- // convert mongoose document to JSON
- var folder = req.folder ? req.folder.toJSON() : {};
+exports.createSub = function(req, res) {
+ var subFolder = new Folder(req.body);
+ subFolder.user = req.user;
+ subFolder.parentfolder = req.folder._id;
- // Add a custom field to the Folder, for determining if the current User is the "owner".
- // NOTE: This field is NOT persisted to the database, since it doesn't exist in the Folder model.
- folder.isCurrentUserOwner = req.user && folder.user && folder.user._id.toString() === req.user._id.toString();
- Article.find({ _id: folder.articles }).sort('-created').populate('user', 'displayName').exec(function(err, articles) {
+ subFolder.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
- folder.articles = articles;
- res.jsonp(folder);
+ var folder = req.folder;
+ folder.subfolders.push(subFolder._id);
+ folder.save(err => {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ }
+ res.jsonp(subFolder);
+ });
}
});
};
+/**
+ * Show the current Folder
+ */
+exports.read = function(req, res) {
+ // convert mongoose document to JSON
+ var folder = req.folder ? req.folder.toJSON() : {};
+
+ // Add a custom field to the Folder, for determining if the current User is the "owner".
+ // NOTE: This field is NOT persisted to the database, since it doesn't exist in the Folder model.
+ folder.isCurrentUserOwner = req.user && folder.user && folder.user._id.toString() === req.user._id.toString();
+ Article.find({ _id: folder.articles }, { 'created': 1, 'title': 1, 'user': 1}).sort('-created')
+ .populate('user', 'displayName').exec(function(err, articles) {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ } else {
+ folder.articles = articles;
+ Folder.find({ _id: folder.subfolders }).sort('-created')
+ .populate('user', 'displayName').exec(function(err, folders) {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ }
+ folder.subfolders = folders;
+ res.jsonp(folder);
+ });
+ }
+ });
+};
+
/**
* Update a Folder
*/
@@ -76,6 +123,7 @@ exports.update = function(req, res) {
*/
exports.delete = function(req, res) {
var folder = req.folder;
+ var project = req.project;
folder.remove(function(err) {
if (err) {
@@ -83,7 +131,28 @@ exports.delete = function(req, res) {
message: errorHandler.getErrorMessage(err)
});
} else {
- res.jsonp(folder);
+ if (folder.parentfolder) {
+ Folder.updateOne({ _id: folder.parentfolder }, {
+ $pull: { subfolders: folder._id }
+ }, function (err, parentfolder) {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ }
+ res.jsonp(folder);
+ });
+ } else {
+ project.folders.splice(project.folders.indexOf(folder._id), 1);
+ project.save(err => {
+ if (err) {
+ return res.status(400).send({
+ message: errorHandler.getErrorMessage(err)
+ });
+ }
+ res.jsonp(folder);
+ });
+ }
}
});
};
diff --git a/viDoc/modules/folders/server/models/folder.server.model.js b/viDoc/modules/folders/server/models/folder.server.model.js
index 0111758..8dbeba9 100644
--- a/viDoc/modules/folders/server/models/folder.server.model.js
+++ b/viDoc/modules/folders/server/models/folder.server.model.js
@@ -35,6 +35,10 @@ var FolderSchema = new Schema({
type: Schema.ObjectId,
ref: 'User'
},
+ parentfolder: {
+ type: Schema.ObjectId,
+ ref: 'Folder'
+ },
user: {
type: Schema.ObjectId,
ref: 'User'
diff --git a/viDoc/modules/folders/server/policies/folders.server.policy.js b/viDoc/modules/folders/server/policies/folders.server.policy.js
index b2a7a10..881e0ca 100644
--- a/viDoc/modules/folders/server/policies/folders.server.policy.js
+++ b/viDoc/modules/folders/server/policies/folders.server.policy.js
@@ -15,28 +15,34 @@ exports.invokeRolesPolicies = function () {
acl.allow([{
roles: ['admin'],
allows: [{
- resources: '/api/folders',
+ resources: '/api/projects/:projectId/folders',
permissions: '*'
}, {
- resources: '/api/folders/:folderId',
+ resources: '/api/projects/:projectId/folders/:folderId',
+ permissions: '*'
+ }, {
+ resources: '/api/projects/:projectId/folders/:folderId/subfolder',
permissions: '*'
}]
}, {
roles: ['user'],
allows: [{
- resources: '/api/folders',
+ resources: '/api/projects/:projectId/folders',
permissions: ['*']
}, {
- resources: '/api/folders/:folderId',
+ resources: '/api/projects/:projectId/folders/:folderId',
permissions: ['*']
+ }, {
+ resources: '/api/projects/:projectId/folders/:folderId/subfolder',
+ permissions: '*'
}]
}, {
roles: ['guest'],
allows: [{
- resources: '/api/folders',
+ resources: '/api/projects/:projectId/folders',
permissions: ['get']
}, {
- resources: '/api/folders/:folderId',
+ resources: '/api/projects/:projectId/folders/:folderId',
permissions: ['get']
}]
}]);
diff --git a/viDoc/modules/folders/server/routes/folders.server.routes.js b/viDoc/modules/folders/server/routes/folders.server.routes.js
index c0c3f2c..b03fcf8 100644
--- a/viDoc/modules/folders/server/routes/folders.server.routes.js
+++ b/viDoc/modules/folders/server/routes/folders.server.routes.js
@@ -8,15 +8,18 @@ var foldersPolicy = require('../policies/folders.server.policy'),
module.exports = function(app) {
// Folders Routes
- app.route('/api/folders').all(foldersPolicy.isAllowed)
+ app.route('/api/projects/:projectId/folders').all(foldersPolicy.isAllowed)
.get(folders.list)
.post(folders.create);
- app.route('/api/folders/:folderId').all(foldersPolicy.isAllowed)
+ app.route('/api/projects/:projectId/folders/:folderId').all(foldersPolicy.isAllowed)
.get(folders.read)
.put(folders.update)
.delete(folders.delete);
+ app.route('/api/projects/:projectId/folders/:folderId/subfolder').all(foldersPolicy.isAllowed)
+ .post(folders.createSub);
+
// Finish by binding the Folder middleware
app.param('folderId', folders.folderByID);
};
diff --git a/viDoc/modules/projects/client/controllers/projects.client.controller.js b/viDoc/modules/projects/client/controllers/projects.client.controller.js
index 90bd4cf..1a91c3f 100644
--- a/viDoc/modules/projects/client/controllers/projects.client.controller.js
+++ b/viDoc/modules/projects/client/controllers/projects.client.controller.js
@@ -17,15 +17,12 @@
vm.form = {};
vm.remove = remove;
vm.save = save;
- vm.close= close;
+ vm.close = close;
// Remove existing Project
- vm.folderName = function (name) {
- return name.replace(/ /gi, '-').toLowerCase();
- };
function remove() {
if ($window.confirm('Are you sure you want to delete?')) {
vm.project.$remove(function() {
- $state.go('projects.list')
+ $state.go('projects.list');
});
}
}
diff --git a/viDoc/modules/projects/client/projects.client.module.js b/viDoc/modules/projects/client/projects.client.module.js
index a932875..4425229 100644
--- a/viDoc/modules/projects/client/projects.client.module.js
+++ b/viDoc/modules/projects/client/projects.client.module.js
@@ -1,6 +1,6 @@
(function (app) {
'use strict';
- app.registerModule('projects',['core']);
+ app.registerModule('projects', ['core']);
app.registerModule('project.routes', ['ui.router', 'core.routes']);
}(ApplicationConfiguration));
diff --git a/viDoc/modules/projects/client/views/list-projects.client.view.html b/viDoc/modules/projects/client/views/list-projects.client.view.html
index 2540381..2af91ae 100644
--- a/viDoc/modules/projects/client/views/list-projects.client.view.html
+++ b/viDoc/modules/projects/client/views/list-projects.client.view.html
@@ -9,7 +9,7 @@
-
- No Folders yet, why don't you
create one?
+
+ No Folders yet, why don't you
create one article
+
create one folder
diff --git a/viDoc/modules/projects/server/controllers/projects.server.controller.js b/viDoc/modules/projects/server/controllers/projects.server.controller.js
index 20c204d..2489fb6 100644
--- a/viDoc/modules/projects/server/controllers/projects.server.controller.js
+++ b/viDoc/modules/projects/server/controllers/projects.server.controller.js
@@ -6,6 +6,7 @@
var path = require('path'),
mongoose = require('mongoose'),
Project = mongoose.model('Project'),
+ Article = mongoose.model('Article'),
Folder = mongoose.model('Folder'),
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
_ = require('lodash');
@@ -40,14 +41,21 @@ exports.read = function(req, res) {
project.isCurrentUserOwner = req.user && project.user && project.user._id.toString() === req.user._id.toString();
Folder.find({ _id: project.folders }).populate('user', 'displayName').exec(function (err, folders) {
if (err) {
- return next(err);
- } else if (!folders) {
return res.status(404).send({
message: 'No Folder with that identifier has been found'
});
}
project.folders = folders;
- res.jsonp(project);
+ Article.find({ _id: project.articles }, { 'created': 1, 'title': 1, 'user': 1 }).sort('-created')
+ .populate('user', 'displayName').exec(function (err, articles) {
+ if (err) {
+ return res.status(404).send({
+ message: 'No Folder with that identifier has been found'
+ });
+ }
+ project.articles = articles;
+ res.jsonp(project);
+ });
});
};
diff --git a/viDoc/modules/projects/server/models/project.server.model.js b/viDoc/modules/projects/server/models/project.server.model.js
index 09d773e..65cf763 100644
--- a/viDoc/modules/projects/server/models/project.server.model.js
+++ b/viDoc/modules/projects/server/models/project.server.model.js
@@ -22,7 +22,7 @@ var ProjectSchema = new Schema({
},
articles: {
type: Array,
- default:[]
+ default: []
},
tag: {
type: Array,
@@ -32,7 +32,7 @@ var ProjectSchema = new Schema({
type: Array,
default: []
},
- description :{
+ description: {
type: String,
default: ''
},