Skip to content

Commit

Permalink
Merge pull request #2560 from ITK-Leantime/feature/1622-edit-comments…
Browse files Browse the repository at this point in the history
…-on-todos

1622: edit comment on todos
  • Loading branch information
marcelfolaron authored Jun 29, 2024
2 parents 5cb62d9 + 8e274a4 commit f89a2f1
Show file tree
Hide file tree
Showing 51 changed files with 217 additions and 88 deletions.
4 changes: 1 addition & 3 deletions app/Domain/Comments/Repositories/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,13 @@ public function deleteComment($id): bool
*/
public function editComment($text, $id): bool
{

$sql = "UPDATE zp_comment SET text = :text WHERE id = :id";
$stmn = $this->db->database->prepare($sql);
$stmn->bindValue(':id', $id, PDO::PARAM_INT);
$stmn->bindValue(':text', $text, PDO::PARAM_INT);
$stmn->bindValue(':text', $text, PDO::PARAM_STR);

$result = $stmn->execute();
$stmn->closeCursor();

return $result;
}
}
Expand Down
11 changes: 9 additions & 2 deletions app/Domain/Comments/Services/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public function getComments($module, $entityId, int $commentOrder = 0): false|ar
*/
public function addComment($values, $module, $entityId, $entity): bool
{

if (isset($values['text']) && $values['text'] != '' && isset($values['father']) && isset($module) && isset($entityId) && isset($entity)) {
$mapper = array(
'text' => $values['text'],
Expand Down Expand Up @@ -120,9 +119,16 @@ public function addComment($values, $module, $entityId, $entity): bool
}

/**
* @param $commentId
* @param $values
* @param $id
* @return bool
* @throws BindingResolutionException
*/
public function editComment($values, $id): bool
{
return $this->commentRepository->editComment($values['text'], $id);
}

/**
* @param $commentId
* @return bool
Expand All @@ -132,6 +138,7 @@ public function deleteComment($commentId): bool

return $this->commentRepository->deleteComment($commentId);
}

}

}
77 changes: 49 additions & 28 deletions app/Domain/Comments/Templates/submodules/generalComment.sub.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<img src="<?= BASE_URL ?>/api/users?profileImage=<?=session("userdata.id") ?>&v=<?=format(session("userdata.modified"))->timestamp() ?>" />
</div>
<div class="commentReply inactive">
<a href="javascript:void(0);" onclick="toggleCommentBoxes(0, '<?=$formHash?>')">
<a href="javascript:void(0);" onclick="toggleCommentBoxes(0, null, '<?=$formHash?>')">
<?php echo $tpl->__('links.add_new_comment') ?>
</a>
</div>
Expand All @@ -39,6 +39,7 @@
</div>
<input type="hidden" name="comment" class="commenterField" value="1"/>
<input type="hidden" name="father" class="commenterField" id="father-<?=$formHash ?>" value="0"/>
<input type="hidden" name="edit-comment-helper" class="commenterField" id="edit-comment-helper-<?=$formHash ?>" />
<br/>
</div>
<?php } ?>
Expand All @@ -47,11 +48,11 @@
<div>
<?php foreach ($tpl->get('comments') as $row) : ?>
<div class="clearall">
<div class="commentImage">
<div class="commentImage" id="comment-image-to-hide-on-edit-<?=$formHash ?>-<?=$row['id']?>">
<img src="<?= BASE_URL ?>/api/users?profileImage=<?= $row['userId'] ?>&v=<?= format($row['userModified'])->timestamp() ?>"/>
</div>
<div class="commentMain">
<div class="commentContent">
<div class="commentContent" id="comment-to-hide-on-edit-<?=$formHash ?>-<?=$row['id']?>">
<div class="right commentDate">
<?php printf(
$tpl->__('text.written_on'),
Expand All @@ -70,6 +71,13 @@
<span class="fa fa-trash"></span> <?php echo $tpl->__('links.delete') ?>
</a></li>
<?php } ?>
<?php if (($row['userId'] == $_SESSION['userdata']['id']) || $login::userIsAtLeast($roles::$manager)) { ?>
<li>
<a href="javascript:void(0);" onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, null, '<?=$formHash?>', true)">
<span class="fa fa-edit"></span> <?php echo $tpl->__('label.edit') ?>
</a>
</li>
<?php } ?>
<?php
if (isset($tpl->get('ticket')->id)) {?>
<li><a href="javascript:void(0);" onclick="leantime.ticketsController.addCommentTimesheetContent(<?=$row['id'] ?>, <?=$tpl->get('ticket')->id ?>);"><?=$tpl->__("links.add_to_timesheets"); ?></a></li>
Expand All @@ -80,16 +88,13 @@
</div>
<span class="name"><?php printf($tpl->__('text.full_name'), $tpl->escape($row['firstname']), $tpl->escape($row['lastname'])); ?></span>
<div class="text mce-content-body" id="commentText-<?=$formHash ?>-<?=$row['id']?>">
<?php echo $tpl->escapeMinimal($row['text']); ?>
<div id="comment-text-to-hide-<?=$formHash ?>-<?=$row['id']?>"><?php echo $tpl->escapeMinimal($row['text']); ?></div>
</div>


</div>

<div class="commentLinks">
<div class="commentLinks" id="comment-link-to-hide-on-edit-<?=$formHash ?>-<?=$row['id']?>">
<?php if ($login::userIsAtLeast($roles::$commenter)) { ?>
<a href="javascript:void(0);"
onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, '<?=$formHash ?>')">
onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, null, '<?=$formHash ?>')">
<span class="fa fa-reply"></span> <?php echo $tpl->__('links.reply') ?>
</a>
<?php } ?>
Expand All @@ -112,20 +117,23 @@
); ?>
</div>
<span class="name"><?php printf($tpl->__('text.full_name'), $tpl->escape($comment['firstname']), $tpl->escape($comment['lastname'])); ?></span>
<div class="text mce-content-body"><?php echo $tpl->escapeMinimal($comment['text']); ?></div>
<div class="text mce-content-body" id="comment-text-to-hide-reply-<?=$formHash ?>-<?=$comment['id']?>"><?php echo $tpl->escapeMinimal($comment['text']); ?></div>
</div>

<div class="commentLinks">
<?php if ($login::userIsAtLeast($roles::$commenter)) { ?>
<a href="javascript:void(0);"
onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, '<?=$formHash ?>')">
onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, null, '<?=$formHash ?>')">
<span class="fa fa-reply"></span> <?php echo $tpl->__('links.reply') ?>
</a>
<?php if ($comment['userId'] == session("userdata.id")) { ?>
<a href="<?php echo $deleteUrlBase . $comment['id'] ?>"
class="deleteComment formModal">
<span class="fa fa-trash"></span> <?php echo $tpl->__('links.delete') ?>
</a>
<a href="javascript:void(0);" onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, <?=$comment['id']?>, '<?=$formHash?>', true, true)">
<span class="fa fa-edit"></span> <?php echo $tpl->__('label.edit') ?>
</a>
<?php } ?>
<?php } ?>
</div>
Expand All @@ -139,7 +147,8 @@ class="deleteComment formModal">
<img src="<?= BASE_URL ?>/api/users?profileImage=<?= session("userdata.id") ?>&v=<?= format(session("userdata.modified"))->timestamp() ?>"/>
</div>
<div class="commentReply">
<input type="submit" value="<?php echo $tpl->__('links.reply') ?>" name="comment" class="btn btn-primary"/>
<input type="submit" value="<?php echo $tpl->__('links.reply') ?>" name="comment" id="submit-reply-button" class="btn btn-primary"/>
<input type="button" onclick="cancel(<?php echo $row['id']; ?>, '<?=$formHash?>')" value="<?php echo $tpl->__('links.cancel') ?>" class="btn btn-primary"/>
</div>
<div class="clearall"></div>
</div>
Expand All @@ -157,28 +166,40 @@ class="deleteComment formModal">

leantime.editorController.initSimpleEditor();

function toggleCommentBoxes(id, formHash) {

function toggleCommentBoxes(id, commentId, formHash,editComment = false, isReply = false) {
<?php if ($login::userIsAtLeast($roles::$commenter)) { ?>
if (id == 0) {
jQuery('.mainToggler-'+formHash).hide();


if (parseInt(id, 10) === 0) {
jQuery(`.mainToggler-${formHash}`).hide();
} else {
jQuery('.mainToggler-'+formHash).show();
jQuery(`.mainToggler-${formHash}`).show();
}
if (editComment) {
jQuery(`#comment-to-hide-on-edit-${formHash}-${id}`).hide();
jQuery(`#comment-link-to-hide-on-edit-${formHash}-${id}`).hide();
jQuery(`#comment-image-to-hide-on-edit-${formHash}-${id}`).hide();
jQuery(`#edit-comment-helper-${formHash}`).val(commentId || id);
jQuery('#submit-reply-button').val('<?php echo $tpl->__('buttons.save') ?>');
}
jQuery('.commentBox-'+formHash+' textarea').remove();

jQuery('.commentBox-'+formHash+'').hide();

jQuery('#comment-'+formHash+'-' + id + ' .commentReply').prepend('<textarea rows="5" cols="75" name="text" id="editor_'+formHash+'" class="tinymceSimple"></textarea>');
jQuery(`.commentBox-${formHash} textarea`).remove();
jQuery(`.commentBox-${formHash}`).hide();
jQuery(`#comment-${formHash}-${id} .commentReply`).prepend(`<textarea rows="5" cols="75" name="text" id="editor_${formHash}-${id}" class="tinymceSimple">${editComment ? jQuery(`#comment-text-to-hide-${isReply ? 'reply-' : ''}${formHash}-${commentId || id}`).html() : ''}</textarea>`);
leantime.editorController.initSimpleEditor();
tinyMCE.get(`editor_${formHash}-${id}`).focus();
jQuery(`#comment-${formHash}-${id}`).show();
jQuery(`#father-${formHash}`).val(id);

setTimeout(function () { // you may not need the timeout
tinyMCE.get('editor_'+formHash+'').focus();
}, 50);

jQuery('#comment-'+formHash+'-' + id + '').show();
jQuery('#father-'+formHash).val(id);

<?php } ?>
}
function cancel(id, formHash) {
<?php if ($login::userIsAtLeast($roles::$commenter)) { ?>
jQuery(`#comment-to-hide-on-edit-${formHash}-${id}`).show();
jQuery(`.commentBox-${formHash} textarea`).remove();
jQuery(`#comment-link-to-hide-on-edit-${formHash}-${id}`).show();
jQuery(`#comment-image-to-hide-on-edit-${formHash}-${id}`).show();
jQuery(`#comment-${formHash}-${id}`).hide();
<?php } ?>
}

Expand Down
12 changes: 9 additions & 3 deletions app/Domain/Tickets/Controllers/ShowTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function get($params): Response

$this->tpl->setNotification($this->language->__("notifications.comment_deleted_error"), "error");
}

//Delete Subtask
if (isset($params['delSubtask']) === true) {

Expand Down Expand Up @@ -205,8 +204,15 @@ public function post($params): Response
$tab = "#files";
}

//Add a comment
if (isset($params['comment']) === true && isset($params['text']) && $params['text'] != '') {
// Add or edit a comment
if (isset($params['comment']) === true && isset($params['text']) && $params['text'] != '' && isset($params['edit-comment-helper']) && $params['edit-comment-helper'] !== "") {
if ($this->commentService->editComment($_POST, (int)$params['edit-comment-helper'])) {
$this->tpl->setNotification($this->language->__("notifications.comment_edited_success"), "success");
} else {
$this->tpl->setNotification($this->language->__("notifications.comment_edit_error"), "error");
}
$tab = "#comment";
} else if (isset($params['comment']) === true && isset($params['text']) && $params['text'] != '') {
if ($this->commentService->addComment($_POST, "ticket", $id, $ticket)) {
$this->tpl->setNotification($this->language->__("notifications.comment_create_success"), "success");
} else {
Expand Down
2 changes: 2 additions & 0 deletions app/Language/ar-SA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ notifications.file_upload_success="File was uploaded successfully"
notifications.file_upload_error="File could not be uploaded"
notifications.comment_create_success="Comment successfully created"
notifications.comment_create_error="Comment could not be added"
notifications.comment_edited_success="Comment successfully edited"
notifications.comment_edit_error="Comment could not be edited"
notifications.time_logged_success="Time logged successfully"
notifications.time_logged_error="There was a problem logging your time"
notifications.time_logged_error_no_hours="Please add more than 0 hours"
Expand Down
2 changes: 2 additions & 0 deletions app/Language/cs-CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ notifications.file_upload_success="File was uploaded successfully"
notifications.file_upload_error="File could not be uploaded"
notifications.comment_create_success="Comment successfully created"
notifications.comment_create_error="Comment could not be added"
notifications.comment_edited_success="Comment successfully edited"
notifications.comment_edit_error="Comment could not be edited"
notifications.time_logged_success="Time logged successfully"
notifications.time_logged_error="There was a problem logging your time"
notifications.time_logged_error_no_hours="Please add more than 0 hours"
Expand Down
Loading

0 comments on commit f89a2f1

Please sign in to comment.