_new_compare.html.haml 4.24 KB
Newer Older
1
%p.lead Compare branches for new Merge Request
2

3
= form_for [@project.namespace.becomes(Namespace), @project, @merge_request], url: new_namespace_project_merge_request_path(@project.namespace, @project), method: :get, html: { class: "merge-request-form form-inline js-requires-input" } do |f|
4
  .hide.alert.alert-danger.mr-compare-errors
5 6 7 8
  .merge-request-branches.row
    .col-md-6
      .panel.panel-default
        .panel-heading
9
          %strong Source branch
10
        .panel-body
11
          = f.select(:source_project_id, [[@merge_request.source_project_path,@merge_request.source_project.id]] , {}, { class: 'source_project select2 span3', disabled: @merge_request.persisted?, required: true })
12
           
13
          = f.select(:source_branch, @merge_request.source_branches, { include_blank: true }, { class: 'source_branch select2 span2', required: true, data: { placeholder: "Select source branch" } })
14 15 16 17 18 19
        .panel-footer
          .mr_source_commit

    .col-md-6
      .panel.panel-default
        .panel-heading
20
          %strong Target branch
21 22
        .panel-body
          - projects =  @project.forked_from_project.nil? ? [@project] : [@project, @project.forked_from_project]
23
          = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted?, required: true })
24
           
25
          = f.select(:target_branch, @merge_request.target_branches, { include_blank: true }, { class: 'target_branch select2 span2', required: true, data: { placeholder: "Select target branch" } })
26 27 28
        .panel-footer
          .mr_target_commit

29
  - if @merge_request.errors.any?
30 31 32 33
    .alert.alert-danger
      - @merge_request.errors.full_messages.each do |msg|
        %div= msg

34
  - elsif @merge_request.source_branch.present? && @merge_request.target_branch.present?
35
    - if @merge_request.compare_failed
36 37
      .alert.alert-danger
        %h4 Compare failed
38
        %p We can't compare selected branches. It may be because of huge diff. Please try again or select different branches.
39
    - else
40
      .light-well.append-bottom-10
41
        .center
42 43 44 45 46 47 48 49 50 51
          %h4
            There isn't anything to merge.
          %p.slead
            - if @merge_request.source_branch == @merge_request.target_branch
              You'll need to use different branch names to get a valid comparison.
            - else
              %span.label-branch #{@merge_request.source_branch}
              and
              %span.label-branch #{@merge_request.target_branch}
              are the same.
52

53

54 55
  %div
    = f.submit 'Compare branches', class: "btn btn-new mr-compare-btn"
56 57 58 59 60 61

:javascript
  var source_branch = $("#merge_request_source_branch")
    , target_branch = $("#merge_request_target_branch")
    , target_project = $("#merge_request_target_project_id");

Vinnie Okada's avatar
Vinnie Okada committed
62 63
  $.get("#{branch_from_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {ref: source_branch.val() });
  $.get("#{branch_to_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id: target_project.val(),ref: target_branch.val() });
64 65

  target_project.on("change", function() {
Vinnie Okada's avatar
Vinnie Okada committed
66
    $.get("#{update_branches_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id:  $(this).val() });
67 68
  });
  source_branch.on("change", function() {
Vinnie Okada's avatar
Vinnie Okada committed
69
    $.get("#{branch_from_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {ref: $(this).val() });
70 71
    $(".mr-compare-errors").fadeOut();
    $(".mr-compare-btn").enable();
72 73
  });
  target_branch.on("change", function() {
Vinnie Okada's avatar
Vinnie Okada committed
74
    $.get("#{branch_to_namespace_project_merge_requests_path(@source_project.namespace, @source_project)}", {target_project_id: target_project.val(),ref: $(this).val() });
75 76
    $(".mr-compare-errors").fadeOut();
    $(".mr-compare-btn").enable();
77 78 79
  });


80 81 82 83 84 85 86 87 88
:javascript
  $(".merge-request-form").on('submit', function () {
    if ($("#merge_request_source_branch").val() === "" || $('#merge_request_target_branch').val() === "") {
      $(".mr-compare-errors").html("You must select source and target branch to proceed");
      $(".mr-compare-errors").fadeIn();
      event.preventDefault();
      return;
    }
  });
89