From 485acb73b65512656b792290e8b0ddd044629d9b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2018 08:38:50 +0000 Subject: [PATCH 1/2] Show the comment on issues in JS if the SSE isn't responding Fixes https://pagure.io/pagure/issue/3760 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index ce5db3a..5a381c1 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -917,6 +917,7 @@ function try_async_comment(form) { console.log('Submitting form:'); console.log(form); set_ui_for_comment(true); + var _data = $(form).serialize(); var btn = $(document.activeElement); if (btn[0].name == 'drop_comment'){ @@ -924,11 +925,15 @@ function try_async_comment(form) { set_ui_for_comment(false); return true; } - if (!sse || source.readyState != 1) { - $(form).off('submit'); - form.submit(); - return false; - } + + /* Keep some variable in memory before sending them in case the SSE is down */ + var _url = form.action; + var _comment = $(form).find('#comment').val(); + var _commit_id = null; + var _line = null; + var _token = "{{ form.csrf_token.current_token }}"; + var _base_url = _url.split('?')[0]; + var _url = form.action + "?js=1"; $.post( _url, _data ) .done(function(data) { @@ -944,7 +949,37 @@ function try_async_comment(form) { $('#comments').find('.edit_comment').remove(); $( ".issue-metadata-form" ).hide(); $( ".issue-metadata-display" ).show(); - set_ui_for_comment(false); + if (!sse || source.readyState != 1) { + console.log('no sse, adding the comment manually'); + $.ajax({ + url: "{{ url_for('ui_ns.markdown_preview') }}" , + type: 'POST', + data: { + content: _comment, + csrf_token: _token, + }, + dataType: 'html', + success: function(res) { + var _comment = emojione.toImage(res); + var data = { + comment_added: _comment, + comment_user: "{{ g.fas_user.username }}", + comment_date: Date.now(), + avatar_url: "{{ g.fas_user.email | avatar_url(16) }}", + } + process_event( + data, + "{{ issue.uid }}", + "{{ g.fas_user.username if g.authenticated or '' }}"); + set_ui_for_comment(false); + setup_reply_btns() + return false; + } + }); + return false; + } else { + set_ui_for_comment(false); + } } else { // Make the browser submit the form sync $(form).off('submit'); From e3c8167070536b1667b41617de2e981fd8174b67 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2018 08:38:50 +0000 Subject: [PATCH 2/2] Little fixes around showing comments in PR without the SSE Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/repo_pull_request.html b/pagure/templates/repo_pull_request.html index b661af1..edc81d8 100644 --- a/pagure/templates/repo_pull_request.html +++ b/pagure/templates/repo_pull_request.html @@ -211,7 +211,7 @@ {{ mergeform.csrf_token }} {% endif %} @@ -1088,7 +1088,7 @@ function try_async_comment(form, inline) { $(item.parent().children()[1]).show() } item.remove(); - if (!sse) { + if (!sse || source.readyState != 1) { console.log('no sse, adding the comment manually'); $.ajax({ url: "{{ url_for('ui_ns.markdown_preview') }}" , @@ -1113,6 +1113,7 @@ function try_async_comment(form, inline) { "{{ request.uid }}", "{{ g.fas_user.username if g.authenticated or '' }}"); set_ui_for_comment(false); + setup_reply_btns() return false; } });