Commit b54b66a7 authored by Curtis Adam's avatar Curtis Adam

Merge branch '506-allow-user-to-edit-the-shuffled-cardset-references' into 'staging'

Resolve "Allow user to edit the shuffled cardset references"

Closes #506

See merge request arsnova/flashcards!474
parents d1bb72c7 a368658d
......@@ -182,7 +182,12 @@
"leave": "Verlassen",
"shuffleCardsets": "Kartensätze mischen",
"shuffle": "Mischen",
"shuffleInfoText": ""
"shuffleInfoText": "",
"shuffleCardsetReferences": "Kartensatz Referenzen bearbeiten",
"shuffleUpdateSuccess": "Referenzen aktualisiert",
"shuffleUpdateFailure": "Fehler beim aktualisieren der Referenzen",
"shuffleRemove": "Alle Referenzen entfernen",
"shuffleRemoveWarning": "Entfernte Referenzen löschen ebenfalls den dazugehörigen Lernstand."
},
"set-list-empty": {
"emptytextlist": "Du hast noch keinen Kartensatz angelegt",
......@@ -196,6 +201,7 @@
"modal-dialog": {
"newcarddeck": "Neuen Kartensatz anlegen",
"editcard": "Kartensatz editieren",
"editreferences": "Referenzen editieren",
"name": "Thema",
"nameplaceholder": "Thema des Kartensatzes",
"descriptionplaceholder": "Beschreibung für den Inhalt des Kartensatzes",
......
......@@ -194,7 +194,12 @@
"leave": "Leave",
"shuffleCardsets": "Shuffle Cardsets",
"shuffle": "Shuffle",
"shuffleInfoText": ""
"shuffleInfoText": "",
"shuffleCardsetReferences": "Update cardset references",
"shuffleUpdateSuccess": "Updated references",
"shuffleUpdateFailure": "Error while updating the references",
"shuffleRemove": "Remove all references",
"shuffleRemoveWarning": "Deleted references will also remove the associated learning progress."
},
"set-list-empty": {
"emptytextlist": "You have not created any deck of cards yet",
......@@ -208,6 +213,7 @@
"modal-dialog": {
"newcarddeck": "Create a new deck of cards",
"editcard": "Edit deck of cards",
"editreferences": "Edit references",
"name": "Title",
"nameplaceholder": "Title of the cardset",
"descriptionplaceholder": "Description for the content of this cardset",
......
......@@ -522,6 +522,51 @@ Meteor.methods({
}
});
},
/**
* Update the cardGroups of the shuffled cardset
* @param {String} id - Database id of the cardset to receive the updated cardGroups
* @param {String} cardGroups - The cardset references
* @param {String} removedCardsets - The previous cardset references that got removed
*/
updateShuffleGroups: function (id, cardGroups, removedCardsets) {
check(id, String);
check(cardGroups, [String]);
check(removedCardsets, [String]);
let cardset = Cardsets.findOne(id);
if (!Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
if (!Meteor.userId() || cardset.owner !== Meteor.userId() || Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
throw new Meteor.Error("not-authorized");
}
}
let quantity = Cards.find({cardset_id: {$in: cardGroups}}).count();
let kind = cardset.kind;
let visible = cardset.visible;
if (cardGroups.length === 0) {
kind = "personal";
visible = false;
}
Cardsets.update({
_id: cardset._id
}, {
$set: {
visible: visible,
kind: kind,
quantity: quantity,
cardGroups: cardGroups
}
});
let removedCards = Cards.find({cardset_id: {$in: removedCardsets}}).fetch();
for (let i = 0; i < removedCards.length; i++) {
Learned.remove({
cardset_id: cardset._id,
card_id: removedCards[i]._id
});
}
return true;
},
activateLearningPeriodSetEdu: function (cardset_id) {
check(cardset_id, String);
......
......@@ -79,6 +79,10 @@ Template.registerHelper("isCardsetOwner", function (cardset_id) {
return owner === Meteor.userId();
});
Template.registerHelper("isShuffleRoute", function () {
return (Router.current().route.getName() === "shuffle" || Router.current().route.getName() === "editshuffle");
});
Template.registerHelper("isCardsetEditor", function (user_id) {
return Cardsets.findOne({"_id": Router.current().params._id, "editors": {$in: [user_id]}});
});
......
......@@ -64,6 +64,14 @@ Router.route('/cardset/:_id', {
}
});
Router.route('/cardset/:_id/editshuffle', {
name: 'editshuffle',
template: 'shuffle',
data: function () {
return Cardsets.findOne({_id: this.params._id});
}
});
Router.route('/cardset/:_id/editors', {
name: 'cardseteditors',
template: 'cardsetManageEditors',
......
......@@ -69,8 +69,12 @@
{{#if countCards this._id}}
{{> flashcards cardset=this}}
{{else}}
{{#if isShuffledCardset this._id}}
{{> flashcards cardset=this}}
{{#if isShuffledCardset}}
{{#if gotReferences}}
{{> flashcards cardset=this}}
{{else}}
{{> flashcardsEmpty}}
{{/if}}
{{else}}
{{> flashcardsEmpty}}
{{/if}}
......@@ -244,6 +248,14 @@
</button>
</div>
{{#unless learningActive}}
{{#if isShuffledCardset this._id}}
<div class="btn-group btn-group-raised">
<button id="editShuffle" class="btn btn-raised btn-default"
type="button" {{disableIfOffline}}>
<i class="fa fa-pencil"></i> {{_ "modal-dialog.editreferences"}}
</button>
</div>
{{/if}}
{{#unless isShuffledCardset this._id}}
{{#if this.quantity}}
<div class="btn-group btn-group-raised">
......
......@@ -466,6 +466,9 @@ Template.cardsetList.helpers({
case "pro":
return "btn-warning";
}
},
gotReferences: function () {
return Cardsets.findOne({_id: Router.current().params._id}).cardGroups !== [""];
}
});
......@@ -550,6 +553,9 @@ Template.cardsetInfo.events({
type: "application/json"
});
saveAs(exportData, cardset.name + ".json");
},
'click #editShuffle': function () {
Router.go('editshuffle', {_id: Router.current().params._id});
}
});
......
......@@ -23,34 +23,58 @@
<template name="shuffle">
{{#if canShuffle}}
{{#unless isActiveRoute 'shuffle'}}
{{#unless isShuffleRoute}}
{{#if shuffleList.count}}
<a href="shuffle" id="shuffleCardsets" class="btn btn-raised btn-success" role="button">{{_
"set-list.shuffleCardsets"}}</a>
{{/if}}
{{else}}
<div class="col-md-12" id="set-list-region">
{{#if gotShuffledCards}}
<a href="#" id="createShuffledCardset" class="btn btn-raised btn-success" role="button"
data-toggle="modal"
data-target="#newSetModal" {{disableIfOffline}}>{{_
"set-list.shuffle"}}</a>
{{#if isActiveRoute 'shuffle'}}
{{#if gotShuffledCards}}
<a href="#" id="createShuffledCardset" class="btn btn-raised btn-success" role="button"
data-toggle="modal"
data-target="#newSetModal" {{disableIfOffline}}>{{_
"set-list.shuffle"}}</a>
{{/if}}
<a href="learn" id="cancelShuffle" class="btn btn-raised btn-danger" role="button">{{_
"declinecard"}}</a>
{{/if}}
<a href="learn" id="cancelShuffle" class="btn btn-raised btn-danger" role="button">{{_
"declinecard"}}</a>
{{#if isActiveRoute 'editshuffle'}}
<h3 class="modal-title">{{_ "set-list.shuffleCardsetReferences"}}</h3>
<br>
{{#if gotShuffledCards}}
<button href="#" id="updateShuffledCardset" class="btn btn-raised btn-success"
role="button" {{disableIfOffline}}>{{_
"set-list.shuffle"}}</button>
{{/if}}
<button id="cancelUpdateShuffle" class="btn btn-raised btn-danger" role="button">{{_
"declinecard"}}</button>
{{/if}}
{{#if displayRemoveButton}}
<button href="#" id="removeShuffledCards" class="btn btn-raised btn-danger"
role="button" {{disableIfOffline}}>{{_
"set-list.shuffleRemove"}}</button>
{{/if}}
<span>
{{_ "set-list.shuffleRemoveWarning"}}
</span>
{{shuffleInfoText}}
{{#if shuffleList.count}}
<div class="responsive-utilities-test visible-on">
<span class="col-md-3 hidden-xs hidden-sm poolHeaderBottom">{{_ "set-list.topic"}}</span>
<span class="col-md-8 hidden-xs hidden-sm poolHeaderBottom">{{_ "set-list.description"}}</span>
<span class="col-md-1 hidden-xs hidden-sm poolHeaderBottom">{{_ "selection"}}</span>
<span class="col-md-7 hidden-xs hidden-sm poolHeaderBottom">{{_ "set-list.description"}}</span>
<span class="col-md-2 hidden-xs hidden-sm poolHeaderBottom">{{_ "selection"}}</span>
</div>
{{#each shuffleList}}
<div class="col-xs-12 col-sm-6 col-md-12 panel panel-default {{#if
oddRow
@index}} altPanel {{/if}} cardsetInfo cardsetRow responsive-utilities-test visible-on">
{{> cardsetRow}}
</div>
{{#unless isActiveCardset}}
<div class="col-xs-12 col-sm-6 col-md-12 panel panel-default {{#if
oddRow
@index}} altPanel {{/if}} cardsetInfo cardsetRow responsive-utilities-test visible-on">
{{> cardsetRow}}
</div>
{{/unless}}
{{/each}}
{{else}}
{{> cardsetEmpty}}
......@@ -121,7 +145,7 @@
</span>
</a>
{{/if}}
{{#if isActiveRoute 'shuffle'}}
{{#if isShuffleRoute}}
<span class="cell col-xs-12 col-sm-12 col-md-2 poolText panelUnit panelUnitDescription panelUnitLicense panelUnitNoBorder">
{{#if inShuffleSelection this._id}}
<a class="btn btn-block btn-raised btn-danger btn-sm shuffleButton removeShuffleCardset"
......
......@@ -196,6 +196,24 @@ Template.cardsetRow.helpers({
Template.shuffle.events({
'click #createShuffledCardset': function () {
Session.set("ShuffleTemplate", Cardsets.findOne({_id: Session.get("ShuffledCardsets")[0]}));
},
'click #updateShuffledCardset': function () {
let removedCardsets = $(Cardsets.findOne({_id: Router.current().params._id}).cardGroups).not(Session.get("ShuffledCardsets")).get();
Meteor.call("updateShuffleGroups", Router.current().params._id, Session.get("ShuffledCardsets"), removedCardsets, function (error, result) {
if (error) {
Bert.alert(TAPi18n.__('set-list.shuffleUpdateFailure'), 'danger', 'growl-bottom-right');
}
if (result) {
Bert.alert(TAPi18n.__('set-list.shuffleUpdateSuccess'), 'success', 'growl-bottom-right');
Router.go('cardsetdetailsid', {_id: Router.current().params._id});
}
});
},
'click #cancelUpdateShuffle': function () {
Router.go('cardsetdetailsid', {_id: Router.current().params._id});
},
'click #removeShuffledCards': function () {
Session.set("ShuffledCardsets", []);
}
});
......@@ -204,6 +222,9 @@ Template.shuffle.helpers({
return TAPi18n.__('set-list.shuffleInfoText');
},
shuffleList: function () {
if (Router.current().route.getName() === "editshuffle") {
Session.set("ShuffledCardsets", Cardsets.findOne({_id: Router.current().params._id}).cardGroups);
}
let learnCards = Learned.find({
user_id: Meteor.userId()
});
......@@ -234,7 +255,17 @@ Template.shuffle.helpers({
});
},
gotShuffledCards: function () {
return Session.get("ShuffledCardsets").length > 1;
if (ActiveRoute.name('shuffle')) {
return Session.get("ShuffledCardsets").length > 0;
} else {
return true;
}
},
displayRemoveButton: function () {
return Session.get("ShuffledCardsets").length > 0;
},
isActiveCardset: function () {
return this._id === Router.current().params._id;
}
});
......
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