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}}
......@@ -13,5 +12,4 @@
{{/if}}
{{/if}}
{{/unless}}
{{/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}}
......@@ -11,5 +10,4 @@
{{/if}}
{{/if}}
{{/unless}}
{{/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">
......@@ -10,5 +9,4 @@
</div>
{{/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/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">{{_
class="btn btn-sm btn-raised btn-success learn btn-learn"><i class="fa fa-graduation-cap"></i> {{_
"cardsToLearn"}}</button>
{{/if}}
{{/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,21 +33,18 @@ 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);
}
}
});
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) {
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;
......@@ -113,6 +106,4 @@ Template.cardsetNavigationLearning.onRendered(function () {
}
Bert.defaults.hideDelay = 7;
}, 2000);
}
}
});
......@@ -12,7 +12,6 @@
<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">{{_
......@@ -22,7 +21,6 @@
"confirm-leave-cardset.btn-txt"}}</li>
{{/if}}
{{/unless}}
{{/unless}}
{{#if isEditor}}
{{#unless isCardsetOwner _id}}
<li id="leaveEditors" class="leaveEditorsList"
......
<template name="cardsetNavigationNewCard">
{{#unless isInBonus}}
{{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group">
......@@ -10,5 +9,4 @@
</div>
{{/unless}}
{{/if}}
{{/unless}}
</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">
......@@ -11,5 +10,4 @@
</div>
{{/if}}
{{/if}}
{{/unless}}
</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">
......@@ -33,5 +32,4 @@
</div>
{{/if}}
{{/if}}
{{/unless}}
</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}}
{{#unless isInBonusAndNotOwner}}
{{> cardsetNavigationPresentation}}
{{/unless}}
{{#if isInBonus}}
{{> cardsetNavigationLearning}}
{{else}}
{{> cardsetNavigationWorkload}}
{{/if}}
{{> cardsetNavigationNewCard}}
{{> cardsetNavigationImport}}
{{> cardsetNavigationEditRepetitorium}}
......@@ -11,7 +16,9 @@
{{> cardsetNavigationEditLicense}}
{{> cardsetNavigationPublishCardset}}
{{> cardsetNavigationBonus}}
{{#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