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 { ...@@ -16,11 +16,15 @@ export let Bonus = class Bonus {
} }
static canJoinBonus (cardset_id) { static canJoinBonus (cardset_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, registrationPeriod: 1, owner: 1}}); let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, registrationPeriod: 1, owner: 1, kind: 1}});
if (Roles.userIsInRole(Meteor.userId(), ['firstLogin', 'blocked']) || cardset.owner === Meteor.userId()) { if (Roles.userIsInRole(Meteor.userId(), ['firstLogin', 'blocked'])) {
return false; 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(); return !this.isInBonus(cardset._id) && moment(cardset.registrationPeriod).endOf('day') > new Date();
} else { } else {
return false; return false;
......
...@@ -32,6 +32,14 @@ Template.registerHelper('getLastAppTitle', function () { ...@@ -32,6 +32,14 @@ Template.registerHelper('getLastAppTitle', function () {
return Meteor.settings.public.welcome.title.last; 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) { Template.registerHelper('extendContext', function (key, value) {
let result = _.clone(this); let result = _.clone(this);
result[key] = value; result[key] = value;
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
{{selectedForLearning}} {{selectedForLearning}}
{{/unless}} {{/unless}}
{{#if isActiveRoute regex='cardsetdetailsid|cardsetcard'}} {{#if isActiveRoute regex='cardsetdetailsid|cardsetcard'}}
{{#unless isInBonus}} {{#unless isInBonusAndNotOwner}}
{{#if this.quantity}} {{#if this.quantity}}
<div class="hidden-xs col-xs-12"> <div class="hidden-xs col-xs-12">
{{> cardNavigation}} {{> cardNavigation}}
......
<template name="cardsetNavigationDeleteAllCards"> <template name="cardsetNavigationDeleteAllCards">
{{#unless isInBonus}}
{{#unless isShuffledCardset this._id}} {{#unless isShuffledCardset this._id}}
{{#if this.quantity}} {{#if this.quantity}}
{{#if isCardsetOwner _id}} {{#if isCardsetOwner _id}}
...@@ -13,5 +12,4 @@ ...@@ -13,5 +12,4 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/unless}}
</template> </template>
//------------------------ IMPORTS //------------------------ 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 "../modal/deleteAllCards.js";
import "./deleteAllCards.html"; import "./deleteAllCards.html";
/*
* ############################################################################
* cardsetNavigationExport
* ############################################################################
*/
Template.cardsetNavigationDeleteAllCards.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
<template name="cardsetNavigationExport"> <template name="cardsetNavigationExport">
{{#unless isInBonus}}
{{#unless isShuffledCardset this._id}} {{#unless isShuffledCardset this._id}}
{{#if this.quantity}} {{#if this.quantity}}
{{#if isCardsetOwner _id}} {{#if isCardsetOwner _id}}
...@@ -11,5 +10,4 @@ ...@@ -11,5 +10,4 @@
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/unless}}
</template> </template>
//------------------------ IMPORTS //------------------------ IMPORTS
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating"; import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import {BertAlertVisuals} from "../../../../api/bertAlertVisuals"; import {BertAlertVisuals} from "../../../../api/bertAlertVisuals";
import "./export.html"; import "./export.html";
...@@ -12,12 +10,6 @@ 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({ Template.cardsetNavigationExport.events({
'click #exportCardsBtn': function () { 'click #exportCardsBtn': function () {
let name = this.name; let name = this.name;
......
<template name="cardsetNavigationImport"> <template name="cardsetNavigationImport">
{{#unless isInBonus}}
{{#if isCardsetOwner _id}} {{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}} {{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group"> <div class="hidden-xs btn-group">
...@@ -10,5 +9,4 @@ ...@@ -10,5 +9,4 @@
</div> </div>
{{/unless}} {{/unless}}
{{/if}} {{/if}}
{{/unless}}
</template> </template>
//------------------------ IMPORTS //------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session"; import {Session} from "meteor/session";
import {Template} from "meteor/templating"; import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import "../modal/import.js"; import "../modal/import.js";
import "./import.html"; import "./import.html";
...@@ -12,12 +10,6 @@ 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({ Template.cardsetNavigationImport.events({
'click #importCardsBtn': function () { 'click #importCardsBtn': function () {
Session.set('importType', 1); Session.set('importType', 1);
......
<template name="cardsetNavigationLearning"> <template name="cardsetNavigationLearning">
{{#if isInBonus}}
{{#if notEmpty}} {{#if notEmpty}}
<button id="learnBoxActive" <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> "cardsToLearn"}}</button>
{{/if}} {{/if}}
{{/if}}
</template> </template>
...@@ -6,7 +6,6 @@ import {Leitner} from "../../../../api/learned"; ...@@ -6,7 +6,6 @@ import {Leitner} from "../../../../api/learned";
import {Cardsets} from "../../../../api/cardsets"; import {Cardsets} from "../../../../api/cardsets";
import {CardsetNavigation} from "../../../../api/cardsetNavigation"; import {CardsetNavigation} from "../../../../api/cardsetNavigation";
import {BertAlertVisuals} from "../../../../api/bertAlertVisuals"; import {BertAlertVisuals} from "../../../../api/bertAlertVisuals";
import {Bonus} from "../../../../api/bonus";
import "./learning.html"; import "./learning.html";
/* /*
...@@ -18,13 +17,10 @@ import "./learning.html"; ...@@ -18,13 +17,10 @@ import "./learning.html";
Template.cardsetNavigationLearning.helpers({ Template.cardsetNavigationLearning.helpers({
notEmpty: function () { notEmpty: function () {
return Leitner.find({ return Leitner.find({
cardset_id: this._id, cardset_id: Router.current().params._id,
user_id: Meteor.userId(), user_id: Meteor.userId(),
active: true active: true
}).count(); }).count();
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
} }
}); });
...@@ -37,21 +33,18 @@ Template.cardsetNavigationLearning.events({ ...@@ -37,21 +33,18 @@ Template.cardsetNavigationLearning.events({
}); });
Template.cardsetNavigationLearning.onCreated(function () { 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 () { 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 () { setTimeout(function () {
Bert.defaults.hideDelay = 97200; Bert.defaults.hideDelay = 97200;
let bertType = "success"; let bertType = "success";
if (Session.get('activeCardset').registrationPeriod.getTime() < new Date()) { 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"; bertType = "warning";
BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.registrationPeriodExpired'), bertType, 'growl-top-left'); BertAlertVisuals.displayBertAlert(TAPi18n.__('bonus.message.registrationPeriodExpired'), bertType, 'growl-top-left');
return; return;
...@@ -113,6 +106,4 @@ Template.cardsetNavigationLearning.onRendered(function () { ...@@ -113,6 +106,4 @@ Template.cardsetNavigationLearning.onRendered(function () {
} }
Bert.defaults.hideDelay = 7; Bert.defaults.hideDelay = 7;
}, 2000); }, 2000);
}
}
}); });
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
<li id="report_button" class="reportList" data-toggle="modal" <li id="report_button" class="reportList" data-toggle="modal"
data-target="#reportModal">{{_ data-target="#reportModal">{{_
"report"}}</li> "report"}}</li>
{{#unless isInBonus}}
{{#if learning}} {{#if learning}}
<li id="leaveCardsetModalButton" class="leaveCardsetList" <li id="leaveCardsetModalButton" class="leaveCardsetList"
data-toggle="modal" data-target="#leaveCardsetModal">{{_ data-toggle="modal" data-target="#leaveCardsetModal">{{_
...@@ -22,7 +21,6 @@ ...@@ -22,7 +21,6 @@
"confirm-leave-cardset.btn-txt"}}</li> "confirm-leave-cardset.btn-txt"}}</li>
{{/if}} {{/if}}
{{/unless}} {{/unless}}
{{/unless}}
{{#if isEditor}} {{#if isEditor}}
{{#unless isCardsetOwner _id}} {{#unless isCardsetOwner _id}}
<li id="leaveEditors" class="leaveEditorsList" <li id="leaveEditors" class="leaveEditorsList"
......
<template name="cardsetNavigationNewCard"> <template name="cardsetNavigationNewCard">
{{#unless isInBonus}}
{{#if isCardsetOwner _id}} {{#if isCardsetOwner _id}}
{{#unless isShuffledCardset _id}} {{#unless isShuffledCardset _id}}
<div class="hidden-xs btn-group"> <div class="hidden-xs btn-group">
...@@ -10,5 +9,4 @@ ...@@ -10,5 +9,4 @@
</div> </div>
{{/unless}} {{/unless}}
{{/if}} {{/if}}
{{/unless}}
</template> </template>
\ No newline at end of file
//------------------------ IMPORTS //------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../api/bonus";
import "./newCard.html"; import "./newCard.html";
/*
* ############################################################################
* cardsetNavigationNewCard
* ############################################################################
*/
Template.cardsetNavigationNewCard.helpers({
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
}
});
<template name="cardsetNavigationPresentation"> <template name="cardsetNavigationPresentation">
{{#unless isInBonus}}
{{#if this.quantity}} {{#if this.quantity}}
{{#if gotPresentation}} {{#if gotPresentation}}
<div class="btn-group"> <div class="btn-group">
...@@ -11,5 +10,4 @@ ...@@ -11,5 +10,4 @@
</div> </div>
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/unless}}
</template> </template>
//------------------------ IMPORTS //------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating"; import {Template} from "meteor/templating";
import {CardType} from "../../../../api/cardTypes"; import {CardType} from "../../../../api/cardTypes";
import {Bonus} from "../../../../api/bonus";
import "./presentation.html"; import "./presentation.html";
/* /*
...@@ -19,9 +16,6 @@ Template.cardsetNavigationPresentation.helpers({ ...@@ -19,9 +16,6 @@ Template.cardsetNavigationPresentation.helpers({
} else { } else {
return CardType.gotPresentationMode(this.cardType); return CardType.gotPresentationMode(this.cardType);
} }
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
} }
}); });
......
<template name="cardsetNavigationWorkload"> <template name="cardsetNavigationWorkload">
{{#unless isInBonus}}
{{#if this.quantity}} {{#if this.quantity}}
{{#if gotLearningModes}} {{#if gotLearningModes}}
<div class="btn-group"> <div class="btn-group">
...@@ -33,5 +32,4 @@ ...@@ -33,5 +32,4 @@
</div> </div>
{{/if}} {{/if}}
{{/if}} {{/if}}
{{/unless}}
</template> </template>
//------------------------ IMPORTS //------------------------ IMPORTS
import {Meteor} from "meteor/meteor"; import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating"; import {Template} from "meteor/templating";
import {CardType} from "../../../../api/cardTypes"; import {CardType} from "../../../../api/cardTypes";
import {Leitner, Wozniak} from "../../../../api/learned"; import {Leitner, Wozniak} from "../../../../api/learned";
import {Cardsets} from "../../../../api/cardsets"; import {Cardsets} from "../../../../api/cardsets";
import {CardsetNavigation} from "../../../../api/cardsetNavigation"; import {CardsetNavigation} from "../../../../api/cardsetNavigation";
import {Bonus} from "../../../../api/bonus";
import "../modal/leitner.js"; import "../modal/leitner.js";
import "../modal/wozniak.js"; import "../modal/wozniak.js";
import "../modal/chooseFlashcards.js"; import "../modal/chooseFlashcards.js";
...@@ -37,9 +35,6 @@ Template.cardsetNavigationWorkload.helpers({ ...@@ -37,9 +35,6 @@ Template.cardsetNavigationWorkload.helpers({
return Wozniak.findOne({ return Wozniak.findOne({
cardset_id: Router.current().params._id, cardset_id: Router.current().params._id,
user_id: Meteor.userId()}); user_id: Meteor.userId()});
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id, Meteor.userId());
} }
}); });
......
<template name="cardsetNavigation"> <template name="cardsetNavigation">
<div class="cardsetInfoFooter panel-footer"> <div class="cardsetInfoFooter panel-footer">
{{#if hasCardsetPermission}} {{#if hasCardsetPermission}}
{{> cardsetNavigationLearning}} {{#unless isInBonusAndNotOwner}}
{{> cardsetNavigationPresentation}} {{> cardsetNavigationPresentation}}
{{/unless}}
{{#if isInBonus}}
{{> cardsetNavigationLearning}}
{{else}}
{{> cardsetNavigationWorkload}} {{> cardsetNavigationWorkload}}
{{/if}}
{{> cardsetNavigationNewCard}} {{> cardsetNavigationNewCard}}
{{> cardsetNavigationImport}} {{> cardsetNavigationImport}}
{{> cardsetNavigationEditRepetitorium}} {{> cardsetNavigationEditRepetitorium}}
...@@ -11,7 +16,9 @@ ...@@ -11,7 +16,9 @@
{{> cardsetNavigationEditLicense}} {{> cardsetNavigationEditLicense}}
{{> cardsetNavigationPublishCardset}} {{> cardsetNavigationPublishCardset}}
{{> cardsetNavigationBonus}} {{> cardsetNavigationBonus}}
{{#unless isInBonusAndNotOwner}}
{{> cardsetNavigationManage}} {{> cardsetNavigationManage}}
{{/unless}}
{{> cardsetNavigationExport}} {{> cardsetNavigationExport}}
{{> cardsetNavigationDeleteAllCards}} {{> cardsetNavigationDeleteAllCards}}
{{else}} {{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