diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js
index f098fae3..a7291c31 100644
--- a/app/controllers/forms.server.controller.js
+++ b/app/controllers/forms.server.controller.js
@@ -12,6 +12,7 @@ var mongoose = require('mongoose'),
config = require('../../config/config'),
fs = require('fs-extra'),
async = require('async'),
+ path = require('path'),
_ = require('lodash');
/**
@@ -38,39 +39,53 @@ exports.create = function(req, res) {
/**
* Upload PDF
*/
-exports.uploadPDF = function(req, res) {
- var parser = new PDFParser(),
- pdfFile = req.files.file;
+var upload_count = 0;
+exports.uploadPDF = function(files, user, cb) {
+ var parser = new PDFParser();
+ console.log("upload count: "+upload_count);
+ upload_count++;
+ if(files) {
- console.log(pdfFile);
+ console.log('inside uploadPDF');
+ console.log(files.file[0]);
+ var pdfFile = files.file[0];
- var form = Form.findById(req.body.form._id);
- console.log(req.files);
-
- if (req.files) {
-
if (pdfFile.size === 0) {
- return res.status(400).send({
- message: 'Hey, first would you select a file?'
- });
+ throw new Error('Files uploaded are EMPTY');
}
fs.exists(pdfFile.path, function(exists) {
+ //If file exists move to user's tmp directory
if(exists) {
- // console.log('UPLOADING FILE \N\N');
- return res.status(200).send({
- message: 'Got your file!'
- });
+
+ var newDestination = path.join(config.tmpUploadPath, user.username);
+ var stat = null;
+ try {
+ stat = fs.statSync(newDestination);
+ } catch (err) {
+ fs.mkdirSync(newDestination);
+ }
+ if (stat && !stat.isDirectory()) {
+ console.log('Directory cannot be created');
+ throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');
+ }
+
+ fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
+ if (err) {
+ throw new Error(err.message);
+ }
+ pdfFile.path = path.join(newDestination, pdfFile.name);
+
+ return cb(pdfFile);
+ });
+
} else {
- return res.status(400).send({
- message: 'Did NOT get your file!'
- });
+ throw new Error('Did NOT get your file!');
}
});
- }
+ }else {
+ throw new Error('File NOT uploaded');
+ }
- return res.status(400).send({
- message: 'FILE NOT UPLOADED'
- });
};
/**
diff --git a/app/routes/forms.server.routes.js b/app/routes/forms.server.routes.js
index 4d240194..d5340659 100644
--- a/app/routes/forms.server.routes.js
+++ b/app/routes/forms.server.routes.js
@@ -12,7 +12,7 @@ module.exports = function(app) {
.post(forms.uploadPDF);
app.route('/forms')
- .get(users.requiresLogin, forms.hasAuthorization, forms.list)
+ .get(users.requiresLogin, forms.list)
.post(users.requiresLogin, forms.create);
app.route('/forms/:formId/submissions')
diff --git a/app/views/index.server.view.html b/app/views/index.server.view.html
index 7e60893b..515f440a 100755
--- a/app/views/index.server.view.html
+++ b/app/views/index.server.view.html
@@ -1,5 +1,5 @@
{% extends 'layout.server.view.html' %}
{% block content %}
-
+
{% endblock %}
diff --git a/app/views/layout.server.view.html b/app/views/layout.server.view.html
index 6c75244e..7fe73090 100755
--- a/app/views/layout.server.view.html
+++ b/app/views/layout.server.view.html
@@ -47,7 +47,7 @@
-
+
diff --git a/config/express.js b/config/express.js
index 135faa44..5cc9d54e 100755
--- a/config/express.js
+++ b/config/express.js
@@ -96,33 +96,28 @@ module.exports = function(db) {
// Setting the app router and static folder
app.use(express.static(path.resolve('./public')));
+ var formCtrl = require('../app/controllers/forms.server.controller');
// Setting the pdf upload route and folder
app.use(multer({ dest: config.tmpUploadPath,
rename: function (fieldname, filename) {
return Date.now();
},
- // changeDest: function(dest, req, res) {
- // console.log(req.body.form);
-
- // var newDestination = dest + req.body.form.title;
- // var stat = null;
- // try {
- // stat = fs.statSync(newDestination);
- // } catch (err) {
- // fs.mkdirSync(newDestination);
- // }
- // if (stat && !stat.isDirectory()) {
- // console.log('Directory cannot be created');
- // throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');
- // }
- // return newDestination;
- // },
onFileUploadStart: function (file) {
console.log(file.originalname + ' is starting ...');
},
- onFileUploadComplete: function (file) {
- console.log(file.fieldname + ' uploaded to ' + file.path);
- // done=true;
+ onFileUploadComplete: function (file, req, res) {
+ console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
+ // console.log(req.files.file[0]);
+ try{
+ formCtrl.uploadPDF(req.files, function(_file){
+ console.log(_file.filename + ' uploaded to ' + _file.path);
+ res.status(200).send(_file);
+ });
+ }catch(err) {
+ res.status(500).send({
+ message: err.message
+ });
+ }
}
}));
diff --git a/public/application.js b/public/application.js
index e260ccf3..f31ecd63 100755
--- a/public/application.js
+++ b/public/application.js
@@ -9,16 +9,24 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio
$locationProvider.hashPrefix('!');
}
]);
-angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope',
- function($rootScope) {
- $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
- // track the state the user wants to go to; authorization service needs this
- $rootScope.toState = toState;
- $rootScope.toStateParams = toStateParams;
- // if the principal is resolved, do an authorization check immediately. otherwise,
- // it'll be done when the state it resolved.
- // if (Principal.isIdentityResolved()) Authorization.authorize();
- });
+angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', '$state', '$stateParams',
+ function($rootScope, $state, $stateParams) {
+ // $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
+ // // track the state the user wants to go to; authorization service needs this
+ // $rootScope.toState = toState;
+ // $rootScope.toStateParams = toStateParams;
+ // // if the principal is resolved, do an authorization check immediately. otherwise,
+ // // it'll be done when the state it resolved.
+ // });
+
+ $rootScope.$state = $state;
+ $rootScope.$stateParams = $stateParams;
+
+ // add previous state property
+ $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState) {
+ $state.previous = fromState;
+ });
+
}
]);
diff --git a/public/modules/core/controllers/header.client.controller.js b/public/modules/core/controllers/header.client.controller.js
index e87b835c..2a2b3d49 100755
--- a/public/modules/core/controllers/header.client.controller.js
+++ b/public/modules/core/controllers/header.client.controller.js
@@ -1,13 +1,41 @@
'use strict';
-angular.module('core').controller('HeaderController', ['$rootScope','$scope','Menus', '$state',
- function($rootScope, $scope, Menus, $state) {
- // $rootScope.authentication = Auth;
- // $rootScope.user = {},
+angular.module('core').controller('HeaderController', ['$rootScope','$scope','Menus', '$state', 'Auth', 'User',
+ function($rootScope, $scope, Menus, $state, Auth, User) {
+ $scope.user = $rootScope.user = Auth.ensureHasCurrentUser(User);
+ $scope.authentication = $rootScope.authentication = Auth;
+
+ console.log('isAuthenticated(): '+$scope.authentication.isAuthenticated());
+
$scope.isCollapsed = false;
$scope.hideNav = false;
$scope.menu = Menus.getMenu('topbar');
+
+ $scope.signout = function() {
+ User.logout(function() {
+ Auth.logout();
+ $rootScope.user = null;
+ $state.go('home');
+ });
+ };
+
+ $scope.toggleCollapsibleMenu = function() {
+ $scope.isCollapsed = !$scope.isCollapsed;
+ };
+
+ // Collapsing the menu after navigation
+ $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
+ $scope.isCollapsed = false;
+ $scope.hideNav = false;
+ if ( angular.isDefined( toState.data ) ) {
+
+ if ( angular.isDefined( toState.data.hideNav ) ) {
+ $scope.hideNav = toState.data.hideNav;
+ }
+ }
+ });
+
// Principal.identity().then(function(user){
// $rootScope.user = user;
// console.log('topbar')
@@ -39,21 +67,6 @@ angular.module('core').controller('HeaderController', ['$rootScope','$scope','Me
// };
- $scope.toggleCollapsibleMenu = function() {
- $scope.isCollapsed = !$scope.isCollapsed;
- };
-
- // Collapsing the menu after navigation
- $scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
- $scope.isCollapsed = false;
- $scope.hideNav = false;
- if ( angular.isDefined( toState.data ) ) {
-
- if ( angular.isDefined( toState.data.hideNav ) ) {
- $scope.hideNav = toState.data.hideNav;
- }
- }
- });
// });
}
diff --git a/public/modules/core/controllers/home.client.controller.js b/public/modules/core/controllers/home.client.controller.js
index 269c4504..0f37d3cd 100755
--- a/public/modules/core/controllers/home.client.controller.js
+++ b/public/modules/core/controllers/home.client.controller.js
@@ -1,22 +1,17 @@
'use strict';
-angular.module('core').controller('HomeController', ['$rootScope', '$scope',
- function($rootScope, $scope) {
- // This provides Principal context.
- // $scope.authentication = Principal;
- // $scope.user = {};
+angular.module('core').controller('HomeController', ['$rootScope', '$scope', 'User', 'Auth', '$state',
+ function($rootScope, $scope, User, Auth, $state) {
+ $scope = $rootScope;
- // $rootScope.user = $window.user;
console.log($rootScope.user);
+ $scope.user = Auth.ensureHasCurrentUser(User);
+ $scope.authentication = Auth;
- // Principal.identity().then(function(user){
- // console.log(user);
- // $scope.user = user;
- // }, function(){
- // console.log('error');
- // });
- // console.log("user.displayName: "+Principal.user()._id);
+ if($scope.authentication.isAuthenticated()){
+ $state.go('listForms');
+ }
}
]);
\ No newline at end of file
diff --git a/public/modules/core/controllers/index.client.controller.js b/public/modules/core/controllers/index.client.controller.js
index 52a851e5..487db31b 100644
--- a/public/modules/core/controllers/index.client.controller.js
+++ b/public/modules/core/controllers/index.client.controller.js
@@ -1,73 +1,25 @@
-'use strict';
+// 'use strict';
-/**
- * @ngdoc function
- * @name medform.controller:IndexCtrl
- * @description
- * # IndexCtrl
- * Controller of core
- */
-angular.module('medform').controller('IndexCtrl', function ($scope, $rootScope, $location, User, Auth, $state) {
- $rootScope.user = Auth.ensureHasCurrentUser(User);
- // $rootScope.user = Auth.getUserState(User).user;
- $rootScope.authorization = Auth;
+// /**
+// * @ngdoc function
+// * @name medform.controller:IndexCtrl
+// * @description
+// * # IndexCtrl
+// * Controller of core
+// */
+// angular.module('medform').controller('IndexCtrl', function ($scope, $rootScope, $location, User, Auth, $state) {
+// $rootScope.user = Auth.ensureHasCurrentUser(User);
+// // $rootScope.user = Auth.getUserState(User).user;
+// $rootScope.authentication = Auth;
+
+// $scope.signout = function() {
+// User.logout(function() {
+// Auth.logout();
+// $rootScope.user = null;
+// $state.go('home');
+// // $scope.$apply();
+// });
+// };
- $scope.signin = function() {
- Auth.currentUser = User.login($scope.credentials,
- function(response) {
-
- // console.log(response);
- // Auth.currentUser = $rootScope.loginResult.user;
- Auth.login();
- $rootScope.user = Auth.ensureHasCurrentUser(User);
-
- // console.log( $rootScope.loginResult.user);
-
- $location.path('listForms');
- },
- function(res) {
-
- $scope.loginError = res.data.error;
- console.log('loginError: '+res.data.error);
- $rootScope.user = Auth.ensureHasCurrentUser(User);
-
- // if(!$scope.loginError){
- // Auth.currentUser = rootScope.loginResult.user;
- // console.log(Auth.currentUser );
- // }
-
- // Auth.currentUser = $rootScope.loginResult.user;
- }
- );
-
- console.log(Auth.currentUser);
- // Auth.currentUser = $rootScope.loginResult;
-
- };
-
- $scope.signup = function() {
- $scope.user = User.save($scope.registration,
- function() {
- },
- function(res) {
- if(res && res.data) {
- $scope.registerError = res.data.error;
- }else {
- console.log('No response received');
- }
- }
- );
- };
-
- $scope.signout = function() {
- User.logout(function() {
- Auth.logout();
- $rootScope.user = null;
- $state.go('home');
- // $scope.$apply();
- });
- };
-
-
- });
+// });
diff --git a/public/modules/core/css/core.css b/public/modules/core/css/core.css
index ec072f82..0b670576 100755
--- a/public/modules/core/css/core.css
+++ b/public/modules/core/css/core.css
@@ -7,9 +7,12 @@
.navbar .navbar-brand span {
text-decoration: underline;
}
+.nav.navbar-nav.navbar-right li {
+ padding-right: 20px;
+}
.content {
- /*margin-top: 50px;*/
+ margin-top: 100px;
}
.undecorated-link:hover {
text-decoration: none;
diff --git a/public/modules/core/views/header.client.view.html b/public/modules/core/views/header.client.view.html
index b20b4bf0..fde993f1 100755
--- a/public/modules/core/views/header.client.view.html
+++ b/public/modules/core/views/header.client.view.html
@@ -13,7 +13,7 @@
diff --git a/public/modules/forms/controllers/create-form.client.controller.js b/public/modules/forms/controllers/create-form.client.controller.js
index 577ea3a0..79647a82 100644
--- a/public/modules/forms/controllers/create-form.client.controller.js
+++ b/public/modules/forms/controllers/create-form.client.controller.js
@@ -1,7 +1,7 @@
'use strict';
-angular.module('forms').controller('EditFormController', ['$scope', '$state', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
- function ($scope, $state, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location) {
+angular.module('forms').controller('EditFormController', ['$scope', '$rootScope', '$state', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
+ function ($scope, $state, $rootScope, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location) {
// Principal.identity().then(function(user){
// $scope.authentication.user = user;
// }).then(function(){
@@ -9,6 +9,8 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', 'U
// console.log('isAuthenticated(): '+Principal.isAuthenticated());\
$scope.isNewForm = false;
+ $scope.pdfLoading = false;
+ var _current_upload = null;
$scope.log = '';
// Get current form if it exists, or create new one
@@ -28,46 +30,52 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', 'U
}
//PDF Functions
-
$scope.cancelUpload = function(){
- //TBD
+ _current_upload.abort();
+ $scope.pdfLoading = false;
};
$scope.removePDF = function(){
$scope.form.pdf = null;
+ $scope.isGenerated = false;
+ $scope.autofillPDFs = false;
- console.log('form.pdf exists: '+!!$scope.form.pdf);
+ console.log('form.pdf: '+$scope.form.pdf+' REMOVED');
};
$scope.uploadPDF = function(files) {
if (files && files.length) {
- for (var i = 0; i < files.length; i++) {
- var file = files[i];
- Upload.upload({
- url: '/upload/pdf',
- fields: {
- 'user': $scope.form.admin,
- 'form': $scope.form
- },
- file: file
- }).progress(function (evt) {
- var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
- $scope.log = 'progress: ' + progressPercentage + '% ' +
- evt.config.file.name + '\n' + $scope.log;
- }).success(function (data, status, headers, config) {
- $scope.log = 'file ' + data.originalname + 'uploaded as '+ data.name +'. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
- $scope.pdf = data;
- $scope.form.pdf = data;
+ // for (var i = 0; i < files.length; i++) {
+ var file = files[0];
+ _current_upload = Upload.upload({
+ url: '/upload/pdf',
+ fields: {
+ 'user': $scope.user,
+ 'form': $scope.form
+ },
+ file: file
+ }).progress(function (evt) {
+ var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
+ $scope.log = 'progress: ' + progressPercentage + '% ' +
+ evt.config.file.name + '\n' + $scope.log;
+ $scope.pdfLoading = true;
+ }).success(function (data, status, headers, config) {
+ $scope.log = 'file ' + data.originalname + 'uploaded as '+ data.name +'. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
+ $scope.form.pdf = data;
+ $scope.pdfLoading = false;
- if(!$scope.$$phase) {
- $scope.$apply();
- }
-
- console.log($scope.log);
- console.log('$scope.pdf: '+$scope.pdf.name);
- });
- }
+ console.log($scope.log);
+ console.log('$scope.pdf: '+$scope.form.pdf.name);
+ if(!$scope.$$phase) {
+ $scope.$apply();
+ }
+ }).error(function(err){
+ $scope.pdfLoading = false;
+ console.log('Error occured during upload.\n');
+ console.log(err);
+ });
+ // }
}
};
@@ -82,7 +90,6 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', 'U
// Create new Form object
var form = new Forms($scope.form);
-
form.$save(function(response) {
console.log('form created');
@@ -92,7 +99,8 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', 'U
$scope.form = {};
// Redirect after save
- $location.path('forms/' + response._id + '/admin');
+ $scope.goToWithId('viewForm', response._id);
+ // $location.path('forms/' + response._id + '/admin');
}, function(errorResponse) {
console.log(errorResponse.data.message);
diff --git a/public/modules/forms/css/form.css b/public/modules/forms/css/form.css
index 913219b9..42c6b6cd 100644
--- a/public/modules/forms/css/form.css
+++ b/public/modules/forms/css/form.css
@@ -10,7 +10,7 @@
.form-item.row.create-new {
border-bottom: 4px inset #ccc;
- background-color: rgb(51,51,51);
+ background-color: rgb(131,131,131);
color: white;
}
diff --git a/public/modules/forms/views/create-form.client.view.html b/public/modules/forms/views/create-form.client.view.html
index 51ba2228..cd933826 100644
--- a/public/modules/forms/views/create-form.client.view.html
+++ b/public/modules/forms/views/create-form.client.view.html
@@ -133,7 +133,7 @@
Delete
-