Commit f46efde1 authored by Curtis Adam's avatar Curtis Adam

Merge branch 'staging' into 'master'

Staging

See merge request arsnova/flashcards!1733
parents 446c6ea5 70c8ad0d
......@@ -269,6 +269,9 @@
"help": {
"resetFilter": "Zeige die Hilfe für alle Seiten…"
},
"webPushNotifications": {
"content": "Kartei: __cardsetName__\nKarten: __cardCount__\nFrist: __deadline__"
},
"notifications": {
"title": "Nachrichten",
"clearAll": "Leeren",
......@@ -283,12 +286,7 @@
"reporteduseradmin": "Adminbenachrichtigung (Gemeldete/r Benutzer/in)",
"reportedcardsetadmin": "Adminbenachrichtigung (Gemeldete Kartei)",
"lecturer": "Dozenten-Anfrage",
"heading": "Aufgaben warten!",
"content": "Kartei: ",
"deadline": "\nFrist: ",
"warning": "\nNicht Bearbeiten der Aufgaben wird deine Lernstatistik zurücksetzen.",
"admin": "Du bist angemeldet als Admin!",
"cards": "\nKarten: "
"admin": "Du bist angemeldet als Admin!"
},
"input-group": {
"newcarddeck": "Neue Kartei"
......
......@@ -47,7 +47,7 @@ var initTestNotificationsCardset = function () {
"userDeleted": false,
"learningActive": false,
"maxCards": 0,
"daysBeforeReset": 0,
"daysBeforeReset": 30,
"learningStart": (new Date().setFullYear(2017, 9, 5)),
"learningEnd": (new Date().setFullYear(2038, 0, 19)),
"registrationPeriod": (new Date().setFullYear(2038, 0, 19)),
......
......@@ -20,9 +20,13 @@ export class Notifications {
/** Function returns the amount of cards that the user has to learn from the cardset
* @param {string} cardset_id - The id of the cardset from which to get the card count from
* @param {string} user_id - The id of the user
* @param {string} testUser - id of the test user if the function got called by a test notification
* @returns {number} - The amount of cards that the user has to learn from the cardset
* */
getActiveCardsCount (cardset_id, user_id) {
getActiveCardsCount (cardset_id, user_id, testUser = undefined) {
if (testUser !== undefined) {
user_id = testUser;
}
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
......
......@@ -15,23 +15,27 @@ function getDateString(date) {
export class WebNotifier {
/** Function returns the deadline text-message depending on if the deadline goes beyond the cardsets learning-phase
* @param {string} cardset_id - The id of the cardset
* @param {Object} cardset - The cardset object for the deadline
* @param {string} user_id - The id of the user
* @param {string} testUser - id of the test user if the function got called by a test notification
* @returns {string} - The deadline text-message
* */
getDeadline (cardset, user_id) {
getDeadline (cardset, user_id, testUser = undefined) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
var active = Leitner.findOne({cardset_id: cardset._id, user_id: user_id, active: true});
var deadline = new Date();
if (testUser !== undefined) {
user_id = testUser;
}
let active = Leitner.findOne({cardset_id: cardset._id, user_id: user_id, active: true});
let deadline = new Date();
if (active !== undefined) {
deadline = new Date(active.currentDate.getTime() + cardset.daysBeforeReset * 86400000);
}
if (deadline.getTime() > cardset.learningEnd.getTime()) {
return (TAPi18n.__('notifications.deadline', null, Meteor.settings.mail.language) + getDateString(cardset.learningEnd));
return getDateString(cardset.learningEnd);
} else {
return (TAPi18n.__('notifications.deadline', null, Meteor.settings.mail.language) + getDateString(deadline) + TAPi18n.__('notifications.warning', null, Meteor.settings.mail.language));
return getDateString(deadline);
}
}
}
......@@ -39,13 +43,14 @@ export class WebNotifier {
/** Function creates and sends the Web-Push payload message
* @param {Object} cardset - The cardset from the active learning-phase
* @param {string} user_id - The id of the user
* @param {string} testUser - id of the test user if the function got called by a test notification
* */
prepareWeb (cardset, user_id) {
prepareWeb (cardset, user_id, testUser = undefined) {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
var notifier = new Notifications();
var message = TAPi18n.__('notifications.content', null, Meteor.settings.mail.language) + cardset.name + TAPi18n.__('notifications.cards', null, Meteor.settings.mail.language) + notifier.getActiveCardsCount(cardset._id, user_id) + this.getDeadline(cardset, user_id);
let notifier = new Notifications();
let message = TAPi18n.__('webPushNotifications.content', {cardsetName: cardset.name, cardCount: notifier.getActiveCardsCount(cardset._id, user_id, testUser), deadline: this.getDeadline(cardset, user_id, testUser)}, Meteor.settings.mail.language);
Meteor.call("sendPushNotificationsToUser", user_id, message);
}
}
......@@ -59,6 +64,6 @@ Meteor.methods({
let web = new WebNotifier();
let settings = AdminSettings.findOne({name: "testNotifications"});
let cardset = Cardsets.findOne({_id: settings.testCardsetID});
web.prepareWeb(cardset, settings.target);
web.prepareWeb(cardset, settings.target, settings.testUserID);
}
});
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