Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions models/submition/Submition.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ SubmitionSchema.statics.findSubmitionsByUserData = function (data, callback) {
Submition.find({ $and: search_query }, (err, submitions) => {
if (err) return callback('database_error');

const filters = JSON.parse(data.filters)["filters"];
User.getUsersFromSubmitionsByFilters(submitions, filters, (err, _submitions)=>{
if (err && err != "missing filters") return callback(err);
if (!err) submitions = _submitions;

async.timesSeries(
submitions.length,
(time, next) => {
Expand All @@ -97,16 +102,16 @@ SubmitionSchema.statics.findSubmitionsByUserData = function (data, callback) {
if (submition.type == 'target') {
User.getUserById(submition.user_id, (err, user) => {
if (err) return next(err);

const data = {
no: time + 1,
// gender: user.gender,
// birth_year: user.birth_year
};

for (let i = 0; i < project.questions.length; i++)
data[project.questions[i].text] = submition.answers[project.questions[i]._id] ? submition.answers[project.questions[i]._id] : '';

return next(null, data);
});
} else {
Expand All @@ -123,7 +128,8 @@ SubmitionSchema.statics.findSubmitionsByUserData = function (data, callback) {
}
},
(err, submitions) => callback(err, submitions)
);
);
})
});
});
};
Expand Down
2 changes: 0 additions & 2 deletions models/user/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ UserSchema.statics.getUsersFromSubmitionsByFilters = function (_submitions, _fil
const User = this;
const submitions = [];

// console.log(_filters.age);

async.forEachOf(_submitions, (submition, key, callback) =>{
User.getUserById(submition.user_id, (err, user) =>{
if(err) callback();
Expand Down
38 changes: 25 additions & 13 deletions public/js/projects/report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function setQuery(){

if (q.type == 'yes_no'){
html_code += `<span class="summary-results-each-question-info-title">${Math.max(q.answers.yes, q.answers.no)}</span>`;
html_code += `<span class="summary-results-each-question-info-data">${question.answers.yes >= question.answers.no ? 'YES' : 'NO'}</span>`;
html_code += `<span class="summary-results-each-question-info-data">${q.answers.yes >= q.answers.no ? 'YES' : 'NO'}</span>`;
}

else if (q.type == 'multiple_choice'){
Expand Down Expand Up @@ -110,7 +110,7 @@ function setQuery(){
html_code += `<span class="each-question-details">${question.details}</span>`;

if (question.type == 'yes_no'){
html_code += '<div class="yes-no-wrapper"><div class="yes-content-wrapper><div class="yes-outer-wrapper>';
html_code += '<div class="yes-no-wrapper"><div class="yes-content-wrapper"><div class="yes-outer-wrapper">';
html_code += `<div class="yes-inner-wrapper" style="height: ${question.answers.yes}%; margin-top: ${question.answers.no}%"></div>`;
html_code += '<div class="yes-no-icon-outer-wrapper">';
html_code += '<div class="yes-icon-wrapper">';
Expand All @@ -137,7 +137,9 @@ function setQuery(){
else if (question.type == 'multiple_choice'){
html_code += `<span class="multiple-choice-answer-title">${question.data.total} answers</span>`;
html_code += '<div class="multiple-choice-answers-wrapper">';
for(key in Object.keys(question.answers)){
for(j in Object.keys(question.answers)){
j = parseInt(j);
const key = j+1;
html_code += '<div class="each-multiple-choice">';
html_code += `<span class="each-multiple-choice-text">${key}</span>`;
html_code += `<span class="each-multiple-choice-number">${question.answers[key]}</span>`;
Expand Down Expand Up @@ -168,22 +170,18 @@ function setQuery(){
html_code += `<span class="seablue">${question.data.median}</span></span>`;
html_code += '</div>';
html_code += '<div class="histogram-inner-wrapper">';
for(j in Object.keys(question.answers)){
j = parseInt(j);
const key = j+1;
for(key of Object.keys(question.answers)){
html_code += `<div class="histogram-each-column" style="height: ${question.answer_percentages[key]}%">`;
html_code += `<span class="histogram-each-column-text"> ${question.answers[key]}</span>`;
html_code += '</div>';
if (j < Object.keys(question.answers).length-1)
if (key < Object.keys(question.answers).length-1)
html_code += '<div class="histogram-column-seperator"></div>';
}
html_code += '</div>';
html_code += '<div class="histogram-inner-line-wrapper">';
for(j in Object.keys(question.answers)){
j = parseInt(j);
const key = j+1;
for(key of Object.keys(question.answers)){
html_code += `<div class="histogram-each-column-explanation">${key}</div>`;
if(j < Object.keys(question.answers).length-1)
if(key < Object.keys(question.answers).length-1)
html_code += '<div class="histogram-column-seperator"></div>';
}
html_code += '</div>';
Expand Down Expand Up @@ -279,9 +277,7 @@ window.onload = () => {
if(event.target.classList.contains('pdf-download')){

html2canvas(document.getElementsByClassName('questions-all-wrapper')[0]).then(function(canvas){
console.log(canvas);
var data = canvas.toDataURL();
console.log(data);
var docDefinition = {
content: [{
image: data,
Expand All @@ -292,6 +288,22 @@ window.onload = () => {
})
}

if(event.target.classList.contains('csv-download')){

const id = window.location.href.split('id=')[1].split('&')[0];
let data = {};

if(selected_filters.age.length != 0 || selected_filters.gender.length != 0){
data = {
filters: selected_filters
}
}

console.log(`/projects/report/csv?id=${id}&filters=${JSON.stringify(data)}`)

window.open(`/projects/report/csv?id=${id}&filters=${JSON.stringify(data)}`)
}

if (event.target.classList.contains('results-download-button-span')) {
if (isDownloadButtonOpen) {
isDownloadButtonOpen = false;
Expand Down
3 changes: 2 additions & 1 deletion views/projects/report/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ block main
.results-download-button
span.results-download-button-span Download Results
.download-options-wrapper
a.each-download-option(href="/projects/report/csv?id=" + project._id) .CSV
a.each-download-option.csv-download .CSV
//- (href="/projects/report/csv?id=" + project._id)
a.each-download-option.pdf-download .PDF
//-.filters-wrapper
.general-filter-button-wrapper
Expand Down