From 3afc7701538755675b709d581359b1b75bae3cee Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:00:41 -0700 Subject: [PATCH 1/8] updated eslint --- app/controllers/forms.server.controller.js | 20 +++--- app/models/form.server.model.js | 72 +++++++++---------- app/tests/form_submission.model.test.js | 2 +- docs/Node-Rules/rules.logic-jump.js | 38 +++++----- .../core/services/menus.client.service.js | 6 +- .../admin-form.client.controller.js | 24 +++---- .../configure-form.client.directive.js | 2 +- .../directives/edit-form.client.directive.js | 26 +++---- .../edit-submissions-form.client.directive.js | 12 ++-- .../directives/field.client.directive.js | 1 - .../submit-form.client.directive.js | 18 ++--- .../list-forms.client.controller.test.js | 16 ++--- .../submit-form.client.controller.test.js | 6 +- .../configure-form.client.directive.test.js | 12 ++-- ...-form-submissions.client.directive.test.js | 18 ++--- .../submit-form.client.directive.test.js | 16 ++--- .../users/services/auth.client.service.js | 2 +- .../users/services/user.client.service.js | 12 ++-- 18 files changed, 152 insertions(+), 151 deletions(-) diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index 5ecdef38..af5936e6 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -33,9 +33,9 @@ exports.uploadPDF = function(req, res, next) { if (req.file.size === 0) { - next(new Error('File uploaded is EMPTY')); + return next(new Error('File uploaded is EMPTY')); }else if(req.file.size > 100000000){ - next(new Error('File uploaded exceeds MAX SIZE of 100MB')); + return next(new Error('File uploaded exceeds MAX SIZE of 100MB')); }else { fs.exists(_path, function(exists) { @@ -52,14 +52,14 @@ exports.uploadPDF = function(req, res, next) { if (stat && !stat.isDirectory()) { console.log('Directory cannot be created'); - next(new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"')); + 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) { - next(new Error(err.message)); + return next(new Error(err.message)); } pdfFile.path = path.join(newDestination, pdfFile.filename); console.log(pdfFile.filename + ' uploaded to ' + pdfFile.path); @@ -67,12 +67,12 @@ exports.uploadPDF = function(req, res, next) { }); } else { - next(new Error('Did NOT get your file!')); + return next(new Error('Did NOT get your file!')); } }); } }else { - next(new Error('Uploaded files were NOT detected')); + return next(new Error('Uploaded files were NOT detected')); } }; @@ -303,7 +303,7 @@ exports.formByID = function(req, res, next, id) { else { Form.findById(id).populate('admin').exec(function(err, form) { if (err) { - return next(err); + return return next(err); } else if (form === undefined || form === null) { res.status(400).send({ message: 'Form not found' @@ -316,7 +316,7 @@ exports.formByID = function(req, res, next, id) { form.provider = undefined; req.form = form; - next(); + return next(); } }); } @@ -332,5 +332,5 @@ exports.hasAuthorization = function(req, res, next) { message: 'User '+req.user.username+' is not authorized to edit Form: '+form.title }); } - next(); + return next(); }; diff --git a/app/models/form.server.model.js b/app/models/form.server.model.js index 2f19bd92..02ff64f4 100644 --- a/app/models/form.server.model.js +++ b/app/models/form.server.model.js @@ -241,31 +241,31 @@ function getDeletedIndexes(needle, haystack){ FormSchema.pre('save', function (next) { var that = this; - async.series([function(cb) { + async.series([function(return cb) { that.constructor .findOne({_id: that._id}).exec(function (err, original) { if (err) { console.log(err); - cb(err); + return cb(err); } else { _original = original; //console.log('_original'); //console.log(_original); - cb(null); + return cb(null); } }); - }, function(cb) { + }, function(return 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); + return cb(null); }, - function(cb) { + function(return cb) { if (that.pdf) { async.series([ - function (callback) { + function (return callback) { if (that.isModified('pdf') && that.pdf.path) { var new_filename = that.title.replace(/ /g, '') + '_template.pdf'; @@ -279,26 +279,26 @@ FormSchema.pre('save', function (next) { mkdirp.sync(newDestination); } 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 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; fs.move(old_path, path.join(newDestination, new_filename), {clobber: true}, function (err) { if (err) { console.error(err); - callback(new Error(err.message), 'task1'); + return callback(new Error(err.message), 'task1'); } else { that.pdf.path = path.join(newDestination, new_filename); that.pdf.name = new_filename; - callback(null, 'task1'); + return callback(null, 'task1'); } }); } else { - callback(null, 'task1'); + return callback(null, 'task1'); } }, - function (callback) { + function (return callback) { if (that.isGenerated) { 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'; @@ -318,9 +318,9 @@ FormSchema.pre('save', function (next) { //console.log(that.pdf.path); if (err) { - callback(new Error(err.message), null); + return 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); + return callback(new Error('Generated formfields is empty'), null); } console.log('autogenerating form'); @@ -347,36 +347,36 @@ FormSchema.pre('save', function (next) { that.form_fields = _form_fields; that.isGenerated = false; - callback(null, 'task2'); + return callback(null, 'task2'); }); } else { - callback(null, 'task2'); + return callback(null, 'task2'); } } ], function (err, results) { if (err) { - cb(new Error({ + return cb(new Error({ message: err.message })); } else { //console.log('ending form save1'); - cb(); + return cb(); } }); } else if (_original) { if (_original.hasOwnProperty('pdf')) { fs.remove(_original.pdf.path, function (err) { - if (err) cb(err); + if (err) return cb(err); console.log('file at ' + _original.pdf.path + ' successfully deleted'); - cb(); + return cb(); }); } - else cb(); + else return cb(); } - else cb(); + else return cb(); }, - function(cb) { + function(return cb) { if(that.isModified('form_fields') && that.form_fields && _original){ @@ -391,7 +391,7 @@ FormSchema.pre('save', function (next) { var modifiedSubmissions = []; async.forEachOfSeries(deletedIds, - function (deletedIdIndex, key, cb_id) { + function (deletedIdIndex, key, return cb_id) { var deleted_id = old_ids[deletedIdIndex]; @@ -401,7 +401,7 @@ FormSchema.pre('save', function (next) { exec(function(err, submissions){ if(err) { console.error(err); - cb_id(err); + return cb_id(err); } else { //Delete field if there are no submission(s) found if (submissions.length) { @@ -409,18 +409,18 @@ FormSchema.pre('save', function (next) { modifiedSubmissions.push.apply(modifiedSubmissions, submissions); } - cb_id(null); + return cb_id(null); } }); }, function (err) { if(err){ console.error(err.message); - cb(err); + return cb(err); } else { //Iterate through all submissions with modified form_fields - async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) { + async.forEachOfSeries(modifiedSubmissions, function (submission, key, return callback) { //Iterate through ids of deleted fields for (var i = 0; i < deletedIds.length; i++) { @@ -450,27 +450,27 @@ FormSchema.pre('save', function (next) { } submission.save(function (err) { - if (err) callback(err); - else callback(null); + if (err) return callback(err); + else return callback(null); }); }, function (err) { if (err) { console.error(err.message); - cb(err); + return cb(err); } - else cb(); + else return cb(); }); } } ); } - else cb(null); + else return cb(null); } - else cb(null); + else return cb(null); }], function(err, results){ - if (err) next(err); - next(); + if (err) return next(err); + return next(); }); }); diff --git a/app/tests/form_submission.model.test.js b/app/tests/form_submission.model.test.js index a910f062..ab1b1bae 100644 --- a/app/tests/form_submission.model.test.js +++ b/app/tests/form_submission.model.test.js @@ -106,7 +106,7 @@ describe('FormSubmission Model Unit Tests:', function() { {'fieldType':'textfield', 'title':'And your last name', 'fieldValue': ''}, {'fieldType':'radio', 'title':'And your sex', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }], 'fieldValue': ''}, {'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''}, - {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''}, + {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''} ], plugins: { oscarhost: { diff --git a/docs/Node-Rules/rules.logic-jump.js b/docs/Node-Rules/rules.logic-jump.js index 11715ed2..0227aa90 100644 --- a/docs/Node-Rules/rules.logic-jump.js +++ b/docs/Node-Rules/rules.logic-jump.js @@ -9,18 +9,18 @@ var multiFact = { { left:"user 4", right:"something something user something", - logicOp: "AND", + logicOp: "AND" }, { left:"something something user something", right:"something", - logicOp: "OR", + logicOp: "OR" } ], left:"", right:"", logicOp:"", - prevResult: null, + prevResult: null }; var _globalRules = function(){}; @@ -39,7 +39,7 @@ _globalRules.Equal = { if(prevResult !== null){ if(logicOp === "AND"){ - + } } this.result = false; @@ -59,7 +59,7 @@ _globalRules.NotEqual = { "consequence" : function(R) { this.result = false; R.next(); - }, + } }; _globalRules.AND = { "condition" : function(R) { @@ -74,7 +74,7 @@ _globalRules.AND = { "consequence" : function(R) { this.result = false; R.next(); - }, + } }; _globalRules.OR = { "condition" : function(R) { @@ -83,7 +83,7 @@ _globalRules.OR = { this.left = currTuple.left; this.right = currTuple.right; } - + R.when(!(this.left || this.right)); }, "consequence" : function(R) { @@ -101,7 +101,7 @@ _stringRules.Contains = { this.left = currTuple.left; this.right = currTuple.right; } - + var contains = (this.left.indexOf(this.right) > -1); R.when(!contains); }, @@ -117,7 +117,7 @@ _stringRules.NotContains = { this.left = currTuple.left; this.right = currTuple.right; } - + var notContains = !(this.left.indexOf(this.right) > -1); R.when(!notContains); }, @@ -133,7 +133,7 @@ _stringRules.BeginsWith = { this.left = currTuple.left; this.right = currTuple.right; } - + R.when(!(this.left.indexOf(this.right) === 0)); }, "consequence" : function(R) { @@ -148,7 +148,7 @@ _stringRules.EndsWith = { this.left = currTuple.left; this.right = currTuple.right; } - + var lenLeft = this.left.length; var lenRight = this.right.length; @@ -157,7 +157,7 @@ _stringRules.EndsWith = { "consequence" : function(R) { this.result = false; R.next(); - }, + } }; var _numberRules = function(){}; @@ -169,14 +169,14 @@ _numberRules.GreaterThan = { this.left = currTuple.left; this.right = currTuple.right; } - + var greaterThan = (this.left > this.right); R.when(!greaterThan); }, "consequence" : function(R) { this.result = false; R.next(); - }, + } }; _numberRules.SmallerThan = { "condition" : function(R) { @@ -185,7 +185,7 @@ _numberRules.SmallerThan = { this.left = currTuple.left; this.right = currTuple.right; } - + var smallerThan = (this.left < this.right); R.when(!smallerThan); }, @@ -201,14 +201,14 @@ _numberRules.GreaterThanOrEqual = { this.left = currTuple.left; this.right = currTuple.right; } - + var greaterThanOrEqual = (this.left >= this.right); R.when(!greaterThanOrEqual); }, "consequence" : function(R) { this.result = false; R.next(); - }, + } }; _numberRules.SmallerThanOrEqual = { @@ -218,14 +218,14 @@ _numberRules.SmallerThanOrEqual = { this.left = currTuple.left; this.right = currTuple.right; } - + var smallerThanOrEqual = (this.left <= this.right); R.when(!smallerThanOrEqual); }, "consequence" : function(R) { this.result = false; R.next(); - }, + } }; module.exports = { diff --git a/public/modules/core/services/menus.client.service.js b/public/modules/core/services/menus.client.service.js index 96d10400..86028991 100755 --- a/public/modules/core/services/menus.client.service.js +++ b/public/modules/core/services/menus.client.service.js @@ -10,10 +10,10 @@ angular.module('core').service('Menus', [ // Define the menus object this.menus = {}; - // A private function for rendering decision + // A private function for rendering decision var shouldRender = function(user) { if (user) { - if (!!~this.roles.indexOf('*')) { + if (~this.roles.indexOf('*')) { return true; } else { for (var userRoleIndex in user.roles) { @@ -168,4 +168,4 @@ angular.module('core').service('Menus', [ //Adding the bottombar menu for the Form-Footer view this.addMenu('bottombar', false, ['*']); } -]); \ No newline at end of file +]); diff --git a/public/modules/forms/controllers/admin-form.client.controller.js b/public/modules/forms/controllers/admin-form.client.controller.js index ec11a342..bdc086dd 100644 --- a/public/modules/forms/controllers/admin-form.client.controller.js +++ b/public/modules/forms/controllers/admin-form.client.controller.js @@ -18,15 +18,15 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope }, { heading: 'Design', - route: 'viewForm.design', + route: 'viewForm.design' }, { heading: 'Configure', - route: 'viewForm.configure', + route: 'viewForm.configure' }, { heading: 'Analyze', - route: 'viewForm.analyze', + route: 'viewForm.analyze' } ]; @@ -39,8 +39,8 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope }); }; - /* - ** DeleteModal Functions + /* + ** DeleteModal Functions */ $scope.openDeleteModal = function(){ $scope.deleteModal = $uibModal.open({ @@ -72,15 +72,15 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope if($scope.deleteModal && $scope.deleteModal.opened){ $scope.deleteModal.close(); - + var form_id = $scope.myform._id; if(!form_id) throw new Error('Error - removeCurrentForm(): $scope.myform._id does not exist'); - + $http.delete('/forms/'+form_id) .success(function(data, status, headers){ console.log('form deleted successfully'); - $state.go('listForms', {}, {reload: true}); + $state.go('listForms', {}, {reload: true}); }).error(function(error){ console.log('ERROR: Form could not be deleted.'); @@ -96,7 +96,7 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope if(!updateImmediately){ continueUpdate = !$rootScope.saveInProgress; } - + //Update form **if we are not currently updating** or if **shouldUpdateNow flag is set** if(continueUpdate){ var err = null; @@ -111,12 +111,12 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope console.log('Error occured during form UPDATE.\n'); // console.log(response.data); err = response.data; - }).finally(function() { + }).finally(function() { // console.log('finished updating'); if(!updateImmediately){$rootScope.saveInProgress = false; } if( (typeof cb) === 'function'){ - cb(err); + return cb(err); } }); } @@ -124,4 +124,4 @@ angular.module('forms').controller('AdminFormController', ['$rootScope', '$scope } -]); \ No newline at end of file +]); diff --git a/public/modules/forms/directives/configure-form.client.directive.js b/public/modules/forms/directives/configure-form.client.directive.js index 94173855..91b58f1c 100644 --- a/public/modules/forms/directives/configure-form.client.directive.js +++ b/public/modules/forms/directives/configure-form.client.directive.js @@ -77,7 +77,7 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$htt console.log('Error occured during upload.\n'); console.log(resp.status); }, function (evt) { - var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); + var progressPercentage = parseInt(100.0 * evt.loaded / evt.total, 10); $scope.log = 'progress: ' + progressPercentage + '% ' + evt.config.data.file.name + '\n' + $scope.log; diff --git a/public/modules/forms/directives/edit-form.client.directive.js b/public/modules/forms/directives/edit-form.client.directive.js index 066e60e9..d2ba8983 100644 --- a/public/modules/forms/directives/edit-form.client.directive.js +++ b/public/modules/forms/directives/edit-form.client.directive.js @@ -6,7 +6,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField templateUrl: 'modules/forms/views/directiveViews/form/edit-form.client.view.html', restrict: 'E', scope: { - myform:'=', + myform:'=' }, controller: function($scope){ var field_ids = _($scope.myform.form_fields).pluck('_id'); @@ -45,7 +45,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField if( $scope.myform.plugins.oscarhost.settings.fieldMap.hasOwnProperty(field_id) ){ currentFields = _(currentFields).difference($scope.myform.plugins.oscarhost.settings.fieldMap[field_id]); - } + } //Get all oscarhostFields that haven't been mapped to a formfield return _(oscarhostFields).difference(currentFields).value(); @@ -59,7 +59,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField $scope.dropzone = { handle: ' .handle', containment: '.dropzoneContainer', - cursor: 'grabbing', + cursor: 'grabbing' }; /* @@ -73,9 +73,9 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField var fieldTitle; for(var i = 0; i < $scope.addField.types.length; i++){ - if($scope.addField.types[i].name === fieldType){ + if($scope.addField.types[i].name === fieldType){ $scope.addField.types[i].lastAddedID++; - fieldTitle = $scope.addField.types[i].value+$scope.addField.types[i].lastAddedID; + fieldTitle = $scope.addField.types[i].value+$scope.addField.types[i].lastAddedID; break; } } @@ -90,12 +90,12 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField // console.log('\n\n---------\nAdded field CLIENT'); // console.log(newField); // newField._id = _.uniqueId(); - + // put newField into fields array if(modifyForm){ $scope.myform.form_fields.push(newField); } - return newField; + return newField; }; // Delete particular field on button click @@ -109,7 +109,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField $scope.myform.form_fields.splice(field_index, 1); }; $scope.duplicateField = function (field_index){ - var currField = _.cloneDeep($scope.myform.form_fields[field_index]); + var currField = _.cloneDeep($scope.myform.form_fields[field_index]); currField._id = 'cloned'+_.uniqueId(); currField.title += ' copy'; @@ -158,8 +158,8 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField $scope.addOption = function(field_index){ var currField = $scope.myform.form_fields[field_index]; console.log(field_index); - console.log(currField); - + console.log(currField); + if(currField.fieldType === 'checkbox' || currField.fieldType === 'dropdown' || currField.fieldType === 'radio'){ if(!currField.fieldOptions) $scope.myform.form_fields[field_index].fieldOptions = []; @@ -175,7 +175,7 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField var newOption = { 'option_id' : Math.floor(100000*Math.random()), 'option_title' : 'Option '+lastOptionID, - 'option_value' : 'Option ' +lastOptionID, + 'option_value' : 'Option ' +lastOptionID }; // put new option into fieldOptions array @@ -208,8 +208,8 @@ angular.module('forms').directive('editFormDirective', ['$rootScope', 'FormField } }; - }, - + } + }; } ]); diff --git a/public/modules/forms/directives/edit-submissions-form.client.directive.js b/public/modules/forms/directives/edit-submissions-form.client.directive.js index fb2954e8..1fb63091 100644 --- a/public/modules/forms/directives/edit-submissions-form.client.directive.js +++ b/public/modules/forms/directives/edit-submissions-form.client.directive.js @@ -49,7 +49,7 @@ angular.module('forms').directive('editSubmissionsFormDirective', ['$rootScope', defaultFormFields = _.cloneDeep($scope.myform.form_fields); // console.log('before textField2: '+data[0].form_fields[1].fieldValue); - + //Iterate through form's submissions for(var i=0; i= 0) { templateUrl = templateUrl+type+'.html'; } - return $templateCache.get('../public/'+templateUrl); }; diff --git a/public/modules/forms/directives/submit-form.client.directive.js b/public/modules/forms/directives/submit-form.client.directive.js index f74e3ede..a17fd684 100644 --- a/public/modules/forms/directives/submit-form.client.directive.js +++ b/public/modules/forms/directives/submit-form.client.directive.js @@ -48,28 +48,30 @@ angular.module('forms').directive('submitFormDirective', ['$http', 'TimeCounter' $scope.fieldBottom = elemBox.bottom; //console.log($scope.forms.myForm); + var field_id; + var field_index; if(!$scope.noscroll){ //Focus on submit button if( $scope.selected.index === $scope.myform.form_fields.length-1 && $scope.fieldBottom < 200){ - var field_index = $scope.selected.index+1; - var field_id = 'submit_field'; + field_index = $scope.selected.index+1; + field_id = 'submit_field'; $scope.setActiveField(field_id, field_index, false); } //Focus on field above submit button else if($scope.selected.index === $scope.myform.form_fields.length){ if($scope.fieldTop > 200){ - var field_index = $scope.selected.index-1; - var field_id = $scope.myform.form_fields[field_index]._id; + field_index = $scope.selected.index-1; + field_id = $scope.myform.form_fields[field_index]._id; $scope.setActiveField(field_id, field_index, false); } }else if( $scope.fieldBottom < 0){ - var field_index = $scope.selected.index+1; - var field_id = $scope.myform.form_fields[field_index]._id; + field_index = $scope.selected.index+1; + field_id = $scope.myform.form_fields[field_index]._id; $scope.setActiveField(field_id, field_index, false); }else if ( $scope.selected.index !== 0 && $scope.fieldTop > 0) { - var field_index = $scope.selected.index-1; - var field_id = $scope.myform.form_fields[field_index]._id; + field_index = $scope.selected.index-1; + field_id = $scope.myform.form_fields[field_index]._id; $scope.setActiveField(field_id, field_index, false); } //console.log('$scope.selected.index: '+$scope.selected.index); diff --git a/public/modules/forms/tests/unit/controllers/list-forms.client.controller.test.js b/public/modules/forms/tests/unit/controllers/list-forms.client.controller.test.js index 961969de..c89e73cf 100644 --- a/public/modules/forms/tests/unit/controllers/list-forms.client.controller.test.js +++ b/public/modules/forms/tests/unit/controllers/list-forms.client.controller.test.js @@ -76,7 +76,7 @@ } }); }); - + // Load the main application module beforeEach(module(ApplicationConfiguration.applicationModuleName)); @@ -136,12 +136,12 @@ dupSampleForm_index = 3, newSampleFormList = _.clone(sampleFormList); dupSampleForm._id = 'a02df75b44c1d26b6a5e05b8'; - newSampleFormList.splice(3, 0, dupSampleForm); + newSampleFormList.splice(3, 0, dupSampleForm); var controller = createListFormsController(); // Set GET response - $httpBackend.expectGET(/^(\/forms)$/).respond(200, sampleFormList); + $httpBackend.expectGET(/^(\/forms)$/).respond(200, sampleFormList); // Run controller functionality scope.findAll(); $httpBackend.flush(); @@ -155,7 +155,7 @@ // Test scope value expect( scope.myforms.length ).toEqual(newSampleFormList.length); for(var i=0; i Date: Thu, 28 Apr 2016 23:04:27 -0700 Subject: [PATCH 2/8] added codeclimate config file --- .codeclimate.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..c658e346 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,6 @@ +exclude_paths: +- public/dist/** +- node_modules/** +- public/lib/** +- uploads/** +- docs/** From a44f3b73d355797fcd0ca16a188e516de64afe6f Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:08:30 -0700 Subject: [PATCH 3/8] updated codeclimate.yml file --- .codeclimate.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.codeclimate.yml b/.codeclimate.yml index c658e346..662176b3 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,3 +1,24 @@ +engines: + eslint: + enabled: true + csslint: + enabled: true + eslint + enabled: true + fixme: + enabled: true + duplication: + enabled: true + config: + languages: + - javascript +ratings: + paths: + - "**.css" + - "**.js" + - "**.jsx" + - "**.module" + exclude_paths: - public/dist/** - node_modules/** From bff92bf2175db35c7f07fbca5f5688d284f5326d Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:10:19 -0700 Subject: [PATCH 4/8] fixed .codeclimate.yml --- .codeclimate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 662176b3..13ec14b7 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -3,7 +3,7 @@ engines: enabled: true csslint: enabled: true - eslint + eslint: enabled: true fixme: enabled: true From 23834543b7c90923a2014d0c97b9228913fed130 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:16:17 -0700 Subject: [PATCH 5/8] improved style of form-submission --- .../users/users.password.server.controller.js | 10 +++ app/models/form_field.server.model.js | 10 +-- app/models/form_submission.server.model.js | 89 ++++++++++--------- 3 files changed, 60 insertions(+), 49 deletions(-) diff --git a/app/controllers/users/users.password.server.controller.js b/app/controllers/users/users.password.server.controller.js index e246baed..fe5ee8ca 100755 --- a/app/controllers/users/users.password.server.controller.js +++ b/app/controllers/users/users.password.server.controller.js @@ -33,6 +33,11 @@ exports.forgot = function(req, res, next) { User.findOne({ username: req.body.username }, '-salt -password', function(err, user) { + if(err){ + return res.status(500).send({ + message: err.message + }); + } if (!user) { return res.status(400).send({ message: 'No account with that username has been found' @@ -102,6 +107,11 @@ exports.validateResetToken = function(req, res) { $gt: Date.now() } }, function(err, user) { + if(err){ + return res.status(500).send({ + message: err.message + }); + } if (!user) { return res.redirect('/#!/password/reset/invalid'); } diff --git a/app/models/form_field.server.model.js b/app/models/form_field.server.model.js index 3b938243..643295af 100644 --- a/app/models/form_field.server.model.js +++ b/app/models/form_field.server.model.js @@ -10,17 +10,17 @@ var mongoose = require('mongoose'), var FieldOptionSchema = new Schema({ option_id: { - type: Number, + type: Number }, option_title: { - type: String, + type: String }, option_value: { type: String, - trim: true, - }, + trim: true + } }); @@ -31,7 +31,7 @@ var FormFieldSchema = new Schema({ title: { type: String, trim: true, - required: 'Field Title cannot be blank', + required: 'Field Title cannot be blank' }, description: { type: String, diff --git a/app/models/form_submission.server.model.js b/app/models/form_submission.server.model.js index 4a5c2e47..cf1774ce 100644 --- a/app/models/form_submission.server.model.js +++ b/app/models/form_submission.server.model.js @@ -17,7 +17,7 @@ var mongoose = require('mongoose'), FieldSchema = require('./form_field.server.model.js'), OscarSecurity = require('../../scripts/oscarhost/OscarSecurity'); -var newDemoTemplate = { +var newDemoTemplate = { address: '880-9650 Velit. St.', city: '', dateOfBirth: '10', @@ -38,10 +38,10 @@ var newDemoTemplate = { sin: '', spokenLanguage: 'English', title: 'MS.', - yearOfBirth: '2015' + yearOfBirth: '2015' }; -/** +/** * Form Submission Schema */ var FormSubmissionSchema = new Schema({ @@ -56,64 +56,64 @@ var FormSubmissionSchema = new Schema({ }, form_fields: { - type: [Schema.Types.Mixed], + type: [Schema.Types.Mixed] }, - form: { - type: Schema.Types.ObjectId, - ref: 'Form', + form: { + type: Schema.Types.ObjectId, + ref: 'Form', required: true }, ipAddr: { - type: String, + type: String }, geoLocation: { Country: { - type: String, + type: String }, Region: { - type: String, + type: String }, City: { - type: String, + type: String } }, device: { type: { - type: String, + type: String }, name: { - type: String, + type: String } }, pdfFilePath: { - type: Schema.Types.Mixed, + type: Schema.Types.Mixed }, pdf: { - type: Schema.Types.Mixed, + type: Schema.Types.Mixed }, fdfData: { - type: Schema.Types.Mixed, + type: Schema.Types.Mixed }, - timeElapsed: { + timeElapsed: { type: Number, - }, + }, percentageComplete: { - type: Number, + type: Number }, //TODO: DAVID: Need to not have this hardcoded oscarDemoNum: { - type: Number, + type: Number }, hasPlugins: { oscarhost: { type: Boolean, - default: false, + default: false } } @@ -127,7 +127,7 @@ FormSubmissionSchema.plugin(mUtilities.timestamp, { //Oscarhost API hook FormSubmissionSchema.pre('save', function (next) { - + var self = this; if(this.hasPlugins.oscarhost){ @@ -140,7 +140,7 @@ FormSubmissionSchema.pre('save', function (next) { // console.log('FormSubmission [form_field ids]\n--------'); // console.log(submission_ids); - if(err) next(err); + 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) ); @@ -175,7 +175,7 @@ FormSubmissionSchema.pre('save', function (next) { var date = new Date(currField.fieldValue); _generatedDemo.dateOfBirth = date.getDate()+''; _generatedDemo.yearOfBirth = date.getFullYear()+''; - _generatedDemo.monthOfBirth = date.getMonth()+''; + _generatedDemo.monthOfBirth = date.getMonth()+''; } } var currDate = new Date(); @@ -183,18 +183,18 @@ FormSubmissionSchema.pre('save', function (next) { _generatedDemo.lastUpdateDate = currDate.toISOString(); return _generatedDemo; }; - + var submissionDemographic = generateDemo(self.form_fields, _form.plugins.oscarhost.settings.fieldMap, newDemoTemplate); console.log(submissionDemographic); async.waterfall([ - function (callback) { + function (callback) { //Authenticate with API soap.createClient(url_login, options, function(err, client) { client.login(args_login, function (err, result) { - if(err) callback(err); + if(err) return callback(err); console.log('SOAP authenticated'); - callback(null, result.return); + return callback(null, result.return); }); }); }, @@ -203,56 +203,57 @@ FormSubmissionSchema.pre('save', function (next) { //Force Add Demographic if(_form.plugins.oscarhost.settings.updateType === 'force_add'){ soap.createClient(url_demo, options, function(err, client) { + if(err) return callback(err); client.setSecurity(new OscarSecurity(security_obj.securityId, security_obj.securityTokenKey) ); client.addDemographic({ arg0: submissionDemographic }, function (err, result) { console.log('FORCE ADDING DEMOGRAPHIC \n'); // console.log(result.return); - if(err) callback(err); - callback(null, result); + if(err) return callback(err); + return callback(null, result); }); }); } }, ], function(err, result) { - if(err) next(err); + if(err) return next(err); self.oscarDemoNum = parseInt(result.return, 10); console.log('self.oscarDemoNum: '+self.oscarDemoNum); - next(); - }); + return next(); + }); }else{ - next(); + return next(); } }); }else{ - next(); + return next(); } }); -//Check for IP Address of submitting person +//Check for IP Address of submitting person FormSubmissionSchema.pre('save', function (next){ var self = this; if(this.ipAddr){ if(this.isModified('ipAddr') || !this.geoLocation){ freegeoip.getLocation(this.ipAddr, function(err, location){ - if(err) next(err); + if(err) return next(err); //self.geoLocation = JSON.parse(location); - next(); + return next(); }); } } - next(); + return next(); }); -//Generate autofilled PDF if flags are set +//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'; @@ -264,13 +265,13 @@ FormSubmissionSchema.pre('save', function (next) { pdfFiller.fillForm(self.pdf.path, dest_path, self.fdfData, function(err){ if(err) { console.log('\n err.message: '+err.message); - next( new Error(err.message) ); + return next( new Error(err.message) ); } console.log('Field data from Form: '+self.title.replace(/ /g,'')+' outputed to new PDF: '+dest_path); - next(); + return next(); }); } else { - next(); + return next(); } }); From e33fdf24432b4bba5467cdaf51f2e84d8dfa493c Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:22:47 -0700 Subject: [PATCH 6/8] fixed server tests --- app/controllers/forms.server.controller.js | 2 +- app/models/form.server.model.js | 18 +++++++++--------- app/tests/form_submission.model.test.js | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/controllers/forms.server.controller.js b/app/controllers/forms.server.controller.js index af5936e6..1f1ca113 100644 --- a/app/controllers/forms.server.controller.js +++ b/app/controllers/forms.server.controller.js @@ -303,7 +303,7 @@ exports.formByID = function(req, res, next, id) { else { Form.findById(id).populate('admin').exec(function(err, form) { if (err) { - return return next(err); + return next(err); } else if (form === undefined || form === null) { res.status(400).send({ message: 'Form not found' diff --git a/app/models/form.server.model.js b/app/models/form.server.model.js index 02ff64f4..4fd607ad 100644 --- a/app/models/form.server.model.js +++ b/app/models/form.server.model.js @@ -241,7 +241,7 @@ function getDeletedIndexes(needle, haystack){ FormSchema.pre('save', function (next) { var that = this; - async.series([function(return cb) { + async.series([function(cb) { that.constructor .findOne({_id: that._id}).exec(function (err, original) { if (err) { @@ -254,7 +254,7 @@ FormSchema.pre('save', function (next) { return cb(null); } }); - }, function(return cb) { + }, 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; @@ -262,10 +262,10 @@ FormSchema.pre('save', function (next) { } return cb(null); }, - function(return cb) { + function(cb) { if (that.pdf) { async.series([ - function (return callback) { + function (callback) { if (that.isModified('pdf') && that.pdf.path) { var new_filename = that.title.replace(/ /g, '') + '_template.pdf'; @@ -279,7 +279,7 @@ FormSchema.pre('save', function (next) { mkdirp.sync(newDestination); } if (stat && !stat.isDirectory()) { - return 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; @@ -298,7 +298,7 @@ FormSchema.pre('save', function (next) { return callback(null, 'task1'); } }, - function (return callback) { + function (callback) { if (that.isGenerated) { 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'; @@ -376,7 +376,7 @@ FormSchema.pre('save', function (next) { } else return cb(); }, - function(return cb) { + function(cb) { if(that.isModified('form_fields') && that.form_fields && _original){ @@ -391,7 +391,7 @@ FormSchema.pre('save', function (next) { var modifiedSubmissions = []; async.forEachOfSeries(deletedIds, - function (deletedIdIndex, key, return cb_id) { + function (deletedIdIndex, key, cb_id) { var deleted_id = old_ids[deletedIdIndex]; @@ -420,7 +420,7 @@ FormSchema.pre('save', function (next) { } else { //Iterate through all submissions with modified form_fields - async.forEachOfSeries(modifiedSubmissions, function (submission, key, return callback) { + async.forEachOfSeries(modifiedSubmissions, function (submission, key, callback) { //Iterate through ids of deleted fields for (var i = 0; i < deletedIds.length; i++) { diff --git a/app/tests/form_submission.model.test.js b/app/tests/form_submission.model.test.js index ab1b1bae..5a048919 100644 --- a/app/tests/form_submission.model.test.js +++ b/app/tests/form_submission.model.test.js @@ -107,16 +107,16 @@ describe('FormSubmission Model Unit Tests:', function() { {'fieldType':'radio', 'title':'And your sex', 'fieldOptions': [{ 'option_id': 0, 'option_title': 'Male', 'option_value': 'M' }, { 'option_id': 1, 'option_title': 'Female', 'option_value': 'F' }], 'fieldValue': ''}, {'fieldType':'date', 'title':'When were you born?', 'fieldValue': ''}, {'fieldType':'number', 'title':'What\'s your phone #?', 'fieldValue': ''} - ], - plugins: { - oscarhost: { - baseUrl: config.oscarhost.baseUrl, - settings: { - updateType: 'force_add' - }, - auth: config.oscarhost.auth - } - } + ] + // plugins: { + // oscarhost: { + // baseUrl: config.oscarhost.baseUrl, + // settings: { + // updateType: 'force_add' + // }, + // auth: config.oscarhost.auth + // } + // } }); myForm.save(function(err, form){ From 0b01d33ec18354357f0b5707b824ab740c1609d4 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:25:04 -0700 Subject: [PATCH 7/8] fixed codeclimate.yml --- .codeclimate.yml | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 13ec14b7..55098d5b 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -4,9 +4,9 @@ engines: csslint: enabled: true eslint: - enabled: true - fixme: - enabled: true + enabled: true + fixme: + enabled: true duplication: enabled: true config: diff --git a/package.json b/package.json index c1c5e482..ad7a0eed 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "math": "0.0.3", "method-override": "~2.3.0", "mkdirp": "^0.5.1", - "mongoose": "~3.8.8", + "mongoose": "^3.8.40", "mongoose-utilities": "~0.1.1", "morgan": "~1.6.1", "multer": "~1.1.0", From da51c41ddae3d729a3c86d833219fe0238947c88 Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Thu, 28 Apr 2016 23:30:28 -0700 Subject: [PATCH 8/8] updated .code-cilmate.yml file --- .codeclimate.yml | 2 ++ gruntfile.js | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 55098d5b..e069e341 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -25,3 +25,5 @@ exclude_paths: - public/lib/** - uploads/** - docs/** +- public/populate_template_cache.js +- scripts/** diff --git a/gruntfile.js b/gruntfile.js index dd579162..c4ee0950 100755 --- a/gruntfile.js +++ b/gruntfile.js @@ -191,7 +191,7 @@ NODE_ENV: 'test', src: watchFiles.allTests, // a folder works nicely options: { mask: '*.test.js', - require: ['server.js'], + require: ['server.js'] } }, coverageClient: { @@ -199,7 +199,7 @@ NODE_ENV: 'test', options: { coverageFolder: 'coverageClient', mask: '*.test.js', - require: ['server.js'], + require: ['server.js'] } }, coverageServer: { @@ -207,7 +207,7 @@ NODE_ENV: 'test', options: { coverageFolder: 'coverageServer', mask: '*.test.js', - require: ['server.js'], + require: ['server.js'] } }, coveralls: { @@ -244,7 +244,7 @@ NODE_ENV: 'test', removeAttributeQuotes: true, removeComments: true, removeEmptyAttributes: true, - removeRedundantAttributes: true, + removeRedundantAttributes: true } }, main: {