Commit 03441769dfc09776eb8511275a3f492ded1a7c42

Authored by Dmitriy Zaporozhets
1 parent be68cc46

Include default labels in issues autocomplete etc. Show colored labels on issues show page

app/controllers/labels_controller.rb
... ... @@ -7,11 +7,11 @@ class LabelsController < ProjectResourceController
7 7 respond_to :js, :html
8 8  
9 9 def index
10   - @labels = @project.issues_labels.order('count DESC')
  10 + @labels = @project.issues_labels
11 11 end
12 12  
13 13 def generate
14   - Gitlab::Labels.generate(@project)
  14 + Gitlab::IssuesLabels.generate(@project)
15 15  
16 16 redirect_to project_labels_path(@project)
17 17 end
... ...
app/helpers/issues_helper.rb
... ... @@ -11,10 +11,6 @@ module IssuesHelper
11 11 classes
12 12 end
13 13  
14   - def issue_tags
15   - @project.issues.tag_counts_on(:labels).map(&:name)
16   - end
17   -
18 14 # Returns an OpenStruct object suitable for use by <tt>options_from_collection_for_select</tt>
19 15 # to allow filtering issues by an unassigned User or Milestone
20 16 def unassigned_filter
... ... @@ -32,12 +28,6 @@ module IssuesHelper
32 28 }
33 29 end
34 30  
35   - def labels_autocomplete_source
36   - labels = @project.issues_labels.order('count DESC')
37   - labels = labels.map{ |l| { label: l.name, value: l.name } }
38   - labels.to_json
39   - end
40   -
41 31 def issues_active_milestones
42 32 @project.milestones.active.order("id desc").all
43 33 end
... ... @@ -88,19 +78,4 @@ module IssuesHelper
88 78 ""
89 79 end
90 80 end
91   -
92   - def label_css_class(name)
93   - case name
94   - when *warning_labels
95   - 'label-warning'
96   - when *neutral_labels
97   - 'label-inverse'
98   - when *positive_labels
99   - 'label-success'
100   - when *important_labels
101   - 'label-important'
102   - else
103   - 'label-info'
104   - end
105   - end
106 81 end
... ...
app/helpers/labels_helper.rb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +module LabelsHelper
  2 + def issue_tags
  3 + @project.issues.tag_counts_on(:labels).map(&:name)
  4 + end
  5 +
  6 + def labels_autocomplete_source
  7 + labels = @project.issues_labels
  8 + labels = labels.map{ |l| { label: l.name, value: l.name } }
  9 + labels.to_json
  10 + end
  11 +
  12 + def label_css_class(name)
  13 + klass = Gitlab::IssuesLabels
  14 +
  15 + case name
  16 + when *klass.warning_labels
  17 + 'label-warning'
  18 + when *klass.neutral_labels
  19 + 'label-inverse'
  20 + when *klass.positive_labels
  21 + 'label-success'
  22 + when *klass.important_labels
  23 + 'label-important'
  24 + else
  25 + 'label-info'
  26 + end
  27 + end
  28 +end
... ...
app/models/project.rb
... ... @@ -34,7 +34,7 @@ class Project &lt; ActiveRecord::Base
34 34  
35 35 attr_accessible :namespace_id, :creator_id, as: :admin
36 36  
37   - acts_as_taggable_on :labels
  37 + acts_as_taggable_on :labels, :issues_default_labels
38 38  
39 39 attr_accessor :import_url
40 40  
... ... @@ -204,7 +204,7 @@ class Project &lt; ActiveRecord::Base
204 204 end
205 205  
206 206 def issues_labels
207   - issues.tag_counts_on(:labels)
  207 + @issues_labels ||= (issues_default_labels + issues.tags_on(:labels)).uniq.sort_by(&:name)
208 208 end
209 209  
210 210 def issue_exists?(issue_id)
... ...
app/views/issues/show.html.haml
... ... @@ -47,7 +47,7 @@
47 47  
48 48 .pull-right
49 49 - @issue.labels.each do |label|
50   - %span.label
  50 + %span{class: "label #{label_css_class(label.name)}"}
51 51 %i.icon-tag
52 52 = label.name
53 53 &nbsp;
... ...
app/views/labels/_label.html.haml
  1 +- frequency = @project.issues.tagged_with(label.name).count
1 2 %li
2 3 %strong
3   - %i.icon-tag
4   - = label.name
  4 + %span{class: "label #{label_css_class(label.name)}"}
  5 + %i.icon-tag
  6 + - if frequency.zero?
  7 + %span.light= label.name
  8 + - else
  9 + = label.name
5 10 .pull-right
6   - = link_to project_issues_path(label_name: label.name) do
7   - %strong
8   - = pluralize(label.count, 'issue')
9   - = "»"
  11 + - unless frequency.zero?
  12 + = link_to project_issues_path(label_name: label.name) do
  13 + %strong
  14 + = pluralize(frequency, 'issue')
  15 + = "»"
... ...
app/views/labels/index.html.haml
... ... @@ -4,12 +4,11 @@
4 4 Labels
5 5 %br
6 6  
7   -.light-well
  7 +- if @labels.present?
8 8 %ul.bordered-list.labels-table
9 9 - @labels.each do |label|
10 10 = render 'label', label: label
11 11  
12   - - unless @labels.present?
13   - %li
14   - %h3.nothing_here_message Add first label to your issues or #{link_to 'generate', generate_project_labels_path(@project), method: :post} default set of labels
15   -
  12 +- else
  13 + .light-well
  14 + %h3.nothing_here_message Add first label to your issues or #{link_to 'generate', generate_project_labels_path(@project), method: :post} default set of labels
... ...
lib/gitlab/issues_labels.rb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +module Gitlab
  2 + class IssuesLabels
  3 + class << self
  4 + def important_labels
  5 + %w(bug critical confirmed)
  6 + end
  7 +
  8 + def warning_labels
  9 + %w(documentation support)
  10 + end
  11 +
  12 + def neutral_labels
  13 + %w(discussion suggestion)
  14 + end
  15 +
  16 + def positive_labels
  17 + %w(feature enhancement)
  18 + end
  19 +
  20 + def generate(project)
  21 + labels = important_labels + warning_labels + neutral_labels + positive_labels
  22 +
  23 + project.issues_default_label_list = labels
  24 + project.save
  25 + end
  26 + end
  27 + end
  28 +end
... ...
lib/gitlab/labels.rb
... ... @@ -1,29 +0,0 @@
1   -module Gitlab
2   - class Labels
3   - class << self
4   - def important_labels
5   - %w(bug critical confirmed)
6   - end
7   -
8   - def warning_labels
9   - %w(documentation support)
10   - end
11   -
12   - def neutral_labels
13   - %w(discussion suggestion)
14   - end
15   -
16   - def positive_labels
17   - %w(feature enhancement)
18   - end
19   -
20   - def self.generate(project)
21   - labels = important_labels + warning_labels + neutral_labels + positive_labels
22   -
23   - labels.each do |label_name|
24   - # create tag for project
25   - end
26   - end
27   - end
28   - end
29   -end