From e15b004a1e5fbea96c4fb1aa0f7785417d64b04f Mon Sep 17 00:00:00 2001 From: kiswa Date: Sun, 2 Nov 2014 09:29:30 -0500 Subject: [PATCH] Comments are now editable. Resolves #33. Also fixed #31. --- api/itemRoutes.php | 24 +++++++++++++++++++++- css/styles.css | 20 +++++++++++++++++++ js/controllers/boardsItemView.js | 31 +++++++++++++++++++++++++---- js/services/board.js | 6 ++++++ partials/boardItemViewModal.html | 34 +++++++++++++++++++++++++------- readme.md | 12 +++++------ 6 files changed, 109 insertions(+), 18 deletions(-) diff --git a/api/itemRoutes.php b/api/itemRoutes.php index 52f4ca3..4ca2b75 100644 --- a/api/itemRoutes.php +++ b/api/itemRoutes.php @@ -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']); diff --git a/css/styles.css b/css/styles.css index 1ff4d52..4536437 100644 --- a/css/styles.css +++ b/css/styles.css @@ -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; } diff --git a/js/controllers/boardsItemView.js b/js/controllers/boardsItemView.js index cce27d9..10dd8b0 100644 --- a/js/controllers/boardsItemView.js +++ b/js/controllers/boardsItemView.js @@ -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.' }); diff --git a/js/services/board.js b/js/services/board.js index 902bf2d..994f8b1 100644 --- a/js/services/board.js +++ b/js/services/board.js @@ -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 diff --git a/partials/boardItemViewModal.html b/partials/boardItemViewModal.html index 6dcec9e..ae5cb92 100644 --- a/partials/boardItemViewModal.html +++ b/partials/boardItemViewModal.html @@ -86,21 +86,41 @@
-

- - +

+ + + + + +
+

+ Posted + Edited + by {{ userNames[comment.user_id] }} on {{ comment.date }}

-

Posted by {{ userNames[comment.user_id] }} on {{ comment.date }}

+
+

Edit Comment

+
+ + + +
+

Add Comment

-
diff --git a/readme.md b/readme.md index 7d9206e..7b8151d 100644 --- a/readme.md +++ b/readme.md @@ -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