fixed autosaving bug
This commit is contained in:
parent
2d15ae3dd5
commit
52632f3328
|
@ -232,11 +232,10 @@ exports.read = function(req, res) {
|
||||||
* Update a form
|
* Update a form
|
||||||
*/
|
*/
|
||||||
exports.update = function(req, res) {
|
exports.update = function(req, res) {
|
||||||
debugger;
|
|
||||||
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) {
|
||||||
|
|
|
@ -55,12 +55,8 @@ module.exports = function (io, socket) {
|
||||||
// a user has visited our page - add them to the visitorsData object
|
// a user has visited our page - add them to the visitorsData object
|
||||||
socket.on('form-visitor-data', function(data) {
|
socket.on('form-visitor-data', function(data) {
|
||||||
|
|
||||||
console.log('\n\nuser has visited our page');
|
|
||||||
|
|
||||||
visitorsData[socket.id] = data;
|
visitorsData[socket.id] = data;
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
if (data.isSubmitted) {
|
if (data.isSubmitted) {
|
||||||
saveVisitorData(data, function () {
|
saveVisitorData(data, function () {
|
||||||
console.log('\n\n user submitted form');
|
console.log('\n\n user submitted form');
|
||||||
|
|
|
@ -80,38 +80,35 @@ angular.module('forms').directive('autoSaveForm', ['$rootScope', '$timeout', fun
|
||||||
newValue = angular.copy(newValue);
|
newValue = angular.copy(newValue);
|
||||||
oldValue = angular.copy(oldValue);
|
oldValue = angular.copy(oldValue);
|
||||||
|
|
||||||
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 = !_.isEqual(oldValue.form_fields,newValue.form_fields) || !_.isEqual(oldValue.startPage, newValue.startPage);
|
var changedFields = !!DeepDiff.diff(oldValue, newValue) && DeepDiff.diff(oldValue, newValue).length > 0;
|
||||||
|
|
||||||
if(oldValue.hasOwnProperty('plugins.oscarhost.settings.fieldMap')){
|
//If our form is undefined, don't save form
|
||||||
changedFieldMap = !!oldValue.plugins.oscarhost.settings.fieldMap && !_.isEqual(oldValue.plugins.oscarhost.settings.fieldMap,newValue.plugins.oscarhost.settings.fieldMap);
|
if( !newValue || !oldValue || !changedFields){
|
||||||
}
|
$rootScope.finishedRender = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//If our form is undefined, don't save form
|
if(oldValue.form_fields.length === 0) {
|
||||||
if( (!newValue && !oldValue) || !oldValue ){
|
$rootScope.finishedRender = true;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// console.log('Autosaving');
|
console.log('Autosaving');
|
||||||
// console.log('\n\n----------');
|
console.log('\n\n----------');
|
||||||
// console.log('!$dirty: '+ !$formCtrl.$dirty );
|
console.log('!$dirty: '+ !$formCtrl.$dirty );
|
||||||
// console.log('changedFields: '+changedFields);
|
console.log('changedFields: '+changedFields);
|
||||||
// console.log('changedFieldMap: '+changedFieldMap);
|
// console.log('changedFieldMap: '+changedFieldMap);
|
||||||
// console.log('finishedRender: '+$rootScope.finishedRender);
|
console.log('finishedRender: '+$rootScope.finishedRender);
|
||||||
// console.log('!saveInProgress: '+!$rootScope.saveInProgress);
|
console.log('!saveInProgress: '+!$rootScope.saveInProgress);
|
||||||
// console.log('newValue: '+newValue);
|
// console.log('newValue: '+newValue);
|
||||||
// console.log('oldValue: '+oldValue);
|
// console.log('oldValue: '+oldValue);
|
||||||
// console.log(oldValue.form_fields);
|
// console.log(oldValue.form_fields);
|
||||||
// console.log(newValue.form_fields);
|
// console.log(newValue.form_fields);
|
||||||
|
|
||||||
if(oldValue.form_fields.length === 0) {
|
|
||||||
$rootScope.finishedRender = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//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 && !$formCtrl.$dirty) && !$rootScope.saveInProgress) {
|
if( $rootScope.finishedRender && (changedFields) && !$rootScope.saveInProgress) {
|
||||||
|
|
||||||
if(savePromise) {
|
if(savePromise) {
|
||||||
$timeout.cancel(savePromise);
|
$timeout.cancel(savePromise);
|
||||||
|
|
|
@ -248,10 +248,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -75,7 +75,6 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
||||||
|
|
||||||
var visitors = $scope.myform.analytics.visitors;
|
var visitors = $scope.myform.analytics.visitors;
|
||||||
|
|
||||||
console.log(visitors);
|
|
||||||
for(var i=0; i<visitors.length; i++){
|
for(var i=0; i<visitors.length; i++){
|
||||||
var visitor = visitors[i];
|
var visitor = visitors[i];
|
||||||
var deviceType = visitor.deviceType;
|
var deviceType = visitor.deviceType;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// Create a controller method for sending visitor data
|
// Create a controller method for sending visitor data
|
||||||
function send(form, lastActiveIndex, timeElapsed) {
|
function send(form, lastActiveIndex, timeElapsed) {
|
||||||
// Create a new message object
|
// Create a new message object
|
||||||
var visitorData = {
|
/*var visitorData = {
|
||||||
referrer: document.referrer,
|
referrer: document.referrer,
|
||||||
isSubmitted: form.submitted,
|
isSubmitted: form.submitted,
|
||||||
formId: form._id,
|
formId: form._id,
|
||||||
|
@ -42,15 +42,15 @@
|
||||||
}
|
}
|
||||||
console.log(visitorData.deviceType);
|
console.log(visitorData.deviceType);
|
||||||
Socket.emit('form-visitor-data', visitorData);
|
Socket.emit('form-visitor-data', visitorData);
|
||||||
});
|
});*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
// Make sure the Socket is connected
|
// Make sure the Socket is connected
|
||||||
if (!Socket.socket) {
|
/*if (!Socket.socket) {
|
||||||
Socket.connect();
|
Socket.connect();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = {
|
var service = {
|
||||||
|
|
Loading…
Reference in a new issue