List only labels that belongs to the group on the group issues page

parent baf47a0b
class Dashboard::LabelsController < Dashboard::ApplicationController class Dashboard::LabelsController < Dashboard::ApplicationController
def index def index
labels = LabelsFinder.new(current_user, project_id: projects)
.execute
.select(:id, :title, :color)
.uniq(:title)
respond_to do |format| respond_to do |format|
format.json { render json: labels } format.json { render json: LabelsFinder.new(current_user).execute }
end end
end end
end end
...@@ -8,9 +8,17 @@ class Groups::LabelsController < Groups::ApplicationController ...@@ -8,9 +8,17 @@ class Groups::LabelsController < Groups::ApplicationController
respond_to :html respond_to :html
def index def index
respond_to do |format|
format.html do
@labels = @group.labels.page(params[:page]) @labels = @group.labels.page(params[:page])
end end
format.json do
render json: LabelsFinder.new(current_user, group_id: @group.id).execute
end
end
end
def new def new
@label = @group.labels.new @label = @group.labels.new
end end
......
...@@ -20,13 +20,17 @@ class LabelsFinder < UnionFinder ...@@ -20,13 +20,17 @@ class LabelsFinder < UnionFinder
label_ids << Label.where(project_id: projects.select(:id)).select(:id) label_ids << Label.where(project_id: projects.select(:id)).select(:id)
end end
def sort(items)
items.reorder(title: :asc, type: :desc)
end
def with_title(items) def with_title(items)
items = items.where(title: title) if title.present? items = items.where(title: title) if title.present?
items items
end end
def sort(items) def group_id
items.reorder(title: :asc) params[:group_id].presence
end end
def project_id def project_id
...@@ -40,13 +44,10 @@ class LabelsFinder < UnionFinder ...@@ -40,13 +44,10 @@ class LabelsFinder < UnionFinder
def projects def projects
return @projects if defined?(@projects) return @projects if defined?(@projects)
if project_id
@projects = ProjectsFinder.new.execute(current_user) @projects = ProjectsFinder.new.execute(current_user)
.where(id: project_id) @projects = @projects.joins(:namespace).where(namespaces: { id: group_id, type: 'Group' }) if group_id
.reorder(nil) @projects = @projects.where(id: project_id) if project_id
else @projects = @projects.reorder(nil)
@projects = Project.none
end
@projects @projects
end end
......
...@@ -172,7 +172,10 @@ module LabelsHelper ...@@ -172,7 +172,10 @@ module LabelsHelper
end end
def labels_filter_path def labels_filter_path
return group_labels_path(@group, :json) if @group
project = @target_project || @project project = @target_project || @project
if project if project
namespace_project_labels_path(project.namespace, project, :json) namespace_project_labels_path(project.namespace, project, :json)
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment