added stuff

This commit is contained in:
David Baldwynn 2015-06-30 10:36:51 -07:00
parent a923b2d30e
commit 3ec944392e
14 changed files with 164 additions and 104 deletions

View file

@ -112,13 +112,6 @@ exports.createSubmission = function(req, res) {
submission.fdfData = fdfData; submission.fdfData = fdfData;
//Create new file
// pdfFiller.fillForm( form.pdf.path, config.pdfUploadPath+form.title+'/'+form.title+'_'+Date.now()+'_submission.pdf', fdfData, function() {
// console.log('\n\n\n fdfData');
// console.log(fdfData);
// console.log('\n\n\n :\n');
// console.log(req.body);
submission.save(function(err){ submission.save(function(err){
if (err) { if (err) {
console.error(err); console.error(err);
@ -129,7 +122,6 @@ exports.createSubmission = function(req, res) {
return res.status(200); return res.status(200);
} }
}); });
// });
}; };
@ -139,7 +131,7 @@ exports.createSubmission = function(req, res) {
exports.listSubmissions = function(req, res) { exports.listSubmissions = function(req, res) {
var _form = req.form; var _form = req.form;
FormSubmission.find({ form: req.form }).exec(function(err, submissions) { FormSubmission.find({ form: req.form }).populate('admin', 'form').exec(function(err, submissions) {
if (err) { if (err) {
return res.status(400).send({ return res.status(400).send({
message: errorHandler.getErrorMessage(err) message: errorHandler.getErrorMessage(err)

View file

@ -33,7 +33,7 @@ var FormSchema = new Schema({
type: String, type: String,
default: '', default: '',
}, },
form_fields: [FieldSchema], form_fields: [{type: Schema.Types.Mixed}],
submissions: [{ submissions: [{
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
@ -141,9 +141,9 @@ FormSchema.pre('save', function (next) {
} }
field.fieldValue = ''; field.fieldValue = '';
// field.created = Date.now(); field.created = Date.now();
// field.required = true; field.required = true;
//field.disabled = false; field.disabled = false;
// field = new Field(field); // field = new Field(field);
// field.save(function(err) { // field.save(function(err) {

View file

@ -11,6 +11,8 @@ var mongoose = require('mongoose'),
config = require('../../config/config'), config = require('../../config/config'),
path = require('path'), path = require('path'),
Form = mongoose.model('Form'), Form = mongoose.model('Form'),
FieldSchema = require('./form_field.server.model.js'),
Field = mongoose.model('Field', FieldSchema),
fs = require('fs-extra'); fs = require('fs-extra');
/** /**
@ -30,7 +32,7 @@ var FormSubmissionSchema = new Schema({
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
ref: 'User', ref: 'User',
}, },
form_fields: [Schema.Types.Mixed], form_fields: [{type: Schema.Types.Mixed}],
form: { form: {
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
ref: 'Form', ref: 'Form',

View file

@ -12,14 +12,17 @@ module.exports = function(app) {
.post(forms.uploadPDF); .post(forms.uploadPDF);
app.route('/forms') app.route('/forms')
.get(forms.list) .get(users.requiresLogin, forms.hasAuthorization, forms.list)
.post(users.requiresLogin, forms.create); .post(users.requiresLogin, forms.create);
app.route('/forms/:formId/submissions')
.get(forms.listSubmissions);
app.route('/forms/:formId') app.route('/forms/:formId')
.get(forms.read) .get(forms.read)
.post(forms.createSubmission) .post(forms.createSubmission)
.put(users.requiresLogin, forms.hasAuthorization, forms.update) .put(users.requiresLogin, forms.hasAuthorization, forms.update)
.delete(users.requiresLogin, forms.delete); .delete(users.requiresLogin, forms.hasAuthorization, forms.delete);
// Finish by binding the form middleware // Finish by binding the form middleware
app.param('formId', forms.formByID); app.param('formId', forms.formByID);

View file

@ -50,9 +50,9 @@
<body class="ng-cloak" > <body class="ng-cloak" >
<header data-ng-include="'/modules/core/views/header.client.view.html'"></header> <header data-ng-include="'/modules/core/views/header.client.view.html'"></header>
<section class="content"> <section class="content">
<section class="container"> <!-- <section class="container"> -->
{% block content %}{% endblock %} {% block content %}{% endblock %}
</section> <!-- </section> -->
</section> </section>
<!--Embedding The User Object--> <!--Embedding The User Object-->

View file

@ -1,5 +1,4 @@
/*Navbar Custom CSS*/
.navbar .navbar-brand { .navbar .navbar-brand {
font-size: 1.6em; font-size: 1.6em;
font-weight: 900; font-weight: 900;
@ -10,7 +9,7 @@
} }
.content { .content {
margin-top: 50px; /*margin-top: 50px;*/
} }
.undecorated-link:hover { .undecorated-link:hover {
text-decoration: none; text-decoration: none;
@ -30,17 +29,22 @@ body.ng-cloak
display: block; display: block;
} }
section > .jumbotron { /*Hero Section CSS (for /home)*/
padding-top: 15px; section.hero-section {
/*padding-top:30px;*/
width: 100%;
}
section.hero-section > .jumbotron {
background-image: url(http://yourplaceandmine.ie/wp-content/uploads/2014/09/Daingean-meeting-048_13-1080x675.jpg); background-image: url(http://yourplaceandmine.ie/wp-content/uploads/2014/09/Daingean-meeting-048_13-1080x675.jpg);
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: 50% 50%; background-position: 0 50%;
background-position-top: 0px;
background-size: cover; background-size: cover;
} }
section > .jumbotron > .opacity-background { section > .jumbotron > .opacity-background {
background-color: rgba(70,51,51,0.5); background-color: rgba(71,61,61,0.5);
height:inherit; color: white;
width:inherit; padding: inherit;
padding:inherit; height: inherit;
} }

View file

@ -1,7 +1,7 @@
<section data-ng-controller="HomeController"> <section data-ng-controller="HomeController" class="hero-section">
<div class="jumbotron text-center"> <div class="jumbotron text-center">
<div class="opacity-background jumbotron"> <div class="opacity-background">
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-12"> <div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-12">
<!-- <img alt="MEAN.JS" class="img-responsive text-center" src="modules/core/img/brand/logo.png" /> --> <!-- <img alt="MEAN.JS" class="img-responsive text-center" src="modules/core/img/brand/logo.png" /> -->

View file

@ -0,0 +1,56 @@
'use strict';
// submissions controller
angular.module('forms').controller('ViewSubmissionController', ['$scope', '$stateParams', '$state', 'Submissions','$http',
function($scope, $stateParams, $state, Submissions, $http) {
$scope.submissionId = undefined;
// Principal.identity().then(function(user){
// $scope.authentication.user = user;
// }).then(function(){
// Return all form's submissions
$scope.findAll = function() {
$scope.submissions = submissions.query({
formId: $stateParams.formId
});
};
// Find a specific submission
$scope.findOne = function() {
$scope.submission = submissions.get({
submissionId: $scope.submissionId,
formId: $stateParams.formId
});
};
// Remove existing submission
$scope.remove = function(submission) {
if (submission) {
submission.$remove();
$http.delete('/forms/'+$stateParams.formId+'submissions/'+$scope.submission._id).
success(function(data, status, headers){
console.log('submission deleted successfully');
alert('submission deleted..');
});
} else {
$scope.submission.$remove(function() {
console.log('remove');
$state.path('submissions');
$http.delete('/forms/'+$stateParams.formId+'/submissions/'+$scope.submission._id).
success(function(data, status, headers){
console.log('submission deleted successfully');
alert('submission deleted..');
});
});
}
};
// });
}
]);

View file

@ -35,7 +35,7 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
$state.go('listForms'); $state.go('listForms');
}); });
} else { } else{
$scope.form.$remove(function() { $scope.form.$remove(function() {
console.log('remove'); console.log('remove');
$state.path('forms'); $state.path('forms');

View file

@ -0,0 +1,22 @@
'use strict';
//Submissions service used for communicating with the forms REST endpoints
angular.module('forms').factory('Submissions', ['$resource',
function($resource) {
return $resource('forms/:formID/submissions/:submissionId', {
submissionId: '@_id',
formId: '@_id'
}, {
'query' : {
method: 'GET',
isArray: true,
},
'update': {
method: 'PUT'
},
'save': {
method: 'POST'
}
});
}
]);

View file

@ -1,37 +1,16 @@
<section data-ng-controller="ViewSubmissionsController" data-ng-init="findAll()"> <section data-ng-controller="ViewSubmissionController" data-ng-init="findAll()">
<div class="row"> <div class="page-header">
<div class="page-header col-xs-10 col-xs-offset-1"> <h1>{{form.title}} Submissions</h1>
<h1>{{submissions[0].form.title}} submissions</h1>
</div>
</div> </div>
<div class="row container"> <div class="list-group">
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row container create-new"> <a data-ng-repeat="submission in submissions" data-ng-href="#!/forms/{{form._id}}/admin" class="list-group-item">
<div class="title-row col-xs-12"> <small class="list-group-item-text">
<h4 class=" fa fa-plus fa-6"></h4> Created on
</div> <span data-ng-bind="submission.created | date:'mediumDate'"></span>
<div class="col-xs-12 details-row"> by
<span data-ng-bind="form.user.displayName"></span>
<small class="list-group-item-text"> </small>
Create a new form <h4 class="list-group-item-heading" data-ng-bind="submission.title"></h4>
</small>
</div>
</a>
<a data-ng-repeat="form in forms" data-ng-href="#!/forms/{{form._id}}/admin" class="col-xs-2 col-xs-offset-1 form-item row">
<div class="title-row col-xs-12">
<h4 class="list-group-item-heading" data-ng-bind="form.title"></h4>
</div>
<div class="col-xs-12 details-row">
<small class="list-group-item-text">
Created on
<span data-ng-bind="form.created | date:'mediumDate'"></span>
by
<span data-ng-bind="form.user.displayName"></span>
</small>
</div>
</a> </a>
</div> </div>

View file

@ -1,30 +1,30 @@
'use strict'; 'use strict';
// Config HTTP Error Handling // Config HTTP Error Handling
// angular.module('users').config(['$httpProvider', angular.module('users').config(['$httpProvider',
// function($httpProvider) { function($httpProvider) {
// // Set the httpProvider "not authorized" interceptor // Set the httpProvider "not authorized" interceptor
// $httpProvider.interceptors.push(['$q', '$state', 'Principal', $httpProvider.interceptors.push(['$q', '$state', 'Principal',
// function($q, $location, Principal) { function($q, $state, Principal) {
// return { return {
// responseError: function(rejection) { responseError: function(rejection) {
// switch (rejection.status) { switch (rejection.status) {
// case 401: case 401:
// // Deauthenticate the global user // Deauthenticate the global user
Principal.authenticate(null);
// // Redirect to signin page // Redirect to signin page
// $state.go('signin'); $state.go('signin');
// break; break;
// case 403: case 403:
// // Add unauthorized behaviour // Add unauthorized behaviour
// break; break;
// } }
// return $q.reject(rejection); return $q.reject(rejection);
// } }
// }; };
// } }
// ]); ]);
// } }
// ]); ]);

View file

@ -14,7 +14,7 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
$scope.askForPasswordReset = function() { $scope.askForPasswordReset = function() {
Principal.askForPasswordReset($scope.credentials).then( Principal.askForPasswordReset($scope.credentials).then(
function(response){ function(response){
$scope.success = response.message $scope.success = response.message;
$scope.credentials = null; $scope.credentials = null;
}, },
function(error){ function(error){
@ -26,13 +26,19 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
// Change user password // Change user password
$scope.resetUserPassword = function() { $scope.resetUserPassword = function() {
Principal.askForPasswordReset($scope.credentials).then( $scope.success = $scope.error = null;
Principal.resetPassword($scope.passwordDetails, $stateParams.token).then(
function(response){ function(response){
$scope.credentials = null; // If successful show success message and clear form
$scope.success = response.message;
$scope.passwordDetails = null;
// And redirect to the index page
$state.go('reset-success');
}, },
function(error){ function(error){
$scope.error = error; $scope.error = error.message || error;
$scope.credentials = null; $scope.passwordDetails = null;
} }
); );
// $scope.success = $scope.error = null; // $scope.success = $scope.error = null;

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$http', angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$http', '$state',
function($window, $q, $timeout, $http) { function($window, $q, $timeout, $http, $state) {
var service = { var service = {
_currentUser: null, _currentUser: null,
@ -75,17 +75,13 @@ angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$htt
return deferred.promise; return deferred.promise;
}, },
resetPassword: function(scope) { resetPassword: function(passwordDetails, token) {
var deferred = $q.defer(); var deferred = $q.defer();
$http.get('/auth/password'+_currentUser._id, scope.passwordDetails).success(function(response) { $http.get('/auth/password/'+token, passwordDetails).success(function(response) {
// If successful show success message and clear form
scope.passwordDetails = null;
// Attach user profile // Attach user profile
// Principal.user() = response; service.authenticate(response);
// And redirect to the index page
$state.go('reset-success');
deferred.resolve(); deferred.resolve();
}).error(function(error) { }).error(function(error) {
deferred.reject(error.message || error); deferred.reject(error.message || error);
@ -96,7 +92,7 @@ angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$htt
// Submit forgotten password account id // Submit forgotten password account id
askForPasswordReset: function(credentials) { askForPasswordReset: function(credentials) {
var deferred = $q.defer();
$http.post('/auth/forgot', credentials).success(function(response) { $http.post('/auth/forgot', credentials).success(function(response) {
// Show user success message and clear form // Show user success message and clear form