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
respond_to :js, :html
def index
@labels = @project.issues_labels
@labels = @project.labels
end
def generate
......
module LabelsHelper
def issue_label_names
def project_label_names
@project.labels.pluck(:title)
end
def labels_autocomplete_source
labels = @project.labels
labels = labels.map { |l| { label: l.name, value: l.name } }
labels.to_json
end
def label_css_class(name)
klass = Gitlab::IssuesLabels
def render_colored_label(label)
label_color = label.color || "#428bca"
r, g, b = label_color.slice(1,7).scan(/.{2}/).map(&:hex)
case name.downcase
when *klass.warning_labels
'label-warning'
when *klass.neutral_labels
'label-primary'
when *klass.positive_labels
'label-success'
when *klass.important_labels
'label-danger'
if (r + g + b) > 500
text_color = "#333"
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
......@@ -31,9 +31,7 @@
.issue-labels
- issue.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"}
%i.icon-tag
= label.name
= render_colored_label(label)
.issue-actions
- if can? current_user, :modify_issue, issue
......
......@@ -68,9 +68,6 @@
.issue-show-labels.pull-right
- @issue.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"}
%i.icon-tag
= label.name
&nbsp;
= render_colored_label(label)
.voting_notes#notes= render "projects/notes/notes_with_form"
......@@ -34,6 +34,4 @@
.merge-request-labels
- merge_request.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"}
%i.icon-tag
= label.name
= render_colored_label(label)
......@@ -5,7 +5,4 @@
.merge-request-show-labels.pull-right
- @merge_request.labels.each do |label|
%span{class: "label #{label_css_class(label.name)}"}
%i.icon-tag
= label.name
&nbsp;
= render_colored_label(label)
......@@ -36,17 +36,15 @@
%fieldset
%legend Labels
%ul.nav.nav-pills.nav-stacked.nav-small.labels-filter
- issue_label_names.each do |label_name|
%li{class: label_filter_class(label_name)}
= link_to labels_filter_path(label_name) do
%span{class: "label #{label_css_class(label_name)}"}
%i.icon-tag
= label_name
- if selected_label?(label_name)
- @project.labels.each do |label|
%li{class: label_filter_class(label.name)}
= link_to labels_filter_path(label.name) do
= render_colored_label(label)
- if selected_label?(label.name)
.pull-right
%i.icon-remove
- if issue_label_names.empty?
- if @project.labels.empty?
.light-well
Add first label to your issues
%br
......
module Gitlab
class IssuesLabels
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)
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|
project.labels.create(title: label_name)
labels.each do |label|
project.labels.create(label)
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