fixed form analyze view
This commit is contained in:
parent
83fe074f56
commit
faa306302b
|
@ -7,74 +7,14 @@ var mongoose = require('mongoose'),
|
||||||
errorHandler = require('./errors.server.controller'),
|
errorHandler = require('./errors.server.controller'),
|
||||||
Form = mongoose.model('Form'),
|
Form = mongoose.model('Form'),
|
||||||
FormSubmission = mongoose.model('FormSubmission'),
|
FormSubmission = mongoose.model('FormSubmission'),
|
||||||
pdfFiller = require('pdffiller'),
|
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
fs = require('fs-extra'),
|
|
||||||
async = require('async'),
|
|
||||||
path = require('path'),
|
|
||||||
diff = require('deep-diff'),
|
diff = require('deep-diff'),
|
||||||
_ = require('lodash');
|
_ = require('lodash');
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload PDF
|
|
||||||
*/
|
|
||||||
exports.uploadPDF = function(req, res, next) {
|
|
||||||
|
|
||||||
if(req.file){
|
|
||||||
var pdfFile = req.file;
|
|
||||||
var _user = req.user;
|
|
||||||
var _path = req.file.path;
|
|
||||||
|
|
||||||
|
|
||||||
if (req.file.size === 0) {
|
|
||||||
return next(new Error('File uploaded is EMPTY'));
|
|
||||||
}else if(req.file.size > 100000000){
|
|
||||||
return next(new Error('File uploaded exceeds MAX SIZE of 100MB'));
|
|
||||||
}else {
|
|
||||||
fs.exists(_path, function(exists) {
|
|
||||||
|
|
||||||
//If file exists move to user's tmp directory
|
|
||||||
if(exists) {
|
|
||||||
|
|
||||||
var newDestination = 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');
|
|
||||||
return 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.filename), function (err) {
|
|
||||||
if (err) {
|
|
||||||
return next(new Error(err.message));
|
|
||||||
}
|
|
||||||
pdfFile.path = path.join(newDestination, pdfFile.filename);
|
|
||||||
console.log(pdfFile.filename + ' uploaded to ' + pdfFile.path);
|
|
||||||
res.json(pdfFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return next(new Error('Did NOT get your file!'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
return next(new Error('Uploaded files were NOT detected'));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a forms submissions
|
* Delete a forms submissions
|
||||||
*/
|
*/
|
||||||
exports.deleteSubmissions = function(req, res) {
|
exports.deleteSubmissions = function(req, res) {
|
||||||
console.log(req.body);
|
|
||||||
|
|
||||||
var submission_id_list = req.body.deleted_submissions,
|
var submission_id_list = req.body.deleted_submissions,
|
||||||
form = req.form;
|
form = req.form;
|
||||||
|
@ -106,7 +46,6 @@ exports.deleteSubmissions = function(req, res) {
|
||||||
* Submit a form entry
|
* Submit a form entry
|
||||||
*/
|
*/
|
||||||
exports.createSubmission = function(req, res) {
|
exports.createSubmission = function(req, res) {
|
||||||
|
|
||||||
var form = req.form;
|
var form = req.form;
|
||||||
|
|
||||||
var submission = new FormSubmission({
|
var submission = new FormSubmission({
|
||||||
|
@ -118,38 +57,36 @@ exports.createSubmission = function(req, res) {
|
||||||
percentageComplete: req.body.percentageComplete
|
percentageComplete: req.body.percentageComplete
|
||||||
});
|
});
|
||||||
|
|
||||||
if(form.pdf) submission.pdf = form.pdf;
|
|
||||||
|
|
||||||
//Save submitter's IP Address
|
//Save submitter's IP Address
|
||||||
if(req.headers['x-forwarded-for'] || req.connection.remoteAddress){
|
if(req.headers['x-forwarded-for'] || req.connection.remoteAddress){
|
||||||
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
if(ip && process.env.NODE_ENV !== 'development') submission.ipAddr = ip;
|
if(ip && process.env.NODE_ENV !== 'development') submission.ipAddr = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(req.device){
|
if (req.device) {
|
||||||
submission.device = req.device;
|
submission.device = req.device;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(form.autofillPDFs){
|
|
||||||
try {
|
|
||||||
submission.fdfData = pdfFiller.convFieldJson2FDF(submission.form_fields);
|
|
||||||
} catch(err){
|
|
||||||
res.status(400).send({
|
|
||||||
message: errorHandler.getErrorMessage(err)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
submission.fdfData = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
submission.save(function(err, submission){
|
submission.save(function(err, submission){
|
||||||
if(err){
|
|
||||||
console.log(err.message);
|
if (err) {
|
||||||
res.status(500).send({
|
console.error(err.message);
|
||||||
|
return res.status(500).send({
|
||||||
message: errorHandler.getErrorMessage(err)
|
message: errorHandler.getErrorMessage(err)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
res.status(200).send('Form submission successfully saved');
|
|
||||||
|
form.submissions.push(submission);
|
||||||
|
|
||||||
|
form.save(function (err) {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).send({
|
||||||
|
message: errorHandler.getErrorMessage(err)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200).send('Form submission successfully saved');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,25 +96,15 @@ exports.createSubmission = function(req, res) {
|
||||||
exports.listSubmissions = function(req, res) {
|
exports.listSubmissions = function(req, res) {
|
||||||
var _form = req.form;
|
var _form = req.form;
|
||||||
var _user = req.user;
|
var _user = req.user;
|
||||||
console.log('listSubmissions');
|
|
||||||
|
|
||||||
FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) {
|
FormSubmission.find({ form: _form._id }).exec(function(err, _submissions) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.error(err);
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
message: errorHandler.getErrorMessage(err)
|
message: errorHandler.getErrorMessage(err)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
res.json(_submissions);
|
||||||
_form.update({ $set : { submissions: _submissions }}).exec(function(err, form){
|
|
||||||
if (err) {
|
|
||||||
console.log(err);
|
|
||||||
res.status(400).send({
|
|
||||||
message: errorHandler.getErrorMessage(err)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
res.json(_submissions);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -188,7 +115,6 @@ exports.listSubmissions = function(req, res) {
|
||||||
*/
|
*/
|
||||||
exports.create = function(req, res) {
|
exports.create = function(req, res) {
|
||||||
|
|
||||||
|
|
||||||
if(!req.body.form){
|
if(!req.body.form){
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
|
@ -215,17 +141,29 @@ exports.create = function(req, res) {
|
||||||
* Show the current form
|
* Show the current form
|
||||||
*/
|
*/
|
||||||
exports.read = function(req, res) {
|
exports.read = function(req, res) {
|
||||||
var newForm = req.form.toJSON({virtuals : true});
|
|
||||||
|
|
||||||
if (req.userId) {
|
FormSubmission.find({ form: req.form._id }).exec(function(err, _submissions) {
|
||||||
if(req.form.admin._id+'' === req.userId+''){
|
if (err) {
|
||||||
return res.json(newForm);
|
console.log(err);
|
||||||
|
res.status(400).send({
|
||||||
|
message: errorHandler.getErrorMessage(err)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return res.status(404).send({
|
|
||||||
message: 'Form Does Not Exist'
|
|
||||||
});
|
var newForm = req.form.toJSON({virtuals : true});
|
||||||
}
|
newForm.submissions = _submissions;
|
||||||
return res.json(newForm);
|
|
||||||
|
if (req.userId) {
|
||||||
|
if(req.form.admin._id+'' === req.userId+''){
|
||||||
|
return res.json(newForm);
|
||||||
|
}
|
||||||
|
return res.status(404).send({
|
||||||
|
message: 'Form Does Not Exist'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return res.json(newForm);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,8 +172,7 @@ exports.read = 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('SENDING DIFFS\n\n\n');
|
|
||||||
var formChanges = req.body.changes;
|
var formChanges = req.body.changes;
|
||||||
|
|
||||||
formChanges.forEach(function (change) {
|
formChanges.forEach(function (change) {
|
||||||
|
|
|
@ -77,6 +77,16 @@ var VisitorDataSchema = new Schema({
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var formSchemaOptions = {
|
||||||
|
toObject: {
|
||||||
|
virtuals: true
|
||||||
|
},
|
||||||
|
toJSON: {
|
||||||
|
virtuals: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form Schema
|
* Form Schema
|
||||||
*/
|
*/
|
||||||
|
@ -176,7 +186,7 @@ var FormSchema = new Schema({
|
||||||
},
|
},
|
||||||
font: String
|
font: String
|
||||||
}
|
}
|
||||||
});
|
}, formSchemaOptions);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** In-Form Analytics Virtual Attributes
|
** In-Form Analytics Virtual Attributes
|
||||||
|
|
|
@ -5,44 +5,15 @@
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Schema = mongoose.Schema,
|
Schema = mongoose.Schema,
|
||||||
pdfFiller = require('pdffiller'),
|
|
||||||
freegeoip = require('node-freegeoip'),
|
freegeoip = require('node-freegeoip'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
config = require('../../config/config'),
|
config = require('../../config/config'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs-extra'),
|
fs = require('fs-extra'),
|
||||||
mUtilities = require('mongoose-utilities'),
|
mUtilities = require('mongoose-utilities'),
|
||||||
soap = require('soap'),
|
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
FieldSchema = require('./form_field.server.model.js');
|
FieldSchema = require('./form_field.server.model.js');
|
||||||
|
|
||||||
var FieldSchema = require('./form_field.server.model.js');
|
|
||||||
|
|
||||||
var newDemoTemplate = {
|
|
||||||
address: '880-9650 Velit. St.',
|
|
||||||
city: '',
|
|
||||||
dateOfBirth: '10',
|
|
||||||
displayName: 'LITTLE, URIAH',
|
|
||||||
email: '',
|
|
||||||
firstName: 'Uriah F.',
|
|
||||||
hin: '',
|
|
||||||
lastName: 'Little',
|
|
||||||
lastUpdateDate: Date.now(),
|
|
||||||
monthOfBirth: '05',
|
|
||||||
officialLanguage: 'English',
|
|
||||||
phone: '250-',
|
|
||||||
phone2: '',
|
|
||||||
postal: 'S4M 7T8',
|
|
||||||
province: 'BC',
|
|
||||||
sex: 'F',
|
|
||||||
sexDesc: 'Female',
|
|
||||||
sin: '',
|
|
||||||
spokenLanguage: 'English',
|
|
||||||
title: 'MS.',
|
|
||||||
yearOfBirth: '2015'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Setter function for form_fields
|
// Setter function for form_fields
|
||||||
function formFieldsSetter(form_fields) {
|
function formFieldsSetter(form_fields) {
|
||||||
for (var i = 0; i < form_fields.length; i++) {
|
for (var i = 0; i < form_fields.length; i++) {
|
||||||
|
@ -50,7 +21,7 @@ function formFieldsSetter(form_fields) {
|
||||||
form_fields[i].submissionId = form_fields[i]._id;
|
form_fields[i].submissionId = form_fields[i]._id;
|
||||||
form_fields[i]._id = new mongoose.mongo.ObjectID();
|
form_fields[i]._id = new mongoose.mongo.ObjectID();
|
||||||
}
|
}
|
||||||
//console.log(form_fields)
|
console.log(form_fields)
|
||||||
return form_fields;
|
return form_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +87,6 @@ var FormSubmissionSchema = new Schema({
|
||||||
type: Number
|
type: Number
|
||||||
},
|
},
|
||||||
|
|
||||||
//TODO: DAVID: Need to not have this hardcoded
|
|
||||||
oscarDemoNum: {
|
|
||||||
type: Number
|
|
||||||
},
|
|
||||||
|
|
||||||
hasPlugins: {
|
hasPlugins: {
|
||||||
oscarhost: {
|
oscarhost: {
|
||||||
|
@ -129,7 +96,17 @@ var FormSubmissionSchema = new Schema({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
FormSubmissionSchema.path('form_fields').set(formFieldsSetter);
|
FormSubmissionSchema.path('form_fields', {
|
||||||
|
set: function(form_fields){
|
||||||
|
for (var i = 0; i < form_fields.length; i++) {
|
||||||
|
form_fields[i].isSubmission = true;
|
||||||
|
form_fields[i].submissionId = form_fields[i]._id;
|
||||||
|
form_fields[i]._id = new mongoose.mongo.ObjectID();
|
||||||
|
}
|
||||||
|
console.log(form_fields);
|
||||||
|
return form_fields;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
||||||
createdPath: 'created',
|
createdPath: 'created',
|
||||||
|
@ -137,35 +114,6 @@ FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
||||||
useVirtual: false
|
useVirtual: false
|
||||||
});
|
});
|
||||||
|
|
||||||
//Oscarhost API hook
|
|
||||||
FormSubmissionSchema.pre('save', function (next) {
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (this.hasPlugins.oscarhost) {
|
|
||||||
mongoose.model('Form').findById(self.form, function (err, _form) {
|
|
||||||
var form_ids = _.map(_.pluck(_form.form_fields, '_id'), function (id) {
|
|
||||||
return '' + id;
|
|
||||||
}),
|
|
||||||
submission_ids = _.pluck(self.form_fields, '_id');
|
|
||||||
|
|
||||||
// console.log('Form form_field ids\n--------');
|
|
||||||
// console.log(form_ids);
|
|
||||||
// console.log('FormSubmission [form_field ids]\n--------');
|
|
||||||
// console.log(submission_ids);
|
|
||||||
|
|
||||||
if (err) return next(err);
|
|
||||||
// console.log(_form);
|
|
||||||
// console.log('should push to api');
|
|
||||||
// console.log( (!this.oscarDemoNum && !!_form.plugins.oscarhost.baseUrl && !!_form.plugins.oscarhost.settings.fieldMap) );
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
//Check for IP Address of submitting person
|
//Check for IP Address of submitting person
|
||||||
FormSubmissionSchema.pre('save', function (next) {
|
FormSubmissionSchema.pre('save', function (next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -181,30 +129,4 @@ FormSubmissionSchema.pre('save', function (next) {
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
//Generate autofilled PDF if flags are set
|
|
||||||
FormSubmissionSchema.pre('save', function (next) {
|
|
||||||
var fdfData, dest_filename, dest_path,
|
|
||||||
self = this,
|
|
||||||
_form = this.form;
|
|
||||||
|
|
||||||
if (this.pdf && this.pdf.path) {
|
|
||||||
dest_filename = self.title.replace(/ /g, '') + '_submission_' + Date.now() + '.pdf';
|
|
||||||
var __path = this.pdf.path.split('/').slice(0, this.pdf.path.split('/').length - 1).join('/');
|
|
||||||
dest_path = path.join(__path, dest_filename);
|
|
||||||
|
|
||||||
self.pdfFilePath = dest_path;
|
|
||||||
|
|
||||||
pdfFiller.fillForm(self.pdf.path, dest_path, self.fdfData, function (err) {
|
|
||||||
if (err) {
|
|
||||||
console.log('\n err.message: ' + err.message);
|
|
||||||
return next(new Error(err.message));
|
|
||||||
}
|
|
||||||
console.log('Field data from Form: ' + self.title.replace(/ /g, '') + ' outputed to new PDF: ' + dest_path);
|
|
||||||
return next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = FormSubmissionSchema;
|
module.exports = FormSubmissionSchema;
|
||||||
|
|
|
@ -27,9 +27,6 @@ var upload = multer({
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
// Form Routes
|
// Form Routes
|
||||||
app.route('/upload/pdf')
|
|
||||||
.post(auth.isAuthenticatedOrApiKey, upload.single('file'), forms.uploadPDF);
|
|
||||||
|
|
||||||
app.route('/forms')
|
app.route('/forms')
|
||||||
.get(auth.isAuthenticatedOrApiKey, forms.list)
|
.get(auth.isAuthenticatedOrApiKey, forms.list)
|
||||||
.post(auth.isAuthenticatedOrApiKey, forms.create);
|
.post(auth.isAuthenticatedOrApiKey, forms.create);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"async-boolean-expression-evaluator": "^1.1.1",
|
"async-boolean-expression-evaluator": "^1.1.1",
|
||||||
"aws-sdk": "^2.3.9",
|
"aws-sdk": "^2.3.9",
|
||||||
"bcrypt": "^0.8.7",
|
"bcrypt": "^0.8.7",
|
||||||
|
"bcrypt-nodejs": "0.0.3",
|
||||||
"body-parser": "~1.14.1",
|
"body-parser": "~1.14.1",
|
||||||
"bower": "~1.6.5",
|
"bower": "~1.6.5",
|
||||||
"chalk": "^1.1.3",
|
"chalk": "^1.1.3",
|
||||||
|
|
36
public/dist/application.js
vendored
36
public/dist/application.js
vendored
|
@ -1726,7 +1726,6 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
||||||
|
|
||||||
$scope.copied = false;
|
$scope.copied = false;
|
||||||
$scope.onCopySuccess = function(e) {
|
$scope.onCopySuccess = function(e) {
|
||||||
console.log("COPY SUCCESSFUL!");
|
|
||||||
$scope.copied = true;
|
$scope.copied = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1754,14 +1753,6 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
||||||
|
|
||||||
|
|
||||||
$scope.tabData = [
|
$scope.tabData = [
|
||||||
/*{
|
|
||||||
heading: $filter('translate')('CREATE_TAB'),
|
|
||||||
templateName: 'create'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
heading: $filter('translate')('DESIGN_TAB'),
|
|
||||||
templateName: 'design'
|
|
||||||
},*/
|
|
||||||
{
|
{
|
||||||
heading: $filter('translate')('CONFIGURE_TAB'),
|
heading: $filter('translate')('CONFIGURE_TAB'),
|
||||||
templateName: 'configure'
|
templateName: 'configure'
|
||||||
|
@ -2464,25 +2455,19 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
(function initController(){
|
(function initController(){
|
||||||
|
|
||||||
var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
||||||
|
var submissions = $scope.myform.submissions;
|
||||||
|
|
||||||
//Iterate through form's submissions
|
//Iterate through form's submissions
|
||||||
|
for(var i = 0; i < submissions.length; i++){
|
||||||
var submissions = _.cloneDeep($scope.myform.submissions);
|
for(var x = 0; x < submissions[i].form_fields; x++){
|
||||||
for(var i = 0; i < submissions.length; i++){
|
var oldValue = submissions[i].form_fields[x].fieldValue || '';
|
||||||
for(var x = 0; x < submissions[i].form_fields; x++){
|
submissions[i].form_fields[x] = _.merge(defaultFormFields, submissions[i].form_fields);
|
||||||
var oldValue = submissions[i].form_fields[x].fieldValue || '';
|
submissions[i].form_fields[x].fieldValue = oldValue;
|
||||||
submissions[i].form_fields[x] = _.merge(defaultFormFields, submissions[i].form_fields);
|
}
|
||||||
submissions[i].form_fields[x].fieldValue = oldValue;
|
submissions[i].selected = false;
|
||||||
}
|
}
|
||||||
submissions[i].selected = false;
|
|
||||||
}
|
|
||||||
// console.log('after textField2: '+data[0].form_fields[1].fieldValue);
|
|
||||||
|
|
||||||
$scope.table.rows = submissions;
|
$scope.table.rows = submissions;
|
||||||
|
|
||||||
// console.log('form submissions successfully fetched');
|
|
||||||
// console.log( JSON.parse(JSON.stringify($scope.submissions)) ) ;
|
|
||||||
// console.log( JSON.parse(JSON.stringify($scope.myform.form_fields)) );
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -2497,7 +2482,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
totalTime += $scope.table.rows[i].timeElapsed;
|
totalTime += $scope.table.rows[i].timeElapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(totalTime/numSubmissions);
|
|
||||||
return totalTime/numSubmissions;
|
return totalTime/numSubmissions;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
10
public/dist/application.min.js
vendored
10
public/dist/application.min.js
vendored
File diff suppressed because one or more lines are too long
8
public/dist/form-application.min.js
vendored
8
public/dist/form-application.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,6 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
||||||
|
|
||||||
$scope.copied = false;
|
$scope.copied = false;
|
||||||
$scope.onCopySuccess = function(e) {
|
$scope.onCopySuccess = function(e) {
|
||||||
console.log("COPY SUCCESSFUL!");
|
|
||||||
$scope.copied = true;
|
$scope.copied = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,29 +25,19 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
||||||
|
|
||||||
$scope.formURL = "/#!/forms/" + $scope.myform._id;
|
$scope.formURL = "/#!/forms/" + $scope.myform._id;
|
||||||
|
|
||||||
if(window.location.host.split('.') < 3){
|
if(window.location.host.split('.').length < 3){
|
||||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host + "/#!/forms/" + $scope.myform._id;
|
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host + $scope.formURL;
|
||||||
} else {
|
} else {
|
||||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host.split('.').slice(1,3).join('.') + "/#!/forms/" + $scope.myform._id;
|
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host.split('.').slice(1,3).join('.') + $scope.formURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var refreshFrame = $scope.refreshFrame = function(){
|
var refreshFrame = $scope.refreshFrame = function(){
|
||||||
if(document.getElementById('iframe')) {
|
if(document.getElementById('iframe')) {
|
||||||
document.getElementById('iframe').contentWindow.location.reload();
|
document.getElementById('iframe').contentWindow.location.reload();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$scope.tabData = [
|
$scope.tabData = [
|
||||||
/*{
|
|
||||||
heading: $filter('translate')('CREATE_TAB'),
|
|
||||||
templateName: 'create'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
heading: $filter('translate')('DESIGN_TAB'),
|
|
||||||
templateName: 'design'
|
|
||||||
},*/
|
|
||||||
{
|
{
|
||||||
heading: $filter('translate')('CONFIGURE_TAB'),
|
heading: $filter('translate')('CONFIGURE_TAB'),
|
||||||
templateName: 'configure'
|
templateName: 'configure'
|
||||||
|
@ -62,6 +51,7 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope
|
||||||
$scope.setForm = function(form){
|
$scope.setForm = function(form){
|
||||||
$scope.myform = form;
|
$scope.myform = form;
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.resetForm = function(){
|
$rootScope.resetForm = function(){
|
||||||
$scope.myform = Forms.get({
|
$scope.myform = Forms.get({
|
||||||
formId: $stateParams.formId
|
formId: $stateParams.formId
|
||||||
|
|
|
@ -1,44 +1,59 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http',
|
angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', '$http', 'Forms', '$stateParams', '$interval',
|
||||||
function ($rootScope, $http) {
|
function ($rootScope, $http, Forms, $stateParams, $interval) {
|
||||||
return {
|
return {
|
||||||
templateUrl: 'modules/forms/admin/views/directiveViews/form/edit-submissions-form.client.view.html',
|
templateUrl: 'modules/forms/admin/views/directiveViews/form/edit-submissions-form.client.view.html',
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
myform:'=',
|
user:'=',
|
||||||
user:'='
|
myform: '@'
|
||||||
},
|
},
|
||||||
controller: function($scope){
|
controller: function($scope){
|
||||||
|
|
||||||
$scope.table = {
|
$scope.table = {
|
||||||
masterChecker: false,
|
masterChecker: false,
|
||||||
rows: []
|
rows: []
|
||||||
};
|
};
|
||||||
|
|
||||||
(function initController(){
|
$scope.table.rows = [];
|
||||||
|
|
||||||
var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
var initController = function(){
|
||||||
|
|
||||||
//Iterate through form's submissions
|
Forms.get({
|
||||||
|
formId: $stateParams.formId
|
||||||
|
}, function(form){
|
||||||
|
console.log('running init controller');
|
||||||
|
console.log(form);
|
||||||
|
$scope.myform = form;
|
||||||
|
var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
||||||
|
|
||||||
var submissions = _.cloneDeep($scope.myform.submissions);
|
var submissions = $scope.myform.submissions || [];
|
||||||
for(var i = 0; i < submissions.length; i++){
|
|
||||||
for(var x = 0; x < submissions[i].form_fields; x++){
|
//Iterate through form's submissions
|
||||||
var oldValue = submissions[i].form_fields[x].fieldValue || '';
|
for(var i = 0; i < submissions.length; i++){
|
||||||
submissions[i].form_fields[x] = _.merge(defaultFormFields, submissions[i].form_fields);
|
for(var x = 0; x < submissions[i].form_fields; x++){
|
||||||
submissions[i].form_fields[x].fieldValue = oldValue;
|
var oldValue = submissions[i].form_fields[x].fieldValue || '';
|
||||||
|
submissions[i].form_fields[x] = _.merge(defaultFormFields, submissions[i].form_fields);
|
||||||
|
submissions[i].form_fields[x].fieldValue = oldValue;
|
||||||
|
}
|
||||||
|
submissions[i].selected = false;
|
||||||
}
|
}
|
||||||
submissions[i].selected = false;
|
|
||||||
|
$scope.table.rows = submissions;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
initController();
|
||||||
|
|
||||||
|
var updateFields = $interval(initController, 500);
|
||||||
|
|
||||||
|
$scope.$on("$destroy", function() {
|
||||||
|
if (updateFields) {
|
||||||
|
$interval.cancel($scope.updateFields);
|
||||||
}
|
}
|
||||||
// console.log('after textField2: '+data[0].form_fields[1].fieldValue);
|
});
|
||||||
|
|
||||||
$scope.table.rows = submissions;
|
|
||||||
|
|
||||||
// console.log('form submissions successfully fetched');
|
|
||||||
// console.log( JSON.parse(JSON.stringify($scope.submissions)) ) ;
|
|
||||||
// console.log( JSON.parse(JSON.stringify($scope.myform.form_fields)) );
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Analytics Functions
|
** Analytics Functions
|
||||||
|
@ -51,7 +66,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
totalTime += $scope.table.rows[i].timeElapsed;
|
totalTime += $scope.table.rows[i].timeElapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(totalTime/numSubmissions);
|
|
||||||
return totalTime/numSubmissions;
|
return totalTime/numSubmissions;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -73,23 +87,22 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
other: newStatItem()
|
other: newStatItem()
|
||||||
};
|
};
|
||||||
|
|
||||||
var visitors = $scope.myform.analytics.visitors;
|
if($scope.myform.analytics && $scope.myform.analytics.visitors) {
|
||||||
|
for (var i = 0; i < visitors.length; i++) {
|
||||||
|
var visitor = visitors[i];
|
||||||
|
var deviceType = visitor.deviceType;
|
||||||
|
|
||||||
for(var i=0; i<visitors.length; i++){
|
stats[deviceType].visits++;
|
||||||
var visitor = visitors[i];
|
|
||||||
var deviceType = visitor.deviceType;
|
|
||||||
|
|
||||||
stats[deviceType].visits++;
|
stats[deviceType].total_time = +visitor.timeElapsed;
|
||||||
|
stats[deviceType].average_time = stats[deviceType].total_time / stats[deviceType].visits || 0;
|
||||||
|
|
||||||
stats[deviceType].total_time =+ visitor.timeElapsed;
|
if (visitor.isSubmitted) stats[deviceType].responses++;
|
||||||
stats[deviceType].average_time = stats[deviceType].total_time/stats[deviceType].visits || 0;
|
|
||||||
|
|
||||||
if(visitor.isSubmitted) stats[deviceType].responses++;
|
stats[deviceType].completion = stats[deviceType].response / stats[deviceType].visits || 0;
|
||||||
|
}
|
||||||
stats[deviceType].completion = stats[deviceType].response/stats[deviceType].visits || 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(stats);
|
|
||||||
return stats;
|
return stats;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
@ -156,16 +169,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
'csv': 'csv'
|
'csv': 'csv'
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log($scope.table.rows);
|
|
||||||
|
|
||||||
angular.element('#table-submission-data').tableExport({type: type, escape:false});
|
angular.element('#table-submission-data').tableExport({type: type, escape:false});
|
||||||
|
|
||||||
/*
|
|
||||||
var blob = new Blob([$scope.table.rows], {
|
|
||||||
type: 'application/'+fileMIMETypeMap[type]+';charset=utf-8'
|
|
||||||
});
|
|
||||||
saveAs(blob, $scope.myform.title+'_sumbissions_export_'+Date.now()+'.'+type);
|
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-3">
|
<div class="col-xs-3">
|
||||||
{{myform.analytics.submissions}}
|
{{table.analytics.submissions}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-3">
|
<div class="col-xs-3">
|
||||||
|
|
|
@ -44,7 +44,7 @@ angular.module('forms').config(['$stateProvider',
|
||||||
templateUrl: 'modules/forms/admin/views/adminTabs/design.html'
|
templateUrl: 'modules/forms/admin/views/adminTabs/design.html'
|
||||||
}).state('viewForm.analyze', {
|
}).state('viewForm.analyze', {
|
||||||
url: '/analyze',
|
url: '/analyze',
|
||||||
templateUrl: 'modules/forms/admin/views/adminTabs/analyze.html',
|
templateUrl: 'modules/forms/admin/views/adminTabs/analyze.html'
|
||||||
}).state('viewForm.create', {
|
}).state('viewForm.create', {
|
||||||
url: '/create',
|
url: '/create',
|
||||||
templateUrl: 'modules/forms/admin/views/adminTabs/create.html'
|
templateUrl: 'modules/forms/admin/views/adminTabs/create.html'
|
||||||
|
|
|
@ -8,6 +8,8 @@ if ((process.env.NODE_ENV || 'development') === 'development') {
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require('events').EventEmitter.prototype._maxListeners = 0;
|
||||||
|
|
||||||
var init = require('./config/init')(),
|
var init = require('./config/init')(),
|
||||||
config = require('./config/config'),
|
config = require('./config/config'),
|
||||||
mongoose = require('mongoose'),
|
mongoose = require('mongoose'),
|
||||||
|
|
Loading…
Reference in a new issue