summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-28 00:43:31 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-31 23:27:49 -0200
commitbc7895fff80a038ff14e7319ef303e58474d161c (patch)
treedcfbddb6993b66b74f4f7fffc61f8b073f32aaa3
parent2525e55ec9bdd4b3a9e3284c71fde978cab6483a (diff)
downloadgitlab-ce-bc7895fff80a038ff14e7319ef303e58474d161c.tar.gz
Use label subject to calculate number of issues/mrs within the group
-rw-r--r--app/finders/labels_finder.rb2
-rw-r--r--app/models/group_label.rb4
-rw-r--r--app/models/label.rb30
-rw-r--r--app/models/project_label.rb4
-rw-r--r--app/views/groups/labels/index.html.haml2
-rw-r--r--app/views/projects/labels/index.html.haml4
-rw-r--r--app/views/shared/_label.html.haml12
7 files changed, 33 insertions, 25 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 865f093f04a..18d1396d78b 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -22,7 +22,7 @@ class LabelsFinder < UnionFinder
label_ids << project.group.labels if project.group.present?
label_ids << project.labels
else
- label_ids << Label.where(group_id: projects.group_ids)
+ label_ids << Label.where(group_id: projects.group_ids.uniq)
label_ids << Label.where(project_id: projects.select(:id))
end
diff --git a/app/models/group_label.rb b/app/models/group_label.rb
index a698b532d19..68841ace2e6 100644
--- a/app/models/group_label.rb
+++ b/app/models/group_label.rb
@@ -5,6 +5,10 @@ class GroupLabel < Label
alias_attribute :subject, :group
+ def subject_foreign_key
+ 'group_id'
+ end
+
def to_reference(source_project = nil, target_project = nil, format: :id)
super(source_project, target_project, format: format)
end
diff --git a/app/models/label.rb b/app/models/label.rb
index 149fd98ecb3..d9287f2dc29 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -92,16 +92,23 @@ class Label < ActiveRecord::Base
nil
end
- def open_issues_count(user = nil, project = nil)
- issues_count(user, project_id: project.try(:id) || project_id, state: 'opened')
+ def open_issues_count(user = nil)
+ issues_count(user, state: 'opened')
end
- def closed_issues_count(user = nil, project = nil)
- issues_count(user, project_id: project.try(:id) || project_id, state: 'closed')
+ def closed_issues_count(user = nil)
+ issues_count(user, state: 'closed')
end
- def open_merge_requests_count(user = nil, project = nil)
- merge_requests_count(user, project_id: project.try(:id) || project_id, state: 'opened')
+ def open_merge_requests_count(user = nil)
+ params = {
+ subject_foreign_key => subject.id,
+ label_name: title,
+ scope: 'all',
+ state: 'opened'
+ }
+
+ MergeRequestsFinder.new(user, params.with_indifferent_access).execute.count
end
def prioritize!(project, value)
@@ -167,15 +174,8 @@ class Label < ActiveRecord::Base
end
def issues_count(user, params = {})
- IssuesFinder.new(user, params.reverse_merge(label_name: title, scope: 'all'))
- .execute
- .count
- end
-
- def merge_requests_count(user, params = {})
- MergeRequestsFinder.new(user, params.reverse_merge(label_name: title, scope: 'all'))
- .execute
- .count
+ params.merge!(subject_foreign_key => subject.id, label_name: title, scope: 'all')
+ IssuesFinder.new(user, params.with_indifferent_access).execute.count
end
def label_format_reference(format = :id)
diff --git a/app/models/project_label.rb b/app/models/project_label.rb
index 33c2b617715..82f47f0e8fd 100644
--- a/app/models/project_label.rb
+++ b/app/models/project_label.rb
@@ -12,6 +12,10 @@ class ProjectLabel < Label
alias_attribute :subject, :project
+ def subject_foreign_key
+ 'project_id'
+ end
+
def to_reference(target_project = nil, format: :id)
super(project, target_project, format: format)
end
diff --git a/app/views/groups/labels/index.html.haml b/app/views/groups/labels/index.html.haml
index 70783a63409..45325d6bc4b 100644
--- a/app/views/groups/labels/index.html.haml
+++ b/app/views/groups/labels/index.html.haml
@@ -13,7 +13,7 @@
.other-labels
- if @labels.present?
%ul.content-list.manage-labels-list.js-other-labels
- = render partial: 'shared/label', collection: @labels, as: :label
+ = render partial: 'shared/label', subject: @group, collection: @labels, as: :label
= paginate @labels, theme: 'gitlab'
- else
.nothing-here-block
diff --git a/app/views/projects/labels/index.html.haml b/app/views/projects/labels/index.html.haml
index f135bf6f6b4..05a8475dcd6 100644
--- a/app/views/projects/labels/index.html.haml
+++ b/app/views/projects/labels/index.html.haml
@@ -22,14 +22,14 @@
%ul.content-list.manage-labels-list.js-prioritized-labels{ "data-url" => set_priorities_namespace_project_labels_path(@project.namespace, @project) }
%p.empty-message{ class: ('hidden' unless @prioritized_labels.empty?) } No prioritized labels yet
- if @prioritized_labels.present?
- = render partial: 'shared/label', collection: @prioritized_labels, as: :label
+ = render partial: 'shared/label', subject: @project, collection: @prioritized_labels, as: :label
.other-labels
- if can?(current_user, :admin_label, @project)
%h5{ class: ('hide' if hide) } Other Labels
%ul.content-list.manage-labels-list.js-other-labels
- if @labels.present?
- = render partial: 'shared/label', collection: @labels, as: :label
+ = render partial: 'shared/label', subject: @project, collection: @labels, as: :label
= paginate @labels, theme: 'gitlab'
- if @labels.blank?
.nothing-here-block
diff --git a/app/views/shared/_label.html.haml b/app/views/shared/_label.html.haml
index 40c8d2af226..e0e58a6b31e 100644
--- a/app/views/shared/_label.html.haml
+++ b/app/views/shared/_label.html.haml
@@ -1,6 +1,6 @@
- label_css_id = dom_id(label)
-- open_issues_count = label.open_issues_count(current_user, @project)
-- open_merge_requests_count = label.open_merge_requests_count(current_user, @project)
+- open_issues_count = label.open_issues_count(current_user)
+- open_merge_requests_count = label.open_merge_requests_count(current_user)
%li{id: label_css_id, data: { id: label.id } }
= render "shared/label_row", label: label
@@ -12,10 +12,10 @@
.dropdown-menu.dropdown-menu-align-right
%ul
%li
- = link_to_label(label, subject: @project, type: :merge_request) do
+ = link_to_label(label, subject: local_assigns[:subject], type: :merge_request) do
= pluralize open_merge_requests_count, 'merge request'
%li
- = link_to_label(label, subject: @project) do
+ = link_to_label(label, subject: local_assigns[:subject]) do
= pluralize open_issues_count, 'open issue'
- if current_user
%li.label-subscription{ data: toggle_subscription_data(label) }
@@ -28,9 +28,9 @@
= link_to 'Delete', destroy_label_path(label), title: 'Delete', method: :delete, remote: true, data: {confirm: 'Remove this label? Are you sure?'}
.pull-right.hidden-xs.hidden-sm.hidden-md
- = link_to_label(label, subject: @project, type: :merge_request, css_class: 'btn btn-transparent btn-action') do
+ = link_to_label(label, subject: local_assigns[:subject], type: :merge_request, css_class: 'btn btn-transparent btn-action') do
= pluralize open_merge_requests_count, 'merge request'
- = link_to_label(label, subject: @project, css_class: 'btn btn-transparent btn-action') do
+ = link_to_label(label, subject: local_assigns[:subject], css_class: 'btn btn-transparent btn-action') do
= pluralize open_issues_count, 'open issue'
- if current_user