fixed autosaving bug for configure tab

This commit is contained in:
David Baldwynn 2017-03-09 16:18:18 -08:00
parent b6e6fb93a6
commit fbc5641388
No known key found for this signature in database
GPG key ID: 15D1C13202224A9B
12 changed files with 81 additions and 73 deletions

View file

@ -162,6 +162,14 @@ exports.read = function(req, res) {
}); });
}; };
/**
* Upload temp file for submissions
*/
exports.uploadTemp = function(req, res) {
//Send uploaded file data back to form
res.json(req.file);
};
/** /**
* Show the current form for rendering form live * Show the current form for rendering form live
*/ */
@ -189,7 +197,6 @@ exports.readForRender = function(req, res) {
exports.update = function(req, res) { exports.update = function(req, res) {
var form = req.form; var form = req.form;
if (req.body.changes) { if (req.body.changes) {
console.log(req.body.changes); console.log(req.body.changes);
var formChanges = req.body.changes; var formChanges = req.body.changes;

View file

@ -7,22 +7,27 @@ var users = require('../../app/controllers/users.server.controller'),
forms = require('../../app/controllers/forms.server.controller'), forms = require('../../app/controllers/forms.server.controller'),
multer = require('multer'), multer = require('multer'),
config = require('../../config/config'), config = require('../../config/config'),
auth = require('../../config/passport_helpers'); auth = require('../../config/passport_helpers'),
multerS3 = require('multer-s3'),
aws = require('aws-sdk');
// Setting the pdf upload route and folder
var storage = multer.diskStorage({
destination: function (req, file, cb) { // Amazon S3 Uploads
cb(null, config.tmpUploadPath); aws.config.update({region: 'us-west-2'});
}, var s3 = new aws.S3();
filename: function (req, file, cb) {
var len = file.originalname.split('.').length;
var ext = file.originalname.split('.')[len-1];
cb(null, Date.now()+ '-' + file.fieldname + '.'+ext);
}
});
var upload = multer({ var upload = multer({
storage: storage storage: multerS3({
s3: s3,
bucket: 'tellform-test',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
}); });
module.exports = function(app) { module.exports = function(app) {
@ -41,6 +46,9 @@ module.exports = function(app) {
.get(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.listSubmissions) .get(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.listSubmissions)
.delete(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.deleteSubmissions); .delete(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.deleteSubmissions);
app.route('/forms/:formId([a-zA-Z0-9]+)/submissions/upload')
.post(upload.single('file'), forms.uploadTemp);
// Finish by binding the form middleware // Finish by binding the form middleware
app.param('formId', forms.formByID); app.param('formId', forms.formByID);
}; };

5
config/env/all.js vendored
View file

@ -14,6 +14,11 @@ module.exports = {
pass: '' pass: ''
} }
}, },
aws: {
"accessKeyId": process.env.AWS_ACCESS_ID,
"secretAccessKey": process.env.AWS_SECRET_KEY,
"region": process.env.AWS_REGION
},
port: process.env.PORT || 3000, port: process.env.PORT || 3000,
socketPort: process.env.SOCKET_PORT || 20523, socketPort: process.env.SOCKET_PORT || 20523,

View file

@ -25,7 +25,7 @@
"dependencies": { "dependencies": {
"async": "^1.4.2", "async": "^1.4.2",
"async-boolean-expression-evaluator": "^1.1.1", "async-boolean-expression-evaluator": "^1.1.1",
"aws-sdk": "^2.3.9", "aws-sdk": "^2.26.0",
"bcrypt": "^0.8.7", "bcrypt": "^0.8.7",
"bcrypt-nodejs": "0.0.3", "bcrypt-nodejs": "0.0.3",
"body-parser": "~1.14.1", "body-parser": "~1.14.1",
@ -74,6 +74,7 @@
"mongoose-utilities": "~0.1.1", "mongoose-utilities": "~0.1.1",
"morgan": "~1.6.1", "morgan": "~1.6.1",
"multer": "~1.1.0", "multer": "~1.1.0",
"multer-s3": "^2.5.0",
"nodemailer": "~1.10.0", "nodemailer": "~1.10.0",
"nodemailer-sendgrid-transport": "^0.2.0", "nodemailer-sendgrid-transport": "^0.2.0",
"nodemailer-sparkpost-transport": "^1.0.0", "nodemailer-sparkpost-transport": "^1.0.0",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -79,12 +79,12 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
delete oldValue.visible_form_fields; delete oldValue.visible_form_fields;
newValue.form_fields = _.removeDateFields(newValue.form_fields); newValue.form_fields = _.removeDateFields(newValue.form_fields);
oldValue.form_fields = _.removeDateFields(oldValue.form_fields); oldValue.form_fields = _.removeDateFields(oldValue.form_fields);
var changedFields = !!DeepDiff.diff(oldValue, newValue) && DeepDiff.diff(oldValue, newValue).length > 0;
console.log(DeepDiff.diff(oldValue, newValue)); var changedStartPage = !!DeepDiff.diff(oldValue.startPage, newValue.startPage) && DeepDiff.diff(oldValue.startPage, newValue.startPage).length > 0;
//If our form is undefined, don't save form var changedFields = !!DeepDiff.diff(oldValue.form_fields, newValue.form_fields) && DeepDiff.diff(oldValue.form_fields, newValue.form_fields).length > 0;
if(!changedFields){
//If our form's startPage or form fields have not changed, don't autosave form
if(!changedFields && !changedStartPage){
$rootScope.finishedRender = true; $rootScope.finishedRender = true;
return; return;
} }
@ -106,7 +106,7 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
// console.log(newValue.form_fields); // console.log(newValue.form_fields);
//Save form ONLY IF rendering is finished, form_fields have been changed AND currently not save in progress //Save form ONLY IF rendering is finished, form_fields have been changed AND currently not save in progress
if( $rootScope.finishedRender && (changedFields) && !$rootScope.saveInProgress) { if( $rootScope.finishedRender && (changedFields || changedStartPage) && !$rootScope.saveInProgress) {
if(savePromise) { if(savePromise) {
$timeout.cancel(savePromise); $timeout.cancel(savePromise);
@ -116,8 +116,6 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
savePromise = $timeout(function() { savePromise = $timeout(function() {
$rootScope.saveInProgress = true; $rootScope.saveInProgress = true;
delete newValue.visible_form_fields;
delete newValue.visible_form_fields;
var _diff = DeepDiff.diff(oldValue, newValue); var _diff = DeepDiff.diff(oldValue, newValue);
debounceSave(_diff); debounceSave(_diff);
}); });

View file

@ -40,10 +40,10 @@ angular.module('forms').service('FormFields', [
// name : 'sig', // name : 'sig',
// value : 'Signature' // value : 'Signature'
// }, // },
// { {
// name : 'file', name : 'file',
// value : 'File Upload' value : 'File Upload'
// }, },
{ {
name : 'rating', name : 'rating',
value : 'Rating' value : 'Rating'
@ -62,13 +62,13 @@ angular.module('forms').service('FormFields', [
// }, // },
// { // {
// name : 'stripe', // name : 'stripe',
// value : 'Payment' // value : 'Payment'
// }, // },
{ {
name : 'statement', name : 'statement',
value : 'Statement' value : 'Statement'
} }
]; ];
} }
]); ]);

View file

@ -17,6 +17,7 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root
var supported_fields = [ var supported_fields = [
'textfield', 'textfield',
'textarea', 'textarea',
'file',
'date', 'date',
'dropdown', 'dropdown',
'hidden', 'hidden',

View file

@ -1,4 +1,4 @@
<div class="field row" ng-if="form.autofillPDFs" ng-click="setActiveField(field._id, index, true)"> <div class="field row" ng-click="setActiveField(field._id, index, true)">
<div class="col-xs-12 field-title" ng-style="{'color': design.colors.questionColor}"> <div class="col-xs-12 field-title" ng-style="{'color': design.colors.questionColor}">
<h3> <h3>
<small class="field-number"> <small class="field-number">
@ -12,8 +12,8 @@
<div class="col-sm-8 field-input"> <div class="col-sm-8 field-input">
<div class="input-group "> <div class="input-group ">
<div tabindex="-1" class="form-control file-caption"> <div tabindex="-1" class="form-control file-caption">
<span class="file-caption-ellipsis" ng-if="!form.pdf"></span> <span class="file-caption-ellipsis" ng-if="!field.file"></span>
<div class="file-caption-name" ng-if="form.pdf"> <div class="file-caption-name" ng-if="field.file">
{{field.file.originalname}} {{field.file.originalname}}
</div> </div>
</div> </div>