Commit b2a6f4e1 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor label rendering and default label set generation

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d79c0ea2
...@@ -6,7 +6,7 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -6,7 +6,7 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to :js, :html respond_to :js, :html
def index def index
@labels = @project.issues_labels @labels = @project.labels
end end
def generate def generate
......
module LabelsHelper module LabelsHelper
def issue_label_names def project_label_names
@project.labels.pluck(:title) @project.labels.pluck(:title)
end end
def labels_autocomplete_source def render_colored_label(label)
labels = @project.labels label_color = label.color || "#428bca"
labels = labels.map { |l| { label: l.name, value: l.name } } r, g, b = label_color.slice(1,7).scan(/.{2}/).map(&:hex)
labels.to_json
end
def label_css_class(name)
klass = Gitlab::IssuesLabels
case name.downcase if (r + g + b) > 500
when *klass.warning_labels text_color = "#333"
'label-warning'
when *klass.neutral_labels
'label-primary'
when *klass.positive_labels
'label-success'
when *klass.important_labels
'label-danger'
else else
'label-info' text_color = "#FFF"
end
content_tag :span, class: 'label', style: "background:#{label_color};color:#{text_color}" do
label.name
end end
end end
end end
...@@ -31,9 +31,7 @@ ...@@ -31,9 +31,7 @@
.issue-labels .issue-labels
- issue.labels.each do |label| - issue.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"} = render_colored_label(label)
%i.icon-tag
= label.name
.issue-actions .issue-actions
- if can? current_user, :modify_issue, issue - if can? current_user, :modify_issue, issue
......
...@@ -68,9 +68,6 @@ ...@@ -68,9 +68,6 @@
.issue-show-labels.pull-right .issue-show-labels.pull-right
- @issue.labels.each do |label| - @issue.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"} = render_colored_label(label)
%i.icon-tag
= label.name
&nbsp;
.voting_notes#notes= render "projects/notes/notes_with_form" .voting_notes#notes= render "projects/notes/notes_with_form"
...@@ -34,6 +34,4 @@ ...@@ -34,6 +34,4 @@
.merge-request-labels .merge-request-labels
- merge_request.labels.each do |label| - merge_request.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"} = render_colored_label(label)
%i.icon-tag
= label.name
...@@ -5,7 +5,4 @@ ...@@ -5,7 +5,4 @@
.merge-request-show-labels.pull-right .merge-request-show-labels.pull-right
- @merge_request.labels.each do |label| - @merge_request.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"} = render_colored_label(label)
%i.icon-tag
= label.name
&nbsp;
...@@ -36,21 +36,19 @@ ...@@ -36,21 +36,19 @@
%fieldset %fieldset
%legend Labels %legend Labels
%ul.nav.nav-pills.nav-stacked.nav-small.labels-filter %ul.nav.nav-pills.nav-stacked.nav-small.labels-filter
- issue_label_names.each do |label_name| - @project.labels.each do |label|
%li{class: label_filter_class(label_name)} %li{class: label_filter_class(label.name)}
= link_to labels_filter_path(label_name) do = link_to labels_filter_path(label.name) do
%span{class: "label #{label_css_class(label_name)}"} = render_colored_label(label)
%i.icon-tag - if selected_label?(label.name)
= label_name
- if selected_label?(label_name)
.pull-right .pull-right
%i.icon-remove %i.icon-remove
- if issue_label_names.empty? - if @project.labels.empty?
.light-well .light-well
Add first label to your issues Add first label to your issues
%br %br
or #{link_to 'generate', generate_project_labels_path(@project, redirect: redirect), method: :post} default set of labels or #{link_to 'generate', generate_project_labels_path(@project, redirect: redirect), method: :post} default set of labels
%fieldset %fieldset
- if %w(state scope milestone_id assignee_id label_name).select { |k| params[k].present? }.any? - if %w(state scope milestone_id assignee_id label_name).select { |k| params[k].present? }.any?
......
module Gitlab module Gitlab
class IssuesLabels class IssuesLabels
class << self class << self
def important_labels
%w(bug critical confirmed)
end
def warning_labels
%w(documentation support)
end
def neutral_labels
%w(discussion suggestion)
end
def positive_labels
%w(feature enhancement)
end
def generate(project) def generate(project)
label_names = important_labels + warning_labels + neutral_labels + positive_labels red = '#d9534f'
yellow = '#f0ad4e'
blue = '#428bca'
green = '#5cb85c'
labels = [
{ title: "bug", color: red },
{ title: "critical", color: red },
{ title: "confirmed", color: red },
{ title: "documentation", color: yellow },
{ title: "support", color: yellow },
{ title: "discussion", color: blue },
{ title: "suggestion", color: blue },
{ title: "feature", color: green },
{ title: "enhancement", color: green }
]
label_names.each do |label_name| labels.each do |label|
project.labels.create(title: label_name) project.labels.create(label)
end end
end end
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