From b10e5764ac0765b556d64dfebb9dad948154e31a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 20 Sep 2016 11:55:31 -0300 Subject: [PATCH] List only labels that belongs to the group on the group issues page --- .../dashboard/labels_controller.rb | 7 +------ app/controllers/groups/labels_controller.rb | 10 +++++++++- app/finders/labels_finder.rb | 19 ++++++++++--------- app/helpers/labels_helper.rb | 3 +++ 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/dashboard/labels_controller.rb b/app/controllers/dashboard/labels_controller.rb index 797f8503b2d..05f7bc37952 100644 --- a/app/controllers/dashboard/labels_controller.rb +++ b/app/controllers/dashboard/labels_controller.rb @@ -1,12 +1,7 @@ class Dashboard::LabelsController < Dashboard::ApplicationController def index - labels = LabelsFinder.new(current_user, project_id: projects) - .execute - .select(:id, :title, :color) - .uniq(:title) - respond_to do |format| - format.json { render json: labels } + format.json { render json: LabelsFinder.new(current_user).execute } end end end diff --git a/app/controllers/groups/labels_controller.rb b/app/controllers/groups/labels_controller.rb index 0ec2fcda0ef..0ebdee55c79 100644 --- a/app/controllers/groups/labels_controller.rb +++ b/app/controllers/groups/labels_controller.rb @@ -8,7 +8,15 @@ class Groups::LabelsController < Groups::ApplicationController respond_to :html def index - @labels = @group.labels.page(params[:page]) + respond_to do |format| + format.html do + @labels = @group.labels.page(params[:page]) + end + + format.json do + render json: LabelsFinder.new(current_user, group_id: @group.id).execute + end + end end def new diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb index a27ff56309b..85ef9bea08d 100644 --- a/app/finders/labels_finder.rb +++ b/app/finders/labels_finder.rb @@ -20,13 +20,17 @@ class LabelsFinder < UnionFinder label_ids << Label.where(project_id: projects.select(:id)).select(:id) end + def sort(items) + items.reorder(title: :asc, type: :desc) + end + def with_title(items) items = items.where(title: title) if title.present? items end - def sort(items) - items.reorder(title: :asc) + def group_id + params[:group_id].presence end def project_id @@ -40,13 +44,10 @@ class LabelsFinder < UnionFinder def projects return @projects if defined?(@projects) - if project_id - @projects = ProjectsFinder.new.execute(current_user) - .where(id: project_id) - .reorder(nil) - else - @projects = Project.none - end + @projects = ProjectsFinder.new.execute(current_user) + @projects = @projects.joins(:namespace).where(namespaces: { id: group_id, type: 'Group' }) if group_id + @projects = @projects.where(id: project_id) if project_id + @projects = @projects.reorder(nil) @projects end diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb index 9df8d37af9e..8e5321c05fa 100644 --- a/app/helpers/labels_helper.rb +++ b/app/helpers/labels_helper.rb @@ -172,7 +172,10 @@ module LabelsHelper end def labels_filter_path + return group_labels_path(@group, :json) if @group + project = @target_project || @project + if project namespace_project_labels_path(project.namespace, project, :json) else