From 7fefb0397eea99910537541bbba70d0a68a44644 Mon Sep 17 00:00:00 2001
From: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Date: Thu, 8 Aug 2013 17:29:31 +0300
Subject: [PATCH] Fix filter context. Dont duplicate target project name for MR

---
 app/assets/stylesheets/common.scss                  | 12 ------------
 app/assets/stylesheets/gitlab_bootstrap/mixins.scss |  4 ++++
 app/assets/stylesheets/sections/merge_requests.scss | 13 +++++++++++--
 app/contexts/filter_context.rb                      |  2 +-
 app/models/concerns/issuable.rb                     |  1 +
 app/models/issue.rb                                 |  1 -
 app/models/merge_request.rb                         |  2 +-
 .../merge_requests/_merge_request.html.haml         | 10 ++++++----
 .../merge_requests/show/_mr_title.html.haml         |  6 +++---
 spec/contexts/filter_context_spec.rb                |  6 ++++--
 10 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss
index ee6d5698e32..2ab3a1b3b52 100644
--- a/app/assets/stylesheets/common.scss
+++ b/app/assets/stylesheets/common.scss
@@ -364,18 +364,6 @@ img.emoji {
   margin-bottom: 10px;
 }
 
-.label-project {
-  @include border-radius(4px);
-  padding: 2px 4px;
-  border: none;
-  font-size: 14px;
-  background: #474D57;
-  color: #fff;
-  font-family: $monospace_font;
-  text-shadow: 0 1px 1px #111;
-  font-weight: normal;
-}
-
 .group-name {
   font-size: 14px;
   line-height: 24px;
diff --git a/app/assets/stylesheets/gitlab_bootstrap/mixins.scss b/app/assets/stylesheets/gitlab_bootstrap/mixins.scss
index 9ddaaf31c1c..8676cc624ce 100644
--- a/app/assets/stylesheets/gitlab_bootstrap/mixins.scss
+++ b/app/assets/stylesheets/gitlab_bootstrap/mixins.scss
@@ -17,6 +17,10 @@
   border-radius: $radius;
 }
 
+@mixin border-radius-left($radius) {
+  @include border-radius($radius 0 0 $radius)
+}
+
 @mixin linear-gradient($from, $to) {
   background-image: -webkit-gradient(linear, 0 0, 0 100%, from($from), to($to));
   background-image: -webkit-linear-gradient($from, $to);
diff --git a/app/assets/stylesheets/sections/merge_requests.scss b/app/assets/stylesheets/sections/merge_requests.scss
index 083c330b1cd..9a8af301442 100644
--- a/app/assets/stylesheets/sections/merge_requests.scss
+++ b/app/assets/stylesheets/sections/merge_requests.scss
@@ -84,14 +84,23 @@
 
 .label-branch {
   @include border-radius(4px);
-  padding: 2px 4px;
+  padding: 3px 4px;
   border: none;
   font-size: 14px;
   background: #474D57;
   color: #fff;
   font-family: $monospace_font;
-  text-shadow: 0 1px 1px #111;
   font-weight: normal;
+  overflow: hidden;
+
+  .label-project {
+    @include border-radius-left(4px);
+    padding: 3px 4px;
+    background: #29A;
+    position: relative;
+    left: -4px;
+    letter-spacing: -1px;
+  }
 }
 
 .mr-list {
diff --git a/app/contexts/filter_context.rb b/app/contexts/filter_context.rb
index cd054e0c2c3..2607b12b4ae 100644
--- a/app/contexts/filter_context.rb
+++ b/app/contexts/filter_context.rb
@@ -12,7 +12,7 @@ class FilterContext
 
   def apply_filter items
     if params[:project_id].present?
-      items = items.where(project_id: params[:project_id])
+      items = items.of_projects(params[:project_id])
     end
 
     if params[:search].present?
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 88de1a037aa..24818a927ed 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -21,6 +21,7 @@ module Issuable
     scope :recent, -> { order("created_at DESC") }
     scope :assigned, -> { where("assignee_id IS NOT NULL") }
     scope :unassigned, -> { where("assignee_id IS NULL") }
+    scope :of_projects, ->(ids) { where(project_id: ids) }
 
     delegate :name,
              :email,
diff --git a/app/models/issue.rb b/app/models/issue.rb
index c171941928c..550041a0224 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -27,7 +27,6 @@ class Issue < ActiveRecord::Base
   scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) }
   scope :opened, -> { with_state(:opened) }
   scope :closed, -> { with_state(:closed) }
-  scope :by_project, ->(project_id) {where(project_id:project_id)}
 
   attr_accessible :title, :assignee_id, :position, :description,
                   :milestone_id, :label_list, :author_id_of_changes,
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 9abdd41ec4e..b7df2e40a16 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -93,8 +93,8 @@ class MergeRequest < ActiveRecord::Base
   scope :by_branch, ->(branch_name) { where("(source_branch LIKE :branch) OR (target_branch LIKE :branch)", branch: branch_name) }
   scope :cared, ->(user) { where('assignee_id = :user OR author_id = :user', user: user.id) }
   scope :by_milestone, ->(milestone) { where(milestone_id: milestone) }
-  scope :by_project, ->(project_id) { where("source_project_id = :project_id OR target_project_id = :project_id", project_id: project_id) }
   scope :in_projects, ->(project_ids) { where("source_project_id in (:project_ids) OR target_project_id in (:project_ids)", project_ids: project_ids) }
+  scope :of_projects, ->(ids) { where(target_project_id: ids) }
   # Closed scope for merge request should return
   # both merged and closed mr's
   scope :closed, -> { with_states(:closed, :merged) }
diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml
index a10ed02a077..276436a9c8e 100644
--- a/app/views/projects/merge_requests/_merge_request.html.haml
+++ b/app/views/projects/merge_requests/_merge_request.html.haml
@@ -9,12 +9,14 @@
     - else
       %span.pull-right
         - if merge_request.for_fork?
-          = "#{merge_request.source_project.path_with_namespace}/#{merge_request.source_branch}"
-          %i.icon-angle-right
-          = "#{merge_request.target_project.path_with_namespace}/#{merge_request.target_branch}"
+          %span.light
+            = "#{merge_request.source_project.path_with_namespace}"
+          = "#{merge_request.source_branch}"
+          %i.icon-angle-right.light
+          = "#{merge_request.target_branch}"
         - else
           = "#{merge_request.source_branch}"
-          %i.icon-angle-right
+          %i.icon-angle-right.light
           = "#{merge_request.target_branch}"
   .merge-request-info
     - if merge_request.author
diff --git a/app/views/projects/merge_requests/show/_mr_title.html.haml b/app/views/projects/merge_requests/show/_mr_title.html.haml
index e7838733af3..7dfc995121f 100644
--- a/app/views/projects/merge_requests/show/_mr_title.html.haml
+++ b/app/views/projects/merge_requests/show/_mr_title.html.haml
@@ -2,10 +2,10 @@
   = "Merge Request ##{@merge_request.id}:"
   &nbsp;
   -if @merge_request.for_fork?
-    %span.label-project= truncate(@merge_request.source_project.path_with_namespace, length: 25)
-    %span.label-branch= @merge_request.source_branch
+    %span.label-branch
+      %span.label-project= truncate(@merge_request.source_project.path_with_namespace, length: 25)
+      #{@merge_request.source_branch}
     &rarr;
-    %span.label-project= truncate(@merge_request.target_project.path_with_namespace, length: 25)
     %span.label-branch= @merge_request.target_branch
   - else
     %span.label-branch= @merge_request.source_branch
diff --git a/spec/contexts/filter_context_spec.rb b/spec/contexts/filter_context_spec.rb
index 0ecdb7416e5..db27742b9b5 100644
--- a/spec/contexts/filter_context_spec.rb
+++ b/spec/contexts/filter_context_spec.rb
@@ -21,17 +21,19 @@ describe FilterContext do
       merge_request3
       merge_request4
     end
+
     it 'should by default filter properly' do
       merge_requests = user.cared_merge_requests
       params ={}
       merge_requests = FilterContext.new(merge_requests, params).execute
       merge_requests.size.should == 3
     end
+
     it 'should apply blocks passed in on creation to the filters' do
       merge_requests = user.cared_merge_requests
       params = {:project_id => project1.id}
       merge_requests = FilterContext.new(merge_requests, params).execute
-      merge_requests.size.should == 2
+      merge_requests.size.should == 1
     end
   end
 
@@ -54,4 +56,4 @@ describe FilterContext do
       issues.size.should == 1
     end
   end
-end
\ No newline at end of file
+end
-- 
2.30.9