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

parent baf47a0b
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
......@@ -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
......
......@@ -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
......
......@@ -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
......
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