Remove scopes/types for labels
This commit is contained in:
parent
07709c5576
commit
0bfa39d5bd
|
@ -140,10 +140,6 @@
|
|||
color: $gray-light;
|
||||
}
|
||||
|
||||
.label-type {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
.draggable-handler {
|
||||
display: inline-block;
|
||||
|
@ -152,11 +148,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
.group-labels + .project-labels {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.group-labels, .project-labels {
|
||||
.other-labels {
|
||||
.remove-priority {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
|
||||
before_action :module_enabled
|
||||
before_action :label, only: [:edit, :update, :destroy]
|
||||
before_action :labels, only: [:index]
|
||||
before_action :find_labels, only: [:index, :set_priorities, :remove_priority]
|
||||
before_action :authorize_read_label!
|
||||
before_action :authorize_admin_labels!, only: [:new, :create, :edit, :update,
|
||||
:generate, :destroy, :remove_priority,
|
||||
|
@ -12,9 +12,8 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
respond_to :js, :html
|
||||
|
||||
def index
|
||||
@prioritized_labels = @labels.prioritized
|
||||
@group_labels = @project.group.labels.unprioritized if @project.group.present?
|
||||
@project_labels = @project.labels.unprioritized.page(params[:page])
|
||||
@prioritized_labels = @available_labels.prioritized
|
||||
@labels = @available_labels.unprioritized.page(params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -70,7 +69,7 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
|
||||
def destroy
|
||||
@label.destroy
|
||||
@labels = labels
|
||||
@labels = find_labels
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
|
@ -83,7 +82,7 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
|
||||
def remove_priority
|
||||
respond_to do |format|
|
||||
label = labels.find(params[:id])
|
||||
label = @available_labels.find(params[:id])
|
||||
|
||||
if label.update_attribute(:priority, nil)
|
||||
format.json { render json: label }
|
||||
|
@ -96,8 +95,10 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
|
||||
def set_priorities
|
||||
Label.transaction do
|
||||
label_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
|
||||
|
||||
params[:label_ids].each_with_index do |label_id, index|
|
||||
next unless labels.where(id: label_id).any?
|
||||
next unless label_ids.include?(label_id.to_i)
|
||||
|
||||
Label.where(id: label_id).update_all(priority: index)
|
||||
end
|
||||
|
@ -125,8 +126,8 @@ class Projects::LabelsController < Projects::ApplicationController
|
|||
end
|
||||
alias_method :subscribable_resource, :label
|
||||
|
||||
def labels
|
||||
@labels ||= LabelsFinder.new(current_user, project_id: @project.id).execute
|
||||
def find_labels
|
||||
@available_labels ||= LabelsFinder.new(current_user, project_id: @project.id).execute
|
||||
end
|
||||
|
||||
def authorize_admin_labels!
|
||||
|
|
|
@ -81,26 +81,6 @@ module LabelsHelper
|
|||
end
|
||||
end
|
||||
|
||||
def label_type_icon(label, options = {})
|
||||
title, icon =
|
||||
case label
|
||||
when GroupLabel then ['Group', 'folder-open']
|
||||
when ProjectLabel then ['Project', 'bookmark']
|
||||
end
|
||||
|
||||
options[:class] ||= ''
|
||||
options[:class] << ' has-tooltip js-label-type'
|
||||
options[:class] << ' hidden' if options.fetch(:hidden, false)
|
||||
|
||||
content_tag :span,
|
||||
class: options[:class],
|
||||
data: { 'placement' => 'top' },
|
||||
title: title,
|
||||
aria: { label: title } do
|
||||
icon(icon, base: true)
|
||||
end
|
||||
end
|
||||
|
||||
def render_colored_label(label, label_suffix = '', tooltip: true)
|
||||
label_color = label.color || Label::DEFAULT_COLOR
|
||||
text_color = text_color_for_bg(label_color)
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
- page_title 'Edit', @label.name, 'Labels'
|
||||
|
||||
%h3.page-title
|
||||
= icon('folder-open')
|
||||
Edit Group Label
|
||||
Edit Label
|
||||
%hr
|
||||
|
||||
= render 'form', url: group_label_path(@group, @label)
|
||||
|
|
|
@ -10,13 +10,9 @@
|
|||
New label
|
||||
|
||||
.labels
|
||||
- hide = @group.labels.empty? || (params[:page].present? && params[:page] != '1')
|
||||
.group-labels
|
||||
%h5{ class: ('hide' if hide) }
|
||||
= icon('folder-open')
|
||||
Group Labels
|
||||
.other-labels
|
||||
- if @labels.present?
|
||||
%ul.content-list.manage-labels-list.js-group-labels
|
||||
%ul.content-list.manage-labels-list.js-other-labels
|
||||
= render partial: 'shared/label', collection: @labels, as: :label
|
||||
= paginate @labels, theme: 'gitlab'
|
||||
- else
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
- page_title 'New Group Label'
|
||||
- page_title 'New Label'
|
||||
- header_title group_title(@group, 'Labels', group_labels_path(@group))
|
||||
|
||||
%h3.page-title
|
||||
= icon('folder-open')
|
||||
New Group Label
|
||||
New Label
|
||||
%hr
|
||||
|
||||
= render 'form', url: group_labels_path
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
%div{ class: container_class }
|
||||
%h3.page-title
|
||||
= icon('bookmark')
|
||||
Edit Project Label
|
||||
Edit Label
|
||||
%hr
|
||||
= render 'form', url: namespace_project_label_path(@project.namespace.becomes(Namespace), @project, @label)
|
||||
|
|
|
@ -14,36 +14,26 @@
|
|||
New label
|
||||
|
||||
.labels
|
||||
- unless @labels.empty?
|
||||
- if can?(current_user, :admin_label, @project)
|
||||
-# Only show it in the first page
|
||||
- hide = params[:page].present? && params[:page] != '1'
|
||||
- hide = @project.labels.empty? || (params[:page].present? && params[:page] != '1')
|
||||
.prioritized-labels{ class: ('hide' if hide) }
|
||||
%h5 Prioritized Labels
|
||||
%ul.content-list.manage-labels-list.js-prioritized-labels{ "data-url" => set_priorities_namespace_project_labels_path(@project.namespace, @project) }
|
||||
%p.empty-message{ class: ('hidden' unless @prioritized_labels.empty?) } No prioritized labels yet
|
||||
- if @prioritized_labels.present?
|
||||
= render partial: 'shared/label', collection: @prioritized_labels, as: :label
|
||||
|
||||
.other-labels
|
||||
- if can?(current_user, :admin_label, @project)
|
||||
.prioritized-labels{ class: ('hidden' if hide) }
|
||||
%h5 Prioritized Labels
|
||||
%ul.content-list.manage-labels-list.js-prioritized-labels{ "data-url" => set_priorities_namespace_project_labels_path(@project.namespace, @project) }
|
||||
%p.empty-message{ class: ('hidden' unless @prioritized_labels.empty?) } No prioritized labels yet
|
||||
- if @prioritized_labels.present?
|
||||
= render partial: 'shared/label', collection: @prioritized_labels, as: :label
|
||||
|
||||
.group-labels{ class: ('hidden' if hide || @project.group.blank? || @group_labels.empty?) }
|
||||
%h5
|
||||
= icon('folder-open')
|
||||
Group Labels
|
||||
%ul.content-list.manage-labels-list.js-group-labels
|
||||
- if @group_labels.present?
|
||||
= render partial: 'shared/label', collection: @group_labels, as: :label
|
||||
|
||||
.project-labels{ class: ('hidden' if @project_labels.empty?) }
|
||||
%h5{ class: ('hidden' if hide) }
|
||||
= icon('bookmark')
|
||||
Project Labels
|
||||
%ul.content-list.manage-labels-list.js-project-labels
|
||||
- if @project_labels.present?
|
||||
= render partial: 'shared/label', collection: @project_labels, as: :label
|
||||
= paginate @project_labels, theme: 'gitlab'
|
||||
- else
|
||||
.nothing-here-block
|
||||
- if can?(current_user, :admin_label, @project)
|
||||
Create a label or #{link_to 'generate a default set of labels', generate_namespace_project_labels_path(@project.namespace, @project), method: :post}.
|
||||
- else
|
||||
No labels created yet.
|
||||
%h5{ class: ('hide' if hide) } Other Labels
|
||||
%ul.content-list.manage-labels-list.js-other-labels
|
||||
- if @labels.present?
|
||||
= render partial: 'shared/label', collection: @labels, as: :label
|
||||
= paginate @labels, theme: 'gitlab'
|
||||
- if @labels.blank?
|
||||
.nothing-here-block
|
||||
- if can?(current_user, :admin_label, @project)
|
||||
Create a label or #{link_to 'generate a default set of labels', generate_namespace_project_labels_path(@project.namespace, @project), method: :post}.
|
||||
- else
|
||||
No labels created
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
%div{ class: container_class }
|
||||
%h3.page-title
|
||||
= icon('bookmark')
|
||||
New Project Label
|
||||
New Label
|
||||
%hr
|
||||
= render 'form', url: namespace_project_labels_path(@project.namespace.becomes(Namespace), @project)
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
= icon('star')
|
||||
%span.label-name
|
||||
= link_to_label(label, subject: @project, tooltip: false)
|
||||
- if can?(current_user, :admin_label, @project)
|
||||
= label_type_icon(label, hidden: label.priority.blank?)
|
||||
- if label.description
|
||||
%span.label-description
|
||||
= markdown_field(label, :description)
|
||||
|
|
|
@ -33,55 +33,29 @@ describe Projects::LabelsController do
|
|||
end
|
||||
|
||||
it 'is sorted by priority, then label title' do
|
||||
expect(assigns(:prioritized_labels)).to match_array [group_label_2, label_1, label_3, group_label_1, label_2]
|
||||
expect(assigns(:prioritized_labels)).to eq [group_label_2, label_1, label_3, group_label_1, label_2]
|
||||
end
|
||||
end
|
||||
|
||||
context '@group_labels' do
|
||||
it 'contains only group labels' do
|
||||
list_labels
|
||||
|
||||
expect(assigns(:group_labels)).to all(have_attributes(group_id: a_value > 0))
|
||||
end
|
||||
|
||||
context '@labels' do
|
||||
it 'contains only unprioritized labels' do
|
||||
list_labels
|
||||
|
||||
expect(assigns(:group_labels)).to all(have_attributes(priority: nil))
|
||||
expect(assigns(:labels)).to all(have_attributes(priority: nil))
|
||||
end
|
||||
|
||||
it 'is sorted by label title' do
|
||||
list_labels
|
||||
|
||||
expect(assigns(:group_labels)).to match_array [group_label_3, group_label_4]
|
||||
expect(assigns(:labels)).to eq [group_label_3, group_label_4, label_4, label_5]
|
||||
end
|
||||
|
||||
it 'is nil when project does not belong to a group' do
|
||||
it 'does not include group labels when project does not belong to a group' do
|
||||
project.update(namespace: create(:namespace))
|
||||
|
||||
list_labels
|
||||
|
||||
expect(assigns(:group_labels)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context '@project_labels' do
|
||||
before do
|
||||
list_labels
|
||||
end
|
||||
|
||||
it 'contains only project labels' do
|
||||
list_labels
|
||||
|
||||
expect(assigns(:project_labels)).to all(have_attributes(project_id: a_value > 0))
|
||||
end
|
||||
|
||||
it 'contains only unprioritized labels' do
|
||||
expect(assigns(:project_labels)).to all(have_attributes(priority: nil))
|
||||
end
|
||||
|
||||
it 'is sorted by label title' do
|
||||
expect(assigns(:project_labels)).to match_array [label_4, label_5]
|
||||
expect(assigns(:labels)).not_to include(group_label_3, group_label_4)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ feature 'Prioritize labels', feature: true do
|
|||
|
||||
expect(page).to have_content('No prioritized labels yet')
|
||||
|
||||
page.within('.group-labels') do
|
||||
first('.js-toggle-priority').click
|
||||
page.within('.other-labels') do
|
||||
all('.js-toggle-priority')[1].click
|
||||
wait_for_ajax
|
||||
expect(page).not_to have_content('feature')
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ feature 'Prioritize labels', feature: true do
|
|||
expect(page).not_to have_content('bug')
|
||||
end
|
||||
|
||||
page.within('.group-labels') do
|
||||
page.within('.other-labels') do
|
||||
expect(page).to have_content('feature')
|
||||
end
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ feature 'Prioritize labels', feature: true do
|
|||
|
||||
expect(page).to have_content('No prioritized labels yet')
|
||||
|
||||
page.within('.project-labels') do
|
||||
page.within('.other-labels') do
|
||||
first('.js-toggle-priority').click
|
||||
wait_for_ajax
|
||||
expect(page).not_to have_content('bug')
|
||||
|
@ -82,7 +82,7 @@ feature 'Prioritize labels', feature: true do
|
|||
expect(page).not_to have_content('bug')
|
||||
end
|
||||
|
||||
page.within('.project-labels') do
|
||||
page.within('.other-labels') do
|
||||
expect(page).to have_content('bug')
|
||||
expect(page).to have_content('wontfix')
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue