Merge branch 'refactor_merge_requests'

This commit is contained in:
Dmitriy Zaporozhets 2011-12-13 23:34:11 +02:00
commit 6c47bcef02
13 changed files with 258 additions and 122 deletions

View file

@ -1,4 +1,4 @@
[Dolphin] [Dolphin]
ShowPreview=true ShowPreview=true
Timestamp=2011,10,28,13,16,25 Timestamp=2011,12,13,12,22,12
Version=2 Version=2

View file

@ -0,0 +1,59 @@
var MergeRequest = {
diffs_loaded: false,
commits_loaded: false,
init:
function() {
$(".merge-tabs a").live("click", function() {
$(".merge-tabs a").removeClass("active");
$(this).addClass("active");
});
$(".merge-tabs a.merge-notes-tab").live("click", function() {
$(".merge-request-commits, .merge-request-diffs").hide();
$(".merge-request-notes").show();
});
$(".merge-tabs a.merge-commits-tab").live("click", function() {
if(!MergeRequest.commits_loaded) {
MergeRequest.loadCommits();
}
$(".merge-request-notes, .merge-request-diffs").hide();
$(".merge-request-commits").show();
});
$(".merge-tabs a.merge-diffs-tab").live("click", function() {
if(!MergeRequest.diffs_loaded) {
MergeRequest.loadDiff();
}
$(".merge-request-notes, .merge-request-commits").hide();
$(".merge-request-diffs").show();
});
},
loadCommits:
function() {
$(".dashboard-loader").show();
$.ajax({
type: "GET",
url: $(".merge-commits-tab").attr("data-url"),
complete: function(){
MergeRequest.commits_loaded = true;
$(".merge-request-notes, .merge-request-diffs").hide();
$(".dashboard-loader").hide()},
dataType: "script"});
},
loadDiff:
function() {
$(".dashboard-loader").show();
$.ajax({
type: "GET",
url: $(".merge-diffs-tab").attr("data-url"),
complete: function(){
MergeRequest.diffs_loaded = true;
$(".merge-request-notes, .merge-request-commits").hide();
$(".dashboard-loader").hide()},
dataType: "script"});
}
}

View file

@ -438,42 +438,6 @@ body.project-page table.no-borders td{
border:none; border:none;
} }
#gitlab-tabs {
.ui-tabs-nav {
border-bottom: 1px solid #DEDFE1;
li {
background: none;
border:none;
font-size: 16px;
margin: 0;
padding: 0;
a {
margin: 0;
padding: 10px 16px;
width:150px;
}
&.ui-tabs-selected {
background-image: -webkit-gradient(linear, 0 0, 0 26, color-stop(0.076, #fefefe), to(#F6F7F8));
background-image: -webkit-linear-gradient(#fefefe 7.6%, #F6F7F8);
background-image: -moz-linear-gradient(#fefefe 7.6%, #F6F7F8);
background-image: -o-linear-gradient(#fefefe 7.6%, #F6F7F8);
font-weight: bold;
border:1px solid #DEDFE1;
border-bottom: 1px solid #DEDFE1;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
}
}
}
.ajax-tab-loading { .ajax-tab-loading {
padding:40px; padding:40px;
display:none; display:none;
@ -587,3 +551,82 @@ h4.middle-panel {
margin-right:30px; margin-right:30px;
display:none; display:none;
} }
.merge-tabs {
margin: 0;
border: 1px solid #ccc;
padding: 5px;
font-size: 12px;
background: #F7F7F7;
margin-bottom:20px;
height:26px;
.tab {
font-weight: bold;
text-transform: uppercase;
border-right: 1px solid #ddd;
background:none;
padding: 10px;
width:60px;
float:left;
position:relative;
top:-5px;
left:-5px;
height:16px;
padding-left:34px;
span {
width: 20px;
height: 20px;
display: inline-block;
position: absolute;
left: 8px;
top: 8px;
}
&.active {
background: #eaeaea;
}
}
}
.merge-notes-tab span { background: url("images.png") no-repeat -161px -1px; }
.merge-commits-tab span { background: url("images.png") no-repeat -86px 1px; }
.merge-diffs-tab span { background: url("images.png") no-repeat -118px 1px; }
.merge-tabs .dashboard-loader { padding:8px; }
.user-mention {
color: #2FA0BB;
font-weight: bold;
}
.author {
color: #999;
}
.red-button{
border-radius: 5px;
font-size: 12px;
font-weight: bold;
padding: 5px 17px;
border: 1px solid #999;
color: #666;
display: inline-block;
box-shadow: 0 1px 2px rgba(0,0,0,.3);
background: #D12F19;
color: white;
}
.positive-button{
border-radius: 5px;
font-size: 12px;
font-weight: bold;
padding: 5px 17px;
border: 1px solid #999;
color: #666;
display: inline-block;
box-shadow: 0 1px 2px rgba(0,0,0,.3);
background: #4A2;
color: white;
}

View file

@ -130,7 +130,7 @@ table tr:hover, .listed_items tr.odd:hover{background-color:#FFFFCF}
border-radius: 5px; border-radius: 5px;
font-size: 12px; font-size: 12px;
font-weight: bold; font-weight: bold;
padding: 6px 20px; padding: 5px 17px;
border: 1px solid #999; border: 1px solid #999;
color: #666; color: #666;
display: inline-block; display: inline-block;

View file

@ -30,14 +30,11 @@ class MergeRequestsController < ApplicationController
def commits def commits
@commits = @project.repo.commits_between(@merge_request.target_branch, @merge_request.source_branch).map {|c| Commit.new(c)} @commits = @project.repo.commits_between(@merge_request.target_branch, @merge_request.source_branch).map {|c| Commit.new(c)}
render :template => "merge_requests/_commits", :layout => false
end end
def diffs def diffs
@diffs = @merge_request.diffs @diffs = @merge_request.diffs
@commit = @merge_request.last_commit @commit = @merge_request.last_commit
render :template => "merge_requests/_diffs", :layout => false
end end
def new def new

View file

@ -90,6 +90,10 @@ class Project < ActiveRecord::Base
users_projects.find_by_user_id(user.id) if user users_projects.find_by_user_id(user.id) if user
end end
def team_member_by_id(user_id)
users_projects.find_by_user_id(user_id)
end
def fresh_issues(n) def fresh_issues(n)
issues.includes(:project, :author).order("created_at desc").first(n) issues.includes(:project, :author).order("created_at desc").first(n)
end end

View file

@ -1,34 +1,49 @@
%div.merge-request-form-holder = form_for [@project, @merge_request] do |f|
.ui-box.width-100p %div
%h3 %span.entity-info
= @merge_request.new_record? ? "New Merge Request" : "Edit Merge Request ##{@merge_request.id}" - if @merge_request.new_record?
= form_for [@project, @merge_request] do |f| = link_to project_merge_requests_path(@project) do
.data .entity-button
%table.no-borders Back
-if @merge_request.errors.any? %i
%tr - else
%td Errors = link_to project_merge_request_path(@project, @merge_request) do
%td .entity-button
#error_explanation Back
- @merge_request.errors.full_messages.each do |msg| %i
%span= msg
%br %h2= @merge_request.new_record? ? "New Merge Request" : "Edit Merge Request ##{@merge_request.id}"
%hr
%table.no-borders
-if @merge_request.errors.any?
%tr
%td{:colspan => 2}
#error_explanation
- @merge_request.errors.full_messages.each do |msg|
%span= msg
%br
%tr
%td= f.label :source_branch, "From"
%td= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
%tr
%td= f.label :target_branch, "To"
%td= f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
%tr
%td= f.label :assignee_id, "Assign to"
%td= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px")
= f.text_area :title, :style => "width:718px; height:100px", :maxlength => 255
%br
%br
.merge-tabs
= f.submit 'Save', :class => "grey-button"
&nbsp;
- unless @merge_request.new_record?
.right
= link_to 'Remove', [@project, @merge_request], :confirm => 'Are you sure?', :method => :delete, :class => "red-button"
%tr
%td= f.label :title
%td= f.text_field :title
%tr
%td= f.label :source_branch, "From"
%td= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" })
%tr
%td= f.label :target_branch, "To"
%td= f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" })
%tr
%td= f.label :assignee_id, "Assign to"
%td= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" })
.buttons
= f.submit 'Save', :class => "grey-button"
.right= link_to 'Back', project_merge_requests_path(@project), :class => "grey-button"
:javascript :javascript
$(function(){ $(function(){

View file

@ -1,7 +1,7 @@
%a.update-item{:href => project_merge_request_path(merge_request.project, merge_request)} %a.update-item{:href => project_merge_request_path(merge_request.project, merge_request)}
= image_tag gravatar_icon(merge_request.author_email), :class => "left", :width => 40 = image_tag gravatar_icon(merge_request.author_email), :class => "left", :width => 40
%span.update-title %span.update-title
= merge_request.title = truncate(merge_request.title, :length => 60)
%span.update-author %span.update-author
%strong= merge_request.author_name %strong= merge_request.author_name
authored authored

View file

@ -0,0 +1,4 @@
:plain
$(".merge-request-commits").html("#{escape_javascript(render(:partial => "commits"))}");

View file

@ -0,0 +1,4 @@
:plain
$(".merge-request-diffs").html("#{escape_javascript(render(:partial => "diffs"))}");

View file

@ -1,59 +1,69 @@
.merge-request-show-holder.ui-box.width-100p %div
%h3 %span.entity-info
= "Merge Request ##{@merge_request.id}:" - if can?(current_user, :admin_project, @project) || @merge_request.author == current_user
&nbsp; = link_to edit_project_merge_request_path(@project, @merge_request) do
.tag.commit.inline= @merge_request.source_branch .entity-button
&rarr; Edit Merge Request
.tag.commit.inline= @merge_request.target_branch %i
.right = image_tag gravatar_icon(@merge_request.author_email), :class => "left", :width => 40, :style => "padding-right:5px;"
- if @merge_request.closed %span.commit-title
%span.tag.high Closed %strong
- else = "Merge Request ##{@merge_request.id}:"
%span.tag.today Open &nbsp;
.tag.commit.inline= @merge_request.source_branch
.data
%p= @merge_request.title
- if @merge_request.author == @merge_request.assignee
= image_tag gravatar_icon(@merge_request.assignee_email), :width => 20, :style => "padding:0 5px;"
= @merge_request.assignee_name
- else
= image_tag gravatar_icon(@merge_request.author_email), :width => 20, :style => "padding:0 5px;"
= @merge_request.author_name
&rarr; &rarr;
= image_tag gravatar_icon(@merge_request.assignee_email), :width => 20, :style => "padding:0 5px;" .tag.commit.inline= @merge_request.target_branch
= @merge_request.assignee_name %span.commit-author
.right %strong
%cite.cgray= @merge_request.created_at.stamp("21 Aug 2011, 11:15pm") = link_to project_team_member_path(@project, @project.team_member_by_id(@merge_request.author.id)) do
.clear %span.author= @merge_request.author_name
&rarr;
= link_to project_team_member_path(@project, @project.team_member_by_id(@merge_request.assignee.id)) do
%span.author= @merge_request.assignee_name
.buttons &nbsp;
- if can? current_user, :write_project, @project &nbsp;
- if @merge_request.closed = @merge_request.created_at.stamp("Aug 21, 2011 9:23pm")
= link_to 'Reopen', project_merge_request_path(@project, @merge_request, :merge_request => {:closed => false }, :status_only => true), :method => :put, :class => "grey-button"
- else %hr
= link_to 'Close', project_merge_request_path(@project, @merge_request, :merge_request => {:closed => true }, :status_only => true), :method => :put, :class => "grey-button" %br
.right %h3
= link_to 'Edit', edit_project_merge_request_path(@project, @merge_request), :class => "grey-button positive" = simple_format @merge_request.title
.clear .clear
%br %br
%br %br
#gitlab-tabs .merge-tabs
%ul = link_to "#notes", :class => "merge-notes-tab active tab" do
%li= link_to "Notes", "#merge-notes" %span
%li= link_to "Commits", commits_project_merge_request_path(@project, @merge_request) Notes
%li= link_to "Diff", diffs_project_merge_request_path(@project, @merge_request) = link_to "#commits", "data-url" => commits_project_merge_request_path(@project, @merge_request), :class => "merge-commits-tab tab" do
%span
Commits
= link_to "#diffs", "data-url" => diffs_project_merge_request_path(@project, @merge_request), :class => "merge-diffs-tab tab" do
%span
Diff
#merge-notes - if can?(current_user, :admin_project, @project) || @merge_request.author == current_user
.issue_notes= render "notes/notes" .right
.loading{ :style => "display:none;"} - if @merge_request.closed
%center= image_tag "ajax-loader.gif" = link_to 'Reopen', project_merge_request_path(@project, @merge_request, :merge_request => {:closed => false }, :status_only => true), :method => :put, :class => "red-button"
.clear - else
= link_to 'Close', project_merge_request_path(@project, @merge_request, :merge_request => {:closed => true }, :status_only => true), :method => :put, :class => "positive-button", :title => "Close merge request"
%img{:src => "/assets/ajax-loader-facebook.gif", :class => "dashboard-loader"}
.merge-request-notes
.issue_notes= render "notes/notes"
.loading{ :style => "display:none;"}
%center= image_tag "ajax-loader.gif"
.clear
.merge-request-commits
.merge-request-diffs
:javascript :javascript
$(function(){ $(function(){
$("#gitlab-tabs").tabs(); MergeRequest.init();
}) })

View file

@ -42,8 +42,8 @@ describe "MergeRequests" do
it { should have_content(@merge_request.title) } it { should have_content(@merge_request.title) }
it "Show page should inform user that merge request closed" do it "Show page should inform user that merge request closed" do
within ".merge-request-show-holder h3" do within ".merge-tabs" do
page.should have_content "Closed" page.should have_content "Reopen"
end end
end end
end end
@ -62,7 +62,7 @@ describe "MergeRequests" do
it { current_path.should == project_merge_request_path(project, project.merge_requests.last) } it { current_path.should == project_merge_request_path(project, project.merge_requests.last) }
it "should create merge request" do it "should create merge request" do
page.should have_content "Open" page.should have_content "Close"
page.should have_content @user.name page.should have_content @user.name
end end
end end

View file

@ -1,5 +1,5 @@
/* /*
* jQuery UI CSS Framework 1.8.16 * jQuery UI CSS Framework 1.8.16 Patched for GitLab HQ
* *
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses. * Dual licensed under the MIT or GPL Version 2 licenses.