Commit af69e912 authored by Curtis Adam's avatar Curtis Adam

Rework wordcloud and display more information for wordcloud items

parent 4050784b
......@@ -2,6 +2,7 @@ import {Meteor} from "meteor/meteor";
import {Leitner} from "./learned.js";
import {Cardsets} from "./cardsets.js";
import {check} from "meteor/check";
import {Session} from "meteor/session";
/**
* Returns the degree, the givenname and the birthname from the author of a cardset
......@@ -9,7 +10,17 @@ import {check} from "meteor/check";
* @returns {*} - Degree + givenname + birthname
*/
export function getAuthorName(owner) {
var author = Meteor.users.findOne({"_id": owner});
let author;
if (Router.current().route.getName() === "home") {
Meteor.call('getWordcloudUserName', owner, function (error, result) {
if (result) {
Session.set('wordcloudAuthor', result);
}
});
author = Session.get('wordcloudAuthor');
} else {
author = Meteor.users.findOne({"_id": owner});
}
if (author) {
var degree = "";
if (author.profile.title) {
......@@ -48,8 +59,8 @@ function getCardsetInfo(cardset) {
[TAPi18n.__('cardset.info.college'), cardset.college],
[TAPi18n.__('cardset.info.course'), cardset.course],
[TAPi18n.__('cardset.info.author'), getAuthorName(cardset.owner)],
[TAPi18n.__('cardset.info.release'), moment(cardset.date).locale("de").format('LL')],
[TAPi18n.__('cardset.info.dateUpdated'), moment(cardset.dateUpdated).locale("de").format('LL')]
[TAPi18n.__('cardset.info.release'), moment(cardset.date).locale("de").format('LL')],
[TAPi18n.__('cardset.info.dateUpdated'), moment(cardset.dateUpdated).locale("de").format('LL')]
];
}
......@@ -228,5 +239,16 @@ Meteor.methods({
$pull: {editors: Meteor.userId()}
});
}
},
getWordcloudUserName: function (owner_id) {
if (Cardsets.findOne({owner: owner_id, wordcloud: true, visible: true})) {
return Meteor.users.findOne({_id: owner_id}, {
fields: {
"profile.title": 1,
"profile.givenname": 1,
"profile.birthname": 1
}
});
}
}
});
......@@ -17,29 +17,56 @@ if (Meteor.isServer) {
universityFilter = Meteor.settings.public.university.default;
}
Meteor.publish("cardsets", function () {
if (Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
return Cardsets.find({college: universityFilter});
} else if (Roles.userIsInRole(this.userId, 'lecturer')) {
return Cardsets.find(
{
college: universityFilter,
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
} else if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
return Cardsets.find(
if (this.userId) {
if (Roles.userIsInRole(this.userId, [
'admin',
'editor'
])) {
return Cardsets.find({college: universityFilter});
} else if (Roles.userIsInRole(this.userId, 'lecturer')) {
return Cardsets.find(
{
college: universityFilter,
$or: [
{visible: true},
{request: true},
{owner: this.userId}
]
});
} else if (this.userId && !Roles.userIsInRole(this.userId, ["firstLogin", "blocked"])) {
return Cardsets.find(
{
college: universityFilter,
$or: [
{visible: true},
{owner: this.userId}
]
});
}
} else {
return Cardsets.find({wordcloud: true, college: universityFilter},
{
college: universityFilter,
$or: [
{visible: true},
{owner: this.userId}
]
fields:
{
_id: 1,
owner: 1,
name: 1,
quantity: 1,
kind: 1,
description: 1,
cardType: 1,
difficulty: 1,
college: 1,
course: 1,
moduleActive: 1,
module: 1,
moduleToken: 1,
moduleNum: 1,
date: 1,
dateUpdated: 1,
wordcloud: 1,
cardGroups: 1
}
});
}
});
......@@ -348,7 +375,6 @@ Meteor.methods({
Ratings.remove({
cardset_id: id
});
Meteor.call("updateWordsForWordcloud");
},
deleteCards: function (id) {
check(id, String);
......
import {Meteor} from "meteor/meteor";
import {Mongo} from "meteor/mongo";
export const Cloud = new Mongo.Collection("wordcloud");
if (Meteor.isServer) {
Meteor.publish("wordcloud", function () {
return Cloud.find({}, {fields: {_id: 1, list: 1}});
});
}
......@@ -8,7 +8,6 @@ import {Notifications} from "./notifications.js";
import {Paid} from "./paid.js";
import {Ratings} from "./ratings.js";
import {Categories} from "./settings.js";
import {Cloud} from "./cloud.js";
Ground.Collection(Meteor.users);
Ground.Collection(AdminSettings);
......@@ -22,4 +21,3 @@ Ground.Collection(Notifications);
Ground.Collection(Paid);
Ground.Collection(Ratings);
Ground.Collection(Categories);
Ground.Collection(Cloud);
......@@ -216,12 +216,24 @@ Template.registerHelper("isShuffledCardset", function (cardset_id) {
// Returns the locale date
Template.registerHelper("getDate", function () {
return moment(this.date).locale(getUserLanguage()).format('LL');
let date;
if (Router.current().route.getName() === "welcome") {
date = Session.get('wordcloudItem')[10];
} else {
date = this.date;
}
return moment(date).locale(getUserLanguage()).format('LL');
});
// Returns the locale date
Template.registerHelper("getDateUpdated", function () {
return moment(this.dateUpdated).locale(getUserLanguage()).format('LL');
let dateUpdated;
if (Router.current().route.getName() === "welcome") {
dateUpdated = Session.get('wordcloudItem')[11];
} else {
dateUpdated = this.dateUpdated;
}
return moment(dateUpdated).locale(getUserLanguage()).format('LL');
});
// Returns the locale date with time
......
......@@ -2,6 +2,7 @@ import {Cardsets} from "../../api/cardsets.js";
import {Cards} from "../../api/cards.js";
import {Leitner, Wozniak} from "../../api/learned";
import {Meteor} from "meteor/meteor";
import {Session} from "meteor/session";
Router.route('/', function () {
this.redirect('home');
......@@ -21,7 +22,10 @@ Router.configure({
Router.route('/home', {
name: 'home',
template: 'welcome'
template: 'welcome',
data: function () {
return Cardsets.findOne({_id: Session.get('wordcloudItem')});
}
});
Router.route('about', {
......
......@@ -655,8 +655,5 @@ Meteor.startup(function () {
for (let learned = 0; learned < testNotificationsLearned.length; learned++) {
Leitner.insert(testNotificationsLearned[learned]);
}
Meteor.call("updateWordsForWordcloud");
cronScheduler.startCron();
cronScheduler.startWordCron();
});
This diff is collapsed.
......@@ -418,6 +418,35 @@ Template.cardsetInfoBox.onRendered(function () {
});
Template.cardsetInfoBox.helpers({
getColors: function () {
switch (this.kind) {
case "personal":
return "btn-warning";
case "free":
return "btn-info";
case "edu":
return "btn-success";
case "pro":
return "btn-danger";
}
},
getName: function () {
let shuffled = "";
if (this.shuffled) {
shuffled = TAPi18n.__('admin.shuffled') + " ";
}
return shuffled;
}
});
/*
* ############################################################################
* cardsetInfoBoxContent
* ############################################################################
*/
Template.cardsetInfoBoxContent.helpers({
canViewForFree: function () {
return (this.kind === "edu" && (Roles.userIsInRole(Meteor.userId(), ['university', 'lecturer'])));
},
......@@ -433,6 +462,17 @@ Template.cardsetInfoBox.helpers({
if (cardset !== null) {
return count !== 0;
}
}, getAuthors: function () {
let cardsets = this.cardGroups;
let owner_id = [];
cardsets.push(this._id);
let owners = _.uniq(Cardsets.find({_id: {$in: cardsets}}, {fields: {owner: 1}}).fetch(), function (item) {
return item.owner;
});
owners.forEach(function (element) {
owner_id.push(element.owner);
});
return owners;
},
getUserRating: function () {
var userrating = Ratings.findOne({
......@@ -448,25 +488,6 @@ Template.cardsetInfoBox.helpers({
hasAmount: function () {
return this.kind === 'pro' || this.kind === 'edu';
},
getColors: function () {
switch (this.kind) {
case "personal":
return "btn-warning";
case "free":
return "btn-info";
case "edu":
return "btn-success";
case "pro":
return "btn-danger";
}
},
getName: function () {
let shuffled = "";
if (this.shuffled) {
shuffled = TAPi18n.__('admin.shuffled') + " ";
}
return shuffled;
},
isPurchased: function () {
return Paid.findOne({cardset_id: this._id}) !== undefined;
},
......@@ -495,7 +516,7 @@ Template.cardsetInfoBox.helpers({
}
});
Template.cardsetInfoBox.events({
Template.cardsetInfoBoxContent.events({
'click #rating': function () {
var cardset_id = Template.parentData(1)._id;
var rating = $('#rating').data('userrating');
......@@ -510,6 +531,7 @@ Template.cardsetInfoBox.events({
}
}
});
/*
* ############################################################################
* leaveLearnPhaseForm
......@@ -811,21 +833,6 @@ Template.cardsetInfoBox.events({
}
});
Template.cardsetInfoBox.helpers({
getAuthors: function () {
let cardsets = this.cardGroups;
let owner_id = [];
cardsets.push(Router.current().params._id);
let owners = _.uniq(Cardsets.find({_id: {$in: cardsets}}, {fields: {owner: 1}}).fetch(), function (item) {
return item.owner;
});
owners.forEach(function (element) {
owner_id.push(element.owner);
});
return Meteor.users.find({_id: {$in: owner_id}}, {sort: {'profile.birthname': 1}, fields: {profile: 1}});
}
});
/*
* ############################################################################
* cardsetLearnActivityStatistic
......
......@@ -922,7 +922,7 @@ th {
color: white;
}
.hintContent .modal-header {
.hintContent .modal-header, .wordCloudDescription {
border-bottom: 1px solid white;
}
......
......@@ -34,20 +34,26 @@
<div class="modal-content hintContent">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 id="wordcloudTitle" class="modal-title">{{getWordcloudSubject}}</h4>
<h4 id="wordcloudTitle" class="modal-title">{{this.name}}</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<div class="col-md-12 wordCloudDescription">
<table class="table">
<tr>
<td>
{{getWordcloudContent}}
{{this.description}}
</td>
</tr>
</table>
</div>
<div class="col-md-12">
<br>
<table class="table">
{{> cardsetInfoBoxContent}}
</table>
</div>
</div>
</div>
</div>
......
......@@ -3,12 +3,12 @@
import {Meteor} from "meteor/meteor";
import {Template} from "meteor/templating";
import WordCloud from "wordcloud";
import {Cloud} from "../../api/cloud.js";
import {Cardsets} from "../../api/cardsets.js";
import {getUserLanguage} from "../../startup/client/i18n";
import "./welcome.html";
import {Session} from "meteor/session";
Meteor.subscribe("wordcloud");
Meteor.subscribe("cardsets");
function setActiveLanguage() {
let language = getUserLanguage();
......@@ -21,7 +21,7 @@ function setActiveLanguage() {
* @param {Object} item - Array containing data of the wordcloud object (name, description, kind and color)
*/
function wordcloudClick(item) {
Session.set('wordcloudItem', item);
Session.set('wordcloudItem', item[2]);
$('#wordcloudModal').modal('show');
}
......@@ -45,14 +45,29 @@ function createTagCloud() {
}
$('#tag-cloud-canvas').css('height', 'unset');
$('#tag-cloud-container').css('height', 'unset');
let cloud = Cloud.find({}).fetch();
let cloud = Cardsets.find({wordcloud: true}, {fields: {name: 1, quantity: 1}}).fetch();
let minimumSize = 10;
let biggestCardsetSize = 0;
cloud.forEach(function (cloud) {
if (cloud.quantity > biggestCardsetSize) {
biggestCardsetSize = cloud.quantity;
}
});
let list = [];
cloud.forEach(function (cloud) {
let name = cloud.name;
if (cloud.length > 0) {
list = cloud[0].list;
} else {
return;
}
if (name.length > 30) {
name = name.substring(0, 30) + "";
}
let quantitiy = cloud.quantity / biggestCardsetSize * 40;
quantitiy = (quantitiy > minimumSize ? quantitiy : minimumSize);
list.push([name, Number(quantitiy), cloud._id]);
});
list.sort(function (a, b) {
return (b[0].length * b[1]) - (a[0].length * a[1]);
});
document.getElementById('tag-cloud-canvas').height = $(window).height() - ($('.panel-heading').outerHeight(true) + $('#login').outerHeight(true));
document.getElementById('tag-cloud-canvas').width = document.getElementById('tag-cloud-container').offsetWidth;
let textScale = 1.2;
......@@ -138,15 +153,6 @@ Template.welcome.events({
}
});
Template.wordcloudModal.helpers({
getWordcloudSubject: function () {
return Session.get('wordcloudItem')[0];
},
getWordcloudContent: function () {
return Session.get('wordcloudItem')[3];
}
});
Template.welcome.onRendered(function () {
if (Meteor.settings.public.displayLoginButtons.displayCas) {
$('.panel-footer').append('<a id="cas" href=""><img src="img/gruen_eckig_Doktorhut.png" alt="use CAS for login"/></a>');
......
......@@ -18,15 +18,4 @@ export class CronScheduler {
});
SyncedCron.start();
}
startWordCron () {
SyncedCron.add({
name: "wordCron",
schedule: function (parser) {
return parser.recur().on('02:00:00').time();
},
job: function () {
Meteor.call("updateWordsForWordcloud");
}
});
}
}
......@@ -19,6 +19,5 @@ import "../imports/api/upload.js";
import "../imports/api/userdata.js";
import "../imports/api/webPushSubscriptions.js";
import "./leitner.js";
import "./wordcloud.js";
WebApp.addHtmlAttributeHook(() => ({lang: 'de'}));
import {Meteor} from "meteor/meteor";
import {Cardsets} from "../imports/api/cardsets.js";
import {Cloud} from "../imports/api/cloud.js";
Meteor.methods({
updateWordsForWordcloud: function () {
if (!Meteor.isServer) {
throw new Meteor.Error("not-authorized");
} else {
const MINIMUM_SIZE = 10;
var cardsets;
if (Meteor.settings.public.university.singleUniversity) {
cardsets = Cardsets.find({wordcloud: true}, {
fields: {
_id: 1,
name: 1,
quantity: 1,
kind: 1,
description: 1
}
});
} else {
cardsets = Cardsets.find({wordcloud: true, college: Meteor.settings.public.university.default}, {
fields: {
_id: 1,
name: 1,
quantity: 1,
kind: 1,
description: 1
}
});
}
var list = [];
// find biggest cardset for normalization
var biggestCardsetSize = 0;
cardsets.forEach(function (cardset) {
if (cardset.quantity > biggestCardsetSize) {
biggestCardsetSize = cardset.quantity;
}
});
cardsets.forEach(function (cardset) {
var name = cardset.name;
if (name.length > 30) {
name = name.substring(0, 30) + "";
}
var colors = ["#003bd1", "#80ba24", "#ffb300"];
var color = colors[0];
switch (cardset.kind) {
case "free":
color = colors[0];
break;
case "edu":
color = colors[1];
break;
case "pro":
color = colors[2];
break;
}
var quantitiy = cardset.quantity / biggestCardsetSize * 40;
quantitiy = (quantitiy > MINIMUM_SIZE ? quantitiy : MINIMUM_SIZE);
list.push([name, quantitiy, color, cardset.description, cardset._id]);
});
list.sort(function (a, b) { return (b[0].length * b[1]) - (a[0].length * a[1]); });
Cloud.remove({});
Cloud.insert({'list': list});
}
}
});
......@@ -10,7 +10,7 @@ checkDirectory
declare -a BLACKLISTEDFILES=("adminSettings.bson" "badges.bson" "colorThemes.bson" "cronHistory.bson" "experience.bson"
"notifications.bson" "system.indexes.bson" "webPushSubscriptions.bson" "roles.bson"
"meteor_accounts_loginServiceConfiguration.bson" "meteor_oauth_pendingCredentials.bson"
"meteor_oauth_pendingRequestTokens.bson")
"meteor_oauth_pendingRequestTokens.bson" "wordcloud.bson")
#Dump the Test-Database
echo -e $GREEN"Dumping the Test-Database..." $NC
......
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