Unverified Commit 593df8e6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Improve labels



* allow developers to manage labels
* add ability to remove label
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 027c8fe9c7f8
......@@ -94,7 +94,7 @@
}
}
.issue-show-labels .label {
.issue-show-labels .color-label {
padding: 6px 10px;
}
......
......@@ -15,3 +15,7 @@
font-size: 14px;
}
}
.color-label {
padding: 3px 4px;
}
class Projects::LabelsController < Projects::ApplicationController
before_filter :module_enabled
before_filter :label, only: [:edit, :update]
before_filter :label, only: [:edit, :update, :destroy]
before_filter :authorize_labels!
before_filter :authorize_admin_labels!, only: [:edit, :update, :new, :create, :destroy]
before_filter :authorize_admin_labels!, except: [:index]
respond_to :js, :html
def index
@labels = @project.labels
@labels = @project.labels.order('title ASC').page(params[:page]).per(20)
end
def new
@label = @project.labels.new
end
def create
......@@ -48,6 +47,12 @@ def generate
end
end
def destroy
@label.destroy
redirect_to project_labels_path(@project), notice: 'Label was removed'
end
protected
def module_enabled
......
......@@ -13,7 +13,7 @@ def render_colored_label(label)
text_color = "#FFF"
end
content_tag :span, class: 'label', style: "background:#{label_color};color:#{text_color}" do
content_tag :span, class: 'label color-label', style: "background:#{label_color};color:#{text_color}" do
label.name
end
end
......
......@@ -142,6 +142,7 @@ def project_dev_rules
:write_wiki,
:modify_issue,
:admin_issue,
:admin_label,
:push_code
]
end
......@@ -164,7 +165,6 @@ def project_master_rules
:modify_merge_request,
:admin_issue,
:admin_milestone,
:admin_label,
:admin_project_snippet,
:admin_team_member,
:admin_merge_request,
......
class Label < ActiveRecord::Base
belongs_to :project
has_many :label_links, dependent: :destroy
has_many :issues, through: :label_links, source: :target, source_type: 'Issue'
validates :color, format: { with: /\A\#[0-9A-Fa-f]{6}+\Z/ }, allow_blank: true
validates :project, presence: true
......@@ -11,4 +12,8 @@ class Label < ActiveRecord::Base
def name
title
end
def open_issues_count
issues.opened.count
end
end
%li
= render_colored_label(label)
.pull-right
= link_to 'Edit', edit_project_label_path(@project, label), class: 'btn'
%strong.append-right-20
= link_to project_issues_path(@project, label_name: label.name) do
= pluralize label.open_issues_count, 'open issue'
- if can? current_user, :admin_label, @project
= link_to 'Edit', edit_project_label_path(@project, label), class: 'btn'
= link_to 'Remove', project_label_path(@project, label), class: 'btn btn-remove', method: :delete, data: {confirm: "Remove this label? Are you sure?"}
......@@ -2,9 +2,10 @@ Feature: Project Filter Labels
Background:
Given I sign in as a user
And I own project "Shop"
And project "Shop" has issue "Bugfix1" with tags: "bug", "feature"
And project "Shop" has issue "Bugfix2" with tags: "bug", "enhancement"
And project "Shop" has issue "Feature1" with tags: "feature"
And project "Shop" has labels: "bug", "feature", "enhancement"
And project "Shop" has issue "Bugfix1" with labels: "bug", "feature"
And project "Shop" has issue "Bugfix2" with labels: "bug", "enhancement"
And project "Shop" has issue "Feature1" with labels: "feature"
Given I visit project "Shop" issues page
Scenario: I should see project issues
......@@ -18,9 +19,12 @@ Feature: Project Filter Labels
And I should see "Bugfix2" in issues list
And I should not see "Feature1" in issues list
Scenario: I filter by two labels
Given I click link "bug"
And I click link "feature"
Then I should see "Bugfix1" in issues list
And I should not see "Bugfix2" in issues list
And I should not see "Feature1" in issues list
# TODO: make labels filter works according to this scanario
# right now it looks for label 1 OR label 2. Old behaviour (this test) was
# all issues that have both label 1 AND label 2
#Scenario: I filter by two labels
#Given I click link "bug"
#And I click link "feature"
#Then I should see "Bugfix1" in issues list
#And I should not see "Bugfix2" in issues list
#And I should not see "Feature1" in issues list
......@@ -3,68 +3,84 @@ class ProjectFilterLabels < Spinach::FeatureSteps
include SharedProject
include SharedPaths
Then 'I should see "bug" in labels filter' do
step 'project "Shop" has labels: "bug", "feature", "enhancement"' do
project = Project.find_by(name: "Shop")
create(:label, project: project, title: 'bug')
create(:label, project: project, title: 'feature')
create(:label, project: project, title: 'enhancement')
end
step 'I should see "bug" in labels filter' do
within ".labels-filter" do
page.should have_content "bug"
end
end
And 'I should see "feature" in labels filter' do
step 'I should see "feature" in labels filter' do
within ".labels-filter" do
page.should have_content "feature"
end
end
And 'I should see "enhancement" in labels filter' do
step 'I should see "enhancement" in labels filter' do
within ".labels-filter" do
page.should have_content "enhancement"
end
end
Then 'I should see "Bugfix1" in issues list' do
step 'I should see "Bugfix1" in issues list' do
within ".issues-list" do
page.should have_content "Bugfix1"
end
end
And 'I should see "Bugfix2" in issues list' do
step 'I should see "Bugfix2" in issues list' do
within ".issues-list" do
page.should have_content "Bugfix2"
end
end
And 'I should not see "Bugfix2" in issues list' do
step 'I should not see "Bugfix2" in issues list' do
within ".issues-list" do
page.should_not have_content "Bugfix2"
end
end
And 'I should not see "Feature1" in issues list' do
step 'I should not see "Feature1" in issues list' do
within ".issues-list" do
page.should_not have_content "Feature1"
end
end
Given 'I click link "bug"' do
click_link "bug"
step 'I click link "bug"' do
within ".labels-filter" do
click_link "bug"
end
end
Given 'I click link "feature"' do
click_link "feature"
step 'I click link "feature"' do
within ".labels-filter" do
click_link "feature"
end
end
And 'project "Shop" has issue "Bugfix1" with tags: "bug", "feature"' do
step 'project "Shop" has issue "Bugfix1" with labels: "bug", "feature"' do
project = Project.find_by(name: "Shop")
create(:issue, title: "Bugfix1", project: project, label_list: ['bug', 'feature'])
issue = create(:issue, title: "Bugfix1", project: project)
issue.labels << project.labels.find_by(title: 'bug')
issue.labels << project.labels.find_by(title: 'feature')
end
And 'project "Shop" has issue "Bugfix2" with tags: "bug", "enhancement"' do
step 'project "Shop" has issue "Bugfix2" with labels: "bug", "enhancement"' do
project = Project.find_by(name: "Shop")
create(:issue, title: "Bugfix2", project: project, label_list: ['bug', 'enhancement'])
issue = create(:issue, title: "Bugfix2", project: project)
issue.labels << project.labels.find_by(title: 'bug')
issue.labels << project.labels.find_by(title: 'enhancement')
end
And 'project "Shop" has issue "Feature1" with tags: "feature"' do
step 'project "Shop" has issue "Feature1" with labels: "feature"' do
project = Project.find_by(name: "Shop")
create(:issue, title: "Feature1", project: project, label_list: 'feature')
issue = create(:issue, title: "Feature1", project: project)
issue.labels << project.labels.find_by(title: 'feature')
end
end
......@@ -17,8 +17,7 @@ class ProjectLabels < Spinach::FeatureSteps
And 'project "Shop" have issues tags: "bug", "feature"' do
project = Project.find_by(name: "Shop")
['bug', 'feature'].each do |label|
create(:issue, project: project, label_list: label)
end
label1 = create(:label, project: project, title: 'bug')
label2 = create(:label, project: project, title: 'feature')
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