Commit 07e4e7fe authored by Curtis Adam's avatar Curtis Adam

Store the cardset _id inside the user transcripts statistic loop

parent 3f903e48
......@@ -3,7 +3,6 @@ import {Meteor} from "meteor/meteor";
import {Cardsets} from "./cardsets";
import {UserPermissions} from "./permissions";
import {SimpleSchema} from "meteor/aldeed:simple-schema";
import {Route} from "./route.js";
import {check} from "meteor/check";
import {Utilities} from "./utilities";
import * as config from "../config/transcriptBonus.js";
......@@ -208,13 +207,10 @@ export let TranscriptBonusList = class TranscriptBonusList {
}
}
static getAchievedBonus (user_id) {
let cardset = Cardsets.findOne({_id: Router.current().params._id}, {fields: {transcriptBonus: 1}});
static getAchievedBonus (cardset_id, user_id) {
let cardset = Cardsets.findOne({_id: cardset_id}, {fields: {transcriptBonus: 1}});
if (cardset !== undefined) {
let query = {user_id: user_id, rating: 1};
if (Route.isTranscriptBonus()) {
query.cardset_id = Router.current().params._id;
}
let query = {cardset_id: cardset_id, user_id: user_id, rating: 1};
let acceptedTranscripts = TranscriptBonus.find(query).count();
if (acceptedTranscripts === 0 || cardset.transcriptBonus.minimumSubmissions === 0) {
return 0;
......@@ -235,11 +231,8 @@ export let TranscriptBonusList = class TranscriptBonusList {
}
}
static getSubmissions (user_id, rating) {
let query = {user_id: user_id};
if (Route.isTranscriptBonus()) {
query.cardset_id = Router.current().params._id;
}
static getSubmissions (cardset_id, user_id, rating) {
let query = {cardset_id: cardset_id, user_id: user_id};
if (rating !== undefined) {
query.rating = rating;
}
......
......@@ -2,7 +2,7 @@
<tr>
<td>
{{{getBonusTranscriptRating 1}}}
{{#if (getSubmissions this._id 1)}}
{{#if (getSubmissions this.cardset_id this.user_id 1)}}
<a href=""
class="filterSubmissionsRating cards-filter-element"
data-id="{{this._id}}" data-rating="1">{{_
......@@ -12,7 +12,7 @@
{{/if}}
</td>
<td>
{{getSubmissions this._id 1}}
{{getSubmissions this.cardset_id this.user_id 1}}
</td>
</tr>
</template>
......@@ -11,7 +11,7 @@ Template.cardsetIndexTranscriptStatisticsItemUserAccepted.helpers({
getBonusTranscriptRating: function (type) {
return TranscriptBonusList.getBonusTranscriptRating(type);
},
getSubmissions: function (user_id, type) {
return TranscriptBonusList.getSubmissions(user_id, type);
getSubmissions: function (cardset_id, user_id, type) {
return TranscriptBonusList.getSubmissions(cardset_id, user_id, type);
}
});
<template name="cardsetIndexTranscriptStatisticsItemUserAuthor">
<tr>
<th colspan="2">
{{getAuthorName this._id}}
{{getAuthorName this.user_id}}
</th>
</tr>
</template>
......@@ -4,7 +4,7 @@
<i class="transcript-achieved-bonus fas fa-award"></i>&nbsp;{{_ "transcriptForm.bonus.statistics.bonus"}}:
</td>
<td>
{{getAchievedBonus this._id}}&nbsp;%
{{getAchievedBonus this.cardset_id this.user_id}}&nbsp;%
</td>
</tr>
</template>
......@@ -8,7 +8,7 @@ import {TranscriptBonusList} from "../../../../../../../api/transcriptBonus";
*/
Template.cardsetIndexTranscriptStatisticsItemUserBonus.helpers({
getAchievedBonus: function (user_id) {
return TranscriptBonusList.getAchievedBonus(user_id);
getAchievedBonus: function (cardset_id, user_id) {
return TranscriptBonusList.getAchievedBonus(cardset_id, user_id);
}
});
......@@ -2,7 +2,7 @@
<tr>
<td>
{{{getBonusTranscriptRating 2}}}
{{#if (getSubmissions this._id 1)}}
{{#if (getSubmissions this.cardset_id this.user_id 1)}}
<a href="" class="filterSubmissionsRating cards-filter-element" data-id="{{this._id}}"
data-rating="2">{{_
"transcriptForm.bonus.statistics.denied"}}:</a>
......@@ -11,7 +11,7 @@
{{/if}}
</td>
<td>
{{getSubmissions this._id 2}}
{{getSubmissions this.cardset_id this.user_id 2}}
</td>
</tr>
</template>
......@@ -11,7 +11,7 @@ Template.cardsetIndexTranscriptStatisticsItemUserDenied.helpers({
getBonusTranscriptRating: function (type) {
return TranscriptBonusList.getBonusTranscriptRating(type);
},
getSubmissions: function (user_id, type) {
return TranscriptBonusList.getSubmissions(user_id, type);
getSubmissions: function (cardset_id, user_id, type) {
return TranscriptBonusList.getSubmissions(cardset_id, user_id, type);
}
});
......@@ -4,7 +4,7 @@
<i class="far fa-calendar"></i>&nbsp;{{_ "transcriptForm.bonus.statistics.lastSubmission"}}:
</td>
<td>
{{lastSubmission this._id}}
{{lastSubmission this.cardset_id this.user_id}}
</td>
</tr>
</template>
......@@ -8,8 +8,8 @@ import {TranscriptBonus, TranscriptBonusList} from "../../../../../../../api/tra
*/
Template.cardsetIndexTranscriptStatisticsItemUserLastSubmission.helpers({
lastSubmission: function (id) {
let bonusTranscript = TranscriptBonus.findOne({user_id: id}, {sort: {date: -1}});
lastSubmission: function (cardset_id, user_id) {
let bonusTranscript = TranscriptBonus.findOne({cardset_id: cardset_id, user_id: user_id}, {sort: {date: -1}});
if (bonusTranscript !== undefined) {
return TranscriptBonusList.getLectureName(bonusTranscript, false);
}
......
<template name="cardsetIndexTranscriptStatisticsItemUserPending">
<tr>
<td>
{{{getBonusTranscriptRating 0}}}&nbsp;
{{#if (getSubmissions this._id 0)}}
{{{getBonusTranscriptRating 0}}}
{{#if (getSubmissions this.cardset_id this.user_id 0)}}
<a href="" class="filterSubmissionsRating cards-filter-element" data-id="{{this._id}}"
data-rating="0">{{_ "transcriptForm.bonus.statistics.pending"}}:</a>
{{else}}
......@@ -10,7 +10,7 @@
{{/if}}
</td>
<td>
{{getSubmissions this._id 0}}
{{getSubmissions this.cardset_id this.user_id 0}}
</td>
</tr>
</template>
......@@ -11,7 +11,7 @@ Template.cardsetIndexTranscriptStatisticsItemUserPending.helpers({
getBonusTranscriptRating: function (type) {
return TranscriptBonusList.getBonusTranscriptRating(type);
},
getSubmissions: function (user_id, type) {
return TranscriptBonusList.getSubmissions(user_id, type);
getSubmissions: function (cardset_id, user_id, type) {
return TranscriptBonusList.getSubmissions(cardset_id, user_id, type);
}
});
......@@ -2,7 +2,7 @@
<tr>
<td>
<i class="fas fa-clipboard"></i>&nbsp;
{{#if (getSubmissions this._id undefined)}}
{{#if (getSubmissions this.cardset_id this.user_id undefined)}}
<a href="" class="filterTranscriptSubmissions cards-filter-element"
data-id="{{this._id}}">{{_ "transcriptForm.info.submissions"}}:</a>
{{else}}
......@@ -10,7 +10,7 @@
{{/if}}
</td>
<td>
{{getSubmissions this._id undefined}}
{{getSubmissions this.cardset_id this.user_id undefined}}
</td>
</tr>
</template>
......@@ -8,7 +8,7 @@ import {TranscriptBonusList} from "../../../../../../../api/transcriptBonus";
*/
Template.cardsetIndexTranscriptStatisticsItemUserSubmissions.helpers({
getSubmissions: function (user_id, type) {
return TranscriptBonusList.getSubmissions(user_id, type);
getSubmissions: function (cardset_id, user_id, type) {
return TranscriptBonusList.getSubmissions(cardset_id, user_id, type);
}
});
......@@ -35,7 +35,12 @@ Template.cardsetIndexTranscriptStatistics.helpers({
}).fetch().map(function (x) {
return x.user_id;
}), true);
return Meteor.users.find({_id: {$in: transcriptBonusUsers}}, {sort: {"profile.birthname": 1}, fields: {_id: 1}}).fetch();
let users = Meteor.users.find({_id: {$in: transcriptBonusUsers}}, {sort: {"profile.birthname": 1}, fields: {_id: 1}}).fetch();
let list = [];
for (let i = 0; i < users.length; i++) {
list.push({user_id: users[i]._id, cardset_id: Router.current().params._id});
}
return list;
},
getSubmissions: function (id, rating = undefined) {
let query = {cardset_id: Router.current().params._id, user_id: 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