comments are displayed, comment server bug

This commit is contained in:
Kenneth Jao 2016-08-27 19:29:51 -04:00
parent 5281bf4117
commit 6b2e56f067
3 changed files with 38 additions and 12 deletions

View File

@ -128,24 +128,24 @@
<p class="workOptionText">Other</p> <p class="workOptionText">Other</p>
</div> </div>
</div> </div>
<div id="workAttach">Attach other files</div> <!-- <div id="workAttach">Attach other files</div>
<div id="workAttachmentHolder"> <div id="workAttachmentHolder">
{{#each work 'attachments'}} {{#each work 'attachments'}}
<a href={{link}}>{{filename}}</a> <a href={{link}}>{{filename}}</a>
{{/each}} {{/each}}
</div> </div> -->
{{#unless newWork}} {{#unless newWork}}
<div id="workComments"> <div id="workComments">
<div> <h3>Comments</h3>
<h3>Comments</h3>
<textarea id="workComment" rows="4" cols="50"></textarea>
<div id="commentSubmit">Submit</div>
</div>
<div id="comment"> <div id="comment">
{{#each work 'comments'}} {{#each work 'comments'}}
{{> comment}} {{> comment}}
{{/each}} {{/each}}
</div> </div>
<div>
<textarea id="workComment" rows="4" cols="50"></textarea>
<div id="commentSubmit">Submit</div>
</div>
</div> </div>
{{/unless}} {{/unless}}
</div> </div>
@ -201,3 +201,11 @@
</div> </div>
</div> </div>
</template> </template>
<template name="comment">
<div class="commentBox">
<span class="commentComment">{{comment}}</span>
<span class="commentUser">{{user}}</span>
<span class="commentDate">{{date}}</span>
</div>
</template>

View File

@ -671,7 +671,9 @@ Template.main.events({
}, },
'click #commentSubmit' (event) { 'click #commentSubmit' (event) {
workId = Session.get("currentWork")._id; workId = Session.get("currentWork")._id;
comment = document.getElementById('workComment').value; var input = document.getElementById('workComment');
comment = input.value;
input.value = "";
if (comment !== "") { if (comment !== "") {
document.getElementById('workComment').value = ""; document.getElementById('workComment').value = "";
Meteor.call('addComment', [comment, workId]); Meteor.call('addComment', [comment, workId]);
@ -889,5 +891,18 @@ function toDate(date) {
function formReadable(input) { function formReadable(input) {
input.dueDate = getReadableDate(input.dueDate); input.dueDate = getReadableDate(input.dueDate);
input.type = input.type[0].toUpperCase() + input.type.slice(1); input.type = input.type[0].toUpperCase() + input.type.slice(1);
var comments = input.comments;
for(var k = 0; k < comments.length; k++) {
comments[k].user = Meteor.users.findOne({_id:comments[k].user}).profile.name;
comments[k].date = moment(comments[k].date).calendar(null, { //change to time if recently posted
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'MMMM Do'
});
}
input.comments = comments;
return input; return input;
} }

View File

@ -434,14 +434,17 @@ Meteor.methods({
if (typeof comment === "string" && comment.length <= 200 && if (typeof comment === "string" && comment.length <= 200 &&
foundsubs.indexOf(Meteor.userId()) != -1 && foundsubs.indexOf(Meteor.userId()) != -1 &&
currentclass.banned.indexOf(Meteor.userId()) === -1) { currentclass.banned.indexOf(Meteor.userId()) === -1) {
var comments = workobject.comments.concat(comment); commentInfo = {
"comment":input[0],
"user":user,
"date": new Date()
};
var comments = workobject.comments.concat(commentInfo);
work.update({ work.update({
_id: input[1] _id: input[1]
}, { }, {
$set: { $set: {
comments: comments, comments: comments
user: user,
time: new Date()
} }
}); });
} else { } else {