Commit 0c25592b authored by Curtis Adam's avatar Curtis Adam

Refactor the cardset info-box template

parent 60c33f64
......@@ -19,7 +19,7 @@
{{> cardsetInfoBox}}
</span>
<span class="col-sm-6 collapseCardsetInfoContainer">
{{> learningPhaseInfoBox}}
{{> bonusInfoBox}}
</span>
</div>
</div>
......
<template name="learningPhaseInfoBox">
<template name="bonusInfoBox">
<a id="collapseLearningPhaseInfoButton" class="col-xs-12 card card-block collapseButton"
href="#collapseLearningPhaseInfo" data-toggle="collapse">
<strong>{{_ "set-list.learnphaseInfo"}}</strong>
......@@ -8,66 +8,17 @@
<div class="card card-block">
<table class="table table-condensed table-striped table-hover infoBoxTable">
<tbody>
<tr>
<td>{{_ "set-list.learnphase"}}:</td>
<td>{{getLearningStatus}}</td>
</tr>
<tr>
<td>{{_ "set-list.bonusPoints"}}:</td>
<td>
<a href="https://www.thm.de/site/hochschule/zentrale-bereiche/pruefungsamt/faq.html#bonuspunkte-an-der-thm"
target="_blank">{{_ "set-list.bonusPointsPercentage"}}</a></td>
</tr>
<tr>
<td>{{_ "bonus.form.maxWorkload.label"}}:</td>
<td>{{getWorkload}}</td>
</tr>
<tr>
<td>{{_ "pomodoro.cardsetInfo.count.label"}}:</td>
<td>{{{getPomodoroCount}}}</td>
</tr>
<tr>
<td>{{_ "pomodoro.cardsetInfo.work.label"}}:</td>
<td>{{{getPomodoroWorkTime}}}</td>
</tr>
<tr>
<td>{{_ "pomodoro.cardsetInfo.break.label"}}:</td>
<td>{{{getPomodoroBreakTime}}}</td>
</tr>
<tr>
<td>{{_ "bonus.form.daysBeforeReset.label"}}:</td>
<td>{{getDeadline}}</td>
</tr>
<tr>
<td>{{_ "bonus.form.startDate.label"}}:</td>
<td>{{getDateStart}}</td>
</tr>
<tr>
<td>{{_ "bonus.form.endDate.label"}}:</td>
<td>{{getDateEnd}}</td>
</tr>
<tr>
<td>{{_ "bonus.form.registrationPeriod.label"}}:</td>
<td>{{getRegistrationPeriod}}</td>
</tr>
{{#if canJoinBonus}}
<tr>
<td colspan="2">
<a class="btn btn-raised btn-block btn-success" data-toggle="modal"
data-target="{{#if isProfileCompleted}}#joinBonusModal{{else}}#profileIncompleteModal{{/if}}">{{_
"bonus.info.button.join"}}</a>
</td>
</tr>
{{/if}}
{{#if isInBonus}}
<tr>
<td colspan="2">
<a class="btn btn-raised btn-block btn-danger" data-toggle="modal"
data-target="#leaveBonusModal">{{_
"bonus.info.button.leave"}}</a>
</td>
</tr>
{{/if}}
{{> cardsetInfoBoxItemBonusStatus}}
{{> cardsetInfoBoxItemBonusPoints}}
{{> cardsetInfoBoxItemBonusWorkload}}
{{> cardsetInfoBoxItemPomodoroCount}}
{{> cardsetInfoBoxItemPomodoroWorkTime}}
{{> cardsetInfoBoxItemPomodoroBreakTime}}
{{> cardsetInfoBoxItemBonusDeadline}}
{{> cardsetInfoBoxItemBonusStart}}
{{> cardsetInfoBoxItemBonusEnd}}
{{> cardsetInfoBoxItemBonusRegistrationPeriod}}
{{> cardsetInfoBoxItemBonusButton}}
</tbody>
</table>
</div>
......
//------------------------ IMPORTS
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Profile} from "../../../../api/profile";
import {Bonus} from "../../../../api/bonus";
import {CardsetVisuals} from "../../../../api/cardsetVisuals";
import "./item/bonusButton.js";
import "./item/bonusDeadline.js";
import "./item/bonusEnd.js";
import "./item/bonusPoints.js";
import "./item/bonusRegistrationPeriod.js";
import "./item/bonusStart.js";
import "./item/bonusStatus.js";
import "./item/bonusWorkload.js";
import "./item/pomodoroBreakTime.js";
import "./item/pomodoroCount.js";
import "./item/pomodoroWorkTime.js";
import "./bonus.html";
/*
* ############################################################################
* learningPhaseInfoBox
* bonusPhaseInfoBox
* ############################################################################
*/
Template.learningPhaseInfoBox.helpers({
getDateEnd: function () {
return moment(this.learningEnd).format("DD.MM.YYYY");
},
getDateStart: function () {
return moment(this.learningStart).format("DD.MM.YYYY");
},
getRegistrationPeriod: function () {
return moment(this.registrationPeriod).format("DD.MM.YYYY");
},
getDeadline: function () {
if (this.daysBeforeReset === 1) {
return this.daysBeforeReset + " " + TAPi18n.__('panel-body-experience.day');
} else {
return this.daysBeforeReset + " " + TAPi18n.__('panel-body-experience.day_plural');
}
},
getLearningStatus: function () {
if (this.learningEnd.getTime() > new Date().getTime()) {
return TAPi18n.__('set-list.activeLearnphase');
} else {
return TAPi18n.__('set-list.inactiveLearnphase');
}
},
getWorkload: function () {
if (this.maxCards === 1) {
return this.maxCards + " " + TAPi18n.__('confirmLearn-form.card');
} else {
return this.maxCards + " " + TAPi18n.__('confirmLearn-form.cards');
}
},
getPomodoroCount: function () {
return TAPi18n.__('pomodoro.cardsetInfo.count.content', {
count: this.pomodoroTimer.quantity,
link: TAPi18n.__('pomodoro.form.link'),
tooltip: TAPi18n.__('pomodoro.form.tooltip.link', {pomodoro: TAPi18n.__('pomodoro.name')}),
pomodoro: TAPi18n.__('pomodoro.name', {count: this.pomodoroTimer.quantity})
});
},
getPomodoroWorkTime: function () {
return TAPi18n.__('pomodoro.cardsetInfo.work.content', {minutes: TAPi18n.__('pomodoro.form.time.minute', {count: this.pomodoroTimer.workLength})});
},
getPomodoroBreakTime: function () {
return TAPi18n.__('pomodoro.cardsetInfo.break.content', {minutes: TAPi18n.__('pomodoro.form.time.minute', {count: this.pomodoroTimer.breakLength})});
},
canJoinBonus: function () {
return Bonus.canJoinBonus(Session.get('activeCardset')._id);
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id);
},
isProfileCompleted: function () {
return Profile.isCompleted();
}
});
Template.learningPhaseInfoBox.events({
Template.bonusInfoBox.events({
"click #collapseLearningPhaseInfoButton": function () {
CardsetVisuals.changeCollapseIcon("#collapseLearningPhaseInfoIcon");
}
......
......@@ -19,153 +19,22 @@
</template>
<template name="cardsetInfoBoxContentOne">
<tr>
<td>
{{#if this.shuffled}}
{{_ "cardset.info.publisher"}}
{{else}}
{{_ "cardset.info.author"}}
{{/if}}:
</td>
<td>
{{getAuthorName this.owner false}}
</td>
</tr>
{{#unless this.shuffled}}
{{#if gotOriginalAuthorData}}
<tr>
<td>{{_ "cardset.info.originalAuthor"}}:</td>
<td>
{{getOriginalAuthorName this.originalAuthorName false}}
</td>
</tr>
{{/if}}
{{/unless}}
{{#if isActiveRoute regex="learn"}}
<tr>
<td>{{_ "set-list.learningMode"}}:</td>
<td>
{{getLearningMode}}
</td>
</tr>
{{/if}}
{{#unless isActiveRoute regex="home"}}
{{#if getReviewer}}
<tr>
<td>{{_ "cardset.info.reviewer"}}:</td>
<td><a
href="{{pathFor 'profileSettings' _id=reviewer}}">{{getAuthorName this.reviewer}}</a>
</td>
</tr>
{{/if}}
{{/unless}}
{{#if isActiveRoute regex="home"}}
<tr>
<td>{{_ "set-list.category"}}:</td>
<td>
{{{getKindText this.kind 1}}}
</td>
</tr>
{{/if}}
{{#unless isShuffledCardset this._id}}
{{#unless isActiveRoute regex="course"}}
<tr>
<td>{{_ "cardType"}}:</td>
<td>
{{getCardType}}
</td>
</tr>
<tr>
<td>{{#if gotNotesForDifficultyLevel}}{{_ "difficultyNotes"}}{{else}}{{_
"difficulty"}}{{/if}}:
</td>
<td>
{{getDifficultyName}}
</td>
</tr>
{{/unless}}
{{/unless}}
{{#unless isActiveRoute regex="create|learn|pool|shuffle"}}
<tr>
<td>{{_ "cardset.info.quantity"}}:</td>
<td class="cardsetCardQuantity" data-quantity="{{this.quantity}}">{{this.quantity}}</td>
</tr>
{{/unless}}
{{#unless isActiveRoute regex="home|create|learn|pool|shuffle"}}
{{#if hasAmount}}
{{#unless canViewForFree}}
<tr>
<td>{{_ "cardset.info.amount"}}:</td>
<td>{{getPrice this.price}}</td>
</tr>
{{/unless}}
{{/if}}
{{#if isPurchased}}
<tr>
<td>{{_ "cardset.info.bought"}}:</td>
<td>{{getDateOfPurchase}}</td>
</tr>
{{/if}}
{{/unless}}
<tr>
<td>{{_ "cardset.info.license"}}:</td>
<td>
{{#unless isShuffledCardset _id}}
{{#if isActiveRoute "home"}}
<span class="info_license showLicense">{{getLicense this._id this.license}}</span>
{{else}}
<a class="info_license showLicense" href="#" data-id="{{this._id}}" data-toggle="modal"
data-target="#showLicenseModal">{{getLicense this._id this.license}}</a>
{{/if}}
{{else}}
{{_ "cardset.info.shuffleLicense"}}
{{/unless}}
</td>
</tr>
{{> cardsetInfoBoxItemAuthor}}
{{> cardsetInfoBoxItemOriginalAuthor}}
{{> cardsetInfoBoxItemLearningMode}}
{{> cardsetInfoBoxItemReviewer}}
{{> cardsetInfoBoxItemKind}}
{{> cardsetInfoBoxItemCardType}}
{{> cardsetInfoBoxItemDifficulty}}
{{> cardsetInfoBoxItemCardCount}}
{{> cardsetInfoBoxItemPrice}}
{{> cardsetInfoBoxItemPurchased}}
{{> cardsetInfoBoxItemLicense}}
</template>
<template name="cardsetInfoBoxContentTwo">
<tr>
<td>{{_ "cardset.info.release"}}:</td>
<td>{{getMomentsDate this.date}}</td>
</tr>
<tr>
<td>{{_ "cardset.info.dateUpdated"}}:</td>
<td>{{getMomentsDate this.dateUpdated}}</td>
</tr>
<tr>
<td>{{_ "cardset.info.workload.normal.count"}}:</td>
<td>{{this.workload.normal.count}}</td>
</tr>
{{#if this.learningActive}}
<tr>
<td>{{_ "cardset.info.workload.bonus.count"}}:</td>
<td>{{this.workload.bonus.count}}</td>
</tr>
{{/if}}
{{#unless isActiveRoute regex="home|course"}}
{{#if ratingEnabled}}
<tr>
<td>{{_ "cardset.info.rating"}}:</td>
<td>
{{#if canRateCardset}}
{{#if isActiveRoute regex="cardsetdetailsid|cardsetlistid"}}
{{> starsRating id="rating" class='star-ratings' rating=getAverageRating mutable=true}}
{{else}}
{{> starsRating class='star-ratings' rating=getAverageRating mutable=false}}
{{/if}}
{{else}}
{{> starsRating class='star-ratings' rating=getAverageRating mutable=false}}
{{/if}} ({{this.raterCount}})
</td>
</tr>
<tr>
{{#if canRateCardset}}
<td>{{_ "cardset.info.userRating"}}:</td>
<td><span id="userRating">{{getUserRating}}</span></td>
{{/if}}
</tr>
{{/if}}
{{/unless}}
{{> cardsetInfoBoxItemDateCreated}}
{{> cardsetInfoBoxItemDateUpdated}}
{{> cardsetInfoBoxItemActiveLearners}}
{{> cardsetInfoBoxItemRatings}}
</template>
//------------------------ IMPORTS
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Leitner, Wozniak} from "../../../../api/learned";
import {Ratings} from "../../../../api/ratings";
import {CardType} from "../../../../api/cardTypes";
import {Cardsets} from "../../../../api/cardsets";
import {Paid} from "../../../../api/paid";
import "./item/activeLearners.js";
import "./item/author.js";
import "./item/cardCount.js";
import "./item/cardType.js";
import "./item/dateCreated.js";
import "./item/dateUpdated.js";
import "./item/difficulty.js";
import "./item/kind.js";
import "./item/learningMode.js";
import "./item/license.js";
import "./item/originalAuthor.js";
import "./item/price.js";
import "./item/purchased.js";
import "./item/ratings.js";
import "./item/reviewer.js";
import "./cardset.html";
import {CardsetVisuals} from "../../../../api/cardsetVisuals";
/*
* ############################################################################
......@@ -45,232 +52,3 @@ Template.cardsetInfoBox.helpers({
return shuffled;
}
});
/*
* ############################################################################
* cardsetInfoBox
* ############################################################################
*/
Template.cardsetInfoBox.events({
"click #collapseCardsetInfoButton": function () {
CardsetVisuals.changeCollapseIcon("#collapseCardsetInfoIcon");
}
});
/*
* ############################################################################
* cardsetInfoBoxContentOne
* ############################################################################
*/
Template.cardsetInfoBoxContentOne.helpers({
canViewForFree: function () {
return (this.kind === "edu" && (Roles.userIsInRole(Meteor.userId(), ['university', 'lecturer'])));
},
ratingEnabled: function () {
return this.ratings === true;
},
canRateCardset: function () {
let result = Cardsets.findOne({_id: this._id}, {fields: {owner: 1}});
if (result !== undefined) {
return result.owner !== Meteor.userId();
} else {
return false;
}
},
getAverageRating: function () {
let ratings = Ratings.find({cardset_id: this._id}).fetch();
let averageRating = 0;
for (let i = 0; i < ratings.length; i++) {
averageRating += ratings[i].rating;
}
return averageRating / ratings.length;
},
getUserRating: function () {
var userrating = Ratings.findOne({
cardset_id: this._id,
user: Meteor.userId()
});
if (userrating) {
return userrating.rating;
} else {
return 0 + " " + TAPi18n.__('cardset.info.notRated');
}
},
gotOriginalAuthorData: function () {
if (this.originalAuthorName !== undefined) {
return (this.originalAuthorName.birthname !== undefined || this.originalAuthorName.legacyName !== undefined);
} else {
return "";
}
},
hasAmount: function () {
return this.kind === 'pro' || this.kind === 'edu';
},
isPurchased: function () {
return Paid.findOne({cardset_id: this._id}) !== undefined;
},
getDateOfPurchase: function () {
return moment(Paid.findOne({cardset_id: this._id}).date).locale(Session.get('activeLanguage')).format('LL');
},
getReviewer: function () {
var reviewer = Meteor.users.findOne(this.reviewer);
return (reviewer !== undefined) ? reviewer.profile.name : undefined;
},
getCardType: function () {
return CardType.getCardTypeName(this.cardType);
},
gotNotesForDifficultyLevel: function () {
return CardType.gotNotesForDifficultyLevel(this.cardType);
},
getDifficultyName: function () {
if (CardType.gotNotesForDifficultyLevel(this.cardType)) {
return TAPi18n.__('difficultyNotes' + this.difficulty);
} else {
if (!CardType.gotDifficultyLevel(this.cardType)) {
return TAPi18n.__('difficulty0');
} else {
return TAPi18n.__('difficulty' + this.difficulty);
}
}
},
getLearningMode: function () {
let actualDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
actualDate.setHours(0, 0, 0, 0);
let count = 0;
if (Leitner.find({cardset_id: this._id, user_id: Meteor.userId(), active: true}).count()) {
count += 1;
}
if (Wozniak.find({
cardset_id: this._id, user_id: Meteor.userId(), nextDate: {
$lte: actualDate
}
}).count()) {
count += 2;
}
switch (count) {
case 0:
return TAPi18n.__('set-list.none');
case 1:
return TAPi18n.__('set-list.leitner');
case 2:
return TAPi18n.__('set-list.wozniak');
case 3:
return TAPi18n.__('set-list.both');
}
}
});
Template.cardsetInfoBoxContentOne.events({
'click #rating': function () {
var cardset_id = Template.parentData(1)._id;
var rating = $('#rating').data('userrating');
var count = Ratings.find({
cardset_id: cardset_id,
user: Meteor.userId()
}).count();
if (count === 0) {
Meteor.call("addRating", cardset_id, rating);
} else {
Meteor.call("updateRating", cardset_id, rating);
}
},
'click .showLicense': function (event) {
event.preventDefault();
Session.set('selectedCardset', $(event.target).data('id'));
}
});
/*
* ############################################################################
* cardsetInfoBoxContentTwo
* ############################################################################
*/
Template.cardsetInfoBoxContentTwo.helpers({
canViewForFree: function () {
return (this.kind === "edu" && (Roles.userIsInRole(Meteor.userId(), ['university', 'lecturer'])));
},
ratingEnabled: function () {
return this.ratings === true && Session.get('ratingsLoaded');
},
hasRated: function () {
var count = Ratings.find({
cardset_id: this._id,
user: Meteor.userId()
}).count();
var cardset = Cardsets.findOne(this._id);
if (cardset !== null) {
return count !== 0;
}
},
canRateCardset: function () {
let result = Cardsets.findOne({_id: this._id}, {fields: {owner: 1}});
if (result !== undefined) {
return result.owner !== Meteor.userId();
} else {
return false;
}
},
getAverageRating: function () {
let ratings = Ratings.find({cardset_id: this._id}).fetch();
let averageRating = 0;
for (let i = 0; i < ratings.length; i++) {
averageRating += ratings[i].rating;
}
return averageRating / ratings.length;
},
getUserRating: function () {
var userrating = Ratings.findOne({
cardset_id: this._id,
user: Meteor.userId()
});
if (userrating) {
return userrating.rating;
} else {
return 0 + " " + TAPi18n.__('cardset.info.notRated');
}
},
hasAmount: function () {
return this.kind === 'pro' || this.kind === 'edu';
},
isPurchased: function () {
return Paid.findOne({cardset_id: this._id}) !== undefined;
},
getDateOfPurchase: function () {
return moment(Paid.findOne({cardset_id: this._id}).date).locale(Session.get('activeLanguage')).format('LL');
},
getReviewer: function () {
var reviewer = Meteor.users.findOne(this.reviewer);
return (reviewer !== undefined) ? reviewer.profile.name : undefined;
},
getCardType: function () {
return CardType.getCardTypeName(this.cardType);
},
gotNotesForDifficultyLevel: function () {
return CardType.gotNotesForDifficultyLevel(this.cardType);
},
getDifficultyName: function () {
if (CardType.gotNotesForDifficultyLevel(this.cardType)) {
return TAPi18n.__('difficultyNotes' + this.difficulty);
} else {
return TAPi18n.__('difficulty' + this.difficulty);
}
}
});
Template.cardsetInfoBoxContentTwo.events({
'click #rating': function () {
var cardset_id = Template.parentData(1)._id;
var rating = $('#rating').data('userrating');
var count = Ratings.find({
cardset_id: cardset_id,
user: Meteor.userId()
}).count();
if (count === 0) {
Meteor.call("addRating", cardset_id, rating);
} else {
Meteor.call("updateRating", cardset_id, rating);
}
}
});
<template name="cardsetInfoBoxItemActiveLearners">
<tr>
<td>{{_ "cardset.info.workload.normal.count"}}:</td>
<td>{{this.workload.normal.count}}</td>
</tr>
{{#if this.learningActive}}
<tr>
<td>{{_ "cardset.info.workload.bonus.count"}}:</td>
<td>{{this.workload.bonus.count}}</td>
</tr>
{{/if}}
</template>
//------------------------ IMPORTS
import "./activeLearners.html";
<template name="cardsetInfoBoxItemAuthor">
<tr>
<td>
{{#if this.shuffled}}
{{_ "cardset.info.publisher"}}
{{else}}
{{_ "cardset.info.author"}}
{{/if}}:
</td>
<td>
{{getAuthorName this.owner false}}
</td>
</tr>
</template>
//------------------------ IMPORTS
import "./author.html";
<template name="cardsetInfoBoxItemBonusButton">
{{#if canJoinBonus}}
<tr>
<td colspan="2">
<a class="btn btn-raised btn-block btn-success" data-toggle="modal"
data-target="{{#if isProfileCompleted}}#joinBonusModal{{else}}#profileIncompleteModal{{/if}}">{{_
"bonus.info.button.join"}}</a>
</td>
</tr>
{{/if}}
{{#if isInBonus}}
<tr>
<td colspan="2">
<a class="btn btn-raised btn-block btn-danger" data-toggle="modal"
data-target="#leaveBonusModal">{{_
"bonus.info.button.leave"}}</a>
</td>
</tr>
{{/if}}
</template>
//------------------------ IMPORTS
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Bonus} from "../../../../../api/bonus";
import {Profile} from "../../../../../api/profile";
import "./bonusButton.html";
/*
* ############################################################################
* cardsetInfoBoxItemBonusButton
* ############################################################################
*/
Template.cardsetInfoBoxItemBonusButton.helpers({
canJoinBonus: function () {
return Bonus.canJoinBonus(Session.get('activeCardset')._id);
},
isInBonus: function () {
return Bonus.isInBonus(Session.get('activeCardset')._id);
},
isProfileCompleted: function () {
return</