fixed edit-submission-form-directive test and removed unnessecary console.log() statements
This commit is contained in:
parent
235a924fae
commit
ed032d6db9
34 changed files with 3134 additions and 2974 deletions
6
app.json
6
app.json
|
@ -10,9 +10,9 @@
|
|||
"description": "Disable support for running subdomains. (This should be true if you are not using your own custom domain.",
|
||||
"value": "TRUE"
|
||||
},
|
||||
"DISABLE_CLUSTER_MODE": {
|
||||
"description": "Disable support for running in cluster mode on pm2",
|
||||
"value": "TRUE"
|
||||
"ENABLE_CLUSTER_MODE": {
|
||||
"description": "ENABLE support for running in cluster mode on pm2",
|
||||
"value": "FALSE"
|
||||
},
|
||||
"NODE_ENV": {
|
||||
"description": "Choose whether to run app in development or production mode",
|
||||
|
|
|
@ -139,27 +139,26 @@ exports.read = function(req, res) {
|
|||
if(!req.user || (req.form.admin.id !== req.user.id) ){
|
||||
readForRender(req, res);
|
||||
} else {
|
||||
|
||||
FormSubmission.find({ form: req.form._id }).exec(function(err, _submissions) {
|
||||
if (err) {
|
||||
res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
|
||||
var newForm = req.form.toJSON();
|
||||
newForm.submissions = _submissions;
|
||||
|
||||
if (req.userId) {
|
||||
if(req.form.admin._id+'' === req.userId+''){
|
||||
return res.json(newForm);
|
||||
FormSubmission.find({ form: req.form._id }).exec(function(err, _submissions) {
|
||||
if (err) {
|
||||
res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
}
|
||||
return res.status(404).send({
|
||||
message: 'Form Does Not Exist'
|
||||
});
|
||||
}
|
||||
return res.json(newForm);
|
||||
});
|
||||
|
||||
var newForm = req.form.toJSON();
|
||||
newForm.submissions = _submissions;
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ FormSchema.virtual('analytics.fields').get(function () {
|
|||
if(this.form_fields.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
for(var i=0; i<this.form_fields.length; i++){
|
||||
var field = this.form_fields[i];
|
||||
|
||||
|
|
|
@ -58,6 +58,16 @@ var FormSubmissionSchema = new Schema({
|
|||
}
|
||||
});
|
||||
|
||||
FormSubmissionSchema.pre('save', function (next) {
|
||||
//Iterate through form fields and format data
|
||||
for(var i = 0; i < this.form_fields.length; i++){
|
||||
if(this.form_fields[i].fieldType === 'dropdown'){
|
||||
this.form_fields[i].fieldValue = this.form_fields[i].fieldValue.option_value;
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
FormSubmissionSchema.path('form_fields', {
|
||||
set: function(form_fields){
|
||||
for (var i = 0; i < form_fields.length; i++) {
|
||||
|
|
2
config/env/all.js
vendored
2
config/env/all.js
vendored
|
@ -28,7 +28,7 @@ module.exports = {
|
|||
reCAPTCHA_Key: process.env.reCAPTCHA_KEY || '',
|
||||
|
||||
signupDisabled: (process.env.SIGNUP_DISABLED === 'TRUE'),
|
||||
disableClusterMode: (process.env.DISABLE_CLUSTER_MODE === 'TRUE'),
|
||||
enableClusterMode: (process.env.ENABLE_CLUSTER_MODE === 'TRUE'),
|
||||
baseUrl: '',
|
||||
tempUserCollection: 'temporary_users',
|
||||
|
||||
|
|
1
config/env/development.js
vendored
1
config/env/development.js
vendored
|
@ -9,7 +9,6 @@ module.exports = {
|
|||
pass: ''
|
||||
}
|
||||
},
|
||||
|
||||
log: {
|
||||
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
|
||||
format: 'dev',
|
||||
|
|
2
config/env/production.js
vendored
2
config/env/production.js
vendored
|
@ -7,7 +7,7 @@ module.exports = {
|
|||
},
|
||||
port: process.env.PORT || 5000,
|
||||
socketUrl: process.env.SOCKET_URL || 'ws.tellform.com',
|
||||
socketPort: process.env.SOCKET_PORT || null,
|
||||
socketPort: process.env.SOCKET_PORT || 20523,
|
||||
log: {
|
||||
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
|
||||
format: 'combined',
|
||||
|
|
|
@ -58,15 +58,12 @@ module.exports = function(db) {
|
|||
|
||||
if(config.socketPort){
|
||||
app.locals.socketPort = config.socketPort;
|
||||
} else {
|
||||
app.locals.socketPort = false;
|
||||
}
|
||||
|
||||
if(config.socketUrl){
|
||||
app.locals.socketUrl = config.socketUrl;
|
||||
} else {
|
||||
app.locals.socketUrl = false;
|
||||
}
|
||||
|
||||
app.locals.bowerJSFiles = config.getBowerJSAssets();
|
||||
app.locals.bowerCssFiles = config.getBowerCSSAssets();
|
||||
app.locals.bowerOtherFiles = config.getBowerOtherAssets();
|
||||
|
|
|
@ -9,9 +9,9 @@ var config = require('./config'),
|
|||
// Define the Socket.io configuration method
|
||||
module.exports = function (app, db) {
|
||||
var server = http.createServer(app);
|
||||
var io = socketio(config.socketPort, { transports: ['websocket', 'polling'] });
|
||||
var io = socketio(config.socketPort, { transports: ['websocket', 'polling'] });
|
||||
|
||||
if(config.disableClusterMode){
|
||||
if(config.enableClusterMode){
|
||||
var redis = require('socket.io-redis');
|
||||
io.adapter(redis( process.env.REDIS_URL || { host: process.env.REDIS_DB_PORT_6379_TCP_ADDR || '127.0.0.1' , port: process.env.REDIS_DB_PORT_6379_TCP_PORT || 6379 }));
|
||||
}
|
||||
|
@ -23,4 +23,4 @@ module.exports = function (app, db) {
|
|||
});
|
||||
|
||||
return server;
|
||||
};
|
||||
};
|
18
gruntfile.js
18
gruntfile.js
|
@ -217,7 +217,15 @@ module.exports = function(grunt) {
|
|||
unit: {
|
||||
configFile: 'karma.conf.js',
|
||||
singleRun: true
|
||||
}
|
||||
},
|
||||
debug: {
|
||||
configFile: 'karma.conf.js',
|
||||
browserConsoleLogOptions: {
|
||||
level: 'log',
|
||||
terminal: true
|
||||
},
|
||||
singleRun: true
|
||||
}
|
||||
},
|
||||
protractor: {
|
||||
options: {
|
||||
|
@ -339,9 +347,9 @@ module.exports = function(grunt) {
|
|||
|
||||
// Code coverage tasks.
|
||||
grunt.registerTask('coveralls', ['env:test','mocha_istanbul:coveralls']);
|
||||
grunt.registerTask('coverage', ['env:test', 'mocha_istanbul:coverage']);
|
||||
grunt.registerTask('coverage:client', ['env:test', 'mocha_istanbul:coverageClient']);
|
||||
grunt.registerTask('coverage:server', ['env:test', 'mocha_istanbul:coverageServer']);
|
||||
grunt.registerTask('coverage', ['env:test', 'mocha_istanbul:coverage']);
|
||||
grunt.registerTask('coverage:client', ['env:test', 'mocha_istanbul:coverageClient']);
|
||||
grunt.registerTask('coverage:server', ['env:test', 'mocha_istanbul:coverageServer']);
|
||||
|
||||
// Default task(s).
|
||||
grunt.registerTask('default', ['lint', 'html2js:main', 'html2js:forms', 'env', 'concurrent:default']);
|
||||
|
@ -367,4 +375,6 @@ module.exports = function(grunt) {
|
|||
grunt.registerTask('test', ['lint:tests', 'test:server', 'test:client']);
|
||||
grunt.registerTask('test:server', ['lint:tests', 'env:test', 'mochaTest']);
|
||||
grunt.registerTask('test:client', ['lint:tests', 'html2js:main', 'html2js:forms', 'env:test', 'karma:unit']);
|
||||
|
||||
grunt.registerTask('testdebug', ['env:test', 'karma:debug']);
|
||||
};
|
||||
|
|
|
@ -126,7 +126,7 @@
|
|||
"karma-jasmine-html-reporter": "^0.1.8",
|
||||
"karma-mocha-reporter": "^1.1.1",
|
||||
"karma-ng-html2js-preprocessor": "^0.2.0",
|
||||
"karma-phantomjs-launcher": "~0.2.1",
|
||||
"karma-phantomjs-launcher": "^1.0.4",
|
||||
"mailosaur": "^1.0.1",
|
||||
"mocha": "^3.1.2",
|
||||
"mocha-lcov-reporter": "^1.0.0",
|
||||
|
|
419
public/dist/application.js
vendored
419
public/dist/application.js
vendored
File diff suppressed because one or more lines are too long
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
20
public/dist/form-application.js
vendored
20
public/dist/form-application.js
vendored
File diff suppressed because one or more lines are too long
4
public/dist/form-application.min.js
vendored
4
public/dist/form-application.min.js
vendored
File diff suppressed because one or more lines are too long
20
public/dist/form_populate_template_cache.js
vendored
20
public/dist/form_populate_template_cache.js
vendored
File diff suppressed because one or more lines are too long
2228
public/dist/vendor.min.js
vendored
2228
public/dist/vendor.min.js
vendored
File diff suppressed because one or more lines are too long
2861
public/dist/vendor_forms_uglified.js
vendored
2861
public/dist/vendor_forms_uglified.js
vendored
File diff suppressed because one or more lines are too long
|
@ -3,9 +3,9 @@
|
|||
|
||||
// Create the Socket.io wrapper service
|
||||
function Socket($timeout, $window) {
|
||||
|
||||
var service;
|
||||
|
||||
|
||||
var service;
|
||||
|
||||
// Connect to Socket.io server
|
||||
function connect(url) {
|
||||
service.socket = io(url, {'transports': ['websocket', 'polling']});
|
||||
|
@ -35,7 +35,7 @@
|
|||
service.socket.removeListener(eventName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
service = {
|
||||
connect: connect,
|
||||
emit: emit,
|
||||
|
@ -44,10 +44,11 @@
|
|||
socket: null
|
||||
};
|
||||
|
||||
console.log($window.socketUrl);
|
||||
var url = '';
|
||||
if($window.socketUrl && $window.socketPort){
|
||||
url = window.location.protocol + '//' + $window.socketUrl + ':' + $window.socketPort;
|
||||
} else if ($window.socketUrl && !$window.socketPort){
|
||||
} else if ($window.socketUrl){
|
||||
url = window.location.protocol + '//' + $window.socketUrl;
|
||||
} else if ($window.socketPort){
|
||||
url = window.location.protocol + '//' + window.location.hostname + ':' + $window.socketPort;
|
||||
|
@ -58,12 +59,11 @@
|
|||
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
angular
|
||||
.module('view-form')
|
||||
.factory('Socket', Socket);
|
||||
|
||||
Socket.$inject = ['$timeout', '$window'];
|
||||
|
||||
|
||||
}());
|
||||
|
|
|
@ -25,13 +25,11 @@ angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope'
|
|||
if(statesToIgnore.indexOf(toState.name) > 0){
|
||||
if(Auth.isAuthenticated()){
|
||||
event.preventDefault(); // stop current execution
|
||||
//console.log('go to forms');
|
||||
$state.go('listForms'); // go to listForms page
|
||||
}
|
||||
}
|
||||
//Redirect to 'signup' route if user is not authenticated
|
||||
else if(toState.name !== 'access_denied' && !Auth.isAuthenticated() && toState.name !== 'submitForm'){
|
||||
console.log('go to signup');
|
||||
event.preventDefault(); // stop current execution
|
||||
$state.go('listForms'); // go to listForms page
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
service.socket.removeListener(eventName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var service = {
|
||||
connect: connect,
|
||||
emit: emit,
|
||||
|
|
|
@ -2,59 +2,59 @@
|
|||
|
||||
// Forms controller
|
||||
angular.module('forms').controller('AdminFormController', ['$rootScope', '$window', '$scope', '$stateParams', '$state', 'Forms', 'CurrentForm', '$http', '$uibModal', 'myForm', '$filter', '$sce',
|
||||
function($rootScope, $window, $scope, $stateParams, $state, Forms, CurrentForm, $http, $uibModal, myForm, $filter, $sce) {
|
||||
function($rootScope, $window, $scope, $stateParams, $state, Forms, CurrentForm, $http, $uibModal, myForm, $filter, $sce) {
|
||||
|
||||
$scope.trustSrc = function (src) {
|
||||
return $sce.trustAsResourceUrl(src);
|
||||
};
|
||||
$scope.trustSrc = function (src) {
|
||||
return $sce.trustAsResourceUrl(src);
|
||||
};
|
||||
|
||||
//Set active tab to Create
|
||||
$scope.activePill = 0;
|
||||
//Set active tab to Create
|
||||
$scope.activePill = 0;
|
||||
|
||||
$scope.copied = false;
|
||||
$scope.onCopySuccess = function (e) {
|
||||
$scope.copied = true;
|
||||
};
|
||||
$scope.copied = false;
|
||||
$scope.onCopySuccess = function (e) {
|
||||
$scope.copied = true;
|
||||
};
|
||||
|
||||
$scope = $rootScope;
|
||||
$scope.animationsEnabled = true;
|
||||
$scope.myform = myForm;
|
||||
$rootScope.saveInProgress = false;
|
||||
$scope = $rootScope;
|
||||
$scope.animationsEnabled = true;
|
||||
$scope.myform = myForm;
|
||||
$rootScope.saveInProgress = false;
|
||||
|
||||
CurrentForm.setForm($scope.myform);
|
||||
CurrentForm.setForm($scope.myform);
|
||||
|
||||
$scope.formURL = '/#!/forms/' + $scope.myform._id;
|
||||
$scope.formURL = '/#!/forms/' + $scope.myform._id;
|
||||
|
||||
if ($scope.myform.isLive) {
|
||||
if ($window.subdomainsDisabled === true) {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + window.location.host + '/view' + $scope.formURL;
|
||||
} else {
|
||||
if (window.location.host.split('.').length < 3) {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host + $scope.formURL;
|
||||
} else {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host.split('.').slice(1, 3).join('.') + $scope.formURL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + window.location.host + $scope.formURL;
|
||||
}
|
||||
if ($scope.myform.isLive) {
|
||||
if ($window.subdomainsDisabled === true) {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + window.location.host + '/view' + $scope.formURL;
|
||||
} else {
|
||||
if (window.location.host.split('.').length < 3) {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host + $scope.formURL;
|
||||
} else {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + $scope.myform.admin.username + '.' + window.location.host.split('.').slice(1, 3).join('.') + $scope.formURL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$scope.actualFormURL = window.location.protocol + '//' + window.location.host + $scope.formURL;
|
||||
}
|
||||
|
||||
|
||||
var refreshFrame = $scope.refreshFrame = function(){
|
||||
if(document.getElementById('iframe')) {
|
||||
document.getElementById('iframe').contentWindow.location.reload();
|
||||
}
|
||||
};
|
||||
var refreshFrame = $scope.refreshFrame = function(){
|
||||
if(document.getElementById('iframe')) {
|
||||
document.getElementById('iframe').contentWindow.location.reload();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.tabData = [
|
||||
$scope.tabData = [
|
||||
{
|
||||
heading: $filter('translate')('CONFIGURE_TAB'),
|
||||
templateName: 'configure'
|
||||
templateName: 'configure'
|
||||
},
|
||||
{
|
||||
/*{
|
||||
heading: $filter('translate')('ANALYZE_TAB'),
|
||||
templateName: 'analyze'
|
||||
}
|
||||
templateName: 'analyze'
|
||||
}*/
|
||||
];
|
||||
|
||||
$scope.setForm = function(form){
|
||||
|
@ -72,19 +72,19 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$windo
|
|||
*/
|
||||
$scope.openDeleteModal = function(){
|
||||
$scope.deleteModal = $uibModal.open({
|
||||
animation: $scope.animationsEnabled,
|
||||
templateUrl: 'formDeleteModal.html',
|
||||
controller: 'AdminFormController',
|
||||
resolve: {
|
||||
myForm: function(){
|
||||
return $scope.myform;
|
||||
}
|
||||
}
|
||||
animation: $scope.animationsEnabled,
|
||||
templateUrl: 'formDeleteModal.html',
|
||||
controller: 'AdminFormController',
|
||||
resolve: {
|
||||
myForm: function(){
|
||||
return $scope.myform;
|
||||
}
|
||||
}
|
||||
});
|
||||
$scope.deleteModal.result.then(function (selectedItem) {
|
||||
$scope.selected = selectedItem;
|
||||
$scope.selected = selectedItem;
|
||||
}, function () {
|
||||
console.log('Modal dismissed at: ' + new Date());
|
||||
console.log('Modal dismissed at: ' + new Date());
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -118,7 +118,7 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$windo
|
|||
|
||||
// Update existing Form
|
||||
$scope.update = $rootScope.update = function(updateImmediately, data, isDiffed, refreshAfterUpdate, cb){
|
||||
refreshFrame();
|
||||
refreshFrame();
|
||||
|
||||
var continueUpdate = true;
|
||||
if(!updateImmediately){
|
||||
|
@ -127,64 +127,64 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$windo
|
|||
|
||||
//Update form **if we are not currently updating** or if **shouldUpdateNow flag is set**
|
||||
if(continueUpdate) {
|
||||
var err = null;
|
||||
var err = null;
|
||||
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = true;
|
||||
}
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = true;
|
||||
}
|
||||
|
||||
if (isDiffed) {
|
||||
$scope.updatePromise = $http.put('/forms/' + $scope.myform._id, {changes: data})
|
||||
.then(function (response) {
|
||||
if (isDiffed) {
|
||||
$scope.updatePromise = $http.put('/forms/' + $scope.myform._id, {changes: data})
|
||||
.then(function (response) {
|
||||
|
||||
if (refreshAfterUpdate) $rootScope.myform = $scope.myform = response.data;
|
||||
// console.log(response.data);
|
||||
}).catch(function (response) {
|
||||
console.log('Error occured during form UPDATE.\n');
|
||||
// console.log(response.data);
|
||||
err = response.data;
|
||||
}).finally(function () {
|
||||
// console.log('finished updating');
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = false;
|
||||
}
|
||||
if (refreshAfterUpdate) $rootScope.myform = $scope.myform = response.data;
|
||||
// console.log(response.data);
|
||||
}).catch(function (response) {
|
||||
console.log('Error occured during form UPDATE.\n');
|
||||
// console.log(response.data);
|
||||
err = response.data;
|
||||
}).finally(function () {
|
||||
// console.log('finished updating');
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = false;
|
||||
}
|
||||
|
||||
if ((typeof cb) === 'function') {
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var dataToSend = data;
|
||||
if(dataToSend.analytics && dataToSend.analytics.visitors){
|
||||
delete dataToSend.analytics.visitors;
|
||||
}
|
||||
if(dataToSend.submissions){
|
||||
delete dataToSend.submissions;
|
||||
}
|
||||
if ((typeof cb) === 'function') {
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var dataToSend = data;
|
||||
if(dataToSend.analytics && dataToSend.analytics.visitors){
|
||||
delete dataToSend.analytics.visitors;
|
||||
}
|
||||
if(dataToSend.submissions){
|
||||
delete dataToSend.submissions;
|
||||
}
|
||||
|
||||
$scope.updatePromise = $http.put('/forms/' + $scope.myform._id, {form: dataToSend})
|
||||
.then(function (response) {
|
||||
$scope.updatePromise = $http.put('/forms/' + $scope.myform._id, {form: dataToSend})
|
||||
.then(function (response) {
|
||||
|
||||
if (refreshAfterUpdate) $rootScope.myform = $scope.myform = response.data;
|
||||
if (refreshAfterUpdate) $rootScope.myform = $scope.myform = response.data;
|
||||
|
||||
}).catch(function (response) {
|
||||
console.log('Error occured during form UPDATE.\n');
|
||||
// console.log(response.data);
|
||||
err = response.data;
|
||||
}).finally(function () {
|
||||
// console.log('finished updating');
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = false;
|
||||
}
|
||||
}).catch(function (response) {
|
||||
console.log('Error occured during form UPDATE.\n');
|
||||
// console.log(response.data);
|
||||
err = response.data;
|
||||
}).finally(function () {
|
||||
// console.log('finished updating');
|
||||
if (!updateImmediately) {
|
||||
$rootScope.saveInProgress = false;
|
||||
}
|
||||
|
||||
if ((typeof cb) === 'function') {
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
if ((typeof cb) === 'function') {
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
]);
|
||||
}
|
||||
]);
|
|
@ -14,7 +14,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
|||
/*
|
||||
** Initialize scope with variables
|
||||
*/
|
||||
var newField;
|
||||
var newField;
|
||||
|
||||
//Setup UI-Sortable
|
||||
$scope.sortableOptions = {
|
||||
|
@ -28,8 +28,6 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField
|
|||
});
|
||||
},
|
||||
start: function(e, ui) {
|
||||
console.log(ui.item);
|
||||
console.log(ui.placeholder);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -7,116 +7,110 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
restrict: 'E',
|
||||
scope: {
|
||||
user:'=',
|
||||
myform: '='
|
||||
myform: '='
|
||||
},
|
||||
controller: function($scope){
|
||||
|
||||
$scope.table = {
|
||||
masterChecker: false,
|
||||
rows: []
|
||||
rows: $scope.myform.submissions
|
||||
};
|
||||
|
||||
$scope.table.rows = [];
|
||||
var initController = function(){
|
||||
Forms.get({
|
||||
formId: $stateParams.formId
|
||||
}, function(form){
|
||||
$scope.myform = form;
|
||||
$scope.table.rows = form.submissions;
|
||||
/*var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
||||
|
||||
var initController = function(){
|
||||
var submissions = $scope.myform.submissions || [];
|
||||
|
||||
Forms.get({
|
||||
formId: $stateParams.formId
|
||||
}, function(form){
|
||||
$scope.myform = form;
|
||||
var defaultFormFields = _.cloneDeep($scope.myform.form_fields);
|
||||
//Iterate through form's submissions
|
||||
for(var i = 0; i < submissions.length; i++){
|
||||
for(var x = 0; x < submissions[i].form_fields.length; x++){
|
||||
if(submissions[i].form_fields[x].fieldType === 'dropdown'){
|
||||
submissions[i].form_fields[x].fieldValue = submissions[i].form_fields[x].fieldValue.option_value;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
var submissions = $scope.myform.submissions || [];
|
||||
$scope.table.rows = submissions;*/
|
||||
});
|
||||
};
|
||||
|
||||
//Iterate through form's submissions
|
||||
for(var i = 0; i < submissions.length; i++){
|
||||
for(var x = 0; x < submissions[i].form_fields.length; x++){
|
||||
if(submissions[i].form_fields[x].fieldType === 'dropdown'){
|
||||
submissions[i].form_fields[x].fieldValue = submissions[i].form_fields[x].fieldValue.option_value;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
$scope.table.rows = submissions;
|
||||
/*
|
||||
** Analytics Functions
|
||||
*/
|
||||
$scope.AverageTimeElapsed = (function(){
|
||||
var totalTime = 0;
|
||||
var numSubmissions = $scope.table.rows.length;
|
||||
|
||||
/*
|
||||
** Analytics Functions
|
||||
*/
|
||||
for(var i=0; i<$scope.table.rows.length; i++){
|
||||
totalTime += $scope.table.rows[i].timeElapsed;
|
||||
}
|
||||
|
||||
$scope.AverageTimeElapsed = (function(){
|
||||
var totalTime = 0;
|
||||
var numSubmissions = $scope.table.rows.length;
|
||||
if(numSubmissions === 0) {
|
||||
return 0;
|
||||
}
|
||||
return (totalTime/numSubmissions).toFixed(0);
|
||||
})();
|
||||
|
||||
for(i=0; i<$scope.table.rows.length; i++){
|
||||
totalTime += $scope.table.rows[i].timeElapsed;
|
||||
}
|
||||
$scope.DeviceStatistics = (function(){
|
||||
var newStatItem = function(){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
completion: 0,
|
||||
average_time: 0,
|
||||
total_time: 0
|
||||
};
|
||||
};
|
||||
|
||||
if(numSubmissions === 0) {
|
||||
return 0;
|
||||
}
|
||||
var stats = {
|
||||
desktop: newStatItem(),
|
||||
tablet: newStatItem(),
|
||||
phone: newStatItem(),
|
||||
other: newStatItem()
|
||||
};
|
||||
|
||||
return (totalTime/numSubmissions).toFixed(0);
|
||||
})();
|
||||
if($scope.myform.analytics && $scope.myform.analytics.visitors) {
|
||||
var visitors = $scope.myform.analytics.visitors;
|
||||
for (var i = 0; i < visitors.length; i++) {
|
||||
var visitor = visitors[i];
|
||||
var deviceType = visitor.deviceType;
|
||||
|
||||
$scope.DeviceStatistics = (function(){
|
||||
var newStatItem = function(){
|
||||
return {
|
||||
visits: 0,
|
||||
responses: 0,
|
||||
completion: 0,
|
||||
average_time: 0,
|
||||
total_time: 0
|
||||
};
|
||||
};
|
||||
stats[deviceType].visits++;
|
||||
|
||||
var stats = {
|
||||
desktop: newStatItem(),
|
||||
tablet: newStatItem(),
|
||||
phone: newStatItem(),
|
||||
other: newStatItem()
|
||||
};
|
||||
if (visitor.isSubmitted) {
|
||||
stats[deviceType].total_time = stats[deviceType].total_time + visitor.timeElapsed;
|
||||
stats[deviceType].responses++;
|
||||
}
|
||||
|
||||
if($scope.myform.analytics && $scope.myform.analytics.visitors) {
|
||||
var visitors = $scope.myform.analytics.visitors;
|
||||
for (i = 0; i < visitors.length; i++) {
|
||||
var visitor = visitors[i];
|
||||
var deviceType = visitor.deviceType;
|
||||
if(stats[deviceType].visits) {
|
||||
stats[deviceType].completion = 100*(stats[deviceType].responses / stats[deviceType].visits).toFixed(2);
|
||||
}
|
||||
|
||||
stats[deviceType].visits++;
|
||||
if(stats[deviceType].responses){
|
||||
stats[deviceType].average_time = (stats[deviceType].total_time / stats[deviceType].responses).toFixed(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
})();
|
||||
|
||||
if (visitor.isSubmitted) {
|
||||
stats[deviceType].total_time = stats[deviceType].total_time + visitor.timeElapsed;
|
||||
stats[deviceType].responses++;
|
||||
}
|
||||
var updateFields = $interval(initController, 1000000);
|
||||
|
||||
if(stats[deviceType].visits) {
|
||||
stats[deviceType].completion = 100*(stats[deviceType].responses / stats[deviceType].visits).toFixed(2);
|
||||
}
|
||||
|
||||
if(stats[deviceType].responses){
|
||||
stats[deviceType].average_time = (stats[deviceType].total_time / stats[deviceType].responses).toFixed(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
})();
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
initController();
|
||||
|
||||
var updateFields = $interval(initController, 1000000);
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
if (updateFields) {
|
||||
$interval.cancel($scope.updateFields);
|
||||
}
|
||||
});
|
||||
$scope.$on('$destroy', function() {
|
||||
if (updateFields) {
|
||||
$interval.cancel($scope.updateFields);
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
** Table Functions
|
||||
|
@ -174,7 +168,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope',
|
|||
//Export selected submissions of Form
|
||||
$scope.exportSubmissions = function(type){
|
||||
|
||||
angular.element('#table-submission-data').tableExport({type: type, escape:false});
|
||||
angular.element('#table-submission-data').tableExport({type: type, escape:false});
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -62,11 +62,14 @@
|
|||
<div class="col-xs-12">
|
||||
<uib-tabset active="activePill" vertical="true" type="pills">
|
||||
<uib-tab index="0" heading="{{ 'CREATE_TAB' | translate }}">
|
||||
<edit-form-directive myform="myform"></edit-form-directive>
|
||||
<edit-submissions-form-directive myform="myform"></edit-submissions-form-directive>
|
||||
</uib-tab>
|
||||
<uib-tab ng-repeat="tab in tabData" index="{{$index}}+1" heading="{{tab.heading}}">
|
||||
<div class='row' data-ng-include="'/static/modules/forms/admin/views/adminTabs/'+tab.templateName+'.html'" onload="form_url = trustSrc(formURL)"></div>
|
||||
</uib-tab>
|
||||
<uib-tab index="2" heading="{{ 'ANALYZE_TAB' | translate }}">
|
||||
<edit-form-directive myform="myform" user="myform.admin"></edit-form-directive>
|
||||
</uib-tab>
|
||||
<uib-tab ng-if="tabData" heading="Share" index="{{tabData.length}}">
|
||||
<div class="config-form">
|
||||
<div class="row">
|
||||
|
|
|
@ -382,7 +382,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-4 col-xs-12 field-input">{{ 'DISABLED' | translate }}</div>
|
||||
<div class="col-md-8 col-xs-12 field-input">
|
||||
<label class="switch-light switch-holo" ng-click="console.log('clicked switch')">
|
||||
<label class="switch-light switch-holo">
|
||||
<input type="checkbox" ng-model="field.disabled">
|
||||
<span>
|
||||
<span> {{ 'OFF' | translate }}</span>
|
||||
|
|
|
@ -261,7 +261,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="row table-outer">
|
||||
<div class="col-xs-12">
|
||||
<div class="col-xs-12">
|
||||
<table id="table-submission-data" class="table table-striped table-hover table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
@ -57,9 +57,7 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root
|
|||
}else if(type === 'rating'){
|
||||
scope.field.fieldValue = 0;
|
||||
}else if(scope.field.fieldType === 'radio'){
|
||||
console.log(scope.field);
|
||||
scope.field.fieldValue = scope.field.fieldOptions[0].option_value;
|
||||
console.log(scope.field.fieldValue);
|
||||
}else if(type === 'legal'){
|
||||
scope.field.fieldValue = 'true';
|
||||
$rootScope.nextField();
|
||||
|
@ -68,7 +66,6 @@ angular.module('forms').directive('fieldDirective', ['$http', '$compile', '$root
|
|||
|
||||
scope.setActiveField = $rootScope.setActiveField;
|
||||
|
||||
console.log(scope);
|
||||
//Set format only if field is a date
|
||||
if(scope.field.fieldType === 'date'){
|
||||
scope.dateOptions = {
|
||||
|
|
|
@ -219,8 +219,6 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter'
|
|||
setTimeout(function () {
|
||||
$scope.submitPromise = $http.post('/forms/' + $scope.myform._id, form)
|
||||
.success(function (data, status, headers) {
|
||||
console.log('\n\n\n\n\nSUBMITTING PROMISE');
|
||||
console.log(data);
|
||||
$scope.myform.submitted = true;
|
||||
$scope.loading = false;
|
||||
SendVisitorData.send($scope.myform, getActiveField(), _timeElapsed);
|
||||
|
|
|
@ -1,49 +1,14 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
//Dummy Service for Previewing Form
|
||||
function SendVisitorData() {
|
||||
|
||||
// Create a controller method for sending visitor data
|
||||
function send(form, lastActiveIndex) {
|
||||
// Create a new message object
|
||||
/*var visitorData = {
|
||||
referrer: document.referrer,
|
||||
isSubmitted: form.submitted,
|
||||
formId: form._id,
|
||||
lastActiveField: form.form_fields[lastActiveIndex]._id,
|
||||
timeElapsed: timeElapsed,
|
||||
//@TODO @FIXME: David: Need to make this get the language from the HTTP Header instead
|
||||
language: window.navigator.userLanguage || window.navigator.language,
|
||||
ipAddr: '',
|
||||
deviceType: ''
|
||||
};
|
||||
|
||||
$http.get('https://jsonip.com/').success(function(response) {
|
||||
visitorData.ipAddr = response['ip']+'';
|
||||
}).error(function(error) {
|
||||
console.error('Could not get users\'s ip');
|
||||
}).then(function(){
|
||||
|
||||
visitorData.userAgent = deviceDetector.raw;
|
||||
|
||||
if(deviceDetector.isTablet()) {
|
||||
visitorData.deviceType = 'tablet';
|
||||
}else if(deviceDetector.isMobile()){
|
||||
visitorData.deviceType = 'phone';
|
||||
}else {
|
||||
visitorData.deviceType = 'desktop';
|
||||
}
|
||||
console.log(visitorData.deviceType);
|
||||
Socket.emit('form-visitor-data', visitorData);
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
function init(){
|
||||
// Make sure the Socket is connected
|
||||
/*if (!Socket.socket) {
|
||||
Socket.connect();
|
||||
}*/
|
||||
}
|
||||
|
||||
var service = {
|
||||
|
@ -54,14 +19,11 @@
|
|||
return service;
|
||||
|
||||
}
|
||||
|
||||
// Create the SendVisitorData service
|
||||
angular
|
||||
.module('forms')
|
||||
.factory('SendVisitorData', SendVisitorData);
|
||||
|
||||
SendVisitorData.$inject = [];
|
||||
|
||||
|
||||
}());
|
||||
|
||||
|
|
|
@ -243,7 +243,6 @@
|
|||
|
||||
//Run controller functionality
|
||||
scope.openDeleteModal();
|
||||
console.log(scope.deleteModal);
|
||||
expect(scope.deleteModal.opened).toEqual(true);
|
||||
});
|
||||
|
||||
|
|
|
@ -140,8 +140,6 @@
|
|||
describe('Form Table Methods', function(){
|
||||
|
||||
it('$scope.toggleAllCheckers should toggle all checkboxes in table', function(){
|
||||
$httpBackend.flush();
|
||||
|
||||
//Run Controller Logic to Test
|
||||
scope.table.masterChecker = true;
|
||||
scope.toggleAllCheckers();
|
||||
|
@ -153,8 +151,6 @@
|
|||
});
|
||||
|
||||
it('$scope.isAtLeastOneChecked should return true when at least one checkbox is selected', function(){
|
||||
$httpBackend.flush();
|
||||
|
||||
scope.table.masterChecker = true;
|
||||
scope.toggleAllCheckers();
|
||||
|
||||
|
@ -165,8 +161,6 @@
|
|||
});
|
||||
|
||||
it('$scope.deleteSelectedSubmissions should delete all submissions that are selected', function(){
|
||||
$httpBackend.flush();
|
||||
|
||||
scope.table.masterChecker = true;
|
||||
scope.toggleAllCheckers();
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@
|
|||
|
||||
// it('should be able to render entryPage in html', function() {
|
||||
// scope.myStartPage = _.cloneDeep(sampleStartPage);
|
||||
// console.log(scope.myStartPage);
|
||||
// var element = angular.element('<entry-page pageData="myStartPage" pageType="startPage"></entry-page>');
|
||||
// $compile(element)(scope);
|
||||
// scope.$digest();
|
||||
|
|
|
@ -12,7 +12,6 @@ angular.module('stateMock').service('$state', function($q){
|
|||
}else{
|
||||
throw Error('No more transitions were expected! Tried to transition to '+ stateName );
|
||||
}
|
||||
console.log('Mock transition to: ' + stateName);
|
||||
var deferred = $q.defer();
|
||||
var promise = deferred.promise;
|
||||
deferred.resolve();
|
||||
|
|
Loading…
Reference in a new issue