Comments are now editable. Resolves #33. Also fixed #31.

This commit is contained in:
kiswa 2014-11-02 09:29:30 -05:00
parent 1875c9682e
commit e15b004a1e
6 changed files with 109 additions and 18 deletions

View File

@ -120,7 +120,7 @@ $app->post('/items/:itemId/comment', function($itemId) use ($app, $jsonResponse)
$item->ownComment[] = $comment;
R::store($item);
logAction($user->username . ' added a comment to item ' . $item->title, null, $comment, $itemId);
logAction($user->username . ' added a comment to item ' . $item->title, null, $comment->export(), $itemId);
$jsonResponse->addAlert('success', 'Comment added to item ' . $item->title . '.');
$jsonResponse->addBeans(R::load('item', $itemId));
}
@ -128,6 +128,28 @@ $app->post('/items/:itemId/comment', function($itemId) use ($app, $jsonResponse)
$app->response->setBody($jsonResponse->asJson());
})->conditions(['itemId' => '\d+']);
// Update an existing comment
$app->post('/comments/:commentId', function($commentId) use ($app, $jsonResponse) {
$data = json_decode($app->environment['slim.input']);
if(validateToken()) {
$user = getUser();
$comment = R::load('comment', $commentId);
$before = $comment->export();
$comment->text = $data->text;
$comment->userId = $user->id;
$comment->timestamp = time();
$comment->isEdited = true;
R::store($comment);
logAction($user->username . ' edited comment ' . $comment->id, $before, $comment->export(), $comment->id);
$jsonResponse->addAlert('success', 'Comment edited.');
$jsonResponse->addBeans(R::load('item', $comment->item_id));
}
$app->response->setBody($jsonResponse->asJson());
})->conditions(['commentId' => '\d+']);
// Remove a comment from an item.
$app->post('/items/:itemId/comment/remove', function($itemId) use ($app, $jsonResponse) {
$data = json_decode($app->environment['slim.input']);

View File

@ -369,6 +369,13 @@ span.fa {
.view-item-comment-form {
overflow: hidden;
}
.edit-item-comment-form {
overflow: hidden;
}
.edit-item-comment-form button {
margin-left: 5px;
margin-top: 5px;
}
.detail {
display: block;
font-size: 80%;
@ -384,6 +391,19 @@ p.detail {
.links a {
margin-left: 3px;
}
.commentText {
display: inline-block;
width: 95%;
overflow: hidden;
}
.commentActions {
position: absolute;
top: .8em;
right: .4em;
}
.commentActions a {
margin-left: 3px;
}
#add-comment {
margin-top: 5px;
}

View File

@ -2,6 +2,7 @@ taskBoardControllers.controller('ItemViewBoardCtrl',
['$scope', '$window', 'BoardService',
function ($scope, $window, BoardService) {
$scope.viewItem = {};
$scope.comment = {};
$scope.toggle = {
sidebar: false
};
@ -38,6 +39,9 @@ function ($scope, $window, BoardService) {
updateItem = function(item) {
$scope.viewItem = item;
$scope.viewItem.laneName = $scope.laneNames[item.lane_id];
convertDates($scope.viewItem.ownComment);
convertDates($scope.viewItem.ownAttachment);
convertDates($scope.viewItem.ownActivity);
};
$scope.openItem = function(item, openModal) {
@ -54,9 +58,6 @@ function ($scope, $window, BoardService) {
$scope.viewItem.ownAttachment = [];
}
convertDates($scope.viewItem.ownComment);
convertDates($scope.viewItem.ownAttachment);
convertDates($scope.viewItem.ownActivity);
$scope.fileReset = true;
if (openModal) {
@ -179,7 +180,7 @@ function ($scope, $window, BoardService) {
$scope.addItemComment = function(comment) {
if (comment === "" || undefined === comment) {
$scope.alerts.showAlert({ type: 'error', text:'Comment cannot be empty.' });
$scope.alerts.showAlert({ type: 'error', text: 'Comment cannot be empty.' });
return;
}
@ -194,6 +195,28 @@ function ($scope, $window, BoardService) {
$scope.comment.text = "";
};
$scope.beginEditComment = function(commentId, comment) {
$scope.comment.isEdit = true;
$scope.comment.editText = comment;
$scope.comment.id = commentId;
};
$scope.editComment = function(commentId, comment) {
$scope.comment.isEdit = false;
if (comment === '' || undefined === comment) {
$scope.alerts.showAlert({ type: 'error', text: 'Comment cannot be empty.' });
return;
}
$scope.viewItem.disabled = true;
BoardService.updateItemComment(commentId, comment)
.success(function(data) {
updateItem(data.data[0]);
$scope.loadBoards();
$scope.viewItem.disabled = false;
});
};
$scope.addItemAttachment = function() {
if ($scope.itemUpload === undefined || $scope.itemUpload.name === '') {
$scope.alerts.showAlert({ type: 'error', text: 'Select a file before uploading.' });

View File

@ -102,6 +102,12 @@ function($http) {
});
},
updateItemComment: function(commentId, comment) {
return $http.post('api/comments/' + commentId, {
text: comment
});
},
removeItemComment: function(itemId, commentId) {
return $http.post('api/items/' + itemId + '/comment/remove', {
id: commentId

View File

@ -86,21 +86,41 @@
<div class="list-group-item"
data-ng-repeat="comment in viewItem.ownComment | orderBy:'timestamp':comments.sorting"
data-ng-class-even="'alternate'">
<p class="comment">
<span data-ng-bind-html="markedComment(comment.text)"></span>
<a class="fa fa-trash-o pull-right"
data-ng-if="currentUser.userId == comment.user_id || currentUser.isAdmin == 1"
data-ng-click="deleteComment(comment.id)"></a>
<div class="comment">
<span class="commentText" data-ng-bind-html="markedComment(comment.text)"></span>
<span class="commentActions">
<a class="fa fa-edit"
data-ng-if="currentUser.userId == comment.user_id || currentUser.isAdmin == 1"
data-ng-click="beginEditComment(comment.id, comment.text)"></a>
<a class="fa fa-trash-o"
data-ng-if="currentUser.userId == comment.user_id || currentUser.isAdmin == 1"
data-ng-click="deleteComment(comment.id)"></a>
</span>
</div>
<p class="detail">
<span data-ng-if="!comment.is_edited == 1">Posted</span>
<span data-ng-if="comment.is_edited == 1">Edited</span>
by {{ userNames[comment.user_id] }} on {{ comment.date }}
</p>
<p class="detail">Posted by {{ userNames[comment.user_id] }} on {{ comment.date }}</p>
</div>
</div>
</div>
<div class="edit-item-comment-form" data-ng-if="comment.isEdit">
<h4>Edit Comment</h4>
<div class="form-group">
<textarea id="editComment" class="form-control" rows="4" data-ng-model="comment.editText"></textarea>
<button id="edit-comment" class="btn btn-info pull-right"
data-ng-class="{ 'disabled': viewItem.disabled }"
data-ng-click="editComment(comment.id, comment.editText)"><span class="fa fa-comment-o"></span> Edit Comment</button>
<button id="cancel-edit-comment" class="btn btn-default pull-right"
data-ng-click="comment.isEdit = false"><span class="fa fa-times"></span> Cancel</button>
</div>
</div>
<div class="view-item-comment-form">
<h4>Add Comment</h4>
<div class="form-group">
<textarea id="itemComment" class="form-control" rows="4" data-ng-model="comment.text"></textarea>
<button type="submit" id="add-comment" class="btn btn-info pull-right"
<button id="add-comment" class="btn btn-info pull-right"
data-ng-class="{ 'disabled': viewItem.disabled }"
data-ng-click="addItemComment(comment.text)"><span class="fa fa-comment-o"></span> Submit Comment</button>
</div>

View File

@ -97,12 +97,12 @@ Count was done from parent directory of TaskBoard as `./cloc-1.62.pl TaskBoard -
Language | Files | Blank Lines | Comments | Code
-------------------|-------:|-------------:|---------:|---------:
Javascript | 23 | 190 | 34 | 1886
HTML | 17 | 10 | 10 | 991
PHP | 6 | 152 | 57 | 855
CSS | 1 | 11 | 33 | 616
Javascript | 23 | 194 | 34 | 1914
HTML | 17 | 10 | 10 | 1011
PHP | 6 | 156 | 58 | 872
CSS | 1 | 11 | 33 | 636
Bourne Again Shell | 4 | 10 | 0 | 53
XML | 1 | 0 | 0 | 12
__SUM:__ | __52__ | __373__ | __134__ | __4413__
__SUM:__ | __52__ | __381__ | __135__ | __4498__
Counts Last Updated: Oct. 31, 2014
Counts Last Updated: Nov. 2, 2014