Commit 910de920 authored by Klaus-Dieter Quibeldey-Cirkel's avatar Klaus-Dieter Quibeldey-Cirkel 🏀

Merge branch '1413-add-the-abillity-to-remove-users-from-a-bonus' into 'staging'

Resolve "Add the abillity to remove users from a bonus"

Closes #1413

See merge request arsnova/flashcards!1715
parents 77cff4e5 a496c268
...@@ -1317,6 +1317,24 @@ ...@@ -1317,6 +1317,24 @@
"percentage": "Prozent", "percentage": "Prozent",
"user": { "user": {
"missingName": "Unvollständig" "missingName": "Unvollständig"
},
"manage": "Verwalten",
"modal": {
"removeUser": {
"title": "Benutzer aus der Bonusphase entfernen?",
"text": "Möchtest Du diesen Datensatz aus der Bonusphase entfernen?",
"button": {
"confirm": "Benutzer aus der Bonusphase entfernen",
"cancel": "Abbrechen"
}
}
},
"tooltip": {
"removeUser": "Benutzer aus der Bonusphase entfernen",
"graph": "Statistik anzeigen"
},
"bertAlert": {
"userRemoved": "Benutzer wurde aus der Bonusphase entfernt"
} }
}, },
"permission": "Kein Zugang", "permission": "Kein Zugang",
......
...@@ -66,7 +66,7 @@ function sortByBirthname(data) { ...@@ -66,7 +66,7 @@ function sortByBirthname(data) {
return data; return data;
} }
function getLearners(data, cardset_id) { export function getLearners(data, cardset_id) {
let learningDataArray = []; let learningDataArray = [];
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
let user = Meteor.users.find({_id: data[i].user_id}).fetch(); let user = Meteor.users.find({_id: data[i].user_id}).fetch();
......
...@@ -2,6 +2,8 @@ import {Meteor} from "meteor/meteor"; ...@@ -2,6 +2,8 @@ import {Meteor} from "meteor/meteor";
import {Mongo} from "meteor/mongo"; import {Mongo} from "meteor/mongo";
import {Cardsets} from "./cardsets.js"; import {Cardsets} from "./cardsets.js";
import {check} from "meteor/check"; import {check} from "meteor/check";
import {UserPermissions} from "./permissions";
import {getLearners} from "./cardsetUserlist";
export const Learned = new Mongo.Collection("learned"); export const Learned = new Mongo.Collection("learned");
export const Leitner = new Mongo.Collection("leitner"); export const Leitner = new Mongo.Collection("leitner");
...@@ -264,6 +266,29 @@ if (Meteor.isServer) { ...@@ -264,6 +266,29 @@ if (Meteor.isServer) {
} else { } else {
throw new Meteor.Error("not-authorized"); throw new Meteor.Error("not-authorized");
} }
},
/** Removes an user from an active bonus
* @param {string} cardset_id - The cardset id of the cardset that is getting updated
* @param {string} user_id - The _id of the user who should be removed
* */
removeUserFromBonus: function (cardset_id, user_id) {
check(cardset_id, String);
check(user_id, String);
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {_id: 1, owner: 1}});
if (cardset !== undefined && (UserPermissions.isOwner(cardset.owner) || UserPermissions.isAdmin())) {
Workload.update({
user_id: user_id,
cardset_id: cardset_id
}, {
$set: {
"leitner.bonus": false
}
});
Meteor.call("updateLearnerCount", cardset._id);
return getLearners(Workload.find({cardset_id: cardset._id, 'leitner.bonus': true}).fetch(), cardset._id);
} else {
throw new Meteor.Error("not-authorized");
}
} }
}); });
} }
...@@ -560,4 +560,13 @@ th .field-tip { ...@@ -560,4 +560,13 @@ th .field-tip {
height: 16px; height: 16px;
margin-top: -2px; margin-top: -2px;
margin-right: 2px; margin-right: 2px;
} }
\ No newline at end of file
.cardsetstats-container {
padding: 0 15px;
}
.removeBonusUser {
margin: 0;
padding: 0 !important;
}
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
{{#unless isEditor}} {{#unless isEditor}}
{{> access_denied_content_only}} {{> access_denied_content_only}}
{{else}} {{else}}
<div class="container"> {{> removeUserFromBonusModal}}
<div class="cardsetstats-container">
<div id="cardsetInfoDetail"> <div id="cardsetInfoDetail">
<div class="panel panel-default cardsetInfo"> <div class="panel panel-default cardsetInfo">
<div class="panel-body"> <div class="panel-body">
...@@ -49,6 +50,7 @@ ...@@ -49,6 +50,7 @@
</th> </th>
<th>{{_ "leitnerProgress.learned"}}</th> <th>{{_ "leitnerProgress.learned"}}</th>
<th>{{_ "details"}}</th> <th>{{_ "details"}}</th>
<th>{{_ "leitnerProgress.manage"}}</th>
</tr> </tr>
{{#each getCardsetStats}} {{#each getCardsetStats}}
<tr> <tr>
...@@ -76,7 +78,27 @@ ...@@ -76,7 +78,27 @@
<td> <td>
<button data-id="{{this.user_id}}" class="btn btn-block detailed-stats"><i <button data-id="{{this.user_id}}" class="btn btn-block detailed-stats"><i
class="glyphicon glyphicon glyphicon-stats" class="glyphicon glyphicon glyphicon-stats"
data-id="{{this.user_id}}"></i></button> data-id="{{this.user_id}}"
title="{{_ "leitnerProgress.tooltip.graph"}}"></i></button>
</td>
<td>
<button class="btn btn-block removeBonusUser" data-toggle="modal"
href="#removeUserFromBonusModal" data-user_id="{{this.user_id}}"
data-firstname="{{this.birthname}}"
data-lastname="{{this.givenname}}"
data-email="{{this.email}}" data-box1="{{this.box1}}"
data-box2="{{this.box2}}" data-box3="{{this.box3}}"
data-box4="{{this.box4}}"
data-box5="{{this.box5}}" data-box6="{{this.box6}}"
title="{{_ "leitnerProgress.tooltip.removeUser"}}">
<i class="fa fa-trash" data-user_id="{{this.user_id}}"
data-firstname="{{this.birthname}}"
data-lastname="{{this.givenname}}"
data-email="{{this.email}}" data-box1="{{this.box1}}"
data-box2="{{this.box2}}" data-box3="{{this.box3}}"
data-box4="{{this.box4}}"
data-box5="{{this.box5}}" data-box6="{{this.box6}}">
</i></button>
</td> </td>
</tr> </tr>
{{/each}} {{/each}}
......
...@@ -3,6 +3,7 @@ import {Meteor} from "meteor/meteor"; ...@@ -3,6 +3,7 @@ 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 {Cardsets} from "../../../../api/cardsets"; import {Cardsets} from "../../../../api/cardsets";
import "./modal/removeUser.js";
import "./bonus.html"; import "./bonus.html";
/* /*
...@@ -75,6 +76,20 @@ Template.cardsetLearnActivityStatistic.events({ ...@@ -75,6 +76,20 @@ Template.cardsetLearnActivityStatistic.events({
event.stopPropagation(); event.stopPropagation();
Session.set('helpFilter', "leitner"); Session.set('helpFilter', "leitner");
Router.go('help'); Router.go('help');
},
"click .removeBonusUser": function (event) {
let user = {};
user.user_id = $(event.target).data('user_id');
user.firstName = $(event.target).data('firstname');
user.lastName = $(event.target).data('lastname');
user.email = $(event.target).data('email');
user.box1 = $(event.target).data('box1');
user.box2 = $(event.target).data('box2');
user.box3 = $(event.target).data('box3');
user.box4 = $(event.target).data('box4');
user.box5 = $(event.target).data('box5');
user.box6 = $(event.target).data('box6');
Session.set('removeBonusUser', user);
} }
}); });
......
<template name="removeUserFromBonusModal">
<div class="modal fade" id="removeUserFromBonusModal" tabindex="-1" role="dialog"
aria-labelledby="removeUserFromBonusTitle">
<div class="modal-dialog modal-lg">
<div class="modal-content modal-content-for-buttons">
<div class="modal-header">
<h4 id="removeUserFromBonusTitle" class="modal-title">{{_ "leitnerProgress.modal.removeUser.title"}}
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</h4>
</div>
<div class="modal-body">
{{_ "leitnerProgress.modal.removeUser.text"}}
{{#with userData}}
<table class="table table-striped table-hover table-user-list">
<tbody>
<tr>
<th>{{_ "panel-body.birthname"}}</th>
<th>{{_ "panel-body.givenname"}}</th>
<th>{{_ "panel-body.email"}}</th>
<th>{{_ "leitnerProgress.box" number=1}}</th>
<th>{{_ "leitnerProgress.box" number=2}}</th>
<th>{{_ "leitnerProgress.box" number=3}}</th>
<th>{{_ "leitnerProgress.box" number=4}}</th>
<th>{{_ "leitnerProgress.box" number=5}}</th>
<th>{{_ "leitnerProgress.learned"}}</th>
</tr>
<tr>
<td>
{{this.firstName}}
</td>
<td>
{{this.lastName}}
</td>
<td>
{{this.email}}
</td>
<td>
{{this.box1}}
</td>
<td>
{{this.box2}}
</td>
<td>
{{this.box3}}
</td>
<td>
{{this.box4}}
</td>
<td>
{{this.box5}}
</td>
<td>
{{this.box6}}
</td>
</tr>
</tbody>
</table>
<button id="removeUserFromBonusConfirm"
class="btn btn-raised btn-danger btn-block col-xs-12 col-sm-3">{{_
"leitnerProgress.modal.removeUser.button.confirm"}}</button>
<button id="removeUserFromBonusCancel"
class="btn btn-raised btn-default btn-block col-xs-12 col-sm-3"
data-dismiss="modal">{{_
"leitnerProgress.modal.removeUser.button.cancel"}}</button>
{{/with}}
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
</template>
//------------------------ IMPORTS
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import "./removeUser.html";
import {Meteor} from "meteor/meteor";
import {BertAlertVisuals} from "../../../../../api/bertAlertVisuals";
Session.setDefault('removeBonusUser', undefined);
/*
* ############################################################################
* removeUserFromBonusModal
* ############################################################################
*/
Template.removeUserFromBonusModal.onCreated(function () {
$('#removeUserFromBonusModal').on('hidden.bs.modal', function () {
Session.set('removeBonusUser', undefined);
});
});
Template.removeUserFromBonusModal.helpers({
userData: function () {
return Session.get('removeBonusUser');
}
});
Template.removeUserFromBonusModal.events({
"click #removeUserFromBonusConfirm": function () {
if (Session.get('removeBonusUser') !== undefined) {
Meteor.call('removeUserFromBonus', Router.current().params._id, Session.get('removeBonusUser').user_id, function (error, result) {
if (error) {
throw new Meteor.Error(error.statusCode, 'Error could not receive content for stats');
}
if (result) {
Session.set("learnerStats", result);
BertAlertVisuals.displayBertAlert(TAPi18n.__('leitnerProgress.bertAlert.userRemoved'), 'success', 'growl-top-left');
}
});
$('#removeUserFromBonusModal').modal("hide");
}
}
});
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
<div id="main" class="{{#if isActiveRoute <div id="main" class="{{#if isActiveRoute
regex='presentation'}}presentation-container{{else}}{{#if isActiveRoute regex='presentation'}}presentation-container{{else}}{{#if isActiveRoute
regex='home'}}{{else}}{{#if isActiveRoute regex='home'}}{{else}}{{#if isActiveRoute
regex='newCard|editCard'}}{{#if regex='newCard|editCard|cardsetstats'}}{{#if
fullscreenActive}}container{{else}}container-fluid{{/if}}{{else}}{{#unless fullscreenActive}}container{{else}}container-fluid{{/if}}{{else}}{{#unless
isFirstTimeVisit}}container{{/unless}}{{/if}}{{/if}}{{/if}}"> isFirstTimeVisit}}container{{/unless}}{{/if}}{{/if}}{{/if}}">
<!-- AREA BETWEEN NAVIGATION AND FOOTER --> <!-- AREA BETWEEN NAVIGATION AND FOOTER -->
......
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