Skip to content

Commit 1cb310a

Browse files
committed
comments: Add comment edition.
1 parent 2bdc4bd commit 1cb310a

File tree

7 files changed

+69
-10
lines changed

7 files changed

+69
-10
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/releases/details/release.comment.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default class ReleaseCommentComponent {
3434
comment: '<',
3535
release: '<',
3636
menuMoveTo: '@',
37+
menuMoveText: '@',
3738
onMoved: '&',
3839
};
3940
}

src/app/releases/details/release.comment.ctrl.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,38 @@ export default class ReleaseCommentCtrl {
3434
// set in the dom via component
3535
this.comment = null;
3636
this.release = null;
37+
this.editing = false;
3738
this.menuMoveTo = '';
3839
this.onMoved = () => {};
3940
}
4041

41-
moveComment(commentId, refName, refId) {
42-
this.CommentResource.update({ id: commentId }, { _ref: { [refName]: refId }}, () => {
42+
$onInit() {
43+
const isOwner = this.AuthService.user && this.AuthService.user.id === this.comment.from.id;
44+
this.hasMoveToMenu = this.menuMoveTo && this.AuthService.hasPermission('releases/moderate');
45+
this.hasEditMenu = isOwner || this.AuthService.hasPermission('releases/moderate');
46+
this.showMenu = this.hasMoveToMenu || this.hasEditMenu;
47+
}
48+
49+
edit() {
50+
this.editedMessage = this.comment.message;
51+
this.editing = true;
52+
}
53+
54+
cancelEdit() {
55+
this.editing = false;
56+
delete this.errors;
57+
delete this.error;
58+
}
59+
60+
updateComment() {
61+
this.CommentResource.update({ id: this.comment.id }, { message: this.editedMessage }, () => {
62+
this.comment.message = this.editedMessage;
63+
this.editing = false;
64+
}, this.ApiHelper.handleErrors(this));
65+
}
66+
67+
moveComment(refName, refId) {
68+
this.CommentResource.update({ id: this.comment.id }, { _ref: { [refName]: refId }}, () => {
4369
this.onMoved();
4470
}, this.ApiHelper.handleErrors(this));
4571
}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include ../../template/_mixins
22

3-
.media.media--no-margin.collapse-in-animation
3+
.media.media--no-margin(ng-show="!vm.editing")
44
.collapse-in-animation-inner
55
.media-left.avatar
66
img.img-avatar.pull-left(gravatar-src="vm.comment.from.gravatar_id", gravatar-default="retro", fallback-icon="user")
@@ -11,10 +11,24 @@ include ../../template/_mixins
1111
label
1212
strong {{ vm.comment.from.name }}
1313
| &nbsp;commented {{ vm.comment.created_at | timeAgo }}
14-
.pull-right(uib-dropdown, ng-if="vm.menuMoveTo && vm.AuthService.hasPermission('releases/moderate')")
14+
.pull-right(uib-dropdown, ng-if="vm.showMenu")
1515
a(uib-dropdown-toggle): +icon('kebab-horizontal')
1616
ul.comment-dropdown-menu(uib-dropdown-menu)
17-
li
18-
a(ng-click="vm.moveComment(vm.comment.id, vm.menuMoveTo, vm.release.id)") Move to moderation comments
17+
li(ng-if="vm.hasEditMenu"): a(ng-click="vm.edit()") Edit comment
18+
li(ng-if="vm.hasMoveToMenu"): a(ng-click="vm.moveComment(vm.menuMoveTo, vm.release.id)") {{ vm.menuMoveText }}
1919
.panel-body
2020
div.markdown(markdown="vm.comment.message")
21+
div.cloak(ng-show="vm.editing")
22+
editor(id="edit-comment-{{ vm.comment.id }}",
23+
ng-model="vm.editedMessage",
24+
user="vm.AuthService.user",
25+
placeholder="Edit comment",
26+
markdown-text="")
27+
div.alert.alert-danger(ng-if="vm.errors.message")
28+
p.shift-down-1px
29+
+icon('warning').shift-up.space-right
30+
| {{ vm.errors.message }}
31+
.clearfix
32+
button.btn.btn-hollow.pull-right.padder-top.padder-bottom(ng-click="vm.updateComment()", ng-disabled="!vm.editedMessage || vm.editedMessage.length === 0") Update Comment
33+
button.btn.btn-hollow.pull-right.padder-top.padder-bottom.space-right(ng-click="vm.cancelEdit()") Cancel
34+
.clearfix

src/app/releases/details/release.details.ctrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export default class ReleaseDetailsCtrl {
330330
this.fetchedCommentPages = 0;
331331

332332
this.ReleaseCommentResource.query({ releaseId: this.release.id, per_page: this.commentsPagesize }, res => {
333-
this.numComments = res.headers('x-list-count');
333+
this.numComments = parseInt(res.headers('x-list-count'), 10);
334334
this.fetchedCommentPages++;
335335
this._addCommentsToHead(res.data);
336336

src/app/releases/details/release.details.pug

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ include ../../template/_mixins
111111
comment="comment",
112112
release="vm.release",
113113
menu-move-to="release",
114+
menu-move-text="Move to public comments",
114115
on-moved="vm.loadComments()")
115116
editor(ng-model="vm.newModerationComment", user="vm.AuthService.user", placeholder="Comment about release moderation", markdown-text="Comments are parsed with Markdown.")
116117

@@ -230,12 +231,22 @@ include ../../template/_mixins
230231
//-- EXISTING COMMENTS
231232
//---------------------------------------------------------------------
232233
label(ng-show="!vm.numComments") No comments yet.
233-
release-comment(ng-repeat="comment in vm.commentsHead track by comment.id", comment="comment", release="vm.release", menu-move-to="release_moderation")
234+
release-comment(ng-repeat="comment in vm.commentsHead track by comment.id",
235+
comment="comment",
236+
release="vm.release",
237+
menu-move-to="release_moderation",
238+
menu-move-text="Move to moderation comments",
239+
on-moved="vm.loadComments()")
234240
.zigzag(ng-show="vm.hiddenComments > 0")
235241
.panel.panel--inner
236242
| {{ vm.hiddenComments }} hidden comments
237243
label.a(ng-click="vm.loadMoreComments()") Load more...
238-
release-comment(ng-repeat="comment in vm.commentsTail track by comment.id", comment="comment", release="vm.release", menu-move-to="release_moderation")
244+
release-comment(ng-repeat="comment in vm.commentsTail track by comment.id",
245+
comment="comment",
246+
release="vm.release",
247+
menu-move-to="release_moderation",
248+
menu-move-text="Move to moderation comments",
249+
on-moved="vm.loadComments()")
239250

240251
//-- NEW COMMENT
241252
//---------------------------------------------------------------------

src/styles/colors/buttons.styl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
color $color-primary
6464
.svg-icon
6565
fill $color-primary
66+
&[disabled]:hover
67+
border-color $color-dark
68+
color $color-light
69+
.svg-icon
70+
fill $color-light
71+
6672
&:active
6773
box-shadow none
6874
border-color $color-dark

0 commit comments

Comments
 (0)