Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Sep 9, 2024
1 parent f5fba44 commit b10ecde
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 37 deletions.
3 changes: 3 additions & 0 deletions assets/assetpack.def
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
! job_next_previous.js
< javascripts/job_next_previous.js

! htmx.js
< ../node_modules/htmx.org/dist/htmx.js

! video.css
< stylesheets/video.scss

Expand Down
30 changes: 15 additions & 15 deletions assets/javascripts/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ function updateNumerOfComments() {
}
}

function deleteComment(deleteButton) {
const author = deleteButton.dataset.author;
if (!window.confirm('Do you really want to delete the comment written by ' + author + '?')) {
return;
}
$.ajax({
url: deleteButton.dataset.deleteUrl,
method: 'DELETE',
success: () => {
$(deleteButton).parents('.comment-row, .pinned-comment-row').remove();
updateNumerOfComments();
},
error: showXhrError.bind(undefined, "The comment couldn't be deleted: ")
});
}
//function deleteComment(deleteButton) {
// const author = deleteButton.dataset.author;
// if (!window.confirm('Do you really want to delete the comment written by ' + author + '?')) {
// return;
// }
// $.ajax({
// url: deleteButton.dataset.deleteUrl,
// method: 'DELETE',
// success: () => {
// $(deleteButton).parents('.comment-row, .pinned-comment-row').remove();
// updateNumerOfComments();
// },
// error: showXhrError.bind(undefined, "The comment couldn't be deleted: ")
// });
//}

function updateComment(form) {
const textElement = form.text;
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dagre-d3": "^0.6.4",
"datatables.net-bs5": "^2.1.5",
"fork-awesome": "^1.2.0",
"htmx.org": "^2.0.2",
"jquery": "^3.7.1",
"jquery-ujs": "^1.2.3",
"timeago": "^1.6.7"
Expand Down
2 changes: 1 addition & 1 deletion t/16-utils-vcs-provider.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Test::Most;
use FindBin;
use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
require OpenQA::Test::Database;
use OpenQA::Test::TimeLimit '5';
use OpenQA::Test::TimeLimit '25';
use OpenQA::VcsProvider;
use Test::Mojo;
use Test::Warnings ':report_warnings';
Expand Down
2 changes: 1 addition & 1 deletion t/api/09-comments.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use FindBin;
use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../external/os-autoinst-common/lib";
use Test::Mojo;
use Test::Warnings ':report_warnings';
use OpenQA::Test::TimeLimit '8';
use OpenQA::Test::TimeLimit '38';
use OpenQA::Test::Case;
use OpenQA::Test::Client 'client';
use OpenQA::Jobs::Constants;
Expand Down
2 changes: 2 additions & 0 deletions t/ui/15-comments.t
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ sub test_comment_editing {
};

subtest 'remove' => sub {
warn __PACKAGE__ . ':' . __LINE__ . $" . Data::Dumper->Dump([$driver], ['$driver']);

# try to remove the first displayed comment (the one which has just been edited)
$driver->find_element('button.remove-edit-button')->click();

Expand Down
46 changes: 26 additions & 20 deletions templates/webapi/comments/comment_row.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@
<div class="well well-lg">
<form onsubmit="updateComment(this); return false;" onreset="hideCommentEditor(this); return true;" data-put-url="<%= url_for($put_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>">
% if (current_user && current_user->is_admin) {
<button class="btn btn-danger btn-circle btn-sm remove-edit-button" type="button" name="removeComment" onclick="deleteComment(this);" data-author="<%= $user->name %>" data-delete-url="<%= url_for($delete_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>">
<i class="fa fa-fw fa-trash"></i>
</button>
% }
% if (current_user && (current_user->id eq $user->id)) {
<button class="btn btn-primary btn-circle btn-sm trigger-edit-button" type="button" name="editComment" onclick="showCommentEditor(this.form);">
<i class="fa fa-fw fa-pencil"></i>
</button>
% }
<h4 class="media-heading">
% if($comment) {
<%= $user->name %> wrote
<a href="#comment-<%= $comment_id %>" class="comment-anchor"><abbr class="timeago" title="<%= $comment->t_created->datetime() %>Z"><%= format_time($comment->t_created) %></abbr></a>
% if ($comment->t_updated->subtract(seconds => OpenQA::Constants::DB_TIMESTAMP_ACCURACY) >= $comment->t_created) {
(last edited <abbr class="timeago" title="<%= $comment->t_updated->datetime() %>Z"><%= format_time($comment->t_updated) %></abbr>)
% }
<button
class="btn btn-danger btn-circle btn-sm remove-edit-button"
hx-delete="<%= url_for($delete_action => ($context->{type}.'_id' => $context->{id}, comment_id => $comment_id)) %>"
hx-confirm="Do you really want to delete the comment written by <%= $user->name %>?"
hx-target="closest .comment-row, .pinned-comment-row"
hx-swap="outerHTML"
>
<i class="fa fa-fw fa-trash"></i>
</button>
% }
% if (current_user && (current_user->id eq $user->id)) {
<button class="btn btn-primary btn-circle btn-sm trigger-edit-button" type="button" name="editComment" onclick="showCommentEditor(this.form);">
<i class="fa fa-fw fa-pencil"></i>
</button>
% }
</h4>
<div class="media-comment markdown">
% if($comment) {
%= $comment->rendered_markdown
<h4 class="media-heading">
% if($comment) {
<%= $user->name %> wrote
<a href="#comment-<%= $comment_id %>" class="comment-anchor"><abbr class="timeago" title="<%= $comment->t_created->datetime() %>Z"><%= format_time($comment->t_created) %></abbr></a>
% if ($comment->t_updated->subtract(seconds => OpenQA::Constants::DB_TIMESTAMP_ACCURACY) >= $comment->t_created) {
(last edited <abbr class="timeago" title="<%= $comment->t_updated->datetime() %>Z"><%= format_time($comment->t_updated) %></abbr>)
% }
% }
</h4>
<div class="media-comment markdown">
% if($comment) {
%= $comment->rendered_markdown
% }
</div>
% if (current_user && ((current_user->id eq $user->id))) {
Expand Down

0 comments on commit b10ecde

Please sign in to comment.