Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested comment #82

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions app/client/common/comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template name="comment">


{{#with comment}}
<li class="comment">
<div class="editable" data-field="body" data-plain="true" data-content="{{body}}">
<span class="user">
<img src="{{avatarUrl user_id}}" height="18">
<a href="#">{{username user_id}}</a>
</span>

<p class="body">{{nl2br body}}</p>
<div class="comment_actions">
<span class=""><a href="#" class="reply">reply</a></span>
<span class=""><a href="#" class="edit_trigger">edit</a></span>
<span class=""><a href="#" class="delete_comment">delete</a></span>
</div>



{{#each attachmentsForComment _id}}
<div class="attachment">
{{#if fileIsImage file}}
<img src="/data/{{file}}">
{{else}}
<img src="{{fileIconPath file}}"> <a href="/data/{{file}}">{{file}}</a>
{{/if}}
</div>
{{/each}}


<form class="reply comment" name="comment">
<div class="form-group">
<textarea name="comment_body" class="form-control" placeholder="Write a comment."></textarea>
</div>
<div class="form-group text-right buttons">
<button class="ct btn reply btn-sm">Comment</button>
<button class="ct btn cancel_reply btn-sm">&times;</button>
</div>
</form>

</div>

{{#each childComments _id}}
<ul class="comments">
{{> comment comment=.}}
</ul>
{{/each}}
</li>
{{/with}}

</template>
47 changes: 47 additions & 0 deletions app/client/common/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Template.comment.helpers({
'childComments': function(id){
return Cento.Comments.find({parent_id: id});
}

});
Template.comment.events({

'click a.reply': function(e){
var $wrap = $(e.target).closest('.comment');
var $f = $wrap.find('form.reply:eq(0)');
$f.show();
$f.addClass('focus');
return false;
},
'click button.cancel_reply': function(e){
var $f = $(e.target).closest('form');
$f.hide();
$f.addClass('focus');
$f[0].reset();
return false;
},

'click button.reply': function(e){
var $f = $(e.target).closest('form');
var body = $f.find('textarea').val();

var parent = this;
var data = {body: body, parent_item_id: parent.parent_item_id, parent_id: parent._id, created:new Date(), user_id: Meteor.userId()};
Cento.Comments.insert(data);
Cento.WorkItems.update({_id: parent.parent_item_id}, {$inc: {comments_count: 1}});


$f[0].reset();
$f.hide();
return false;

},
'click .delete_comment': function(e, tpl){
var cid = this._id;
Cento.Comments.remove({_id:cid});
console.log("comment deleted : ", cid, pid);

return false;
},

});
29 changes: 2 additions & 27 deletions app/client/common/modal_comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,8 @@
</div>
</form>
<ul class="comments list-unstyled">
{{#each comments}}
<li class="comment">
<div class="editable" data-field="body" data-plain="true" data-content="{{body}}">
<span class="user">
<img src="{{avatarUrl user_id}}" height="18">
<a href="#">{{username user_id}}</a>
</span>

<p class="body">{{nl2br body}}</p>
<div class="comment_actions">
<span class=""><a href="#" class="edit_trigger">edit</a></span>
<span class=""><a href="#" class="delete_comment">delete</a></span>
</div>



{{#each attachmentsForComment _id}}
<div class="attachment">
{{#if fileIsImage file}}
<img src="/data/{{file}}">
{{else}}
<img src="{{fileIconPath file}}"> <a href="/data/{{file}}">{{file}}</a>
{{/if}}
</div>
{{/each}}
</div>
</li>
{{#each commentsForItem _id}}
{{> comment comment=. depth=123}}

{{/each}}
</ul>
Expand Down
27 changes: 12 additions & 15 deletions app/client/common/modal_comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Template.modal_comment.helpers({
},
'commentFiles': function(){
return Session.get('currentCommentFiles');
},
'commentsForItem': function(id){
return Cento.Comments.find({parent_item_id: id, parent_id: {$exists: false}});
}

});
Expand Down Expand Up @@ -61,13 +64,15 @@ Template.modal_comment.events({


if(this.type != null && this.type != ''){
var cid = Random.id();
Cento.WorkItems.update({_id: id},
{$inc: {comments_count: 1}, $push: {comments:{_id: cid, body: txt, 'created':new Date(), user_id: Meteor.userId()}}});

var data = {body: txt, parent_type: 'work_item', parent_item_id: id, created:new Date(), user_id: Meteor.userId()};
var newComment = Cento.Comments.insert(data);
Cento.WorkItems.update({_id: id}, {$inc: {comments_count: 1}});

attachments.forEach(function(a){
var data = {
work_item_id: id,
comment_id: cid,
comment_id: newComment._id,
file: a,
created: new Date(),
user_id: Meteor.userId()
Expand All @@ -80,23 +85,15 @@ Template.modal_comment.events({


}else{
Cento.Artifacts.update({_id: id},
{$push: {comments:{_id: Random.id(), body: txt, 'created':new Date(), user_id: Meteor.userId()}}});
var data = {body: txt, parent_type: 'artifact', parent_item_id: id, created:new Date(), user_id: Meteor.userId()};
var newComment = Cento.Comments.insert(data);
}
Cento.createAction(Cento.ActionTypes.COMMENT_ON_USERNEEDS, id, {body: txt});
// Cento.createAction(Cento.ActionTypes.COMMENT_ON_USERNEEDS, id, {body: txt});
f[0].reset();
Session.set('currentCommentFiles', null);
return false;
},

'click .delete_comment': function(e, tpl){
var pid = tpl.data._id;
var cid = this._id;
Cento.WorkItems.update({_id:pid}, {$pull:{comments:{_id: cid}}});
console.log("comment deleted : ", cid, pid);

return false;
},
'done .editable': function(e){
var $editable = $(e.target);
var $f = $editable.prev('form[name=edit]');
Expand Down
103 changes: 103 additions & 0 deletions app/client/styles/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -893,3 +893,106 @@ form.ct {
}

}




/* comments */
.comment_wrap {
margin-top: 10px;

form {

}

form.comment {
textarea {
height: 30px;
overflow-y: hidden;
-webkit-transition: height ease-in-out 85ms;

}
.buttons {
display: none;

}

&.focus {
textarea {
height: 90px;

}
.buttons {
display: block;

}

}

}
.files_to_upload {
font-size: 12px;

}
.buttons {
a, button {
display: inline-block;
margin-left: 10px;

}
a {
font-size: 12px;
color: @blue-color;
}

}
}
.comments {
position: relative;
list-style-type: none;


.comments {
background-color: @row-alt-bg-color;
padding: 0;
margin-left: 20px;
}
img {
max-width: 400px;
}
.comment {

form.reply {
display: none;

}

.attachment {
margin-bottom: 10px;

}
padding: 10px 5px;

/* &:nth-child(odd) { */
/* background-color: @row-alt-bg-color; */
/* } */
font-size: 12px;
span {
display: block;
}
span.user a {
color: @blue-color;
}
p.body {
color: @gray-color;
padding: 15px 5px;
}
.comment_actions {
text-align: right;
span {
display: inline;
}
}

}
}
86 changes: 0 additions & 86 deletions app/client/styles/modal.less
Original file line number Diff line number Diff line change
Expand Up @@ -88,92 +88,6 @@
}
}

.comment_wrap {
margin-top: 10px;

form {

}
}
.comment_wrap {
form.comment {
textarea {
height: 30px;
overflow-y: hidden;
-webkit-transition: height ease-in-out 85ms;

}
.buttons {
display: none;

}

&.focus {
textarea {
height: 90px;

}
.buttons {
display: block;

}

}

}
.files_to_upload {
font-size: 12px;

}
.buttons {
a, button {
display: inline-block;
margin-left: 10px;

}
a {
font-size: 12px;
color: @blue-color;
}

}
}
.comments {
margin-top: 20px;
position: relative;
img {
max-width: 400px;
}
.comment {

.attachment {
margin-bottom: 10px;

}
padding: 5px;
&:nth-child(odd) {
background-color: @row-alt-bg-color;
}
font-size: 12px;
span {
display: block;
}
span.user a {
color: @blue-color;
}
p.body {
color: @gray-color;
padding: 15px 5px;
}
.comment_actions {
text-align: right;
span {
display: inline;
}
}

}
}

}

Expand Down
Loading