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

Commit 90261f08 authored by Curtis Adam's avatar Curtis Adam

Add an option to sort the card topic content by date

parent 263ff693
......@@ -611,6 +611,13 @@
}
}
},
"cardsetForm": {
"sortType": {
"label": "Sortieroption für den Inhalt der Themen:",
"sortDate": "Nach Erstelldatum sortieren",
"sortContent": "Nach Inhalt sortieren"
}
},
"modal-dialog": {
"missingFields": "Bitte fülle die folgenden Felder aus",
"newcarddeck": "Kartei anlegen (Kartenbox)",
......
......@@ -615,6 +615,13 @@
}
}
},
"cardsetForm": {
"sortType": {
"label": "Sortieroption für den Inhalt der Themen:",
"sortDate": "Nach Erstelldatum sortieren",
"sortContent": "Nach Inhalt sortieren"
}
},
"modal-dialog": {
"missingFields": "Bitte fülle die folgenden Felder aus",
"newcarddeck": "Kartei erstellen (Box für Lernkarten)",
......
......@@ -72,7 +72,7 @@ export let CardIndex = class CardIndex {
fields: {_id: 1, cardType: 1}
});
cardGroups.forEach(function (cardGroup) {
sortQuery = CardType.getSortQuery(cardGroup.cardType);
sortQuery = CardType.getSortQuery(cardGroup.cardType, cardGroup.sortType);
indexCards = Cards.find({cardset_id: cardGroup._id}, {
sort: sortQuery, fields: {_id: 1}
});
......@@ -81,7 +81,7 @@ export let CardIndex = class CardIndex {
});
});
} else {
sortQuery = CardType.getSortQuery(cardset.cardType);
sortQuery = CardType.getSortQuery(cardset.cardType, cardset.sortType);
indexCards = Cards.find({cardset_id: cardset._id}, {sort: sortQuery, fields: {_id: 1}});
indexCards.forEach(function (indexCard) {
cardIndex.push(indexCard._id);}
......
......@@ -55,29 +55,33 @@ export let CardType = class CardType {
}
}
static getSortQuery (cardType) {
static getSortQuery (cardType, sortType) {
let sortQuery = {};
sortQuery.subject = 1;
let cubeSides = this.getCardTypeCubeSides(cardType);
switch (cubeSides[0].contentId) {
case 1:
sortQuery.front = 1;
break;
case 2:
sortQuery.back = 1;
break;
case 3:
sortQuery.hint = 1;
break;
case 4:
sortQuery.lecture = 1;
break;
case 5:
sortQuery.top = 1;
break;
case 6:
sortQuery.bottom = 1;
break;
if (sortType === 0) {
let cubeSides = this.getCardTypeCubeSides(cardType);
switch (cubeSides[0].contentId) {
case 1:
sortQuery.front = 1;
break;
case 2:
sortQuery.back = 1;
break;
case 3:
sortQuery.hint = 1;
break;
case 4:
sortQuery.lecture = 1;
break;
case 5:
sortQuery.top = 1;
break;
case 6:
sortQuery.bottom = 1;
break;
}
} else {
sortQuery.date = 1;
}
return sortQuery;
}
......
......@@ -306,6 +306,10 @@ const CardsetsSchema = new SimpleSchema({
learners: {
type: Number,
optional: true
},
sortType: {
type: Number,
optional: true
}
});
......@@ -434,8 +438,9 @@ Meteor.methods({
* @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
* @param {Number} sortType - Sort the topic content by card content or date created, 0 = content, 1 = date created
*/
addCardset: function (name, description, visible, ratings, kind, shuffled, cardGroups, cardType, difficulty) {
addCardset: function (name, description, visible, ratings, kind, shuffled, cardGroups, cardType, difficulty, sortType) {
check(name, String);
check(description, String);
check(visible, Boolean);
......@@ -444,6 +449,7 @@ Meteor.methods({
check(shuffled, Boolean);
check(cardType, Number);
check(difficulty, Number);
check(sortType, Number);
let quantity;
if (shuffled) {
if (!Roles.userIsInRole(Meteor.userId(), ['admin', 'editor', 'lecturer', 'university', 'pro'])) {
......@@ -495,7 +501,8 @@ Meteor.methods({
cardGroups: cardGroups,
cardType: cardType,
difficulty: difficulty,
noDifficulty: !CardType.gotDifficultyLevel(cardType)
noDifficulty: !CardType.gotDifficultyLevel(cardType),
sortType: sortType
}, {trimStrings: false});
Meteor.call('updateCardsetCount', Meteor.userId());
return cardset;
......@@ -716,14 +723,15 @@ Meteor.methods({
* @param {String} description - Description for the content of the cardset
* @param {Number} cardType - The type that this cardset allows
* @param {Number} difficulty - The difficulty level of the cardset
* @param {Number} sortType - Sort the topic content by card content or date created, 0 = content, 1 = date created
*/
updateCardset: function (id, name, description, cardType, difficulty) {
updateCardset: function (id, name, description, cardType, difficulty, sortType) {
check(id, String);
check(name, String);
check(description, String);
check(cardType, Number);
check(difficulty, Number);
check(sortType, Number);
// Make sure only the task owner can make a task private
let cardset = Cardsets.findOne(id);
if (UserPermissions.isAdmin() || UserPermissions.isOwner(cardset.owner)) {
......@@ -738,7 +746,8 @@ Meteor.methods({
dateUpdated: new Date(),
cardType: cardType,
difficulty: difficulty,
noDifficulty: !CardType.gotDifficultyLevel(cardType)
noDifficulty: !CardType.gotDifficultyLevel(cardType),
sortType: sortType
}
}, {trimStrings: false});
} else {
......
......@@ -161,6 +161,9 @@ Meteor.methods({
} else {
originalAuthorName = data[0].originalAuthorName;
}
if (data[0].sortType !== undefined) {
data[0].sortType = 0;
}
let cardset_id = Cardsets.insert({
name: data[0].name,
description: data[0].description,
......@@ -195,7 +198,8 @@ Meteor.methods({
cardType: data[0].cardType,
difficulty: data[0].difficulty,
noDifficulty: CardType.gotDifficultyLevel(data[0].cardType),
originalAuthorName: originalAuthorName
originalAuthorName: originalAuthorName,
sortType: data[0].sortType
}, {trimStrings: false});
if (cardset_id) {
data.shift();
......@@ -310,7 +314,8 @@ Meteor.methods({
cardType: cardset[0].cardType,
difficulty: cardset[0].difficulty,
noDifficulty: CardType.gotDifficultyLevel(cardset[0].cardType),
originalAuthorName: originalAuthorName
originalAuthorName: originalAuthorName,
sortType: 0
}, {trimStrings: false});
cardGroups.push(cardset_id);
cardset.shift();
......@@ -353,7 +358,8 @@ Meteor.methods({
cardType: 0,
difficulty: 0,
noDifficulty: CardType.gotDifficultyLevel(0),
originalAuthorName: ""
originalAuthorName: "",
sortType: 0
}, {trimStrings: false});
} catch (error) {
throw new Meteor.Error(error);
......
//Settings for new cardsets
let defaultSortTopicContentByDateCreate = true;
module.exports = {
defaultSortTopicContentByDateCreate
};
......@@ -790,6 +790,19 @@ Meteor.startup(function () {
Meteor.call('updateCardsetRating', cardsets[i]._id);
}
cardsets = Cardsets.find({sortType: {$exists: false}}).fetch();
for (let i = 0; i < cardsets.length; i++) {
Cardsets.update({
_id: cardsets[i]._id
},
{
$set: {
sortType: 0
}
}
);
}
let wozniak;
wozniak = Wozniak.find({skipped: {$exists: true}}).fetch();
for (let i = 0; i < wozniak.length; i++) {
......
......@@ -96,7 +96,8 @@ Template.cardsetList.helpers({
},
cardList: function (countCards) {
let sortQuery;
sortQuery = CardType.getSortQuery(Cardsets.findOne({_id: this.cardset_id}).cardType);
let cardset = Cardsets.findOne({_id: this.cardset_id}, {fields: {cardType: 1, sortType: 1}});
sortQuery = CardType.getSortQuery(cardset.cardType, cardset.sortType);
if (countCards) {
return Cards.find({
cardset_id: this.cardset_id,
......
......@@ -151,6 +151,13 @@
{{> difficultyEditor}}
</div>
{{/if}}
<br>
<label id="setSortTypeyLabel" class="col-xs-12 control-label" for="setSortType">{{_
"cardsetForm.sortType.label"}}</label>
<div id="setSortType" class="col-xs-12 cardtext editorElement">
<label class="radio-inline"><input type="radio" id="sortDate" name="sortType" value="1">{{_ "cardsetForm.sortType.sortDate"}}</label>
<label class="radio-inline"><input type="radio" id="sortContent" name="sortType" value="0">{{_ "cardsetForm.sortType.sortContent"}}</label>
</div>
{{/unless}}
{{/unless}}
</div>
......
......@@ -6,6 +6,7 @@ import {CardType} from '../../api/cardTypes.js';
import {Route} from '../../api/route.js';
import {BertAlertVisuals} from "../../api/bertAlertVisuals";
import {Cardsets} from "../../api/cardsets";
import * as config from "../../config/cardset";
export function isNewCardset() {
return Session.get('isNewCardset');
......@@ -73,6 +74,23 @@ export function cleanModal() {
Session.set('difficultyColor', 1);
}
$('#contentEditor').css('height', 'unset');
if (isNewCardset()) {
if (config.defaultSortTopicContentByDateCreate) {
$('#sortDate').prop('checked', true);
$('#sortContent').prop('checked', false);
} else {
$('#sortDate').prop('checked', false);
$('#sortContent').prop('checked', true);
}
} else {
if (Session.get('previousCardsetData').sortType === 0) {
$('#sortDate').prop('checked', false);
$('#sortContent').prop('checked', true);
} else {
$('#sortDate').prop('checked', true);
$('#sortContent').prop('checked', false);
}
}
}
export function saveCardset() {
......@@ -80,6 +98,7 @@ export function saveCardset() {
let bertDelayMultiplier = 0;
let error = false;
let errorMessage = "<ul>";
let sortType = $("input[name='sortType']:checked").val();
if ($('#setName').val() === "") {
error = true;
errorMessage += "<li>" + TAPi18n.__('modal-dialog.name') + "</li>";
......@@ -125,7 +144,7 @@ export function saveCardset() {
shuffled = false;
cardGroups = [];
}
Meteor.call("addCardset", name, description, false, true, 'personal', shuffled, cardGroups, Number(cardType), Session.get('difficultyColor'), function (error, result) {
Meteor.call("addCardset", name, description, false, true, 'personal', shuffled, cardGroups, Number(cardType), Session.get('difficultyColor'), Number(sortType), function (error, result) {
$('#setCardsetFormModal').modal('hide');
if (result) {
if (Session.get('importCards') !== undefined) {
......@@ -144,7 +163,7 @@ export function saveCardset() {
if (Session.get('previousCardsetData').shuffled) {
cardType = -1;
}
Meteor.call("updateCardset", Session.get('previousCardsetData')._id, name, description, Number(cardType), Session.get('difficultyColor'));
Meteor.call("updateCardset", Session.get('previousCardsetData')._id, name, description, Number(cardType), Session.get('difficultyColor'), Number(sortType));
if (Number(cardType) !== -1) {
Session.set('cardType', Number(cardType));
}
......
......@@ -3012,7 +3012,7 @@
},
"fibers": {
"version": "1.0.15",
"resolved": "http://registry.npmjs.org/fibers/-/fibers-1.0.15.tgz",
"resolved": "https://registry.npmjs.org/fibers/-/fibers-1.0.15.tgz",
"integrity": "sha1-IvA5yPGLhWGQ+75N7PBWFUwerpw=",
"dev": true
},
......@@ -3045,7 +3045,7 @@
},
"d": {
"version": "1.0.0",
"resolved": "http://registry.npmjs.org/d/-/d-1.0.0.tgz",
"resolved": "https://registry.npmjs.org/d/-/d-1.0.0.tgz",
"integrity": "sha1-dUu1v+VUUdpppYuU1F9MWwRi1Y8=",
"dev": true,
"requires": {
......@@ -3406,14 +3406,14 @@
},
"dependencies": {
"es5-ext": {
"version": "0.10.48",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.48.tgz",
"integrity": "sha512-CdRvPlX/24Mj5L4NVxTs4804sxiS2CjVprgCmrgoDkdmjdY4D+ySHa7K3jJf8R40dFg0tIm3z/dk326LrnuSGw==",
"version": "0.10.49",
"resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.49.tgz",
"integrity": "sha512-3NMEhi57E31qdzmYp2jwRArIUsj1HI/RxbQ4bgnSB+AIKIxsAmTiK83bYMifIcpWvEc3P1X30DhUKOqEtF/kvg==",
"dev": true,
"requires": {
"es6-iterator": "~2.0.3",
"es6-symbol": "~3.1.1",
"next-tick": "1"
"next-tick": "^1.0.0"
}
}
}
......@@ -4920,7 +4920,7 @@
},
"gherkin": {
"version": "4.0.0",
"resolved": "http://registry.npmjs.org/gherkin/-/gherkin-4.0.0.tgz",
"resolved": "https://registry.npmjs.org/gherkin/-/gherkin-4.0.0.tgz",
"integrity": "sha1-edzgTRIj6kO0hip2vlzo+JwSwyw=",
"dev": true
},
......@@ -6123,7 +6123,8 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
......@@ -6144,12 +6145,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -6164,17 +6167,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -6291,7 +6297,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
......@@ -6303,6 +6310,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -6317,6 +6325,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -6324,12 +6333,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -6348,6 +6359,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -6428,7 +6440,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
......@@ -6440,6 +6453,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -6525,7 +6539,8 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
......@@ -6561,6 +6576,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -6580,6 +6596,7 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......@@ -6623,12 +6640,14 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
}
}
},
......@@ -9584,7 +9603,7 @@
},
"next-tick": {
"version": "1.0.0",
"resolved": "http://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
"integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=",
"dev": true
},
......@@ -11590,7 +11609,7 @@
"dependencies": {
"source-map": {
"version": "0.5.6",
"resolved": "http://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz",
"integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=",
"dev": true
}
......@@ -12803,7 +12822,8 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
......@@ -12824,7 +12844,8 @@
},
"concat-map": {
"version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
......
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