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

Move difficulty setting to cardset

parent 620c9bd1
......@@ -4,6 +4,7 @@
@import '../imports/ui/cardset/cardset.scss';
@import '../imports/ui/card/card.scss';
@import '../imports/ui/courseIterations/coursesIterations.scss';
@import '../imports/ui/forms/cardsetCourseIterationForm.scss';
@import '../imports/ui/profile/profile.scss';
@import '../imports/ui/learn/learn.scss';
@import '../imports/ui/pool/pool.scss';
......
......@@ -204,13 +204,12 @@ var CardsSchema = new SimpleSchema({
Cards.attachSchema(CardsSchema);
Meteor.methods({
addCard: function (cardset_id, subject, hint, front, back, difficulty, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
addCard: function (cardset_id, subject, hint, front, back, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
check(cardset_id, String);
check(subject, String);
check(hint, String);
check(front, String);
check(back, String);
check(difficulty, Number);
check(lecture, String);
check(centerTextElement, [Boolean]);
check(date, Date);
......@@ -238,7 +237,7 @@ Meteor.methods({
front: front,
back: back,
cardset_id: cardset_id,
difficulty: difficulty,
difficulty: cardset.difficulty,
lecture: lecture,
centerTextElement: centerTextElement,
date: date,
......@@ -355,13 +354,12 @@ Meteor.methods({
});
}
},
updateCard: function (card_id, subject, hint, front, back, difficulty, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
updateCard: function (card_id, subject, hint, front, back, lecture, centerTextElement, date, learningGoalLevel, backgroundStyle, learningUnit) {
check(card_id, String);
check(subject, String);
check(hint, String);
check(front, String);
check(back, String);
check(difficulty, Number);
check(lecture, String);
check(centerTextElement, [Boolean]);
check(date, Date);
......@@ -395,7 +393,6 @@ Meteor.methods({
hint: hint,
front: front,
back: back,
difficulty: difficulty,
lecture: lecture,
centerTextElement: centerTextElement,
date: date,
......
......@@ -178,6 +178,9 @@ const CardsetsSchema = new SimpleSchema({
},
cardType: {
type: Number
},
difficulty: {
type: Number
}
});
......@@ -233,8 +236,9 @@ Meteor.methods({
* @param {Boolean} shuffled - Is the cardset made out of shuffled cards
* @param {String} cardGroups - The group names of the shuffled cards
* @param {Number} cardType - The type that this cardset allows
* @param {Number} difficulty - The difficulty level of the cardset
*/
addCardset: function (name, description, visible, ratings, kind, moduleActive, module, moduleShort, moduleNum, moduleLink, college, course, shuffled, cardGroups, cardType) {
addCardset: function (name, description, visible, ratings, kind, moduleActive, module, moduleShort, moduleNum, moduleLink, college, course, shuffled, cardGroups, cardType, difficulty) {
if (Meteor.settings.public.university.singleUniversity || college === "") {
college = Meteor.settings.public.university.default;
}
......@@ -252,6 +256,7 @@ Meteor.methods({
check(course, String);
check(shuffled, Boolean);
check(cardType, Number);
check(difficulty, Number);
let quantity;
if (shuffled) {
if (!Roles.userIsInRole(Meteor.userId(), ['admin', 'editor', 'lecturer', 'university', 'pro'])) {
......@@ -305,7 +310,8 @@ Meteor.methods({
wordcloud: false,
shuffled: shuffled,
cardGroups: cardGroups,
cardType: cardType
cardType: cardType,
difficulty: difficulty
});
},
/**
......@@ -504,8 +510,9 @@ Meteor.methods({
* @param {String} college - Assigned university
* @param {String} course - Assigned university course
* @param {Number} cardType - The type that this cardset allows
* @param {Number} difficulty - The difficulty level of the cardset
*/
updateCardset: function (id, name, description, moduleActive, module, moduleShort, moduleNum, moduleLink, college, course, cardType) {
updateCardset: function (id, name, description, moduleActive, module, moduleShort, moduleNum, moduleLink, college, course, cardType, difficulty) {
if (Meteor.settings.public.university.singleUniversity) {
college = Meteor.settings.public.university.default;
}
......@@ -520,6 +527,7 @@ Meteor.methods({
check(college, String);
check(course, String);
check(cardType, Number);
check(difficulty, Number);
// Make sure only the task owner can make a task private
let cardset = Cardsets.findOne(id);
......@@ -549,7 +557,8 @@ Meteor.methods({
moduleLink: moduleLink.trim(),
college: college.trim(),
course: course.trim(),
cardType: cardType
cardType: cardType,
difficulty: difficulty
}
});
......@@ -558,7 +567,8 @@ Meteor.methods({
},
{
$set: {
cardType: cardType
cardType: cardType,
difficulty: difficulty
}
},
{
......
......@@ -59,7 +59,8 @@ var initTestNotificationsCardset = function () {
"editors": [],
"shuffled": false,
"cardGroups": [],
"cardType": 0
"cardType": 0,
"difficulty": 1
}
];
};
......@@ -83,7 +84,7 @@ var initTestNotificationsCards = function () {
{
"_id": "NotificationsTestCard2",
"subject": "NotificationsTest: Card Nr. 2",
"difficulty": 2,
"difficulty": 1,
"front": "Front of NotificationsTest: Card Nr. 2",
"back": "Back of NotificationsTest: Card Nr. 2",
"hint": "Hint of NotificationsTest: Card Nr. 2",
......@@ -97,7 +98,7 @@ var initTestNotificationsCards = function () {
{
"_id": "NotificationsTestCard3",
"subject": "NotificationsTest: Card Nr. 3",
"difficulty": 0,
"difficulty": 1,
"front": "Front of NotificationsTest: Card Nr. 3",
"back": "Back of NotificationsTest: Card Nr. 3",
"hint": "Hint of NotificationsTest: Card Nr. 3",
......@@ -111,7 +112,7 @@ var initTestNotificationsCards = function () {
{
"_id": "NotificationsTestCard4",
"subject": "NotificationsTest: Card Nr. 4",
"difficulty": 2,
"difficulty": 1,
"front": "Front of NotificationsTest: Card Nr. 4",
"back": "Back of NotificationsTest: Card Nr. 4",
"hint": "Hint of NotificationsTest: Card Nr. 4",
......@@ -125,7 +126,7 @@ var initTestNotificationsCards = function () {
{
"_id": "NotificationsTestCard5",
"subject": "NotificationsTest: Card Nr. 5",
"difficulty": 0,
"difficulty": 1,
"front": "Front of NotificationsTest: Card Nr. 5",
"back": "Back of NotificationsTest: Card Nr. 5",
"hint": "Hint of NotificationsTest: Card Nr. 5",
......@@ -308,20 +309,7 @@ Meteor.startup(function () {
});
}
let cards = Cards.find({difficulty: {$exists: false}}).fetch();
for (let i = 0; i < cards.length; i++) {
Cards.update({
_id: cards[i]._id
},
{
$set: {
difficulty: 0
}
}
);
}
cards = Cards.find({lecture: {$exists: false}}).fetch();
let cards = Cards.find({lecture: {$exists: false}}).fetch();
for (let i = 0; i < cards.length; i++) {
Cards.update({
_id: cards[i]._id
......@@ -491,6 +479,19 @@ Meteor.startup(function () {
);
}
cardsets = Cardsets.find({difficulty: {$exists: false}}).fetch();
for (let i = 0; i < cardsets.length; i++) {
Cardsets.update({
_id: cardsets[i]._id
},
{
$set: {
difficulty: 1
}
}
);
}
cardsets = Cardsets.find({shuffled: {$exists: false}}).fetch();
for (let i = 0; i < cardsets.length; i++) {
Cardsets.update({
......@@ -512,7 +513,8 @@ Meteor.startup(function () {
},
{
$set: {
cardType: cardsets[i].cardType
cardType: cardsets[i].cardType,
difficulty: cardsets[i].difficulty
}
},
{
......
......@@ -40,20 +40,8 @@
{{> selectLearningUnit}}
{{> subjectEditor}}
</div>
{{#if gotDifficultyLevel}}
<div id="difficulty" class="col-md-6 cardtext editorElement">
{{#if gotNotesForDifficultyLevel}}
<h5>{{_ "difficulty"}}</h5>
{{else}}
<h5>{{_ "difficultyNotes"}}</h5>
{{/if}}
{{> difficultyEditor}}
</div>
{{/if}}
</div>
<div class="row">
{{#if gotLearningGoal}}
<div id="learningGoalLevel" class="col-md-6 col-md-offset-6 cardtext editorElement">
<div id="learningGoalLevel" class="col-md-6 cardtext editorElement">
<h5>{{_ "learning-goal.name"}}</h5>
{{> learningGoalLevel}}
</div>
......@@ -96,77 +84,6 @@
</div>
</template>
<template name="difficultyEditor">
<div id="difficultyGroup" class="form-group btn-group" role="group" data-toggle="buttons">
{{#if gotNotesForDifficultyLevel}}
<label id="difficulty0"
class="col-xs-6 col-sm-3 btn btn-default {{#if
gotNotesForDifficultyLevel}}btn-orange{{else}}btn-white{{/if}} {{#if
isDifficultyChecked 0}}active{{/if}}"
data-color="0">
{{#if isDifficultyChecked 0}}
<input type="radio" name="difficulty" value="0" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="0">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty0"}}
{{else}}
{{_ "difficultyNotes0"}}
{{/unless}}
</label>
{{/if}}
<label id="difficulty1"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-info {{#if
isDifficultyChecked 1}}active{{/if}}"
data-color="1">
{{#if isDifficultyChecked 1}}
<input type="radio" name="difficulty" value="1" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="1">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty1"}}
{{else}}
{{_ "difficultyNotes1"}}
{{/unless}}
</label>
<label id="difficulty2"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-success {{#if
isDifficultyChecked 2}}active{{/if}}"
data-color="2">
{{#if isDifficultyChecked 2}}
<input type="radio" name="difficulty" value="2" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="2">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty2"}}
{{else}}
{{_ "difficultyNotes2"}}
{{/unless}}
</label>
<label id="difficulty3"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-danger {{#if
isDifficultyChecked 3}}active{{/if}}"
data-color="3">
{{#if isDifficultyChecked 3}}
<input type="radio" name="difficulty" value="3" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="3">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty3"}}
{{else}}
{{_ "difficultyNotes3"}}
{{/unless}}
</label>
</div>
</template>
<template name="learningGoalLevel">
<div id="learningGoalLevelGroup" class="form-group btn-group col-xs-12" role="group" data-toggle="buttons">
<label id="learningGoalLevel0"
......@@ -398,21 +315,8 @@
style="display: {{#if gotDictionary}}{{#unless
reversedViewOrder}}none{{/unless}}{{else}}none{{/if}}">{{getBackTitle}}
)</span>{{/unless}}</span><br>
{{#if gotDifficultyLevel}}
{{#unless gotNotesForDifficultyLevel}}{{_ "difficulty"}}:{{/unless}}
<strong>{{getDifficultyName}}</strong>
{{#if gotNotesForDifficultyLevel}}
<span class="cardBackHeader"
style="display: {{#if gotDictionary}}{{#unless
reversedViewOrder}}none{{/unless}}{{else}}none{{/if}}">
({{getBackTitle}})
</span>
{{/if}}
{{#if gotLearningGoal}}
| {{_ "learning-goal.name"}}:
<strong>{{getLearningGoalName}}</strong>
{{/if}}
{{else}}
{{#if gotLearningGoal}}
{{_ "learning-goal.name"}}: <strong>{{getLearningGoalName}}</strong>
{{/if}}
</div>
<div class="cardNumber">
......
......@@ -25,10 +25,6 @@ import {
*/
function resetSessionData(resetSubject = false) {
let difficulty = 0;
if (!gotNotesForDifficultyLevel(Session.get('cardType'))) {
difficulty = 1;
}
if (resetSubject) {
Session.set('subjectText', '');
Session.get('learningUnit', '');
......@@ -37,7 +33,6 @@ function resetSessionData(resetSubject = false) {
Session.set('backText', '');
Session.set('hintText', '');
Session.set('lectureText', '');
Session.set('difficultyColor', difficulty);
defaultCenteredText();
Session.set('learningGoalLevel', 0);
Session.set('backgroundStyle', 0);
......@@ -629,10 +624,6 @@ function initializeContent() {
Session.set('hintText', '');
}
if (Session.get('difficultyColor') === undefined) {
Session.set('difficultyColor', 1);
}
if (Session.get('learningGoalLevel') === undefined) {
Session.set('learningGoalLevel', 0);
}
......@@ -712,12 +703,8 @@ function saveCard(card_id, returnToCardset) {
}
let editorsValidLength = (frontText.length <= 10000 && backText.length <= 10000 && lectureText.length <= 30000 && $('#subjectEditor').val().length <= 150 && hintText.length <= 10000);
if (gotSubject && editorsValidLength) {
let difficulty = 1;
if (gotDifficultyLevel(cardType)) {
difficulty = $('input[name=difficulty]:checked').val();
}
if (ActiveRoute.name('newCard')) {
Meteor.call("addCard", Router.current().params._id, subjectText, hintText, frontText, backText, Number(difficulty), lectureText, centerTextElement, date, Number(learningGoalLevel), Number(backgroundStyle), learningUnit, function (error, result) {
Meteor.call("addCard", Router.current().params._id, subjectText, hintText, frontText, backText, lectureText, centerTextElement, date, Number(learningGoalLevel), Number(backgroundStyle), learningUnit, function (error, result) {
if (result) {
Bert.alert(TAPi18n.__('savecardSuccess'), "success", 'growl-top-left');
if (returnToCardset) {
......@@ -734,7 +721,7 @@ function saveCard(card_id, returnToCardset) {
}
});
} else {
Meteor.call("updateCard", card_id, subjectText, hintText, frontText, backText, Number(difficulty), lectureText, centerTextElement, date, Number(learningGoalLevel), Number(backgroundStyle), learningUnit);
Meteor.call("updateCard", card_id, subjectText, hintText, frontText, backText, lectureText, centerTextElement, date, Number(learningGoalLevel), Number(backgroundStyle), learningUnit);
Bert.alert(TAPi18n.__('savecardSuccess'), "success", 'growl-top-left');
if (returnToCardset) {
Router.go('cardsetdetailsid', {
......@@ -827,13 +814,8 @@ Template.editor.helpers({
if (Router.current().route.getName() === "newCard") {
resetSessionData(true);
Session.set('cardType', Cardsets.findOne({_id: Router.current().params._id}).cardType);
Session.set('difficultyColor', Cardsets.findOne({_id: Router.current().params._id}).difficulty);
} else if (Router.current().route.getName() === "editCard") {
let difficulty;
if (this.difficulty === 0 && !gotNotesForDifficultyLevel(this.cardType)) {
difficulty = 1;
} else {
difficulty = this.difficulty;
}
Session.set('subjectText', this.subject);
Session.set('frontText', this.front);
Session.set('backText', this.back);
......@@ -841,7 +823,7 @@ Template.editor.helpers({
Session.set('cardType', this.cardType);
Session.set('lectureText', this.lecture);
Session.set('centerTextElement', this.centerTextElement);
Session.set('difficultyColor', difficulty);
Session.set('difficultyColor', this.difficulty);
Session.set('learningGoalLevel', this.learningGoalLevel);
Session.set('backgroundStyle', this.backgroundStyle);
Session.set('learningUnit', this.learningUnit);
......@@ -991,27 +973,6 @@ Template.subjectEditor.rendered = function () {
Session.set('subjectText', $('#subjectEditor').val());
};
/*
* ############################################################################
* difficultyEditor
* ############################################################################
*/
Template.difficultyEditor.helpers({
isDifficultyChecked: function (difficulty) {
return difficulty === Session.get('difficultyColor');
},
gotNotesForDifficultyLevel: function () {
return gotNotesForDifficultyLevel(this.cardType);
}
});
Template.difficultyEditor.events({
'click #difficultyGroup': function (event) {
Session.set('difficultyColor', Number($(event.target).data('color')));
}
});
/*
* ############################################################################
* learningGoalLevel
......@@ -1219,21 +1180,6 @@ Template.flashcards.helpers({
}
return TAPi18n.__('card.cardType' + activeCardType + '.name');
},
getDifficultyName: function () {
let activeCardType = this.cardType;
if (Session.get('shuffled')) {
activeCardType = Session.get('cardType');
}
if (activeCardType === 2) {
return TAPi18n.__('difficultyNotes' + this.difficulty);
} else {
let difficulty = this.difficulty;
if (difficulty === 0) {
difficulty++;
}
return TAPi18n.__('difficulty' + difficulty);
}
},
getLearningGoalName: function () {
return TAPi18n.__('learning-goal.level' + (this.learningGoalLevel + 1));
},
......
$input_difficulty0: #FFFFFF;
$input_difficulty1: #5cb85c;
$input_difficulty2: #5bc0de;
$input_difficulty3: #d9534f;
$background_difficultyNote0: ivory;
$background_difficulty1: honeydew;
$background_difficulty2: lightcyan;
$background_difficulty3: mistyrose;
$color_difficultyNote0: #F8E1AE;
$color_difficulty0: #E6EAE9;
$color_difficulty1: rgba(92, 184, 92, 0.3);
$color_difficulty2: rgba(91, 192, 222, 0.3);
$color_difficulty3: rgba(217, 83, 79, 0.3);
$background_lecture: papayawhip;
$background_hint: lightseagreen;
$color_item_selection_border: $color_item_separator;
$color_card_header_text: $color_thm_gray;
#difficultyGroup, #cardTypeGroup {
margin-top: 0 !important;
margin-bottom: 0 !important;
padding: 0;
width: 100%;
}
#difficulty .btn, #cardType .btn {
background-color: $color_wild_sand_approx;
padding: 9px 0 9px 0;
font-weight: bold;
font-size: 13px;
text-align: center;
@media(max-width: 767px) {
padding: 20px 0 20px 0;
}
}
.btn-white.active {
color: $black !important;
background-color: white !important;
......@@ -49,33 +12,6 @@ $color_card_header_text: $color_thm_gray;
background-color: $color_thm_orange !important;
}
#difficulty .btn-info {
color: $input_difficulty1 !important;
}
#difficulty .btn-info.active {
color: $white !important;
background-color: $input_difficulty1;
}
#difficulty .btn-success {
color: $input_difficulty2 !important;
}
#difficulty .btn-success.active {
color: $white !important;
background-color: $input_difficulty2;
}
#difficulty .btn-danger {
color: $input_difficulty3 !important;
}
#difficulty .btn-danger.active {
color: $white !important;
background-color: $input_difficulty3;
}
#cardType .btn-white.active, #learningGoalLevelGroup .btn-primary.active {
color: white !important;
background-color: $input_difficulty2 !important;
......
......@@ -103,6 +103,12 @@
{{getCardType}}
</td>
</tr>
<tr>
<td><strong>{{#if gotNotesForDifficultyLevel}}{{_ "difficultyNotes"}}{{else}}{{_ "difficulty"}}{{/if}}:</strong></td>
<td>
{{getDifficultyName}}
</td>
</tr>
{{#if ratingEnabled}}
<tr>
<td><strong>{{_ "cardset.info.rating"}}:</strong></td>
......
......@@ -14,7 +14,7 @@ import "../card/card.js";
import "../learn/learn.js";
import "../forms/cardsetCourseIterationForm.js";
import "./cardset.html";
import {getCardTypeName, gotLearningModes} from "../../api/cardTypes";
import {getCardTypeName, gotLearningModes, gotNotesForDifficultyLevel} from "../../api/cardTypes";
Meteor.subscribe("cardsets");
Meteor.subscribe("paid");
......@@ -481,6 +481,16 @@ Template.cardsetInfoBox.helpers({
},
getCardType: function () {
return getCardTypeName(this.cardType);
},
gotNotesForDifficultyLevel: function () {
return gotNotesForDifficultyLevel(this.cardType);
},
getDifficultyName: function () {
if (gotNotesForDifficultyLevel(this.cardType)) {
return TAPi18n.__('difficultyNotes' + this.difficulty);
} else {
return TAPi18n.__('difficulty' + this.difficulty);
}
}
});
......
......@@ -66,6 +66,14 @@
</div>
</div>
{{/unless}}
{{#if gotDifficultyLevel}}
<br>
<label id="setDifficultyLabel" class="col-md-3 control-label" for="setDifficulty">{{#if
gotNotesForDifficultyLevel}}{{_ "difficultyNotes"}}{{else}}{{_ "difficulty"}}{{/if}}</label>
<div id="setDifficulty" class="col-md-9 cardtext editorElement">
{{> difficultyEditor}}
</div>
{{/if}}
</div>
<div class="panel panel-primary">
<div class="panel-heading">
......@@ -247,3 +255,74 @@
</div>
{{/unless}}
</template>
<template name="difficultyEditor">
<div id="difficultyGroup" class="form-group btn-group" role="group" data-toggle="buttons">
{{#if gotNotesForDifficultyLevel}}
<label id="difficulty0"
class="col-xs-6 col-sm-3 btn btn-default {{#if
gotNotesForDifficultyLevel}}btn-orange{{else}}btn-white{{/if}} {{#if
isDifficultyChecked 0}}active{{/if}}"
data-color="0">
{{#if isDifficultyChecked 0}}
<input type="radio" name="difficulty" value="0" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="0">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty0"}}
{{else}}
{{_ "difficultyNotes0"}}
{{/unless}}
</label>
{{/if}}
<label id="difficulty1"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-info {{#if
isDifficultyChecked 1}}active{{/if}}"
data-color="1">
{{#if isDifficultyChecked 1}}
<input type="radio" name="difficulty" value="1" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="1">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty1"}}
{{else}}
{{_ "difficultyNotes1"}}
{{/unless}}
</label>
<label id="difficulty2"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-success {{#if
isDifficultyChecked 2}}active{{/if}}"
data-color="2">
{{#if isDifficultyChecked 2}}
<input type="radio" name="difficulty" value="2" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="2">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty2"}}
{{else}}
{{_ "difficultyNotes2"}}
{{/unless}}
</label>
<label id="difficulty3"
class="col-xs-6 {{#if
gotNotesForDifficultyLevel}}col-sm-3{{else}}col-sm-4{{/if}} btn btn-default btn-danger {{#if
isDifficultyChecked 3}}active{{/if}}"
data-color="3">
{{#if isDifficultyChecked 3}}
<input type="radio" name="difficulty" value="3" checked tabindex="3">
{{else}}
<input type="radio" name="difficulty" value="3">
{{/if}}
{{#unless gotNotesForDifficultyLevel}}
{{_ "difficulty3"}}
{{else}}
{{_ "difficultyNotes3"}}
{{/unless}}
</label>
</div>
</template>
......@@ -4,7 +4,7 @@ import {Session} from "meteor/session";
import "./cardsetCourseIterationForm.html";
import {Cardsets} from "../../api/cardsets.js";
import {image, tex} from '/imports/ui/card/card.js';
import {getCardTypeName} from '../../api/cardTypes';
import {getCardTypeName, gotDifficultyLevel, gotNotesForDifficultyLevel} from '../../api/cardTypes';
function newCardsetCourseIterationRoute() {
return Router.current().route.getName() === 'create' || Router.current().route.getName() === 'shuffle' || Router.current().route.getName() === 'courseIterations';
......@@ -40,6 +40,18 @@ function deactivateModule() {
Session.set('moduleActive', false);
}
function adjustDifficultyColor() {
if (cardsetRoute()) {
Session.set('difficultyColor', Cardsets.findOne({_id: Router.current().params._id}).difficulty);
} else {
let difficulty = 0;
if (!gotNotesForDifficultyLevel(Session.get('cardType'))) {
difficulty = 1;
}
Session.set('difficultyColor', difficulty);
}
}
export function cleanModal() {
let previousCollegeName, previousCourseName;
if (!newCardsetCourseIterationRoute()) {
......@@ -202,6 +214,7 @@ export function cleanModal() {
if (createRoute() || courseIterationRoute()) {
deactivateModule();
Session.set('cardType', Number(0));
} else if (shuffleRoute()) {
if (Session.get("ShuffleTemplate").moduleActive) {
activateModule();
......@@ -215,6 +228,7 @@ export function cleanModal() {
deactivateModule();
}
}
adjustDifficultyColor();
}
export function saveCardset() {
......@@ -301,7 +315,7 @@ export function saveCardset() {
Meteor.call("addCourseIteration", name, description, false, true, 'personal', Session.get('moduleActive'), module, moduleShort, moduleNum, moduleLink, college, course);
$('#setCardsetCourseIterationFormModal').modal('hide');
} else {
Meteor.call("addCardset", name, description, false, true, 'personal', Session.get('moduleActive'), module, moduleShort, moduleNum, moduleLink, college, course, shuffled, cardGroups, Number(cardType), function (error, result) {
Meteor.call("addCardset", name, description, false, true, 'personal', Session