GitLab steht Mittwoch, den 08. Juli, zwischen 09:00 und 13:00 Uhr aufgrund von Wartungsarbeiten nicht zur Verfügung.

Commit b7937d7e authored by Curtis Adam's avatar Curtis Adam Committed by Tom Käsler

Update the cardset navigation for users which are in a bonus

parent b4439da7
......@@ -16,11 +16,15 @@ export let Bonus = class Bonus {
}
static canJoinBonus (cardset_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, registrationPeriod: 1, owner: 1}});
if (Roles.userIsInRole(Meteor.userId(), ['firstLogin', 'blocked']) || cardset.owner === Meteor.userId()) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, registrationPeriod: 1, owner: 1, kind: 1}});
if (Roles.userIsInRole(Meteor.userId(), ['firstLogin', 'blocked'])) {
return false;
}
if (Roles.userIsInRole(Meteor.userId(), ['admin', 'editor', 'lecturer', 'university', 'pro'])) {
let roles = ['admin', 'editor', 'lecturer', 'university', 'pro'];
if (cardset.kind === "free") {
roles.push('standard');
}
if (Roles.userIsInRole(Meteor.userId(), roles)) {
return !this.isInBonus(cardset._id) && moment(cardset.registrationPeriod).endOf('day') > new Date();
} else {
return false;
......
......@@ -32,6 +32,14 @@ Template.registerHelper('getLastAppTitle', function () {
return Meteor.settings.public.welcome.title.last;
});
Template.registerHelper('isInBonus', function () {
return Bonus.isInBonus(Router.current().params._id, Meteor.userId());
});
Template.registerHelper('isInBonusAndNotOwner', function () {
return Bonus.isInBonus(Router.current().params._id) && (!UserPermissions.isOwner(Cardsets.findOne({_id: Router.current().params._id}).owner) && !UserPermissions.isAdmin());
});
Template.registerHelper('extendContext', function (key, value) {
let result = _.clone(this);
result[key] = value;
......
......@@ -47,7 +47,7 @@
{{selectedForLearning}}
{{/unless}}
{{#if isActiveRoute regex='cardsetdetailsid|cardsetcard'}}
{{#unless isInBonus}}
{{#unless isInBonusAndNotOwner}}
{{#if this.quantity}}
<div class="hidden-xs col-xs-12">
{{> cardNavigation}}
......
<template name="cardsetNavigationDeleteAllCards">
{{#unless isInBonus}}
{{#unless isShuffledCardset this._id}}
{{#if this.quantity}}
{{#if isCardsetOwner _id}}
<div class="hidden-xs btn-group">
<button id="delete_cards" class="btn btn-sm btn-raised deleteAllCardsBtn"
data-toggle="modal"
data-target="#deleteCardsModal" {{disableIfOffline}}>
<i class="fa fa-trash"></i> {{_ "deleteCards"}}
</button>
</div>
{{/if}}
{{#unless isShuffledCardset this._id}}
{{#if this.quantity}}
{{#if isCardsetOwner _id}}
<div class="hidden-xs btn-group">
<button id="delete_cards" class="btn btn-sm btn-raised deleteAllCardsBtn"
data-toggle="modal"
data-target="#deleteCardsModal" {{disableIfOffline}}>
<i class="fa fa-trash"></i> {{_ "deleteCards"}}
</button>
</div>
{{/if}}
{{/unless}}
{{/if}}
{{/unless}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import "../modal/deleteAllCards.js";
import "./deleteAllCards.html";
/*
* ############################################################################
* cardsetNavigationExport
* ############################################################################
*/
Template.cardsetNavigationDeleteAllCards.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
<template name="cardsetNavigationExport">
{{#unless isInBonus}}
{{#unless isShuffledCardset this._id}}
{{#if this.quantity}}
{{#if isCardsetOwner _id}}
<div class="hidden-xs btn-group">
<button id="exportCardsBtn" class="btn btn-sm btn-raised exportCardsBtn"><i
class="fa fa-cloud-download"></i> {{_ "sidebar-nav.exportcard"}}
</button>
</div>
{{/if}}
{{#unless isShuffledCardset this._id}}
{{#if this.quantity}}
{{#if isCardsetOwner _id}}
<div class="hidden-xs btn-group">
<button id="exportCardsBtn" class="btn btn-sm btn-raised exportCardsBtn"><i
class="fa fa-cloud-download"></i> {{_ "sidebar-nav.exportcard"}}
</button>
</div>
{{/if}}
{{/unless}}
{{/if}}
{{/unless}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import {BertAlertVisuals} from "../../../../api/bertAlertVisuals";
import "./export.html";
......@@ -12,12 +10,6 @@ import "./export.html";
* ############################################################################
*/
Template.cardsetNavigationExport.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
Template.cardsetNavigationExport.events({
'click #exportCardsBtn': function () {
let name = this.name;
......
<template name="cardsetNavigationImport">
{{#unless isInBonus}}
{{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group">
<a href="#" id="importCardsBtn" class="btn btn-sm btn-raised importCardBtn"
data-toggle="modal"
data-target="#importModal"><i
class="fa fa-cloud-upload"></i> {{_ "sidebar-nav.importcard"}}</a>
</div>
{{/unless}}
{{/if}}
{{/unless}}
{{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group">
<a href="#" id="importCardsBtn" class="btn btn-sm btn-raised importCardBtn"
data-toggle="modal"
data-target="#importModal"><i
class="fa fa-cloud-upload"></i> {{_ "sidebar-nav.importcard"}}</a>
</div>
{{/unless}}
{{/if}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import "../modal/import.js";
import "./import.html";
......@@ -12,12 +10,6 @@ import "./import.html";
* ############################################################################
*/
Template.cardsetNavigationImport.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
Template.cardsetNavigationImport.events({
'click #importCardsBtn': function () {
Session.set('importType', 1);
......
<template name="cardsetNavigationLearning">
{{#if isInBonus}}
{{#if notEmpty}}
<button id="learnBoxActive"
class="btn btn-sm btn-raised btn-success learn btn-learn">{{_
"cardsToLearn"}}</button>
{{/if}}
{{#if notEmpty}}
<button id="learnBoxActive"
class="btn btn-sm btn-raised btn-success learn btn-learn"><i class="fa fa-graduation-cap"></i> {{_
"cardsToLearn"}}</button>
{{/if}}
</template>
......@@ -6,7 +6,6 @@ import {Leitner} from "../../../../api/learned";
import {Cardsets} from "../../../../api/cardsets";
import {CardsetNavigation} from "../../../../api/cardsetNavigation";
import {BertAlertVisuals} from "../../../../api/bertAlertVisuals";
import {Bonus} from "../../../../api/bonus";
import "./learning.html";
/*
......@@ -18,13 +17,10 @@ import "./learning.html";
Template.cardsetNavigationLearning.helpers({
notEmpty: function () {
return Leitner.find({
cardset_id: this._id,
cardset_id: Router.current().params._id,
user_id: Meteor.userId(),
active: true
}).count();
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
......@@ -37,82 +33,77 @@ Template.cardsetNavigationLearning.events({
});
Template.cardsetNavigationLearning.onCreated(function () {
if (!Roles.userIsInRole(Meteor.userId(), ["admin", "editor"])) {
if (Session.get('activeCardset').owner !== Meteor.userId() && !Session.get('activeCardset').editors.includes(Meteor.userId())) {
CardsetNavigation.addToLeitner(Session.get('activeCardset')._id);
}
}
CardsetNavigation.addToLeitner(Session.get('activeCardset')._id);
});
Template.cardsetNavigationLearning.onRendered(function () {
if (!Roles.userIsInRole(Meteor.userId(), ["admin", "editor"])) {
if (Meteor.userId() !== Session.get('activeCardset').owner && !Session.get('activeCardset').editors.includes(Meteor.userId())) {
setTimeout(function () {
Bert.defaults.hideDelay = 97200;
let bertType = "success";
if (Session.get('activeCardset').registrationPeriod.getTime() < new Date()) {
if (Leitner.findOne({cardset_id: Session.get('activeCardset')._id, user_id: Meteor.userId()}, {fields: {_id: 1}}) === undefined) {
bertType = "warning";
BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.registrationPeriodExpired'), bertType, 'growl-top-left');
return;
}
setTimeout(function () {
Bert.defaults.hideDelay = 97200;
let bertType = "success";
if (Session.get('activeCardset').registrationPeriod.getTime() < new Date()) {
if (Leitner.findOne({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId()
}, {fields: {_id: 1}}) === undefined) {
bertType = "warning";
BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.registrationPeriodExpired'), bertType, 'growl-top-left');
return;
}
}
if (Session.get('activeCardset').learningEnd.getTime() > new Date().getTime()) {
let text = "";
if (Leitner.find({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId(),
active: true
}).count()) {
var active = Leitner.findOne({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId(),
active: true
});
var deadline = new Date(active.currentDate.getTime() + Session.get('activeCardset').daysBeforeReset * 86400000);
if (deadline.getTime() > Session.get('activeCardset').learningEnd.getTime()) {
text += (TAPi18n.__('deadlinePrologue') + moment(Session.get('activeCardset').learningEnd).format("DD.MM.YYYY") + TAPi18n.__('deadlineEpilogue1'));
} else {
text += (TAPi18n.__('deadlinePrologue') + moment(deadline).format("DD.MM.YYYY") + TAPi18n.__('deadlineEpilogue2'));
}
if (Session.get('activeCardset').learningEnd.getTime() > new Date().getTime()) {
let text = "";
if (Leitner.find({
cardset_id: Session.get('activeCardset')._id,
bertType = "warning";
} else {
if (Leitner.find({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId(),
box: {$ne: 6}
}).count() === 0) {
text += TAPi18n.__('bonus.message.learnedEverything');
} else {
let nextCardDate = Leitner.findOne({
cardset_id: Router.current().params._id,
user_id: Meteor.userId(),
active: true
}).count()) {
var active = Leitner.findOne({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId(),
active: true
});
var deadline = new Date(active.currentDate.getTime() + Session.get('activeCardset').daysBeforeReset * 86400000);
if (deadline.getTime() > Session.get('activeCardset').learningEnd.getTime()) {
text += (TAPi18n.__('deadlinePrologue') + moment(Session.get('activeCardset').learningEnd).format("DD.MM.YYYY") + TAPi18n.__('deadlineEpilogue1'));
} else {
text += (TAPi18n.__('deadlinePrologue') + moment(deadline).format("DD.MM.YYYY") + TAPi18n.__('deadlineEpilogue2'));
}
bertType = "warning";
box: {$ne: 6}
}, {sort: {nextDate: 1}}).nextDate;
let learningEnd = Cardsets.findOne({_id: Router.current().params._id}).learningEnd;
if (nextCardDate.getTime() > learningEnd.getTime()) {
text += TAPi18n.__('noMoreCardsBeforeEnd');
}
let nextDate;
if (nextCardDate.getTime() < new Date().getTime()) {
nextDate = moment(new Date());
} else {
if (Leitner.find({
cardset_id: Session.get('activeCardset')._id,
user_id: Meteor.userId(),
box: {$ne: 6}
}).count() === 0) {
text += TAPi18n.__('bonus.message.learnedEverything');
} else {
let nextCardDate = Leitner.findOne({
cardset_id: Router.current().params._id,
user_id: Meteor.userId(),
box: {$ne: 6}
}, {sort: {nextDate: 1}}).nextDate;
let learningEnd = Cardsets.findOne({_id: Router.current().params._id}).learningEnd;
if (nextCardDate.getTime() > learningEnd.getTime()) {
text += TAPi18n.__('noMoreCardsBeforeEnd');
}
let nextDate;
if (nextCardDate.getTime() < new Date().getTime()) {
nextDate = moment(new Date());
} else {
nextDate = moment(nextCardDate);
}
if (nextDate.get('hour') >= Meteor.settings.public.leitner.dayIntervalHour) {
nextDate.add(1, 'day');
}
nextDate.hour(Meteor.settings.public.leitner.dayIntervalHour);
nextDate.minute(0);
text += TAPi18n.__('noCardsToLearn') + nextDate.format("DD.MM.YYYY") + TAPi18n.__('at') + nextDate.format("HH:mm") + TAPi18n.__('released');
}
nextDate = moment(nextCardDate);
}
BertAlertVisuals.displayBertAlert(text, bertType, 'growl-top-left');
} else {
BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.bonusEnded'), bertType, 'growl-top-left');
if (nextDate.get('hour') >= Meteor.settings.public.leitner.dayIntervalHour) {
nextDate.add(1, 'day');
}
nextDate.hour(Meteor.settings.public.leitner.dayIntervalHour);
nextDate.minute(0);
text += TAPi18n.__('noCardsToLearn') + nextDate.format("DD.MM.YYYY") + TAPi18n.__('at') + nextDate.format("HH:mm") + TAPi18n.__('released');
}
Bert.defaults.hideDelay = 7;
}, 2000);
}
BertAlertVisuals.displayBertAlert(text, bertType, 'growl-top-left');
} else {
BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.bonusEnded'), bertType, 'growl-top-left');
}
}
Bert.defaults.hideDelay = 7;
}, 2000);
});
......@@ -12,16 +12,14 @@
<li id="report_button" class="reportList" data-toggle="modal"
data-target="#reportModal">{{_
"report"}}</li>
{{#unless isInBonus}}
{{#if learning}}
<li id="leaveCardsetModalButton" class="leaveCardsetList"
data-toggle="modal" data-target="#leaveCardsetModal">{{_
"confirm-leave-cardset.btn-txt"}}</li>
{{else}}
<li id="leaveCardsetButton" class="leaveCardsetList">{{_
"confirm-leave-cardset.btn-txt"}}</li>
{{/if}}
{{/unless}}
{{#if learning}}
<li id="leaveCardsetModalButton" class="leaveCardsetList"
data-toggle="modal" data-target="#leaveCardsetModal">{{_
"confirm-leave-cardset.btn-txt"}}</li>
{{else}}
<li id="leaveCardsetButton" class="leaveCardsetList">{{_
"confirm-leave-cardset.btn-txt"}}</li>
{{/if}}
{{/unless}}
{{#if isEditor}}
{{#unless isCardsetOwner _id}}
......
<template name="cardsetNavigationNewCard">
{{#unless isInBonus}}
{{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group">
<a type="button" id="newCardBtn" class="btn btn-sm btn-raised newCardBtn"
href="{{pathFor 'newCard'}}"
{{disableIfOffline}}><i class="fa fa-plus"></i> {{_ "sidebar-nav.createcard"}}
</a>
</div>
{{/unless}}
{{/if}}
{{/unless}}
{{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group">
<a type="button" id="newCardBtn" class="btn btn-sm btn-raised newCardBtn"
href="{{pathFor 'newCard'}}"
{{disableIfOffline}}><i class="fa fa-plus"></i> {{_ "sidebar-nav.createcard"}}
</a>
</div>
{{/unless}}
{{/if}}
</template>
\ No newline at end of file
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import "./newCard.html";
/*
* ############################################################################
* cardsetNavigationNewCard
* ############################################################################
*/
Template.cardsetNavigationNewCard.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
<template name="cardsetNavigationPresentation">
{{#unless isInBonus}}
{{#if this.quantity}}
{{#if gotPresentation}}
<div class="btn-group">
<button id="startPresentation"
class="btn btn-sm btn-raised presentationBtn" {{disableIfOffline}}><img
src="/img/projector_white.png" class="projectorIconButton"
title="{{_ "presentation.create"}}"> {{_ "presentation.create"}}
</button>
</div>
{{/if}}
{{#if this.quantity}}
{{#if gotPresentation}}
<div class="btn-group">
<button id="startPresentation"
class="btn btn-sm btn-raised presentationBtn" {{disableIfOffline}}><img
src="/img/projector_white.png" class="projectorIconButton"
title="{{_ "presentation.create"}}"> {{_ "presentation.create"}}
</button>
</div>
{{/if}}
{{/unless}}
{{/if}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {CardType} from "../../../../api/cardTypes";
import {Bonus} from "../../../../api/bonus";
import "./presentation.html";
/*
......@@ -19,9 +16,6 @@ Template.cardsetNavigationPresentation.helpers({
} else {
return CardType.gotPresentationMode(this.cardType);
}
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
......
<template name="cardsetNavigationWorkload">
{{#unless isInBonus}}
{{#if this.quantity}}
{{#if gotLearningModes}}
<div class="btn-group">
<button type="button" class="btn btn-sm btn-raised learnBtn"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fa fa-graduation-cap"></i> {{_ "learn"}} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li id="learnBox" class="leitnerList" {{disableIfOffline}}>{{_
"learnfile"}}</li>
<li id="learnMemo" class="wozniakList" {{disableIfOffline}}>{{_
"memo"}}</li>
{{#if learningLeitner}}
<li id="leitnerProgress" class="progressList" {{disableIfOffline}}>{{_
"admin.myProgress"}}</li>
{{/if}}
{{#if learningLeitner}}
<li id="resetLeitner" class="resetLeitnerList"
data-toggle="modal"
data-target="#resetLeitnerModal" {{disableIfOffline}}>{{_
"resetLearnfile"}}</li>
{{/if}}
{{#if learningMemo}}
<li id="resetMemo" class="resetWozniakList"
data-toggle="modal"
data-target="#resetMemoModal" {{disableIfOffline}}>{{_
"resetWozniak"}}</li>
{{/if}}
</ul>
</div>
{{/if}}
{{#if this.quantity}}
{{#if gotLearningModes}}
<div class="btn-group">
<button type="button" class="btn btn-sm btn-raised learnBtn"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="fa fa-graduation-cap"></i> {{_ "learn"}} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li id="learnBox" class="leitnerList" {{disableIfOffline}}>{{_
"learnfile"}}</li>
<li id="learnMemo" class="wozniakList" {{disableIfOffline}}>{{_
"memo"}}</li>
{{#if learningLeitner}}
<li id="leitnerProgress" class="progressList" {{disableIfOffline}}>{{_
"admin.myProgress"}}</li>
{{/if}}
{{#if learningLeitner}}
<li id="resetLeitner" class="resetLeitnerList"
data-toggle="modal"
data-target="#resetLeitnerModal" {{disableIfOffline}}>{{_
"resetLearnfile"}}</li>
{{/if}}
{{#if learningMemo}}
<li id="resetMemo" class="resetWozniakList"
data-toggle="modal"
data-target="#resetMemoModal" {{disableIfOffline}}>{{_
"resetWozniak"}}</li>
{{/if}}
</ul>
</div>
{{/if}}
{{/unless}}
{{/if}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {CardType} from "../../../../api/cardTypes";
import {Leitner, Wozniak} from "../../../../api/learned";
import {Cardsets} from "../../../../api/cardsets";
import {CardsetNavigation} from "../../../../api/cardsetNavigation";
import {Bonus} from "../../../../api/bonus";
import "../modal/leitner.js";
import "../modal/wozniak.js";
import "../modal/chooseFlashcards.js";
......@@ -37,9 +35,6 @@ Template.cardsetNavigationWorkload.helpers({
return Wozniak.findOne({
cardset_id: Router.current().params._id,
user_id: Meteor.userId()});
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
......
<template name="cardsetNavigation">
<div class="cardsetInfoFooter panel-footer">
{{#if hasCardsetPermission}}
{{> cardsetNavigationLearning}}
{{> cardsetNavigationPresentation}}
{{> cardsetNavigationWorkload}}
{{#unless isInBonusAndNotOwner}}
{{> cardsetNavigationPresentation}}
{{/unless}}
{{#if isInBonus}}
{{> cardsetNavigationLearning}}
{{else}}
{{> cardsetNavigationWorkload}}
{{/if}}
{{> cardsetNavigationNewCard}}
{{> cardsetNavigationImport}}
{{> cardsetNavigationEditRepetitorium}}
......@@ -11,7 +16,9 @@
{{> cardsetNavigationEditLicense}}
{{> cardsetNavigationPublishCardset}}
{{> cardsetNavigationBonus}}
{{> cardsetNavigationManage}}
{{#unless isInBonusAndNotOwner}}
{{> cardsetNavigationManage}}
{{/unless}}
{{> cardsetNavigationExport}}
{{> cardsetNavigationDeleteAllCards}}
{{else}}
......
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