got pdf conversion working

This commit is contained in:
David Baldwynn 2016-04-28 19:48:02 -07:00
parent 1ddf23a848
commit 1279314299
16 changed files with 391 additions and 329 deletions

View file

@ -19,21 +19,26 @@ var mongoose = require('mongoose'),
*/ */
exports.uploadPDF = function(req, res, next) { exports.uploadPDF = function(req, res, next) {
// console.log('inside uploadPDF'); console.log('inside uploadPDF');
// console.log(req.files.file);
// console.log('\n\nProperty Descriptor\n-----------'); // console.log('\n\nProperty Descriptor\n-----------');
// console.log(Object.getOwnPropertyDescriptor(req.files.file, 'path')); // console.log(Object.getOwnPropertyDescriptor(req.files.file, 'path'));
console.log(req.file);
if(req.file){ if(req.file){
var pdfFile = req.file; var pdfFile = req.file;
var _user = req.user; var _user = req.user;
var _path = req.file.path;
if (req.file.size === 0) { if (req.file.size === 0) {
next(new Error('File uploaded is EMPTY')); next(new Error('File uploaded is EMPTY'));
}else if(req.files.size > 200000000){ }else if(req.file.size > 100000000){
next(new Error('File uploaded exceeds MAX SIZE of 200MB')); next(new Error('File uploaded exceeds MAX SIZE of 100MB'));
}else { }else {
fs.exists(pdfFile.path, function(exists) { fs.exists(_path, function(exists) {
//If file exists move to user's tmp directory //If file exists move to user's tmp directory
if(exists) { if(exists) {
@ -44,17 +49,20 @@ exports.uploadPDF = function(req, res, next) {
} catch (err) { } catch (err) {
fs.mkdirSync(newDestination); fs.mkdirSync(newDestination);
} }
if (stat && !stat.isDirectory()) { if (stat && !stat.isDirectory()) {
console.log('Directory cannot be created'); console.log('Directory cannot be created');
next(new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"')); next(new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"'));
} }
console.log(path.join(newDestination, pdfFile.filename));
fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) { fs.move(pdfFile.path, path.join(newDestination, pdfFile.filename), function (err) {
if (err) { if (err) {
next(new Error(err.message)); next(new Error(err.message));
} }
pdfFile.path = path.join(newDestination, pdfFile.name); pdfFile.path = path.join(newDestination, pdfFile.filename);
console.log(pdfFile.name + ' uploaded to ' + pdfFile.path); console.log(pdfFile.filename + ' uploaded to ' + pdfFile.path);
res.json(pdfFile); res.json(pdfFile);
}); });

View file

@ -12,8 +12,13 @@ var mongoose = require('mongoose'),
mUtilities = require('mongoose-utilities'), mUtilities = require('mongoose-utilities'),
fs = require('fs-extra'), fs = require('fs-extra'),
async = require('async'), async = require('async'),
mkdirp = require('mkdirp'),
Random = require('random-js'),
mt = Random.engines.mt19937(),
util = require('util'); util = require('util');
mt.autoSeed();
//Mongoose Models //Mongoose Models
var FieldSchema = require('./form_field.server.model.js'); var FieldSchema = require('./form_field.server.model.js');
var Field = mongoose.model('Field'); var Field = mongoose.model('Field');
@ -48,7 +53,7 @@ var FormSchema = new Schema({
title: { title: {
type: String, type: String,
trim: true, trim: true,
required: 'Form Title cannot be blank', required: 'Form Title cannot be blank'
}, },
language: { language: {
type: String, type: String,
@ -85,7 +90,7 @@ var FormSchema = new Schema({
startPage: { startPage: {
showStart:{ showStart:{
type: Boolean, type: Boolean,
default: false, default: false
}, },
introTitle:{ introTitle:{
type: String, type: String,
@ -144,7 +149,7 @@ var FormSchema = new Schema({
type: String, type: String,
match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/], match: [/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/],
default: '#333' default: '#333'
}, }
}, },
font: String, font: String,
backgroundImage: { type: Schema.Types.Mixed } backgroundImage: { type: Schema.Types.Mixed }
@ -153,7 +158,7 @@ var FormSchema = new Schema({
plugins: { plugins: {
oscarhost: { oscarhost: {
baseUrl: { baseUrl: {
type: String, type: String
}, },
settings: { settings: {
lookupField: { lookupField: {
@ -206,16 +211,6 @@ FormSchema.plugin(mUtilities.timestamp, {
useVirtual: false useVirtual: false
}); });
//DAVID: TODO: Make this so we don't have to update the validFields property ever save
FormSchema.pre('save', function (next) {
if(this.plugins.oscarhost.hasOwnProperty('baseUrl')){
var validUpdateTypes= mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues;
this.plugins.oscarhost.settings.validUpdateTypes = validUpdateTypes;
}
next();
});
//Delete template PDF of current Form //Delete template PDF of current Form
FormSchema.pre('remove', function (next) { FormSchema.pre('remove', function (next) {
if(this.pdf && process.env.NODE_ENV === 'development'){ if(this.pdf && process.env.NODE_ENV === 'development'){
@ -229,23 +224,6 @@ FormSchema.pre('remove', function (next) {
var _original; var _original;
//Set _original
FormSchema.pre('save', function (next) {
this.constructor
.findOne({_id: this._id}).exec(function(err, original){
if(err) {
console.log(err);
next(err);
} else {
_original = original;
//console.log('_original');
// console.log(_original);
next();
}
});
});
function getDeletedIndexes(needle, haystack){ function getDeletedIndexes(needle, haystack){
var deletedIndexes = []; var deletedIndexes = [];
@ -261,234 +239,240 @@ function getDeletedIndexes(needle, haystack){
//Move PDF to permanent location after new template is uploaded //Move PDF to permanent location after new template is uploaded
FormSchema.pre('save', function (next) { FormSchema.pre('save', function (next) {
if(this.pdf){ var that = this;
var that = this;
async.series([
function(callback){
if(that.isModified('pdf') && that.pdf.path){
var new_filename = that.title.replace(/ /g,'')+'_template.pdf'; async.series([function(cb) {
that.constructor
var newDestination = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g,''), that.title.replace(/ /g,'')), .findOne({_id: that._id}).exec(function (err, original) {
stat = null; if (err) {
console.log(err);
try { cb(err);
stat = fs.statSync(newDestination); } else {
} catch (err) { _original = original;
fs.mkdirSync(newDestination); //console.log('_original');
} //console.log(_original);
if (stat && !stat.isDirectory()) { cb(null);
return callback( new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"'), null);
}
var old_path = that.pdf.path;
fs.move(old_path, path.join(newDestination, new_filename), {clobber: true}, function (err) {
if (err) {
console.error(err);
callback( new Error(err.message), 'task1');
}else {
that.pdf.path = path.join(newDestination, new_filename);
that.pdf.name = new_filename;
callback(null,'task1');
}
});
}else {
callback(null,'task1');
}
},
function(callback){
if(that.isGenerated){
that.pdf.path = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g,''), that.title.replace(/ /g,''), that.title.replace(/ /g,'')+'_template.pdf');
that.pdf.name = that.title.replace(/ /g,'')+'_template.pdf';
var _typeConvMap = {
'Multiline': 'textarea',
'Text': 'textfield',
'Button': 'checkbox',
'Choice': 'radio',
'Password': 'password',
'FileSelect': 'filefield',
'Radio': 'radio'
};
// console.log('autogenerating form');
// console.log(that.pdf.path);
pdfFiller.generateFieldJson(that.pdf.path, function(err, _form_fields){
if(err){
callback( new Error(err.message), null);
}else if(!_form_fields.length || _form_fields === undefined || _form_fields === null){
callback( new Error('Generated formfields is empty'), null);
}
//Map PDF field names to FormField field names
for(var i = 0; i < _form_fields.length; i++){
var field = _form_fields[i];
//Convert types from FDF to 'FormField' types
if(_typeConvMap[ field.fieldType+'' ]){
field.fieldType = _typeConvMap[ field.fieldType+'' ];
}
// field = new Field(field);
field.required = false;
_form_fields[i] = field;
}
// console.log('NEW FORM_FIELDS: ');
// console.log(_form_fields);
that.form_fields = that.form_fields.concat(_form_fields);
// console.log('\n\nOLD FORM_FIELDS: ');
// console.log(that.form_fields);
that.isGenerated = false;
callback(null, 'task2');
});
}else{
callback(null, 'task2');
}
} }
], function(err, results) {
if(err){
next(new Error({
message: err.message
}));
}
console.log('ending form save');
next();
}); });
}else if(_original){ }, function(cb) {
if(_original.hasOwnProperty('pdf')){ //DAVID: TODO: Make this so we don't have to update the validFields property ever save
fs.remove(_original.pdf.path, function (err) { if (that.plugins.oscarhost.hasOwnProperty('baseUrl')) {
if(err) next(err); var validUpdateTypes = mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues;
console.log('file at '+_original.pdf.path+' successfully deleted'); that.plugins.oscarhost.settings.validUpdateTypes = validUpdateTypes;
next();
});
} }
} cb(null);
next(); },
}); function(cb) {
if (that.pdf) {
async.series([
function (callback) {
if (that.isModified('pdf') && that.pdf.path) {
FormSchema.pre('save', function (next) { var new_filename = that.title.replace(/ /g, '') + '_template.pdf';
// console.log('_original\n------------'); var newDestination = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g, ''), that.title.replace(/ /g, '')),
// console.log(_original); stat = null;
//console.log('field has been deleted: ');
//console.log(this.isModified('form_fields') && !!this.form_fields && !!_original);
if(this.isModified('form_fields') && this.form_fields && _original){ try {
stat = fs.statSync(newDestination);
var old_form_fields = _original.form_fields, } catch (err) {
new_ids = _.map(_.pluck(this.form_fields, '_id'), function(id){ return ''+id;}), mkdirp.sync(newDestination);
old_ids = _.map(_.pluck(old_form_fields, '_id'), function(id){ return ''+id;}), }
deletedIds = getDeletedIndexes(old_ids, new_ids), if (stat && !stat.isDirectory()) {
that = this; return callback(new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"'), null);
// console.log('deletedId Indexes\n--------');
// console.log(deletedIds);
// console.log('old_ids\n--------');
// console.log(old_ids);
// console.log('new_ids\n--------');
// console.log(new_ids);
//Preserve fields that have at least one submission
if( deletedIds.length > 0 ){
var modifiedSubmissions = [];
async.forEachOfSeries(deletedIds,
function (deletedIdIndex, key, callback) {
var deleted_id = old_ids[deletedIdIndex];
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
FormSubmission.
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
exec(function(err, submissions){
if(err){
console.error(err);
return callback(err);
} }
//Delete field if there are no submission(s) found var old_path = that.pdf.path;
if(submissions.length) { fs.move(old_path, path.join(newDestination, new_filename), {clobber: true}, function (err) {
// console.log('adding submissions'); if (err) {
// console.log(submissions); console.error(err);
//Add submissions callback(new Error(err.message), 'task1');
modifiedSubmissions.push.apply(modifiedSubmissions, submissions); } else {
} that.pdf.path = path.join(newDestination, new_filename);
that.pdf.name = new_filename;
callback(null); callback(null, 'task1');
}); }
// } });
}, } else {
function (err) { callback(null, 'task1');
if(err){ }
console.error(err.message); },
next(err); function (callback) {
if (that.isGenerated) {
that.pdf.path = config.pdfUploadPath + that.admin.username.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '/' + that.title.replace(/ /g, '') + '_template.pdf';
that.pdf.name = that.title.replace(/ /g, '') + '_template.pdf';
var _typeConvMap = {
'Multiline': 'textarea',
'Text': 'textfield',
'Button': 'checkbox',
'Choice': 'radio',
'Password': 'password',
'FileSelect': 'filefield',
'Radio': 'radio'
};
pdfFiller.generateFieldJson(that.pdf.path, '', function (err, _form_fields) {
//console.log(that.pdf.path);
if (err) {
callback(new Error(err.message), null);
} else if (!_form_fields.length || _form_fields === undefined || _form_fields === null) {
callback(new Error('Generated formfields is empty'), null);
}
console.log('autogenerating form');
//Map PDF field names to FormField field names
for (var i = 0; i < _form_fields.length; i++) {
var _field = _form_fields[i];
//Convert types from FDF to 'FormField' types
if (_typeConvMap[_field.fieldType + '']) {
_field.fieldType = _typeConvMap[_field.fieldType + ''];
}
var new_field = {};
new_field.title = _field.fieldType + ' ' + Math.abs(mt());
new_field.fieldValue = '';
new_field.disabled = false;
new_field.fieldType = _field.fieldType;
new_field.deletePreserved = false;
new_field.required = false;
_form_fields[i] = new_field;
}
that.form_fields = _form_fields;
that.isGenerated = false;
callback(null, 'task2');
});
} else {
callback(null, 'task2');
}
} }
], function (err, results) {
// console.log('modifiedSubmissions\n---------\n\n'); if (err) {
// console.log(modifiedSubmissions); cb(new Error({
message: err.message
}));
//Iterate through all submissions with modified form_fields } else {
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) { //console.log('ending form save1');
cb();
//Iterate through ids of deleted fields }
for(var i = 0; i < deletedIds.length; i++){ });
}
var index = _.findIndex(submission.form_fields, function(field){ else if (_original) {
var tmp_id = field._id+''; if (_original.hasOwnProperty('pdf')) {
return tmp_id === old_ids[ deletedIds[i] ]; fs.remove(_original.pdf.path, function (err) {
} if (err) cb(err);
); console.log('file at ' + _original.pdf.path + ' successfully deleted');
cb();
var deletedField = submission.form_fields[index];
//Hide field if it exists
if(deletedField){
// console.log('deletedField\n-------\n\n');
// console.log(deletedField);
//Delete old form_field
submission.form_fields.splice(index, 1);
deletedField.deletePreserved = true;
//Move deleted form_field to start
submission.form_fields.unshift(deletedField);
that.form_fields.unshift(deletedField);
// console.log('form.form_fields\n--------\n\n');
// console.log(that.form_fields);
}
}
submission.save(function (err) {
if(err) callback(err);
else callback(null);
});
}, function (err) {
if(err){
console.error(err.message);
next(err);
}
// console.log('form.form_fields\n--------\n\n');
// console.log(that.form_fields);
next();
}); });
} }
); else cb();
}else { }
next(); else cb();
} },
}else { function(cb) {
next();
}
});
if(that.isModified('form_fields') && that.form_fields && _original){
var old_form_fields = _original.form_fields,
new_ids = _.map(_.pluck(that.form_fields, '_id'), function(id){ return ''+id;}),
old_ids = _.map(_.pluck(old_form_fields, '_id'), function(id){ return ''+id;}),
deletedIds = getDeletedIndexes(old_ids, new_ids);
//Preserve fields that have at least one submission
if( deletedIds.length > 0 ){
var modifiedSubmissions = [];
async.forEachOfSeries(deletedIds,
function (deletedIdIndex, key, cb_id) {
var deleted_id = old_ids[deletedIdIndex];
//Find FormSubmissions that contain field with _id equal to 'deleted_id'
FormSubmission.
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
exec(function(err, submissions){
if(err) {
console.error(err);
cb_id(err);
} else {
//Delete field if there are no submission(s) found
if (submissions.length) {
//Add submissions
modifiedSubmissions.push.apply(modifiedSubmissions, submissions);
}
cb_id(null);
}
});
},
function (err) {
if(err){
console.error(err.message);
cb(err);
} else {
//Iterate through all submissions with modified form_fields
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
//Iterate through ids of deleted fields
for (var i = 0; i < deletedIds.length; i++) {
var index = _.findIndex(submission.form_fields, function (field) {
var tmp_id = field._id + '';
return tmp_id === old_ids[deletedIds[i]];
});
var deletedField = submission.form_fields[index];
//Hide field if it exists
if (deletedField) {
// console.log('deletedField\n-------\n\n');
// console.log(deletedField);
//Delete old form_field
submission.form_fields.splice(index, 1);
deletedField.deletePreserved = true;
//Move deleted form_field to start
submission.form_fields.unshift(deletedField);
that.form_fields.unshift(deletedField);
// console.log('form.form_fields\n--------\n\n');
// console.log(that.form_fields);
}
}
submission.save(function (err) {
if (err) callback(err);
else callback(null);
});
}, function (err) {
if (err) {
console.error(err.message);
cb(err);
}
else cb();
});
}
}
);
}
else cb(null);
}
else cb(null);
}],
function(err, results){
if (err) next(err);
next();
});
});
mongoose.model('Form', FormSchema); mongoose.model('Form', FormSchema);

View file

@ -35,7 +35,7 @@ var FormFieldSchema = new Schema({
}, },
description: { description: {
type: String, type: String,
default: '', default: ''
}, },
logicJump: { logicJump: {
@ -46,11 +46,11 @@ var FormFieldSchema = new Schema({
fieldOptions: [FieldOptionSchema], fieldOptions: [FieldOptionSchema],
required: { required: {
type: Boolean, type: Boolean,
default: true, default: true
}, },
disabled: { disabled: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
deletePreserved: { deletePreserved: {
@ -84,7 +84,7 @@ var FormFieldSchema = new Schema({
'yes_no', 'yes_no',
'natural', 'natural',
'number' 'number'
], ]
}, },
fieldValue: Schema.Types.Mixed fieldValue: Schema.Types.Mixed
}); });

View file

@ -9,18 +9,18 @@ var users = require('../../app/controllers/users.server.controller'),
config = require('../../config/config'); config = require('../../config/config');
// Setting the pdf upload route and folder // Setting the pdf upload route and folder
var upload = multer({ dest: config.tmpUploadPath, var storage = multer.diskStorage({
rename: function (fieldname, filename) { destination: function (req, file, cb) {
return Date.now(); cb(null, config.tmpUploadPath);
}, },
onFileUploadStart: function (file) { filename: function (req, file, cb) {
//Check to make sure we can only upload images and pdfs var len = file.originalname.split('.').length;
console.log(file.originalname + ' is starting ...'); var ext = file.originalname.split('.')[len-1];
}, cb(null, Date.now()+ '-' + file.fieldname + '.'+ext);
onFileUploadComplete: function (file, req, res) { }
console.log(file.originalname + ' uploaded to ' + file.path); });
}
}); var upload = multer({ storage: storage });
module.exports = function(app) { module.exports = function(app) {
// Form Routes // Form Routes

View file

@ -96,7 +96,7 @@
{% endif %} {% endif %}
<script> <script>
Raven.config('http://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2', { /*Raven.config('http://825fefd6b4ed4a4da199c1b832ca845c@sentry.tellform.com/2', {
// Raven settings // Raven settings
}) })
.setUser({ .setUser({
@ -104,6 +104,7 @@
"email": "SERVER_RENDERED_EMAIL" "email": "SERVER_RENDERED_EMAIL"
}) })
.install() .install()
*/
</script> </script>
<!-- [if lt IE 9]> <!-- [if lt IE 9]>

View file

@ -17,7 +17,7 @@
"angular-bootstrap": "~0.14.3", "angular-bootstrap": "~0.14.3",
"angular-ui-utils": "~3.0.0", "angular-ui-utils": "~3.0.0",
"angular-ui-router": "~0.2.11", "angular-ui-router": "~0.2.11",
"ng-file-upload": "~10.0.2", "ng-file-upload": "^12.0.4",
"angular-raven": "~0.5.11", "angular-raven": "~0.5.11",
"angular-ui-date": "~0.0.8", "angular-ui-date": "~0.0.8",
"lodash": "~3.10.0", "lodash": "~3.10.0",
@ -35,11 +35,12 @@
}, },
"resolutions": { "resolutions": {
"angular-bootstrap": "^0.14.0", "angular-bootstrap": "^0.14.0",
"angular": "1.4.x" "angular": "1.4.x",
"ng-file-upload": "^12.0.4"
}, },
"overrides": { "overrides": {
"BOWER-PACKAGE": { "BOWER-PACKAGE": {
"main": "**/*.min.js" "main": "**/*.min.js"
}
} }
}
} }

View file

@ -16,7 +16,7 @@ var minBowerFiles = function(type){
var newPath = path.replace(/.([^.]+)$/g, '.min.$1'); var newPath = path.replace(/.([^.]+)$/g, '.min.$1');
return exists( newPath ) ? newPath : path; return exists( newPath ) ? newPath : path;
}); });
} };
/** /**
* Load app configurations * Load app configurations
*/ */

67
data1461898034126.fdf Normal file
View file

@ -0,0 +1,67 @@
%FDF-1.2
%âãÏÓ
1 0 obj
<<
/FDF
<<
/Fields [<<
/V(aeuoaeou)
/T(textfield 1458815121)
>><<
/V(aoue)
/T(textfield 1523785639)
>><<
/V(aoeuaeou)
/T(textfield 1688115162)
>><<
/V(aoeueoau)
/T(textfield 1157050326)
>><<
/V(aoueoaeuaoueeoaueaouaeouaeouaeouaoeuaoeueuaoaeou)
/T(textfield 1463000179)
>><<
/V()
/T(radio 787550015)
>><<
/V(aeouaoeu)
/T(textfield 1367065276)
>><<
/V(aoeuoeuaoeuaoueaoeu)
/T(textfield 302001252)
>><<
/V()
/T(checkbox 1420080456)
>><<
/V()
/T(radio 787819715)
>><<
/V()
/T(checkbox 782280334)
>><<
/V()
/T(checkbox 1977914846)
>><<
/V()
/T(checkbox 284150450)
>><<
/V()
/T(checkbox 336764222)
>><<
/V()
/T(checkbox 227255374)
>><<
/V()
/T(radio 1029379241)
>><<
/V()
/T(textfield 1998389145)
>>]
>>
>>
endobj
trailer
<<
/Root 1 0 R
>>
%%EOF

View file

@ -143,13 +143,19 @@ module.exports = function(grunt) {
env: { env: {
test: { test: {
NODE_ENV: 'test', NODE_ENV: 'test',
src: '/opt/deploy/.env' src: '/opt/deploy/.env'
}, },
secure: { secure: {
NODE_ENV: 'secure', NODE_ENV: 'secure',
src: '/opt/deploy/.env'
}, },
production: { production: {
NODE_ENV: 'production' NODE_ENV: 'production',
src: '/opt/deploy/.env'
},
dev: {
NODE_ENV: 'development',
src: '/opt/deploy/.env'
}, },
src: '/opt/deploy/.env' src: '/opt/deploy/.env'
}, },
@ -282,7 +288,7 @@ module.exports = function(grunt) {
// Default task(s). // Default task(s).
grunt.registerTask('default', ['lint', 'html2js:main', 'env', 'concurrent:default']); grunt.registerTask('default', ['lint', 'html2js:main', 'env', 'concurrent:default']);
grunt.registerTask('dev', ['lint', 'html2js:main', 'env:dev', 'concurrent:default']);
// Debug task. // Debug task.
grunt.registerTask('debug', ['lint', 'html2js:main', 'concurrent:debug']); grunt.registerTask('debug', ['lint', 'html2js:main', 'concurrent:debug']);

View file

@ -58,6 +58,7 @@
"main-bower-files": "~2.9.0", "main-bower-files": "~2.9.0",
"math": "0.0.3", "math": "0.0.3",
"method-override": "~2.3.0", "method-override": "~2.3.0",
"mkdirp": "^0.5.1",
"mongoose": "~3.8.8", "mongoose": "~3.8.8",
"mongoose-utilities": "~0.1.1", "mongoose-utilities": "~0.1.1",
"morgan": "~1.6.1", "morgan": "~1.6.1",
@ -74,6 +75,7 @@
"path-exists": "^2.1.0", "path-exists": "^2.1.0",
"pdffiller": "~0.1.1", "pdffiller": "~0.1.1",
"prerender-node": "^2.2.1", "prerender-node": "^2.2.1",
"random-js": "^1.0.8",
"raven": "^0.9.0", "raven": "^0.9.0",
"soap": "^0.11.0", "soap": "^0.11.0",
"swig": "~1.4.1" "swig": "~1.4.1"

View file

@ -47,9 +47,9 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope'
else if(toState.name !== 'access_denied' && !Auth.isAuthenticated() && toState.name !== 'submitForm'){ else if(toState.name !== 'access_denied' && !Auth.isAuthenticated() && toState.name !== 'submitForm'){
console.log('go to home'); console.log('go to home');
event.preventDefault(); // stop current execution event.preventDefault(); // stop current execution
$state.go('home'); // go to listForms page $state.go('listForms'); // go to listForms page
} }
}); });
} }

View file

@ -4,7 +4,7 @@
var ApplicationConfiguration = (function() { var ApplicationConfiguration = (function() {
// Init module configuration options // Init module configuration options
var applicationModuleName = 'NodeForm'; var applicationModuleName = 'NodeForm';
var applicationModuleVendorDependencies = ['duScroll', 'ui.select', 'cgBusy', 'ngSanitize', 'vButton', 'ngResource', 'NodeForm.templates', 'ui.router', 'ui.bootstrap', 'ui.utils', 'ngRaven']; var applicationModuleVendorDependencies = ['duScroll', 'ui.select', 'cgBusy', 'ngSanitize', 'vButton', 'ngResource', 'NodeForm.templates', 'ui.router', 'ui.bootstrap', 'ui.utils'];
// Add a new vertical module // Add a new vertical module
var registerModule = function(moduleName, dependencies) { var registerModule = function(moduleName, dependencies) {

View file

@ -17,8 +17,8 @@ angular.module('core').controller('HeaderController', ['$rootScope', '$scope', '
Auth.logout(); Auth.logout();
Auth.ensureHasCurrentUser(User); Auth.ensureHasCurrentUser(User);
$scope.user = $rootScope.user = null; $scope.user = $rootScope.user = null;
$state.go('home'); $state.go('listForms');
}, },
function(reason) { function(reason) {
console.log('Logout Failed: ' + reason); console.log('Logout Failed: ' + reason);
}); });
@ -41,4 +41,4 @@ angular.module('core').controller('HeaderController', ['$rootScope', '$scope', '
}); });
} }
]); ]);

View file

@ -7,20 +7,11 @@ angular.module('forms').run(['Menus',
Menus.addMenuItem('topbar', 'My Forms', 'forms', '', '/forms', false); Menus.addMenuItem('topbar', 'My Forms', 'forms', '', '/forms', false);
} }
]) ])
/*.filter('highlight', function() {
function escapeRegexp(queryToEscape) {
return ('' + queryToEscape).replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
}
return function(matchItem, query) {
return query && matchItem ? ('' + matchItem).replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
};
})*/
.filter('formValidity', .filter('formValidity',
function(){ function(){
return function(formObj){ return function(formObj){
if(formObj && formObj.form_fields && formObj.visible_form_fields){ if(formObj && formObj.form_fields && formObj.visible_form_fields){
//get keys //get keys
var formKeys = Object.keys(formObj); var formKeys = Object.keys(formObj);
@ -42,7 +33,7 @@ angular.module('forms').run(['Menus',
return 0; return 0;
}; };
}).config(['$provide', function ($provide){ }).config(['$provide', function ($provide){
$provide.decorator('accordionDirective', function($delegate) { $provide.decorator('accordionDirective', function($delegate) {
var directive = $delegate[0]; var directive = $delegate[0];
directive.replace = true; directive.replace = true;
return $delegate; return $delegate;

View file

@ -21,7 +21,7 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$htt
$scope.log = ''; $scope.log = '';
$scope.pdfLoading = false; $scope.pdfLoading = false;
$scope.languages = $rootScope.languages; $scope.languages = $rootScope.languages;
this._current_upload = null; this._current_upload = null;
$scope.resetForm = $rootScope.resetForm; $scope.resetForm = $rootScope.resetForm;
$scope.update = $rootScope.update; $scope.update = $rootScope.update;
@ -48,47 +48,47 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$htt
console.log('form.pdf: '+$scope.myform.pdf+' REMOVED'); console.log('form.pdf: '+$scope.myform.pdf+' REMOVED');
}; };
$scope.uploadPDF = function(files) { $scope.uploadPDF = function(file) {
// console.log(files);
if (files && files.length) { if (file) {
var file = files[0];
console.log(file); console.log(file);
this._current_upload = Upload.upload({ Upload.upload({
url: '/upload/pdf', url: '/upload/pdf',
fields: { data: {
'user': $scope.user, 'user': $scope.user,
'form': $scope.myform file: file
}, }
file: file }).then(function (resp) {
}).progress(function (evt) { var data = resp.data;
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); $scope.log = 'file ' + data.originalname + ' uploaded as ' + data.filename + '. JSON: ' + JSON.stringify(data) + '\n' + $scope.log;
$scope.log = 'progress: ' + progressPercentage + '% ' + $scope.myform.pdf = angular.fromJson(angular.toJson(data));
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.myform.pdf = angular.fromJson(angular.toJson(data));
// console.log($scope.myform.pdf); //console.log($scope.myform.pdf);
$scope.pdfLoading = false; $scope.pdfLoading = false;
console.log($scope.log); console.log($scope.log);
if(!$scope.$$phase && !$scope.$digest){ if (!$scope.$$phase && !$scope.$digest) {
$scope.$apply(); $scope.$apply();
} }
}).error(function(err){ }, function(resp){
$scope.pdfLoading = false; $scope.pdfLoading = false;
console.log('Error occured during upload.\n'); console.log('Error occured during upload.\n');
console.log(err); console.log(resp.status);
}); }, function (evt) {
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
$scope.log = 'progress: ' + progressPercentage + '% ' +
evt.config.data.file.name + '\n' + $scope.log;
console.log($scope.log);
$scope.pdfLoading = true;
});
} }
}; };
} }
}; };
} }
]); ]);

View file

@ -42,11 +42,13 @@
<div tabindex="-1" class="form-control file-caption"> <div tabindex="-1" class="form-control file-caption">
<span class="file-caption-ellipsis" ng-if="!myform.pdf"></span> <span class="file-caption-ellipsis" ng-if="!myform.pdf"></span>
<div class="file-caption-name" ng-if="myform.pdf"> <div class="file-caption-name" ng-if="myform.pdf">
{{myform.pdf.originalname}} {{myform.pdf.name}}
</div> </div>
</div> </div>
<div class="input-group-btn"> <div class="input-group-btn">
<button type="button" ng-if="myform.pdf" ng-click="removePDF();" title="Clear selected files" class="btn btn-danger fileinput-remove fileinput-remove-button"> <button type="button" ng-if="myform.pdf" ng-click="removePDF();"
title="Clear selected files"
class="btn btn-danger fileinput-remove fileinput-remove-button">
<i class="glyphicon glyphicon-trash" ></i> <i class="glyphicon glyphicon-trash" ></i>
Delete Delete
</button> </button>
@ -56,7 +58,7 @@
Cancel Cancel
</button> </button>
<div class="btn btn-success btn-file" ngf-select ngf-change="uploadPDF($files)" ng-if="!myform.pdf"> <div class="btn btn-success btn-file" ngf-select="uploadPDF($file)">
<i class="glyphicon glyphicon-upload"></i> <i class="glyphicon glyphicon-upload"></i>
Upload your PDF Upload your PDF
</div> </div>
@ -331,4 +333,4 @@
<button class="btn btn-default" type="button" ng-click="resetForm()"><i class="icon-eye-open icon-white"></i> Cancel</button> <button class="btn btn-default" type="button" ng-click="resetForm()"><i class="icon-eye-open icon-white"></i> Cancel</button>
</div> </div>
</div> </div>
</div> </div>