Commit 71647fd579e4df8e12e87d1fee459ed46a02e7d2
Exists in
master
and in
4 other branches
Merge branch 'feature/labels_set' of /home/git/repositories/gitlab/gitlabhq
Showing
11 changed files
with
94 additions
and
30 deletions
Show diff stats
app/controllers/labels_controller.rb
... | ... | @@ -7,7 +7,13 @@ 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 | + end | |
12 | + | |
13 | + def generate | |
14 | + Gitlab::IssuesLabels.generate(@project) | |
15 | + | |
16 | + redirect_to project_labels_path(@project) | |
11 | 17 | end |
12 | 18 | |
13 | 19 | protected | ... | ... |
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 | ... | ... |
... | ... | @@ -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 < 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 < 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/_issue.html.haml
app/views/issues/show.html.haml
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
... | ... | @@ -3,12 +3,12 @@ |
3 | 3 | %h3.page_title |
4 | 4 | Labels |
5 | 5 | %br |
6 | -%div.ui-box | |
7 | - %ul.well-list.labels-table | |
6 | + | |
7 | +- if @labels.present? | |
8 | + %ul.bordered-list.labels-table | |
8 | 9 | - @labels.each do |label| |
9 | 10 | = render 'label', label: label |
10 | 11 | |
11 | - - unless @labels.present? | |
12 | - %li | |
13 | - %h3.nothing_here_message Nothing to show here | |
14 | - | |
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 | ... | ... |
config/routes.rb
... | ... | @@ -269,7 +269,13 @@ Gitlab::Application.routes.draw do |
269 | 269 | |
270 | 270 | resources :team, controller: 'team_members', only: [:index] |
271 | 271 | resources :milestones, except: [:destroy] |
272 | - resources :labels, only: [:index] | |
272 | + | |
273 | + resources :labels, only: [:index] do | |
274 | + collection do | |
275 | + post :generate | |
276 | + end | |
277 | + end | |
278 | + | |
273 | 279 | resources :issues, except: [:destroy] do |
274 | 280 | collection do |
275 | 281 | post :bulk_update | ... | ... |
... | ... | @@ -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 | ... | ... |
spec/requests/api/projects_spec.rb
... | ... | @@ -485,9 +485,9 @@ describe Gitlab::API do |
485 | 485 | response.status.should == 200 |
486 | 486 | end |
487 | 487 | |
488 | - it "should return a 400 error if hook id not given" do | |
488 | + it "should return a 405 error if hook id not given" do | |
489 | 489 | delete api("/projects/#{project.id}/hooks", user) |
490 | - response.status.should == 400 | |
490 | + response.status.should == 405 | |
491 | 491 | end |
492 | 492 | end |
493 | 493 | ... | ... |