From 4730482e742d4cc95b1c230e74bb43cfdefb5c1e Mon Sep 17 00:00:00 2001 From: cep Date: Jan 09 2017 14:21:19 +0000 Subject: [PATCH 1/3] Fix request_diff showing instead of commit_list in new tab Fixed the issue where opening the 'Commits' tab in a new browser tab showed the 'Files Changed' tab instead. Fixes https://pagure.io/pagure/issue/787 --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 92bec98..c4aef29 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -1244,10 +1244,23 @@ function updateHighlight(onload) { highlight_comment(); } else { if (onload) { - $('#request_diff').addClass('active'); - $('#comments').removeClass('active'); + $('#comments').removeClass('active'); + $('[href="#comments"]').removeClass('active'); + // When the hash points to 'Files Changed' tab. + if (location.hash.indexOf("request_diff") > -1) { $('[href="#request_diff"]').addClass('active'); - $('[href="#comments"]').removeClass('active'); + $('#request_diff').addClass('active'); + } + // When the hash points to 'Commits' tab. + else if (location.hash.indexOf("commit_list") > -1) { + $('[href="#commit_list"]').addClass('active'); + $('#commit_list').addClass('active'); + } + // If neither, then show the 'Comments' tab by default. + else { + $('#comments').addClass('active'); + $('[href="#comments"]').addClass('active'); + } } var file = parseInt(location.hash.substr(2).split(',')[0], 10); var lines = location.hash.split(',')[1].split('-').map(function (x) { return parseInt(x, 10) }); From efc3dc78443310ceb22965049ca1f31448cf060c Mon Sep 17 00:00:00 2001 From: cep Date: Jan 09 2017 14:21:19 +0000 Subject: [PATCH 2/3] Proper links for PR tabs Fix issue with the URL not updating when tabs in the PR page are clicked. Fixes https://pagure.io/pagure/issue/1698 --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index c4aef29..0c1db3a 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -1383,6 +1383,12 @@ $("[data-line-number]").click(function (ev) { window.location.hash = hash; return false; }); + +// Update hash links in the addressbar according to which tab is clicked +// on the PR page. +$(document).on('click', '#pr-tabs a', function() { + window.location.hash = $(this).attr('href'); +}); From a8a75255d185da4cb565fad255cf7138bf123123 Mon Sep 17 00:00:00 2001 From: cep Date: Jan 09 2017 14:21:19 +0000 Subject: [PATCH 3/3] Handle URL hashes for highlights. Also fix tabs view breaking when the web broweser's 'Back' button is pressed. --- diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 0c1db3a..3fc031b 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -26,7 +26,7 @@ {% endblock %} {% block repo %} -
+
{% if pull_request %}

PR#{{requestid}} @@ -1244,10 +1244,14 @@ function updateHighlight(onload) { highlight_comment(); } else { if (onload) { - $('#comments').removeClass('active'); - $('[href="#comments"]').removeClass('active'); - // When the hash points to 'Files Changed' tab. - if (location.hash.indexOf("request_diff") > -1) { + // Hide all tabs, and then show the one pointed to by the hash. + // This is neccessary to handle 'Back' button presses in the browser, + // which otherwise break the tabs view . + $('#pr-tabs .nav-item a.nav-link').removeClass('active'); + $('#pr-wrapper .tab-pane').removeClass('active'); + // When the hash points to 'Files Changed' tab, or a highlight. + if (location.hash.indexOf("request_diff") > -1 || + location.hash.indexOf("_") === 1) { $('[href="#request_diff"]').addClass('active'); $('#request_diff').addClass('active'); }