From 2fea2405e69eff970cd3b8c6b0a9a55079dd0b64 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 14 Sep 2016 23:14:11 -0300 Subject: List group labels on project labels page --- app/controllers/projects/labels_controller.rb | 3 ++- app/models/label.rb | 22 ++++++++++++++++++---- app/views/groups/labels/_label.html.haml | 2 +- app/views/groups/labels/index.html.haml | 5 +---- app/views/projects/labels/index.html.haml | 8 +++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index 0d8c13abc41..126afb865a8 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -11,7 +11,8 @@ class Projects::LabelsController < Projects::ApplicationController respond_to :js, :html def index - @labels = @project.labels.unprioritized.page(params[:page]) + @group_labels = @project.labels.unprioritized.with_type(:group_label).page(params[:page]) + @labels = @project.labels.unprioritized.with_type(:project_label).page(params[:page]) @prioritized_labels = @project.labels.prioritized respond_to do |format| diff --git a/app/models/label.rb b/app/models/label.rb index a78fe16f762..87d94247acc 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -103,15 +103,20 @@ class Label < ActiveRecord::Base end def open_issues_count(user = nil) - issues.visible_to_user(user).opened.count + issues_count(user, 'opened') end def closed_issues_count(user = nil) - issues.visible_to_user(user).closed.count + issues_count(user, 'closed') end - def open_merge_requests_count - merge_requests.opened.count + def open_merge_requests_count(user = nil) + params = { label_name: title, scope: 'all', state: 'opened' } + + params[:group_id] = subject_id if subject.is_a?(Group) + params[:project_id] = subject_id if subject.is_a?(Project) + + MergeRequestsFinder.new(user, params).execute.count end def template? @@ -128,6 +133,15 @@ class Label < ActiveRecord::Base private + def issues_count(user, state) + params = { label_name: title, scope: 'all', state: state } + + params[:group_id] = subject_id if subject.is_a?(Group) + params[:project_id] = subject_id if subject.is_a?(Project) + + IssuesFinder.new(user, params).execute.count + end + def cross_project_reference?(from_project) if self.is_a?(Project) self != from_project diff --git a/app/views/groups/labels/_label.html.haml b/app/views/groups/labels/_label.html.haml index 39d102a6acb..2395e2dade6 100644 --- a/app/views/groups/labels/_label.html.haml +++ b/app/views/groups/labels/_label.html.haml @@ -10,7 +10,7 @@ %ul %li = link_to_label(label, type: :merge_request) do - = pluralize label.open_merge_requests_count, 'merge request' + = pluralize label.open_merge_requests_count(current_user), 'merge request' %li = link_to_label(label) do = pluralize label.open_issues_count(current_user), 'open issue' diff --git a/app/views/groups/labels/index.html.haml b/app/views/groups/labels/index.html.haml index 848bf2da9b1..d8a6654673f 100644 --- a/app/views/groups/labels/index.html.haml +++ b/app/views/groups/labels/index.html.haml @@ -2,7 +2,7 @@ .top-area.adjust .nav-text - Labels can be applied to issues and merge requests. Star a label to make it a priority label. Order the prioritized labels to change their relative priority, by dragging. + Labels can be applied to issues and merge requests. .nav-controls - if can?(current_user, :admin_label, @group) @@ -10,10 +10,7 @@ New label .labels - - hide = @group.labels.empty? || (params[:page].present? && params[:page] != '1') .other-labels - - if can?(current_user, :admin_label, @group) - %h5{ class: ('hide' if hide) } Other Labels - if @labels.present? %ul.content-list.manage-labels-list.js-other-labels = render @labels diff --git a/app/views/projects/labels/index.html.haml b/app/views/projects/labels/index.html.haml index db66a0edbd8..210964686e8 100644 --- a/app/views/projects/labels/index.html.haml +++ b/app/views/projects/labels/index.html.haml @@ -24,8 +24,14 @@ - if @prioritized_labels.present? = render @prioritized_labels .other-labels + %h5{ class: ('hide' if hide) } Group Labels + - if @group_labels.present? + %ul.content-list.manage-labels-list.js-other-labels + = render @group_labels + - else + %p.empty-message No group labels yet - if can?(current_user, :admin_label, @project) - %h5{ class: ('hide' if hide) } Other Labels + %h5{ class: ('hide' if hide) } Project Labels - if @labels.present? %ul.content-list.manage-labels-list.js-other-labels = render @labels -- cgit v1.2.1