Commit a704a185 authored by Curtis Adam's avatar Curtis Adam

Add csv export support for cardset transcript statistics

parent b330b115
......@@ -737,7 +737,9 @@
"pending": "Noch nicht bewertet",
"accepted": "Akzeptiert",
"denied": "Abgelehnt",
"bonus": "Erhaltene Bonuspunkte"
"bonus": "Erhaltene Bonuspunkte",
"export": "Statistik exportieren",
"exportName": "Mitschriften_Statistik"
}
}
},
......
......@@ -739,7 +739,9 @@
"pending": "Noch nicht bewertet",
"accepted": "Akzeptiert",
"denied": "Abgelehnt",
"bonus": "Erhaltene Bonuspunkte"
"bonus": "Erhaltene Bonuspunkte",
"export": "Statistik exportieren",
"exportName": "Mitschriften_Statistik"
}
}
},
......
......@@ -62,56 +62,6 @@ const TranscriptBonusSchema = new SimpleSchema({
TranscriptBonus.attachSchema(TranscriptBonusSchema);
Meteor.methods({
addTranscriptBonus: function (card_id, cardset_id, user_id, date_id) {
if (Meteor.isServer) {
check(card_id, String);
check(user_id, String);
check(cardset_id, String);
check(date_id, Number);
let cardset = Cardsets.findOne({_id: cardset_id});
if (cardset !== undefined) {
TranscriptBonus.upsert({card_id: card_id}, {
$set: {
cardset_id: cardset._id,
card_id: card_id,
user_id: user_id,
date: cardset.transcriptBonus.dates[date_id],
lectureEnd: cardset.transcriptBonus.lectureEnd,
deadline: cardset.transcriptBonus.deadline,
deadlineEditing: cardset.transcriptBonus.deadlineEditing,
dateCreated: new Date(),
rating: 0
}
});
}
Meteor.call('updateTranscriptBonusStats', cardset._id);
}
},
updateTranscriptBonusStats: function (cardset_id) {
if (Meteor.isServer) {
check(cardset_id, String);
let cardset = Cardsets.findOne({_id: cardset_id});
if (cardset !== undefined && cardset.transcriptBonus !== undefined) {
let bonusTranscripts = TranscriptBonus.find({cardset_id: cardset._id}).fetch();
let submissions = TranscriptBonus.find({cardset_id: cardset._id}).count();
let userFilter = [];
for (let i = 0; i < bonusTranscripts.length; i++) {
userFilter.push(bonusTranscripts[i].user_id);
}
let participants = Meteor.users.find({_id: {$in: userFilter}}).count();
Cardsets.update({_id: cardset._id}, {
$set: {
'transcriptBonus.stats.submissions': submissions,
'transcriptBonus.stats.participants': participants
}
});
}
}
}
});
export let TranscriptBonusList = class TranscriptBonusList {
static addLectureEndTime (transcriptBonus, date) {
let hours = Number(transcriptBonus.lectureEnd.substring(0, 2));
......@@ -250,3 +200,90 @@ export let TranscriptBonusList = class TranscriptBonusList {
}
}
};
Meteor.methods({
addTranscriptBonus: function (card_id, cardset_id, user_id, date_id) {
if (Meteor.isServer) {
check(card_id, String);
check(user_id, String);
check(cardset_id, String);
check(date_id, Number);
let cardset = Cardsets.findOne({_id: cardset_id});
if (cardset !== undefined) {
TranscriptBonus.upsert({card_id: card_id}, {
$set: {
cardset_id: cardset._id,
card_id: card_id,
user_id: user_id,
date: cardset.transcriptBonus.dates[date_id],
lectureEnd: cardset.transcriptBonus.lectureEnd,
deadline: cardset.transcriptBonus.deadline,
deadlineEditing: cardset.transcriptBonus.deadlineEditing,
dateCreated: new Date(),
rating: 0
}
});
}
Meteor.call('updateTranscriptBonusStats', cardset._id);
}
},
updateTranscriptBonusStats: function (cardset_id) {
if (Meteor.isServer) {
check(cardset_id, String);
let cardset = Cardsets.findOne({_id: cardset_id});
if (cardset !== undefined && cardset.transcriptBonus !== undefined) {
let bonusTranscripts = TranscriptBonus.find({cardset_id: cardset._id}).fetch();
let submissions = TranscriptBonus.find({cardset_id: cardset._id}).count();
let userFilter = [];
for (let i = 0; i < bonusTranscripts.length; i++) {
userFilter.push(bonusTranscripts[i].user_id);
}
let participants = Meteor.users.find({_id: {$in: userFilter}}).count();
Cardsets.update({_id: cardset._id}, {
$set: {
'transcriptBonus.stats.submissions': submissions,
'transcriptBonus.stats.participants': participants
}
});
}
}
},
getTranscriptCSVExport: function (cardset_id, header) {
check(cardset_id, String);
check(header, [String]);
let cardset = Cardsets.findOne({_id: cardset_id});
if (UserPermissions.gotBackendAccess() || (UserPermissions.isOwner(cardset.owner) || cardset.editors.includes(Meteor.userId()))) {
let content;
let colSep = ";"; // Separates columns
let newLine = "\r\n"; //Adds a new line
content = "";
for (let i = 0; i < header.length; i++) {
content += header[i] + colSep;
}
content += newLine;
let transcriptUsers = _.uniq(TranscriptBonus.find({cardset_id: cardset_id}, {
fields: {user_id: 1}
}).fetch().map(function (x) {
return x.user_id;
}), true);
let users = Meteor.users.find({_id: {$in: transcriptUsers}}, {
sort: {'profile.birthname': 1, 'profile.givenname': 1}, fields: {_id: 1, email: 1, profile: 1}
}).fetch();
for (let i = 0; i < users.length; i++) {
content += users[i].profile.birthname + colSep;
content += users[i].profile.givenname + colSep;
content += users[i].email + colSep;
content += TranscriptBonusList.getSubmissions(cardset_id, users[i]._id, undefined) + colSep;
content += TranscriptBonusList.getSubmissions(cardset_id, users[i]._id, 0) + colSep;
content += TranscriptBonusList.getSubmissions(cardset_id, users[i]._id, 1) + colSep;
content += TranscriptBonusList.getSubmissions(cardset_id, users[i]._id, 2) + colSep;
content += TranscriptBonusList.getAchievedBonus(cardset_id, users[i]._id) + " %" + colSep;
content += newLine;
}
return content;
}
}
});
import {Session} from "meteor/session";
import {Cardsets} from "./cardsets";
import {CardType} from "./cardTypes";
import {ServerStyle} from "./styles";
export let Utilities = class Utilities {
static getCalendarString (type = '', minutes = '', displayAsDeadline = false) {
let today = '[Today]';
let yesterday = '[Yesterday]';
let tomorrow = '[Tomorrow]';
if (Session.get('activeLanguage') === 'de') {
let language;
if (Meteor.isServer) {
language = ServerStyle.getServerLanguage();
} else {
language = Session.get('activeLanguage');
}
if (language === 'de') {
if (minutes !== '') {
if (displayAsDeadline) {
minutes = '[ bis ]' + minutes + '[ Uhr ]';
......@@ -46,9 +53,15 @@ export let Utilities = class Utilities {
dateFormat = "D. MMM YY " + minutes;
minutes = "H:mm";
}
let language;
if (Meteor.isServer) {
language = ServerStyle.getServerLanguage();
} else {
language = Session.get('activeLanguage');
}
if (!transformToSpeech) {
dateFormat = "DD";
return moment(date).locale(Session.get('activeLanguage')).calendar(null, {
return moment(date).locale(language).calendar(null, {
sameDay: dateFormat,
lastDay: dateFormat,
nextDay: dateFormat,
......@@ -58,7 +71,7 @@ export let Utilities = class Utilities {
});
}
if (displayAsDeadline) {
return moment(date).locale(Session.get('activeLanguage')).calendar(null, {
return moment(date).locale(language).calendar(null, {
sameDay: this.getCalendarString("today", minutes, displayAsDeadline),
lastDay: this.getCalendarString("yesterday", minutes, displayAsDeadline),
nextDay: this.getCalendarString("nextDay", minutes, displayAsDeadline),
......@@ -67,7 +80,7 @@ export let Utilities = class Utilities {
sameElse: this.getCalendarString(dateFormat, minutes, displayAsDeadline)
});
} else {
return moment(date).locale(Session.get('activeLanguage')).calendar(null, {
return moment(date).locale(language).calendar(null, {
sameDay: this.getCalendarString("today", minutes),
lastDay: this.getCalendarString("yesterday", minutes),
nextDay: this.getCalendarString("nextDay", minutes),
......@@ -83,7 +96,13 @@ export let Utilities = class Utilities {
}
static getMomentsDateShort (date) {
return moment(date).locale(Session.get('activeLanguage')).calendar(null, {
let language;
if (Meteor.isServer) {
language = ServerStyle.getServerLanguage();
} else {
language = Session.get('activeLanguage');
}
return moment(date).locale(language).calendar(null, {
sameDay: this.getCalendarString("today"),
lastDay: this.getCalendarString("yesterday"),
nextWeek: 'D.MMM YY',
......
......@@ -6,14 +6,19 @@
<h4>{{this.name}}</h4>
<hr>
<div class="row">
<span class="col-sm-6 collapseCardsetInfoContainer">
{{> cardsetInfoBox}}
</span>
<span class="col-sm-6 collapseCardsetInfoContainer">
{{> cardsetInfoBox}}
</span>
<span class="col-sm-6 collapseCardsetInfoContainer">
{{> bonusTranscriptInfoBox}}
</span>
</div>
</div>
<div class="panel-footer">
<button id="exportCSV" class="btn btn-success btn-raised"><span class="flex-content"><i class="fas fa-clipboard-list"></i>&nbsp;<i
class="fas fa-cloud-download-alt"></i>&nbsp;{{_
"transcriptForm.bonus.statistics.export"}}</span></button>
</div>
</div>
</div>
</template>
import "./cardset.html";
import {Cardsets} from "../../../../../../api/cardsets";
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
/*
* ############################################################################
* cardsetIndexTranscriptStatisticsItemCardset
* ############################################################################
*/
Template.cardsetIndexTranscriptStatisticsItemCardset.events({
'click #exportCSV': function () {
var cardset = Cardsets.findOne({_id: Router.current().params._id});
var hiddenElement = document.createElement('a');
var header = [];
header[0] = TAPi18n.__('box_export_birth_name');
header[1] = TAPi18n.__('box_export_given_name');
header[2] = TAPi18n.__('box_export_mail');
header[3] = TAPi18n.__('transcriptForm.info.submissions');
header[4] = TAPi18n.__('transcriptForm.bonus.statistics.pending');
header[5] = TAPi18n.__('transcriptForm.bonus.statistics.accepted');
header[6] = TAPi18n.__('transcriptForm.bonus.statistics.denied');
header[7] = TAPi18n.__('transcriptForm.bonus.statistics.bonus');
Meteor.call("getTranscriptCSVExport", cardset._id, header, function (error, result) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error could not receive content for .csv');
}
if (result) {
let statistics = TAPi18n.__('transcriptForm.bonus.statistics.exportName');
hiddenElement.href = 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(result);
hiddenElement.target = '_blank';
let str = (cardset.name + "_" + statistics + "_" + moment(new Date()).locale(Session.get('activeLanguage')).format("D_MMMM_YYYY") + ".csv");
hiddenElement.download = str.replace(/ /g, "_").replace(/:/g, "_");
document.body.appendChild(hiddenElement);
hiddenElement.click();
}
});
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment