Remove scopes/types for labels

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