summaryrefslogtreecommitdiffstats
path: root/public/javascripts/merge_requests.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/javascripts/merge_requests.js')
-rw-r--r--public/javascripts/merge_requests.js236
1 files changed, 236 insertions, 0 deletions
diff --git a/public/javascripts/merge_requests.js b/public/javascripts/merge_requests.js
new file mode 100644
index 0000000..8ebb5d5
--- /dev/null
+++ b/public/javascripts/merge_requests.js
@@ -0,0 +1,236 @@
+/*
+#--
+# Copyright (C) 2007-2009 Johan Sørensen <johan@johansorensen.com>
+# Copyright (C) 2009 Marius Mathiesen <marius.mathiesen@gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#--
+*/
+
+$(document).ready(function() {
+ $("body#merge_requests", function(){
+ var spec = Gitorious.ShaSpec.parseLocationHash(document.location.hash);
+ if (spec) {
+ Gitorious.MergeRequestController.getInstance().loadFromBookmark(spec);
+ }
+ });
+
+ // toggling of diffs in diff browsers
+ $('.file-diff .header').live("click", function(event) {
+ var hunksContainer = $(this).next();
+ if (hunksContainer.is(":visible")) {
+ $(this).removeClass("open").addClass("closed");
+ hunksContainer.slideUp();
+ } else {
+ $(this).removeClass("closed").addClass("open");
+ hunksContainer.slideDown();
+ }
+ event.preventDefault();
+ });
+ $(".file-diff-controls a#expand-all").live("click", function(e){
+ var container = $(this).parent().parent().parent();
+ var cookiePrefix = $(this).attr("gts:cookie-prefix") || 'generic';
+ container.find('.file-diff .header').removeClass("closed").addClass("open");
+ container.find('.diff-hunks:hidden').show();
+ $.cookie(cookiePrefix + "-diff-hunks-state", "expanded");
+ e.preventDefault();
+ });
+ $(".file-diff-controls a#collapse-all").live("click", function(e){
+ var container = $(this).parent().parent().parent();
+ var cookiePrefix = $(this).attr("gts:cookie-prefix") || 'generic';
+ container.find('.file-diff .header').removeClass("open").addClass("closed");
+ container.find('.diff-hunks').hide();
+ $.cookie(cookiePrefix + "-diff-hunks-state", "collapsed");
+ e.preventDefault();
+ });
+
+ // merge request diffing loading indimacator
+ Gitorious.MergeRequestDiffSpinner = $("#merge_request_diff_loading").html();
+ $("#merge_request_diff").html(Gitorious.MergeRequestDiffSpinner);
+
+ // Merge request selection of branches, compact mode
+ // wrapped in a function so we can reuse it when we load another version
+ var diffBrowserCompactCommitSelectable = function() {
+ var selectingAndUnselecting = function() {
+ var commits = $("li.ui-selecting a");
+ if (!commits[0]) return true;
+ var first_commit_sha = $(commits[0]).attr("data-commit-sha");
+ var last_commit_sha = $(commits[commits.length - 1]).attr("data-commit-sha");
+
+ var shaSpec = new Gitorious.ShaSpec();
+ shaSpec.addSha(first_commit_sha);
+ shaSpec.addSha(last_commit_sha);
+
+ Gitorious.MergeRequestController.getInstance().isSelectingShas(shaSpec);
+ };
+ return jQuery("#merge_request_commit_selector.compact").selectable({
+ filter: "li.single_commit",
+ stop: function(e, ui) {
+ var sha_spec = new Gitorious.ShaSpec();
+ jQuery("li.ui-selected a", this).each(function() {
+ sha = jQuery(this).attr("data-commit-sha");
+ sha_spec.addSha(sha);
+ });
+ Gitorious.MergeRequestController.getInstance().didSelectShas(sha_spec);
+ },
+ start: function(e, ui) {
+ Gitorious.MergeRequestController.getInstance().willSelectShas();
+ },
+ selecting: function(e, ui) {
+ selectingAndUnselecting();
+ },
+ unselecting: function(e,ui) {
+ selectingAndUnselecting();
+ },
+ cancel: ".merge_base"
+ });
+ }
+ Gitorious.currentMRCompactSelectable = diffBrowserCompactCommitSelectable();
+
+ $("#merge_request_version").changableSelection({
+ onChange: function() {
+ var version = $(this).text().replace(/[^0-9]+/g, '');
+ var url = $(this).parent().prev().attr("gts:url") + '?version=' + version;
+ $("#diff_browser_for_current_version").load(url, null, function() {
+ new Gitorious.DiffBrowser(
+ jQuery("#current_shas").attr("data-merge-request-current-shas") );
+ // jump through hoops and beat the selectable into submission,
+ // since it doesn't use live events, we have to re-create it, which sucks...
+ Gitorious.currentMRCompactSelectable.selectable("destroy");
+ Gitorious.currentMRCompactSelectable = diffBrowserCompactCommitSelectable();
+ });
+ }
+ });
+
+ $("#merge_request_current_version ul.compact li.single_commit").hoverBubble();
+
+ // Merge request selection of branches, monster mode
+ $("#large_commit_selector_toggler").live("click", function(event) {
+ $("#large_commit_selector").slideToggle();
+ event.preventDefault();
+ });
+
+ // Handle selection of multiple commits in the large merge-request commit diff browser
+ var previousSelectedCommitRowIndex;
+ $("#large_commit_selector table#commit_table tr input").live("click", function(event) {
+ var selectedTr = $(this).parents("tr");
+ var commitRows = selectedTr.parents("table").find("tr.commit_row");
+
+ if (commitRows.filter(".selected").length === 0) {
+ // mark initial selection
+ selectedTr.addClass("selected");
+ return;
+ }
+
+ var firstSelRowIndex = commitRows.indexOf(commitRows.filter(".selected:first")[0]);
+ var lastSelRowIndex = commitRows.indexOf(commitRows.filter(".selected:last")[0]);
+ var selectedRowIndex = commitRows.indexOf(selectedTr[0]);
+ var markRange = function(start, end) {
+ commitRows.slice(start, end + 1).addClass("selected");
+ };
+
+ // reset selections first
+ commitRows.filter(".selected").removeClass("selected");
+ if (selectedRowIndex === firstSelRowIndex || selectedRowIndex === lastSelRowIndex) {
+ selectedTr.addClass("selected");
+ return;
+ }
+
+ if (selectedRowIndex > firstSelRowIndex &&
+ selectedRowIndex < lastSelRowIndex) // in-between
+ {
+ if (previousSelectedCommitRowIndex === firstSelRowIndex) {
+ markRange(selectedRowIndex, lastSelRowIndex);
+ } else {
+ markRange(firstSelRowIndex, selectedRowIndex);
+ }
+ } else if (selectedRowIndex > firstSelRowIndex) { // downwards
+ markRange(firstSelRowIndex, selectedRowIndex);
+ } else { // upwards
+ markRange(selectedRowIndex, lastSelRowIndex);
+ }
+
+ previousSelectedCommitRowIndex = selectedRowIndex;
+ });
+
+ // Display a range of commits from the large merge-request commit diff browser
+ $("#show-large-diff-range").live("click", function(event) {
+ var selected = $("#large_commit_selector table#commit_table tr.commit_row.selected");
+ var spec = new Gitorious.ShaSpec();
+ var firstSHA = selected.filter(":first").find("input.merge_to").val();
+ var lastSHA = selected.filter(":last").find("input.merge_to").val();
+ spec.addSha(firstSHA);
+ if (firstSHA != lastSHA)
+ spec.addSha(lastSHA);
+ spec.summarizeHtml();
+ var diff_browser = new Gitorious.DiffBrowser(spec.shaSpec());
+ $("#large_commit_selector").hide();
+ event.preventDefault();
+ });
+
+ // Show a single commit in the large merge-request commit diff browser
+ $("#large_commit_selector #commit_table a.clickable_commit").live("click", function(e){
+ var spec = new Gitorious.ShaSpec();
+ spec.addSha($(this).attr("data-commit-sha"));
+ var diff_browser = new Gitorious.DiffBrowser(spec.shaSpec());
+ $("#large_commit_selector").hide();
+ e.preventDefault();
+ });
+
+ jQuery("#current_shas").each(function(){
+ var sha_spec = jQuery(this).attr("data-merge-request-current-shas");
+ diff_browser = new Gitorious.DiffBrowser(sha_spec);
+ }
+ );
+
+ // Diff commenting
+ $("table tr td.inline_comments a.diff-comment-count").live("click", function(e) {
+ var lineNum = $(this).parents("td").next("td").text();
+ if (lineNum === "") // look in the next TD
+ lineNum = $(this).parents("td").next("td").next("td").text();
+ $(this).parents("tr.changes")
+ .find("td.code .diff-comments.line-" + lineNum).slideToggle();
+ e.preventDefault();
+ });
+
+ // Clicking on a comment relating to a merge request
+ // version displays the comment in context
+ $("#merge_request_comments .comment.inline .inline_comment_link a").live("click", function() {
+ var comment = $(this).parent().parent();
+ var path = $(comment).attr("data-diff-path");
+ var last_line = $(comment).attr("data-last-line-in-diff");
+ var elementInDiff = function(s) {
+ return $(".file-diff[data-diff-path=" + path + "] " + s);
+ }
+ var hunks = elementInDiff(".diff-hunks");
+ hunks.removeClass("closed").addClass("open");
+ hunks.slideDown();
+ elementInDiff(".diff-comments.line-" + last_line).slideToggle();
+ Gitorious.DiffBrowser.CommentHighlighter.add( $($(this).attr("href")) );
+ return true;
+ });
+
+ $("#toggle_inline_comments").live("change", function(){
+ if ($(this).is(":checked")) {
+ $(".comment.inline").show();
+ } else {
+ $(".comment.inline").hide();
+ }
+ });
+});
+
+
+if (!Gitorious)
+ var Gitorious = {};
+