cleaned up submissions table

This commit is contained in:
David Baldwynn 2015-07-01 21:54:46 -07:00
parent 0c8c320a71
commit 8204980626
8 changed files with 333 additions and 313 deletions

View file

@ -15,7 +15,7 @@ var mongoose = require('mongoose'),
_ = require('lodash');
/**
* Create a new form manually
* Create a new form
*/
exports.create = function(req, res) {
var form = new Form(req.body);
@ -107,9 +107,9 @@ exports.createSubmission = function(req, res) {
submission.form_fields = req.body.form_fields;
submission.title = req.body.title;
submission.timeElapsed = req.body.timeElapsed;
console.log(req.body);
// submission.ipAddr = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
if (form.isGenerated){
fdfTemplate = form.convertToFDF();
} else {
@ -120,9 +120,10 @@ exports.createSubmission = function(req, res) {
}
}
if(form.autofillPDFs){
fdfData = pdfFiller.fillFdfTemplate(fdfTemplate, submission.form_fields, null);
submission.fdfData = fdfData;
}
submission.save(function(err){
if (err) {
@ -146,10 +147,12 @@ exports.listSubmissions = function(req, res) {
FormSubmission.find({ form: req.form }).populate('admin', 'form').exec(function(err, submissions) {
if (err) {
res.status(400).send({
console.log(err);
res.status(500).send({
message: errorHandler.getErrorMessage(err)
});
} else {
console.log('hello');
res.json(submissions);
}
});
@ -186,7 +189,7 @@ exports.delete = function(req, res) {
console.log('deleting form');
Form.remove({_id: form._id}, function(err) {
if (err) {
res.status(400).send({
res.status(500).send({
message: err.message
});
} else {
@ -228,12 +231,14 @@ exports.formByID = function(req, res, next, id) {
}
Form.findById(id).populate('admin').exec(function(err, form) {
if (err) return next(err);
if (!form) {
if (err) {
return next(err);
} else if (!form || form === null) {
res.status(404).send({
message: 'Form not found'
});
}
else {
if(!form.admin){
form.admin = req.user;
form.save(function(err) {
@ -261,6 +266,7 @@ exports.formByID = function(req, res, next, id) {
req.form = form;
next();
}
});
};

View file

@ -85,10 +85,10 @@ FormSubmissionSchema.pre('save', function (next) {
Form.findById(that.form, function(err, _form){
if(err) next( new Error(err.mesasge) );
// that.title = _form.title;
that.title = _form.title;
// console.log(_form);
if(true){ //_form.autofillPDFs){
if(_form.autofillPDFs){
dest_filename = _form.title.trim()+'_submission_'+Date.now()+'.pdf';
dest_path = path.join(config.pdfUploadPath, dest_filename);
@ -97,7 +97,6 @@ FormSubmissionSchema.pre('save', function (next) {
// console.log('autofillPDFs check');
pdfFiller.fillForm(_form.pdf.path, dest_path, this.fdfData, function(err){
console.log('fdfData: \n');
console.log(that.fdfData);
@ -113,13 +112,11 @@ FormSubmissionSchema.pre('save', function (next) {
next();
});
} else {
next();
}
});
});
mongoose.model('FormSubmission', FormSubmissionSchema);

View file

@ -2,11 +2,6 @@
angular.module('forms').controller('EditFormController', ['$scope', '$state', '$rootScope', '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(){
// console.log('aeouaoeuaoeuaou');
// console.log('isAuthenticated(): '+Principal.isAuthenticated());\
$scope.isNewForm = false;
$scope.pdfLoading = false;
@ -234,7 +229,5 @@ angular.module('forms').controller('EditFormController', ['$scope', '$state', '$
else
return false;
};
// });
}
]);

View file

@ -4,19 +4,9 @@
angular.module('forms').controller('SubmitFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm',
function($scope, $stateParams, $state, Forms, CurrentForm) {
// Principal.identity().then(function(user){
// $scope.authentication.user = user;
// }).then(function(){
$scope.form = Forms.get({
formId: $stateParams.formId
});
CurrentForm.setForm($scope.form);
// console.log($scope.form);
// });
}
]);

View file

@ -5,12 +5,37 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
function($scope, $stateParams, $state, Forms, CurrentForm, $http) {
// view form submissions
$scope.form = CurrentForm.getForm();
$scope.submissions = undefined;
$scope.viewSubmissions = false;
//show submissions of Form
$scope.showSubmissions = function(){
$scope.viewSubmissions = true;
if(!$scope.submissions){
$http.get('/forms/'+$scope.form._id+'/submissions')
.success(function(data, status, headers){
console.log(data);
$scope.submissions = data;
console.log('form submissions successfully fetched');
})
.error(function(err){
console.log('Could not fetch form submissions.\nError: '+err);
});
} else if(!$scope.submissions.length){
$http.get('/forms/'+$scope.form._id+'/submissions')
.success(function(data, status, headers){
$scope.submissions = data;
console.log('form submissions successfully fetched');
})
.error(function(err){
console.log('Could not fetch form submissions.\nError: '+err);
});
}
console.log($scope.submissions);
}
//hide submissions of Form
$scope.hideSubmissions = function(){
$scope.viewSubmissions = false;
@ -47,8 +72,5 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
});
};
// });
}
]);

View file

@ -41,14 +41,14 @@
</div>
<br><br><br><br><br>
<div class="row form-actions">
<p class="text-center col-xs-3 col-xs-offset-2">
<p class="text-center col-xs-3 col-xs-offset-4">
<button class="btn btn-success left" type="button">
<a href="/#!/form/{{form._id}}" style="color:white;"> Submit again?</a>
<a href="/#!/forms/{{form._id}}" style="color:white;"> Submit again?</a>
</button>
</p>
<p class="text-center col-xs-2" ng-if="authentication.isAuthenticated()">
<button class="btn btn-caution left" type="button">
<a href="/form/{{form.id}}/admin" style="color:white;">Edit Form</a>
<a href="/#!/forms/{{form._id}}/admin" style="color:white;">Edit Form</a>
</button>
</p>
</div>

View file

@ -25,20 +25,32 @@
</p>
</div>
<div class="submissions-table col-xs-8" ng-if="viewSubmissions">
<table class="table table-striped">
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>#</th>
<th data-ng-repeat="(key, val) in submissions[0].form_fields">
{{key}}
<th data-ng-repeat="(key, value) in submissions[0].form_fields">
{{value.title}}
</th>
<th>
Time Elapsed
</th>
<th>
Date Submitted (UTC)
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="submission in submissions">
<td>{{$index+1}}</td>
<td data-ng-repeat="(key, val) in submission.form_fields">
{{value}}
<th class="scope">{{$index+1}}</th>
<td data-ng-repeat="(key, value) in submission.form_fields">
{{value.fieldValue}}
</td>
<td>
{{submission.timeElapsed}}
</th>
<td>
{{submission.created | date:'yyyy-MM-dd HH:mm:ss'}}
</td>
</tr>
</tbody>