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

This commit is contained in:
Douglas Barbosa Alexandre 2016-09-20 11:55:31 -03:00
parent baf47a0bd0
commit b10e5764ac
4 changed files with 23 additions and 16 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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