Skip to content

Commit

Permalink
implementation of q14 (custom file upload).
Browse files Browse the repository at this point in the history
WIP!
  • Loading branch information
speckij committed Mar 24, 2018
1 parent 8861034 commit 1c7c583
Show file tree
Hide file tree
Showing 30 changed files with 540 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ node_modules/*
ssl/*
public/bower_components/*
public/files/temp/*
public/files/custom/*
sql/schema/examples.sql
sql/schema/defaults.sql
*.env
*.log
*.DS_Store
.securestorage.json
.dejavuerc
.idea/*

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Version 1.4.1
- Added Email Notification to all Members when Review is started (and not pending anymore)
- Added q14 (Custom Files)

# Version 1.4.0
- Added Reminder Email to be sent out after 7 days of inactivity with still pending reviews.
Expand All @@ -12,3 +13,7 @@

# Version 1.0
- Initial App


# TODO
- q14 in email templates
3 changes: 2 additions & 1 deletion controllers/comments/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ exports.request = function(req, res) {
req.body.q11_1_comment,
req.body.q11_2_comment,
req.body.q12_comment,
req.body.q13_comment
req.body.q13_comment,
req.body.q14_comment
], function(err, result) {
done();
if (err) {
Expand Down
9 changes: 4 additions & 5 deletions controllers/concerns/upload_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,28 @@ exports.upload = function(req, res) {
var object = {
concern_id: req.params.concern_id,
q14_filename: req.file.originalname,
q14_filepath: req.file.path
q14_filepath: '/files/custom/' + req.headers['x-documentid'] + "/" + req.file.filename
};
var params = _.values(object);
callback(null, client, done, params);
},
function(client, done, params, callback){
console.log(req.file);
// Database query
client.query(query_add_file, params, function(err, result) {
done();
if (err) {
callback(err, 500);
} else {
callback(null, 200, result.rows[0]);
callback(null, 200, params[2], result.rows[0]);
}
});
}
], function(err, code, result) {
], function(err, code, destination, result) {
if(err){
console.error(colors.red(err));
res.status(code).send(err.message);
} else {
res.status(code).send(result);
res.status(code).send(destination);
}
});
};
8 changes: 6 additions & 2 deletions controllers/documents/change_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ exports.request = function(req, res) {
concern.q12_value,
concern.q12_explanation,
concern.q13_value,
concern.q13_explanation
concern.q13_explanation,
concern.q14_value,
concern.q14_explanation,
concern.q14_filename,
concern.q14_filepath
], function(err, result) {
done();
if (err) {
Expand Down Expand Up @@ -399,7 +403,7 @@ exports.request = function(req, res) {
html: output
}, function(err, info) {
if (err) {
callback(err);
callback(err, 500);
} else {
callback(null, 200, updated_document);
}
Expand Down
8 changes: 8 additions & 0 deletions controllers/documents/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,14 @@ exports.request = function(req, res) {
concern.q13_label = "badge-success";
concern.q13_sign = "no";
}

if(concern.q14_value){
concern.q14_label = "badge-danger";
concern.q14_sign = "yes";
} else {
concern.q14_label = "badge-success";
concern.q14_sign = "no";
}

// Notify each committee member
async.eachOfSeries(members, function (member, key, callback) {
Expand Down
6 changes: 1 addition & 5 deletions controllers/reviewers/put_by_revision.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,11 @@ exports.request = function(req, res) {
html: output,
}, function(err, info) {
if (err) {
callback(err);
callback(err ,500);
} else {
callback();
}
});
}, function(err){
if (err) {
callback(err, 500);
}
});
callback(null, client, done)
} else {
Expand Down
59 changes: 59 additions & 0 deletions migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var colors = require('colors');
var async = require('async');
var pg = require('pg');
var fs = require('fs');
var config = require('dotenv').config();


// DATABASE CONFIGURATION
var pool = new pg.Pool({
host: process.env.POSTGRES_HOST,
port: Number(process.env.POSTGRES_PORT),
database: process.env.POSTGRES_DB_NAME,
user: process.env.POSTGRES_USERNAME,
password: process.env.POSTGRES_PASSWORD,
ssl: JSON.parse(process.env.POSTGRES_SSL)
});
exports.pool = pool;

// Load files
var dir = "/sql/migration/";
var queries = [];


var query = fs.readFileSync(__dirname + dir + 'migrate_100_to_141.sql', 'utf8').toString();

// Start setup
async.waterfall([
function(callback) {
// Connect to database
pool.connect(function(err, client, done) {
if(err) {
callback(err);
} else {
callback(null, client, done);
}
});
},
function(client, done, callback) {
client.query(query, function(err, result) {
done();
if (err) {
callback(err);
} else {
console.log(colors.blue(query));
console.log(colors.green("Done!\n\n"));
callback(null);
}
});
}
], function(err){
// Close database connection
pool.end();

if(err) {
console.error(colors.red(err));
} else {
console.log(colors.green("Migration successfull!"));
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ app.controller("documentReviewController", function($scope, $rootScope, $routePa
$scope.authenticated_member = $authenticationService.get();
$scope.document = $documentService.get();
$scope.latest_revision = $documentService.getLatestRevision();

//TODO Add concerns to make filepath available in review.html

// Update navbar
$scope.$parent.document = $documentService.get();
Expand Down
37 changes: 37 additions & 0 deletions public/member-client/js/templates/document/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,43 @@ <h6>
</div>
</div>
</div>

<!-- 14th question -->
<div class="list-group-item">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 justified">
<b>14. {{ 'CONCERN_14' | translate }}?</b>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div ng-repeat="revision in document.revisions | orderBy: ['version']:true | limitTo: status.concerns.limit">
<div class="row" ng-style="!$last && {'padding-bottom':'2px', 'border-bottom':'1px dashed rgba(0, 0, 0, .125)'}">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<code>{{ 'REV' | translate}}{{revision.version}}</code>
</div>
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
<span class="badge badge-pill badge-danger " ng-if="revision.concerns.q14_value">
{{ 'YES' | translate }}
</span>
<span class="badge badge-pill badge-success " ng-if="!revision.concerns.q14_value">
{{ 'NO' | translate }}
</span>
&nbsp;&nbsp;<a ng-if="revision.concerns.q14_value" href="{{revision.concerns.q14_filepath}}" download="{{revision.concerns.q14_filename}}" target="_blank">
<i class="fa fa-file-pdf-o fa-1x text-danger" aria-hidden="true">{{ 'DOCUMENT' | translate}}</i>
</a>&nbsp;&nbsp;<i>{{revision.concerns.q14_explanation}}</i>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
<!-- devider -->
</div>
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" ng-if="status.concerns.comments">
<span class="comment" ng-if="revision.comments.q14_comment !== null && revision.comments.q14_comment !== ''">
<i class="fa fa-comment-o" aria-hidden="true"></i>&nbsp;&nbsp;{{revision.comments.q14_comment}}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Expand Down
53 changes: 53 additions & 0 deletions public/member-client/js/templates/document/review.html
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,59 @@ <h6>
</div>
</div>
</div>

<!-- 14th question -->
<div class="list-group-item">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4 justified">
<b>14. {{ 'CONCERN_14' | translate }}?</b>
</div>
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
<div ng-repeat="revision in document.revisions | orderBy: ['version']:true | limitTo: status.concerns.limit">
<div class="row" ng-style="!$last && {'padding-bottom':'2px', 'border-bottom':'1px dashed rgba(0, 0, 0, .125)'}">
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<code>{{ 'REV' | translate}}{{revision.version}}</code>
</div>
<div class="col-xs-9 col-sm-9 col-md-9 col-lg-9">
<span class="badge badge-pill badge-danger " ng-if="revision.concerns.q14_value">
{{ 'YES' | translate }}
</span>
<span class="badge badge-pill badge-success " ng-if="!revision.concerns.q14_value">
{{ 'NO' | translate }}
</span>
&nbsp;&nbsp;<a href="{{revision.concerns.q14_filepath}}" download="{{revision.concerns.q14_filename}}" ng-if="revision.concerns.q14_value" target="_blank">
<i class="fa fa-file-pdf-o fa-1x text-danger" aria-hidden="true">{{ 'DOCUMENT' | translate }}</i>
</a>
&nbsp;&nbsp;<i>{{revision.concerns.q14_explanation}}</i>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
<!-- divider -->
</div>
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" ng-if="!$first && status.concerns.comments">
<span class="comment" ng-if="revision.comments.q14_comment !== null && revision.comments.q14_comment !== ''">
<i class="fa fa-comment-o" aria-hidden="true"></i>&nbsp;&nbsp;{{revision.comments.q14_comment}}
</span>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" ng-if="$first">
<p>
<div class="input-group">
<textarea class="form-control"
rows="3"
ng-model="latest_revision.comments.q14_comment"
name="q14_comment"
id="q14_comment"
></textarea>
<span class="input-group-addon">
<span class="flag-icon flag-icon-gb"></span>
</span>
</div>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions public/translations/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ app.constant("en_US", {
AUTO_SAVING: 'Auto saving',
AUTO_SAVING_HINT: 'You don\'t need to submit your document now! Everytime when you click on the \'Next page\' buttons in the previous pages (\'Study description\' and \'Study concerns\') all your information has been automatically saved in the background. As soon as you enter this page (\'Submit\'), you can savely logout and come back later to continue your work.',
DOCUMENT_FILES: 'Download the associated Files',

CURRENTLY_ATTACHED_DOCUMENT: 'Currently the following document is provided: ',
DELETE_ATTACHED_DOCUMENT: 'Delete Document',

YES: 'yes',
NO: 'no',
Expand Down
3 changes: 3 additions & 0 deletions public/user-client/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ footer {
background-color: #f5f5f5;
}

.flexarea {
flex: 1 1 auto;
}

.left {
text-align: left;
Expand Down
25 changes: 20 additions & 5 deletions public/user-client/js/controllers/document/editController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ app.controller("documentEditController", function($scope, $rootScope, $filter, $
$scope.redirect = function(path){
$location.url(path);
};

/**
* [cancel description]
* @return {[type]} [description]
Expand All @@ -33,6 +33,14 @@ app.controller("documentEditController", function($scope, $rootScope, $filter, $
$scope.redirect("/documents/" + $documentService.getId() + "/status/" + $documentService.getStatus());
};

/**
* []
*/
$scope.resetFile = function(){
$scope.status = "fail";
$scope.latest_revision.concerns.q14_filename = null;
};

/**
* [upload file]
* @return {[type]} [file]
Expand All @@ -43,15 +51,18 @@ app.controller("documentEditController", function($scope, $rootScope, $filter, $
url: config.getUploadEndpoint() + $scope.latest_revision.concerns.concern_id,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + $authenticationService.getToken()
},
'Authorization': 'Bearer ' + $authenticationService.getToken(),
'X-DocumentId' : $documentService.getId()
},
data: {
filename: files[0], // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
}
}).then(
function (response) {
$scope.status = "success";
$scope.latest_revision.concerns.q14_file = true;
$scope.latest_revision.concerns.q14_filename = files[0].name;
$scope.latest_revision.concerns.q14_filepath = response.data;
},
function (response) {
$scope.status = "fail";
Expand Down Expand Up @@ -117,7 +128,7 @@ app.controller("documentEditController", function($scope, $rootScope, $filter, $
*/
$scope.submit = function() {
// Validate input
if($scope.editDocumentForm.$invalid) {
if($scope.editDocumentForm.$invalid || ($scope.status == "fail" && $scope.editDocumentForm.q14_value)) {
// Update UI

// Descriptions (en)
Expand Down Expand Up @@ -244,7 +255,11 @@ app.controller("documentEditController", function($scope, $rootScope, $filter, $
$scope.$parent.loading = { status: false, message: "" };
$scope.changeTab(1);
}


if ($scope.latest_revision.concerns.q14_filename !== null) {
$scope.status= 'success';
}

// Study description 8
$scope.startDate = moment().format("DD.MM.YYYY");
$scope.endDate = moment().add(14, 'days').format("DD.MM.YYYY");
Expand Down
Loading

0 comments on commit 1c7c583

Please sign in to comment.