added submission view
This commit is contained in:
parent
0cd8fca8e6
commit
3843a93e4b
|
@ -1,120 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
errorHandler = require('./errors.server.controller'),
|
||||
Article = mongoose.model('Article'),
|
||||
_ = require('lodash');
|
||||
|
||||
/**
|
||||
* Create a article
|
||||
*/
|
||||
exports.create = function(req, res) {
|
||||
var article = new Article(req.body);
|
||||
article.user = req.user;
|
||||
|
||||
article.save(function(err) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(article);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the current article
|
||||
*/
|
||||
exports.read = function(req, res) {
|
||||
res.json(req.article);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a article
|
||||
*/
|
||||
exports.update = function(req, res) {
|
||||
var article = req.article;
|
||||
|
||||
article = _.extend(article, req.body);
|
||||
|
||||
article.save(function(err) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(article);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Delete an article
|
||||
*/
|
||||
exports.delete = function(req, res) {
|
||||
var article = req.article;
|
||||
|
||||
article.remove(function(err) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(article);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* List of Articles
|
||||
*/
|
||||
exports.list = function(req, res) {
|
||||
Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
res.json(articles);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Article middleware
|
||||
*/
|
||||
exports.articleByID = function(req, res, next, id) {
|
||||
|
||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||
return res.status(400).send({
|
||||
message: 'Article is invalid'
|
||||
});
|
||||
}
|
||||
|
||||
Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
|
||||
if (err) return next(err);
|
||||
if (!article) {
|
||||
return res.status(404).send({
|
||||
message: 'Article not found'
|
||||
});
|
||||
}
|
||||
req.article = article;
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Article authorization middleware
|
||||
*/
|
||||
exports.hasAuthorization = function(req, res, next) {
|
||||
if (req.article.user.id !== req.user.id) {
|
||||
return res.status(403).send({
|
||||
message: 'User is not authorized'
|
||||
});
|
||||
}
|
||||
next();
|
||||
};
|
|
@ -8,7 +8,6 @@ var mongoose = require('mongoose'),
|
|||
Form = mongoose.model('Form'),
|
||||
FormSubmission = mongoose.model('FormSubmission'),
|
||||
pdfFiller = require( 'pdffiller' ),
|
||||
PDFParser = require('pdf2json/pdfparser'),
|
||||
config = require('../../config/config'),
|
||||
fs = require('fs-extra'),
|
||||
async = require('async'),
|
||||
|
@ -23,14 +22,12 @@ exports.create = function(req, res) {
|
|||
form.admin = req.user;
|
||||
|
||||
form.save(function(err) {
|
||||
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
|
||||
return res.json(form);
|
||||
}
|
||||
});
|
||||
|
@ -39,11 +36,11 @@ exports.create = function(req, res) {
|
|||
/**
|
||||
* Upload PDF
|
||||
*/
|
||||
var upload_count = 0;
|
||||
exports.uploadPDF = function(files, user, cb) {
|
||||
var parser = new PDFParser();
|
||||
console.log("upload count: "+upload_count);
|
||||
upload_count++;
|
||||
var _user = JSON.parse(''+user);
|
||||
console.log(_user.username);
|
||||
console.log(config.tmpUploadPath);
|
||||
|
||||
if(files) {
|
||||
|
||||
console.log('inside uploadPDF');
|
||||
|
@ -57,7 +54,7 @@ exports.uploadPDF = function(files, user, cb) {
|
|||
//If file exists move to user's tmp directory
|
||||
if(exists) {
|
||||
|
||||
var newDestination = path.join(config.tmpUploadPath, user.username);
|
||||
var newDestination = path.join(config.tmpUploadPath, _user.username);
|
||||
var stat = null;
|
||||
try {
|
||||
stat = fs.statSync(newDestination);
|
||||
|
@ -66,7 +63,7 @@ exports.uploadPDF = function(files, user, cb) {
|
|||
}
|
||||
if (stat && !stat.isDirectory()) {
|
||||
console.log('Directory cannot be created');
|
||||
throw new Error('Directory cannot be created because an inode of a different type exists at "' + dest + '"');
|
||||
throw new Error('Directory cannot be created because an inode of a different type exists at "' + newDestination + '"');
|
||||
}
|
||||
|
||||
fs.move(pdfFile.path, path.join(newDestination, pdfFile.name), function (err) {
|
||||
|
@ -193,22 +190,25 @@ exports.delete = function(req, res) {
|
|||
});
|
||||
} else {
|
||||
return res.status(200);
|
||||
// res.json(form);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Get List of Template Forms
|
||||
* Get All of Users' Forms
|
||||
*/
|
||||
exports.list = function(req, res) {
|
||||
Form.find({ type: 'template' }).sort('-created').populate('admin').exec(function(err, forms) {
|
||||
//Allow 'admin' user to view all forms
|
||||
var searchObj = {admin: req.user};
|
||||
if(req.user.isAdmin()){
|
||||
searchObj = {};
|
||||
}
|
||||
Form.find({}).sort('-created').populate('admin').exec(function(err, forms) {
|
||||
if (err) {
|
||||
return res.status(400).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
console.log(forms);
|
||||
return res.json(forms);
|
||||
}
|
||||
});
|
||||
|
@ -251,13 +251,11 @@ exports.hasAuthorization = function(req, res, next) {
|
|||
|
||||
var form = req.form;
|
||||
|
||||
// console.log('\n\n\nreq.form:\n');
|
||||
// console.log(form);
|
||||
// console.log('req.user.id: '+req.user.id);
|
||||
|
||||
if (req.form.admin.id !== req.user.id) {
|
||||
// console.log(req.form.admin);
|
||||
// console.log(req.user);
|
||||
if (req.form.admin.id !== req.user.id || req.user.roles.indexOf('admin') === -1) {
|
||||
return res.status(403).send({
|
||||
message: 'User is not authorized'
|
||||
message: 'User '+req.user.username+' is not authorized'
|
||||
});
|
||||
}
|
||||
next();
|
||||
|
|
|
@ -23,7 +23,6 @@ exports.userByID = function(req, res, next, id) {
|
|||
* Require login routing middleware
|
||||
*/
|
||||
exports.requiresLogin = function(req, res, next) {
|
||||
|
||||
if (!req.isAuthenticated()) {
|
||||
return res.status(401).send({
|
||||
message: 'User is not logged in'
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema;
|
||||
|
||||
/**
|
||||
* Article Schema
|
||||
*/
|
||||
var ArticleSchema = new Schema({
|
||||
created: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
trim: true,
|
||||
required: 'Title cannot be blank'
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: '',
|
||||
trim: true
|
||||
},
|
||||
user: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User'
|
||||
}
|
||||
});
|
||||
|
||||
mongoose.model('Article', ArticleSchema);
|
|
@ -59,6 +59,10 @@ var FormSchema = new Schema({
|
|||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isLive: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
autofillPDFs: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
|
@ -109,6 +113,17 @@ FormSchema.pre('save', function (next) {
|
|||
}
|
||||
});
|
||||
|
||||
//Delete template PDF of current Form
|
||||
FormSchema.pre('remove', function (next) {
|
||||
if(this.pdf){
|
||||
//Delete template form
|
||||
fs.unlink(this.pdf.path, function(err){
|
||||
if (err) throw err;
|
||||
console.log('successfully deleted', this.pdf.path);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//Autogenerate FORM from PDF if 'isGenerated' flag is 'true'
|
||||
FormSchema.pre('save', function (next) {
|
||||
var field, _form_fields;
|
||||
|
|
|
@ -144,4 +144,16 @@ UserSchema.statics.findUniqueUsername = function(username, suffix, callback) {
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to check if user has Admin priviledges
|
||||
*/
|
||||
UserSchema.methods.isAdmin = function() {
|
||||
|
||||
if(this.roles.indexOf('admin') !== -1){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
mongoose.model('User', UserSchema);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var users = require('../../app/controllers/users.server.controller'),
|
||||
articles = require('../../app/controllers/articles.server.controller');
|
||||
|
||||
module.exports = function(app) {
|
||||
// Article Routes
|
||||
app.route('/articles')
|
||||
.get(articles.list)
|
||||
.post(users.requiresLogin, articles.create);
|
||||
|
||||
app.route('/articles/:articleId')
|
||||
.get(articles.read)
|
||||
.put(users.requiresLogin, articles.hasAuthorization, articles.update)
|
||||
.delete(users.requiresLogin, articles.hasAuthorization, articles.delete);
|
||||
|
||||
// Finish by binding the article middleware
|
||||
app.param('articleId', articles.articleByID);
|
||||
};
|
|
@ -106,10 +106,10 @@ module.exports = function(db) {
|
|||
console.log(file.originalname + ' is starting ...');
|
||||
},
|
||||
onFileUploadComplete: function (file, req, res) {
|
||||
console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||
// console.log(req.files.file[0]);
|
||||
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
||||
console.log(req.body.user);
|
||||
try{
|
||||
formCtrl.uploadPDF(req.files, function(_file){
|
||||
formCtrl.uploadPDF(req.files, req.body.user, function(_file){
|
||||
console.log(_file.filename + ' uploaded to ' + _file.path);
|
||||
res.status(200).send(_file);
|
||||
});
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
%FDF-1.2
|
||||
%âãÏÓ
|
||||
1 0 obj
|
||||
<<
|
||||
/FDF
|
||||
<<
|
||||
/Fields []
|
||||
>>
|
||||
>>
|
||||
endobj
|
||||
trailer
|
||||
|
||||
<<
|
||||
/Root 1 0 R
|
||||
>>
|
||||
%%EOF
|
|
@ -47,7 +47,8 @@
|
|||
"passport-local": "~1.0.0",
|
||||
"passport-twitter": "~1.0.2",
|
||||
"satelize": "^0.1.1",
|
||||
"swig": "~1.4.1"
|
||||
"swig": "~1.4.1",
|
||||
"then-fs": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"supertest": "~0.14.0",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
}
|
||||
|
||||
.content {
|
||||
margin-top: 100px;
|
||||
margin-top: 70px;
|
||||
}
|
||||
.undecorated-link:hover {
|
||||
text-decoration: none;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('forms').controller('EditFormController', ['$scope', '$rootScope', '$state', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
|
||||
angular.module('forms').controller('EditFormController', ['$scope', '$state', '$rootScope', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
|
||||
function ($scope, $state, $rootScope, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location) {
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
|
@ -80,7 +80,7 @@ angular.module('forms').controller('EditFormController', ['$scope', '$rootScope'
|
|||
};
|
||||
|
||||
$scope.goToWithId = function(route, id) {
|
||||
$state.transitionTo(route, { 'formId' : id }, { reload: true });
|
||||
$state.go(route, {'formId': id}, {reload: true});
|
||||
};
|
||||
|
||||
// Create new Form
|
||||
|
@ -100,7 +100,6 @@ angular.module('forms').controller('EditFormController', ['$scope', '$rootScope'
|
|||
|
||||
// Redirect after save
|
||||
$scope.goToWithId('viewForm', response._id);
|
||||
// $location.path('forms/' + response._id + '/admin');
|
||||
|
||||
}, function(errorResponse) {
|
||||
console.log(errorResponse.data.message);
|
||||
|
@ -117,8 +116,8 @@ angular.module('forms').controller('EditFormController', ['$scope', '$rootScope'
|
|||
var form = new Forms($scope.form);
|
||||
form.$update(function(response) {
|
||||
console.log('form updated');
|
||||
// console.log(response.pdf);
|
||||
$location.path('forms/' + response._id + '/admin');
|
||||
$scope.goToWithId('viewForm', response._id);
|
||||
// $location.path('forms/' + response._id + '/admin');
|
||||
}, function(errorResponse) {
|
||||
console.log(errorResponse.data.message);
|
||||
$scope.error = errorResponse.data.message;
|
||||
|
@ -131,7 +130,6 @@ angular.module('forms').controller('EditFormController', ['$scope', '$rootScope'
|
|||
$scope.addField.new = $scope.addField.types[0].name;
|
||||
$scope.addField.lastAddedID = 0;
|
||||
|
||||
|
||||
// preview form mode
|
||||
$scope.previewMode = false;
|
||||
|
||||
|
|
|
@ -4,10 +4,17 @@
|
|||
angular.module('forms').controller('ViewFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm','$http',
|
||||
function($scope, $stateParams, $state, Forms, CurrentForm, $http) {
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
// }).then(function(){
|
||||
// view form submissions
|
||||
$scope.viewSubmissions = false;
|
||||
|
||||
//show submissions of Form
|
||||
$scope.showSubmissions = function(){
|
||||
$scope.viewSubmissions = true;
|
||||
}
|
||||
//hide submissions of Form
|
||||
$scope.hideSubmissions = function(){
|
||||
$scope.viewSubmissions = false;
|
||||
}
|
||||
|
||||
// Return all user's Forms
|
||||
$scope.findAll = function() {
|
||||
|
@ -22,10 +29,10 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
|
|||
CurrentForm.setForm($scope.form);
|
||||
};
|
||||
|
||||
|
||||
// Remove existing Form
|
||||
$scope.remove = function(form) {
|
||||
if (form) {
|
||||
$scope.remove = function() {
|
||||
if (CurrentForm.getForm()) {
|
||||
var form = CurrentForm.getForm();
|
||||
form.$remove();
|
||||
|
||||
$http.delete('/forms/'+$scope.form._id).
|
||||
|
@ -37,8 +44,6 @@ angular.module('forms').controller('ViewFormController', ['$scope', '$stateParam
|
|||
|
||||
} else{
|
||||
$scope.form.$remove(function() {
|
||||
console.log('remove');
|
||||
$state.path('forms');
|
||||
$http.delete('/forms/'+$scope.form._id).
|
||||
success(function(data, status, headers){
|
||||
console.log('form deleted successfully');
|
||||
|
|
|
@ -1,21 +1,49 @@
|
|||
/* Styles for form list view (/forms) */
|
||||
/* Styles for form admin view (/forms/:formID/admin) */
|
||||
.admin-form > .page-header {
|
||||
padding-bottom: 0px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
.admin-form > .page-header h1 {
|
||||
margin-bottom: 0px
|
||||
}
|
||||
.admin-form > .page-header > .col-xs-3 {
|
||||
padding-top: 1.4em;
|
||||
}
|
||||
.admin-form .form-controls .row {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
|
||||
.status-light {
|
||||
padding-left:0.6em;
|
||||
}
|
||||
.status-light.status-light-off {
|
||||
color: red;
|
||||
}
|
||||
.status-light.status-light-on {
|
||||
color: green;
|
||||
}
|
||||
|
||||
/* Styles for form list view (/forms) */
|
||||
section > section.ng-scope {
|
||||
padding: 0 60px 20px 60px;
|
||||
}
|
||||
.form-item.row {
|
||||
text-align: center;
|
||||
border-bottom: 4px inset #ccc;
|
||||
border-bottom: 6px inset #ccc;
|
||||
background-color: #eee;
|
||||
width: 180px;
|
||||
height: 215px;
|
||||
margin-bottom: 45px;
|
||||
}
|
||||
|
||||
.form-item.row.create-new {
|
||||
border-bottom: 4px inset #ccc;
|
||||
background-color: rgb(131,131,131);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.form-item.row:hover, .form-item.row.create-new:hover {
|
||||
border-bottom: 6px inset #ccc;
|
||||
border-bottom: 8px inset #ccc;
|
||||
background-color: #d9d9d9;
|
||||
}
|
||||
|
||||
|
@ -24,7 +52,6 @@
|
|||
background-color: rgb(81,81,81);
|
||||
}
|
||||
|
||||
|
||||
.form-item.row > .title-row{
|
||||
position: relative;
|
||||
top: 15px;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
// Use Application configuration module to register a new module
|
||||
ApplicationConfiguration.registerModule('forms', ['ngFileUpload']);
|
||||
ApplicationConfiguration.registerModule('forms', ['ngFileUpload', 'users']);
|
|
@ -1,3 +1,5 @@
|
|||
<link rel="stylesheet" href="./modules/forms/css/form.css">
|
||||
|
||||
<section data-ng-controller="EditFormController">
|
||||
<div ng-if="isNewForm">
|
||||
<h1>Create your form</h1> <br>
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<h1>My MedForms</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row container">
|
||||
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row container create-new">
|
||||
<div class="row">
|
||||
<a data-ng-href="#!/forms/create" class="col-xs-2 col-xs-offset-1 form-item row create-new">
|
||||
<div class="title-row col-xs-12">
|
||||
<h4 class=" fa fa-plus fa-6"></h4>
|
||||
</div>
|
||||
|
@ -28,7 +28,7 @@
|
|||
Created on
|
||||
<span data-ng-bind="form.created | date:'mediumDate'"></span>
|
||||
by
|
||||
<span data-ng-bind="form.user.displayName"></span>
|
||||
<span data-ng-bind="form.admin.username"></span>
|
||||
</small>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,38 @@
|
|||
<section data-ng-controller="ViewSubmissionController" data-ng-init="findAll()">
|
||||
<div class="page-header">
|
||||
<h1>{{form.title}} Submissions</h1>
|
||||
<div class="page-header row" style="padding-bottom: 0px;">
|
||||
<div class="col-xs-9">
|
||||
<h1 data-ng-bind="form.title" style="margin-bottom: 0px;"></h1> <small>Submissions </small>
|
||||
</div>
|
||||
<div class="list-group">
|
||||
<div class="col-xs-3">
|
||||
<small class=" pull-right">
|
||||
<a class="btn btn-default" href="/#!/forms/{{form._id}}" disabled="form.isLive">
|
||||
View Live Form
|
||||
<i class="status-light status-light-on fa fa-dot-circle-o fa-3" ng-show="form.isLive"></i>
|
||||
<i class="status-light status-light-off fa fa-circle-o fa-3" ng-hide="form.isLive"></i>
|
||||
</a>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
||||
<table class="table table-striped col-xs-7">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th data-ng-repeat="(key, val) in submissions[0].form_fields">
|
||||
{{key}}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="submission in submissions">
|
||||
<td>{{$index+1}}</td>
|
||||
<td data-ng-repeat="(key, val) in submission.form_fields">
|
||||
{{value}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<a data-ng-repeat="submission in submissions" data-ng-href="#!/forms/{{form._id}}/admin" class="list-group-item">
|
||||
<small class="list-group-item-text">
|
||||
Created on
|
||||
|
|
|
@ -1,25 +1,74 @@
|
|||
<section data-ng-controller="ViewFormController" data-ng-init="findOne()">
|
||||
<div class="page-header">
|
||||
<h1 data-ng-bind="form.title"></h1>
|
||||
<section data-ng-controller="ViewFormController" data-ng-init="findOne()" class="container admin-form">
|
||||
<div class="page-header row" style="padding-bottom: 0px;">
|
||||
<div class="col-xs-9">
|
||||
<h1 data-ng-bind="form.title" style="margin-bottom: 0px;"></h1>
|
||||
</div>
|
||||
<div class="pull-right" data-ng-show="authentication.user._id == form.user._id">
|
||||
<a class="btn btn-primary" href="/#!/forms/{{form._id}}/edit">
|
||||
<i class="glyphicon glyphicon-edit"></i>
|
||||
<div class="col-xs-3">
|
||||
<small class=" pull-right">
|
||||
<a class="btn btn-default" href="/#!/forms/{{form._id}}">
|
||||
View <span ng-show="form.isLive">Live</span> <span ng-hide="form.isLive">Preview</span> Form
|
||||
<i class="status-light status-light-on fa fa-dot-circle-o" ng-show="form.isLive"></i>
|
||||
<i class="status-light status-light-off fa fa-circle-o" ng-hide="form.isLive"></i>
|
||||
<!-- <i class="fa fa-sign-out"></i> -->
|
||||
</a>
|
||||
<a class="btn btn-primary" data-ng-click="remove();">
|
||||
<i class="glyphicon glyphicon-trash"></i>
|
||||
</a>
|
||||
<a class="btn btn-primary" href="/#!/forms/{{form._id}}">
|
||||
View Public Form
|
||||
</a>
|
||||
<a class="btn btn-primary" href="/#!/forms/{{form._id}}/submissions">
|
||||
View Form Submissions
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-8" ng-if="!viewSubmissions">
|
||||
<p ng-show="form.form_fields.length == 0">No fields added yet.</p>
|
||||
<accordion class="col-xs-10" close-others="accordion.oneAtATime">
|
||||
<accordion-group heading="{{field.title}} (is a {{field.fieldType}})" ng-repeat="field in form.form_fields">
|
||||
</accordion-group>
|
||||
</accordion>
|
||||
</p>
|
||||
</div>
|
||||
<div class="submissions-table col-xs-8" ng-if="viewSubmissions">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th data-ng-repeat="(key, val) in submissions[0].form_fields">
|
||||
{{key}}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr data-ng-repeat="submission in submissions">
|
||||
<td>{{$index+1}}</td>
|
||||
<td data-ng-repeat="(key, val) in submission.form_fields">
|
||||
{{value}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-xs-3 col-xs-offset-1 container text-right form-controls" data-ng-show="authentication.user._id == form.user._id">
|
||||
<div class="row">
|
||||
<a class="col-xs-12 btn btn-default" href="/#!/forms/{{form._id}}/edit">
|
||||
<i class="glyphicon glyphicon-edit"></i> Edit Form
|
||||
</a>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span class="col-md-5" data-ng-bind="form"></span>
|
||||
<a class="col-xs-12 btn btn-danger" data-ng-click="remove();">
|
||||
<i class="glyphicon glyphicon-trash"></i> Delete Form
|
||||
</a>
|
||||
</div>
|
||||
<small>
|
||||
<div class="row">
|
||||
<a class="col-xs-12 btn btn-default" data-ng-click="showSubmissions();" ng-hide="viewSubmissions">
|
||||
View Form Submissions
|
||||
</a>
|
||||
<a class="col-xs-12 btn btn-primary" data-ng-click="hideSubmissions();" ng-show="viewSubmissions">
|
||||
Back to Main View
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<small class="col-xs-12">
|
||||
<em class="text-muted">
|
||||
Created on
|
||||
<span data-ng-bind="form.created | date:'mediumDate'"></span>
|
||||
|
@ -27,5 +76,6 @@
|
|||
<span data-ng-bind="form.admin.displayName"></span>
|
||||
</em>
|
||||
</small>
|
||||
</div>
|
||||
<!-- <p class="lead" data-ng-bind="form.content"></p> -->
|
||||
</section>
|
|
@ -19,26 +19,22 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
|||
Auth.login();
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
$scope = $rootScope;
|
||||
console.log('$state.previous: \n');
|
||||
console.log($state.previous);
|
||||
|
||||
if($state.previous !== 'home'){
|
||||
$state.go($state.previous);
|
||||
$state.go($state.previous.name);
|
||||
}else{
|
||||
$state.go('home');
|
||||
}
|
||||
|
||||
},
|
||||
function(error) {
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
$scope = $rootScope;
|
||||
|
||||
$scope.error = error;
|
||||
console.log('loginError: '+error);
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
$scope = $rootScope;
|
||||
// if(!$scope.loginError){
|
||||
// Auth.currentUser = rootScope.loginResult.user;
|
||||
// console.log(Auth.currentUser );
|
||||
// }
|
||||
|
||||
// Auth.currentUser = $rootScope.loginResult.user;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
@ -7,36 +7,36 @@ angular.module('users')
|
|||
isLoggedIn: false
|
||||
};
|
||||
|
||||
return {
|
||||
var service = {
|
||||
currentUser: null,
|
||||
|
||||
// Note: we can't make the User a dependency of Auth
|
||||
// because that would create a circular dependency
|
||||
// Auth <- $http <- $resource <- LoopBackResource <- User <- Auth
|
||||
ensureHasCurrentUser: function(User) {
|
||||
if (this.currentUser && this.currentUser.displayName) {
|
||||
if (service.currentUser && service.currentUser.displayName) {
|
||||
console.log('Using local current user.');
|
||||
console.log(this.currentUser);
|
||||
return this.currentUser;
|
||||
console.log(service.currentUser);
|
||||
return service.currentUser;
|
||||
}
|
||||
else if ($window.user){
|
||||
console.log('Using cached current user.');
|
||||
console.log($window.user);
|
||||
this.currentUser = $window.user;
|
||||
return this.currentUser;
|
||||
service.currentUser = $window.user;
|
||||
return service.currentUser;
|
||||
}
|
||||
else{
|
||||
console.log('Fetching current user from the server.');
|
||||
User.getCurrent().then(function(user) {
|
||||
// success
|
||||
this.currentUser = user;
|
||||
service.currentUser = user;
|
||||
userState.isLoggedIn = true;
|
||||
$window.user = this.currentUser;
|
||||
return this.currentUser;
|
||||
$window.user = service.currentUser;
|
||||
return service.currentUser;
|
||||
},
|
||||
function(response) {
|
||||
userState.isLoggedIn = false;
|
||||
this.currentUser = null;
|
||||
service.currentUser = null;
|
||||
$window.user = null;
|
||||
console.log('User.getCurrent() err', response);
|
||||
return null;
|
||||
|
@ -45,7 +45,7 @@ angular.module('users')
|
|||
},
|
||||
|
||||
isAuthenticated: function() {
|
||||
return !!this.currentUser;
|
||||
return !!service.currentUser;
|
||||
},
|
||||
|
||||
getUserState: function() {
|
||||
|
@ -59,8 +59,9 @@ angular.module('users')
|
|||
logout: function() {
|
||||
$window.user = null;
|
||||
userState.isLoggedIn = false;
|
||||
this.currentUser = null;
|
||||
this.ensureHasCurrentUser(null);
|
||||
service.currentUser = null;
|
||||
service.ensureHasCurrentUser(null);
|
||||
},
|
||||
};
|
||||
return service;
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<label for="currentPassword">Current Password</label>
|
||||
<input type="password" id="currentPassword" name="currentPassword" class="form-control" data-ng-model="passwordDetails.currentPassword" placeholder="Current Password">
|
||||
</div>
|
||||
<hr>
|
||||
<div class="form-group">
|
||||
<label for="newPassword">New Password</label>
|
||||
<input type="password" id="newPassword" name="newPassword" class="form-control" data-ng-model="passwordDetails.newPassword" placeholder="New Password">
|
||||
|
|
|
@ -3,6 +3,13 @@
|
|||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form name="userForm" data-ng-submit="updateUserProfile(userForm.$valid)" class="signin form-horizontal" autocomplete="off">
|
||||
<fieldset>
|
||||
<div data-ng-show="success" class="text-center text-success">
|
||||
<strong>Profile Saved Successfully</strong>
|
||||
</div>
|
||||
<div data-ng-show="error" class="text-center text-danger">
|
||||
Couldn't Save your Profile.<br>
|
||||
Error: <strong data-ng-bind="error"></strong>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="firstName">First Name</label>
|
||||
<input type="text" id="firstName" name="firstName" class="form-control" data-ng-model="user.firstName" placeholder="First Name">
|
||||
|
@ -15,19 +22,10 @@
|
|||
<label for="email">Email</label>
|
||||
<input type="email" id="email" name="email" class="form-control" data-ng-model="user.email" placeholder="Email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" class="form-control" data-ng-model="user.username" placeholder="Username">
|
||||
</div>
|
||||
<div class="text-center form-group">
|
||||
<button type="submit" class="btn btn-large btn-primary">Save Profile</button>
|
||||
</div>
|
||||
<div data-ng-show="success" class="text-center text-success">
|
||||
<strong>Profile Saved Successfully</strong>
|
||||
</div>
|
||||
<div data-ng-show="error" class="text-center text-danger">
|
||||
<strong data-ng-bind="error"></strong>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue