got pdf conversion working
This commit is contained in:
parent
1ddf23a848
commit
1279314299
|
@ -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 + '"'));
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
|
console.log(path.join(newDestination, pdfFile.filename));
|
||||||
|
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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,47 +239,69 @@ 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(cb) {
|
||||||
|
that.constructor
|
||||||
|
.findOne({_id: that._id}).exec(function (err, original) {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
cb(err);
|
||||||
|
} else {
|
||||||
|
_original = original;
|
||||||
|
//console.log('_original');
|
||||||
|
//console.log(_original);
|
||||||
|
cb(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, function(cb) {
|
||||||
|
//DAVID: TODO: Make this so we don't have to update the validFields property ever save
|
||||||
|
if (that.plugins.oscarhost.hasOwnProperty('baseUrl')) {
|
||||||
|
var validUpdateTypes = mongoose.model('Form').schema.path('plugins.oscarhost.settings.updateType').enumValues;
|
||||||
|
that.plugins.oscarhost.settings.validUpdateTypes = validUpdateTypes;
|
||||||
|
}
|
||||||
|
cb(null);
|
||||||
|
},
|
||||||
|
function(cb) {
|
||||||
|
if (that.pdf) {
|
||||||
async.series([
|
async.series([
|
||||||
function(callback){
|
function (callback) {
|
||||||
if(that.isModified('pdf') && that.pdf.path){
|
if (that.isModified('pdf') && that.pdf.path) {
|
||||||
|
|
||||||
var new_filename = that.title.replace(/ /g,'')+'_template.pdf';
|
var new_filename = that.title.replace(/ /g, '') + '_template.pdf';
|
||||||
|
|
||||||
var newDestination = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g,''), that.title.replace(/ /g,'')),
|
var newDestination = path.join(config.pdfUploadPath, that.admin.username.replace(/ /g, ''), that.title.replace(/ /g, '')),
|
||||||
stat = null;
|
stat = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stat = fs.statSync(newDestination);
|
stat = fs.statSync(newDestination);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
fs.mkdirSync(newDestination);
|
mkdirp.sync(newDestination);
|
||||||
}
|
}
|
||||||
if (stat && !stat.isDirectory()) {
|
if (stat && !stat.isDirectory()) {
|
||||||
return callback( new Error('Directory cannot be created because an inode of a different type exists at "' + config.pdfUploadPath + '"'), 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;
|
var old_path = that.pdf.path;
|
||||||
fs.move(old_path, path.join(newDestination, new_filename), {clobber: true}, function (err) {
|
fs.move(old_path, path.join(newDestination, new_filename), {clobber: true}, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
callback( new Error(err.message), 'task1');
|
callback(new Error(err.message), 'task1');
|
||||||
}else {
|
} else {
|
||||||
that.pdf.path = path.join(newDestination, new_filename);
|
that.pdf.path = path.join(newDestination, new_filename);
|
||||||
that.pdf.name = new_filename;
|
that.pdf.name = new_filename;
|
||||||
|
|
||||||
callback(null,'task1');
|
callback(null, 'task1');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else {
|
} else {
|
||||||
callback(null,'task1');
|
callback(null, 'task1');
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
function(callback){
|
function (callback) {
|
||||||
if(that.isGenerated){
|
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.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';
|
that.pdf.name = that.title.replace(/ /g, '') + '_template.pdf';
|
||||||
var _typeConvMap = {
|
var _typeConvMap = {
|
||||||
'Multiline': 'textarea',
|
'Multiline': 'textarea',
|
||||||
'Text': 'textfield',
|
'Text': 'textfield',
|
||||||
|
@ -312,87 +312,78 @@ FormSchema.pre('save', function (next) {
|
||||||
'Radio': 'radio'
|
'Radio': 'radio'
|
||||||
};
|
};
|
||||||
|
|
||||||
// console.log('autogenerating form');
|
|
||||||
// console.log(that.pdf.path);
|
|
||||||
|
|
||||||
pdfFiller.generateFieldJson(that.pdf.path, function(err, _form_fields){
|
pdfFiller.generateFieldJson(that.pdf.path, '', function (err, _form_fields) {
|
||||||
if(err){
|
|
||||||
callback( new Error(err.message), null);
|
//console.log(that.pdf.path);
|
||||||
}else if(!_form_fields.length || _form_fields === undefined || _form_fields === null){
|
|
||||||
callback( new Error('Generated formfields is empty'), null);
|
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
|
//Map PDF field names to FormField field names
|
||||||
for(var i = 0; i < _form_fields.length; i++){
|
for (var i = 0; i < _form_fields.length; i++) {
|
||||||
var field = _form_fields[i];
|
var _field = _form_fields[i];
|
||||||
|
|
||||||
//Convert types from FDF to 'FormField' types
|
//Convert types from FDF to 'FormField' types
|
||||||
if(_typeConvMap[ field.fieldType+'' ]){
|
if (_typeConvMap[_field.fieldType + '']) {
|
||||||
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
_field.fieldType = _typeConvMap[_field.fieldType + ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
// field = new Field(field);
|
var new_field = {};
|
||||||
field.required = false;
|
new_field.title = _field.fieldType + ' ' + Math.abs(mt());
|
||||||
_form_fields[i] = field;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log('NEW FORM_FIELDS: ');
|
that.form_fields = _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;
|
that.isGenerated = false;
|
||||||
callback(null, 'task2');
|
callback(null, 'task2');
|
||||||
});
|
});
|
||||||
}else{
|
} else {
|
||||||
callback(null, 'task2');
|
callback(null, 'task2');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
], function(err, results) {
|
], function (err, results) {
|
||||||
if(err){
|
if (err) {
|
||||||
next(new Error({
|
cb(new Error({
|
||||||
message: err.message
|
message: err.message
|
||||||
}));
|
}));
|
||||||
|
} else {
|
||||||
|
//console.log('ending form save1');
|
||||||
|
cb();
|
||||||
}
|
}
|
||||||
console.log('ending form save');
|
|
||||||
next();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}else if(_original){
|
}
|
||||||
if(_original.hasOwnProperty('pdf')){
|
else if (_original) {
|
||||||
|
if (_original.hasOwnProperty('pdf')) {
|
||||||
fs.remove(_original.pdf.path, function (err) {
|
fs.remove(_original.pdf.path, function (err) {
|
||||||
if(err) next(err);
|
if (err) cb(err);
|
||||||
console.log('file at '+_original.pdf.path+' successfully deleted');
|
console.log('file at ' + _original.pdf.path + ' successfully deleted');
|
||||||
next();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else cb();
|
||||||
}
|
}
|
||||||
next();
|
else cb();
|
||||||
});
|
},
|
||||||
|
function(cb) {
|
||||||
|
|
||||||
FormSchema.pre('save', function (next) {
|
if(that.isModified('form_fields') && that.form_fields && _original){
|
||||||
|
|
||||||
// console.log('_original\n------------');
|
|
||||||
// console.log(_original);
|
|
||||||
//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){
|
|
||||||
|
|
||||||
var old_form_fields = _original.form_fields,
|
var old_form_fields = _original.form_fields,
|
||||||
new_ids = _.map(_.pluck(this.form_fields, '_id'), function(id){ return ''+id;}),
|
new_ids = _.map(_.pluck(that.form_fields, '_id'), function(id){ return ''+id;}),
|
||||||
old_ids = _.map(_.pluck(old_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),
|
deletedIds = getDeletedIndexes(old_ids, new_ids);
|
||||||
that = this;
|
|
||||||
|
|
||||||
// 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
|
//Preserve fields that have at least one submission
|
||||||
if( deletedIds.length > 0 ){
|
if( deletedIds.length > 0 ){
|
||||||
|
@ -400,7 +391,7 @@ FormSchema.pre('save', function (next) {
|
||||||
var modifiedSubmissions = [];
|
var modifiedSubmissions = [];
|
||||||
|
|
||||||
async.forEachOfSeries(deletedIds,
|
async.forEachOfSeries(deletedIds,
|
||||||
function (deletedIdIndex, key, callback) {
|
function (deletedIdIndex, key, cb_id) {
|
||||||
|
|
||||||
var deleted_id = old_ids[deletedIdIndex];
|
var deleted_id = old_ids[deletedIdIndex];
|
||||||
|
|
||||||
|
@ -408,49 +399,41 @@ FormSchema.pre('save', function (next) {
|
||||||
FormSubmission.
|
FormSubmission.
|
||||||
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
|
find({ form: that._id, admin: that.admin, form_fields: {$elemMatch: {_id: deleted_id} } }).
|
||||||
exec(function(err, submissions){
|
exec(function(err, submissions){
|
||||||
if(err){
|
if(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return callback(err);
|
cb_id(err);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
//Delete field if there are no submission(s) found
|
//Delete field if there are no submission(s) found
|
||||||
if(submissions.length) {
|
if (submissions.length) {
|
||||||
// console.log('adding submissions');
|
|
||||||
// console.log(submissions);
|
|
||||||
//Add submissions
|
//Add submissions
|
||||||
modifiedSubmissions.push.apply(modifiedSubmissions, submissions);
|
modifiedSubmissions.push.apply(modifiedSubmissions, submissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null);
|
cb_id(null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
function (err) {
|
function (err) {
|
||||||
if(err){
|
if(err){
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
next(err);
|
cb(err);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// console.log('modifiedSubmissions\n---------\n\n');
|
|
||||||
// console.log(modifiedSubmissions);
|
|
||||||
|
|
||||||
|
|
||||||
//Iterate through all submissions with modified form_fields
|
//Iterate through all submissions with modified form_fields
|
||||||
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
|
async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) {
|
||||||
|
|
||||||
//Iterate through ids of deleted fields
|
//Iterate through ids of deleted fields
|
||||||
for(var i = 0; i < deletedIds.length; i++){
|
for (var i = 0; i < deletedIds.length; i++) {
|
||||||
|
|
||||||
var index = _.findIndex(submission.form_fields, function(field){
|
var index = _.findIndex(submission.form_fields, function (field) {
|
||||||
var tmp_id = field._id+'';
|
var tmp_id = field._id + '';
|
||||||
return tmp_id === old_ids[ deletedIds[i] ];
|
return tmp_id === old_ids[deletedIds[i]];
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
var deletedField = submission.form_fields[index];
|
var deletedField = submission.form_fields[index];
|
||||||
|
|
||||||
//Hide field if it exists
|
//Hide field if it exists
|
||||||
if(deletedField){
|
if (deletedField) {
|
||||||
// console.log('deletedField\n-------\n\n');
|
// console.log('deletedField\n-------\n\n');
|
||||||
// console.log(deletedField);
|
// console.log(deletedField);
|
||||||
//Delete old form_field
|
//Delete old form_field
|
||||||
|
@ -467,28 +450,29 @@ FormSchema.pre('save', function (next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
submission.save(function (err) {
|
submission.save(function (err) {
|
||||||
if(err) callback(err);
|
if (err) callback(err);
|
||||||
else callback(null);
|
else callback(null);
|
||||||
});
|
});
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
if(err){
|
if (err) {
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
next(err);
|
cb(err);
|
||||||
}
|
}
|
||||||
// console.log('form.form_fields\n--------\n\n');
|
else cb();
|
||||||
// console.log(that.form_fields);
|
|
||||||
next();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}else {
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
}else {
|
else cb(null);
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
else cb(null);
|
||||||
|
}],
|
||||||
|
function(err, results){
|
||||||
|
if (err) next(err);
|
||||||
|
next();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
mongoose.model('Form', FormSchema);
|
mongoose.model('Form', FormSchema);
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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]>
|
||||||
|
|
|
@ -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,7 +35,8 @@
|
||||||
},
|
},
|
||||||
"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": {
|
||||||
|
|
|
@ -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
67
data1461898034126.fdf
Normal 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
|
10
gruntfile.js
10
gruntfile.js
|
@ -147,9 +147,15 @@ module.exports = function(grunt) {
|
||||||
},
|
},
|
||||||
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']);
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -47,7 +47,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -17,7 +17,7 @@ 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);
|
||||||
|
|
|
@ -7,15 +7,6 @@ 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){
|
||||||
|
|
|
@ -48,42 +48,42 @@ 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
|
||||||
}).progress(function (evt) {
|
}
|
||||||
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
|
}).then(function (resp) {
|
||||||
$scope.log = 'progress: ' + progressPercentage + '% ' +
|
var data = resp.data;
|
||||||
evt.config.file.name + '\n' + $scope.log;
|
$scope.log = 'file ' + data.originalname + ' uploaded as ' + data.filename + '. JSON: ' + JSON.stringify(data) + '\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));
|
$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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue