-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init new feature to choose priorities colors
- Loading branch information
Showing
12 changed files
with
188 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Deface::Override.new :virtual_path => "enumerations/_form", | ||
:name => "add-color-select-to-issues-Priorities-form", | ||
:insert_after => "p[1]", | ||
:text => "<% if @enumeration.type == 'IssuePriority' %><p><%= f.select :color, valid_priority_color_list %></p><% end %>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddColorToEnumerations < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :enumerations, :color, :string, :default => '', :null => false | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
lib/redmine_tiny_features/enumerations_controller_patch.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require_dependency 'enumerations_controller' | ||
|
||
module RedmineTinyFeatures::EnumerationsControllerPatch | ||
|
||
def enumeration_params | ||
# can't require enumeration on #new action | ||
cf_ids = @enumeration.available_custom_fields.map {|c| c.multiple? ? {c.id.to_s => []} : c.id.to_s} | ||
params.permit(:enumeration => [:name, :active, :is_default, :position, :color, :custom_field_values => cf_ids])[:enumeration] | ||
end | ||
|
||
end | ||
|
||
EnumerationsController.prepend RedmineTinyFeatures::EnumerationsControllerPatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require_dependency 'enumerations_helper' | ||
|
||
module RedmineTinyFeatures | ||
module EnumerationsHelperPatch | ||
def valid_priority_color_list | ||
IssuePriority.valid_priority_color_list.collect {|o| [l(o.last), o.first]} | ||
end | ||
end | ||
end | ||
|
||
EnumerationsHelper.prepend RedmineTinyFeatures::EnumerationsHelperPatch | ||
ActionView::Base.send(:include, EnumerationsHelper) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require_dependency 'issue_priority' | ||
|
||
module RedmineTinyFeatures::IssuePriorityPatch | ||
def css_classes | ||
if !Rails.env.test? || plugin_test_mode? | ||
"priority-#{color}" | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
class IssuePriority < Enumeration | ||
|
||
COLOR_LIST = [ | ||
['green', :label_green], | ||
['orange', :label_orange], | ||
['red', :label_red], | ||
['grey', :label_grey], | ||
] | ||
|
||
validates_inclusion_of :color, :in => COLOR_LIST.collect(&:first) | ||
|
||
before_validation :set_color | ||
|
||
def set_color | ||
self.color = COLOR_LIST.collect(&:first).first if self.color.blank? | ||
true | ||
end | ||
|
||
def self.valid_priority_color_list | ||
COLOR_LIST | ||
end | ||
|
||
def plugin_test_mode? | ||
Rails.env.test? && $testing_plugin | ||
end | ||
end | ||
|
||
IssuePriority.prepend RedmineTinyFeatures::IssuePriorityPatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
describe EnumerationsController do | ||
include ApplicationHelper | ||
render_views | ||
|
||
fixtures :users, :enumerations | ||
|
||
before do | ||
@controller = EnumerationsController.new | ||
@request = ActionDispatch::TestRequest.create | ||
@request.session[:user_id] = 1 | ||
end | ||
|
||
it "should add the option of color" do | ||
get :new, :params => {:type => "IssuePriority" } | ||
|
||
assert_select "select#enumeration_color" do |element| | ||
assert_select element, "option", 4 | ||
end | ||
end | ||
|
||
it "should create priority with color" do | ||
expect { | ||
post( | ||
:create, | ||
:params => { | ||
:enumeration => { | ||
:type => "IssuePriority", | ||
:name => "test", | ||
:color => "green", | ||
:active =>"1", | ||
:is_default => "0" | ||
} | ||
} | ||
) | ||
}.to change{ Enumeration.count }.by(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require File.expand_path('../../../../config/environment', __FILE__) | ||
require File.expand_path("../../../redmine_base_rspec/spec/spec_helper", __FILE__) | ||
|
||
RSpec.configure do |config| | ||
config.before(:each) do | ||
$testing_plugin = true | ||
end | ||
|
||
config.after(:each) do | ||
$testing_plugin = false | ||
end | ||
end |