Commit a496c268 authored by Curtis Adam's avatar Curtis Adam

Add the abillity to remove users from a bonus

parent 5271d9a5
......@@ -1317,6 +1317,24 @@
"percentage": "Prozent",
"user": {
"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",
......
......@@ -66,7 +66,7 @@ function sortByBirthname(data) {
return data;
}
function getLearners(data, cardset_id) {
export function getLearners(data, cardset_id) {
let learningDataArray = [];
for (let i = 0; i < data.length; i++) {
let user = Meteor.users.find({_id: data[i].user_id}).fetch();
......
......@@ -2,6 +2,8 @@ import {Meteor} from "meteor/meteor";
import {Mongo} from "meteor/mongo";
import {Cardsets} from "./cardsets.js";
import {check} from "meteor/check";
import {UserPermissions} from "./permissions";
import {getLearners} from "./cardsetUserlist";
export const Learned = new Mongo.Collection("learned");
export const Leitner = new Mongo.Collection("leitner");
......@@ -264,6 +266,29 @@ if (Meteor.isServer) {
} else {
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");
}
}
});
}
......@@ -565,3 +565,8 @@ th .field-tip {
.cardsetstats-container {
padding: 0 15px;
}
.removeBonusUser {
margin: 0;
padding: 0 !important;
}
......@@ -8,6 +8,7 @@
{{#unless isEditor}}
{{> access_denied_content_only}}
{{else}}
{{> removeUserFromBonusModal}}
<div class="cardsetstats-container">
<div id="cardsetInfoDetail">
<div class="panel panel-default cardsetInfo">
......@@ -49,6 +50,7 @@
</th>
<th>{{_ "leitnerProgress.learned"}}</th>
<th>{{_ "details"}}</th>
<th>{{_ "leitnerProgress.manage"}}</th>
</tr>
{{#each getCardsetStats}}
<tr>
......@@ -76,7 +78,27 @@
<td>
<button data-id="{{this.user_id}}" class="btn btn-block detailed-stats"><i
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>
</tr>
{{/each}}
......
......@@ -3,6 +3,7 @@ import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
import {Template} from "meteor/templating";
import {Cardsets} from "../../../../api/cardsets";
import "./modal/removeUser.js";
import "./bonus.html";
/*
......@@ -75,6 +76,20 @@ Template.cardsetLearnActivityStatistic.events({
event.stopPropagation();
Session.set('helpFilter', "leitner");
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");
}
}
});
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