forked from mathieu-mbru/redmine_tiny_features
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Colorisation des demandes par priorité : pouvoir choisir la couleur p…
…our chaque priorité
- Loading branch information
Showing
9 changed files
with
166 additions
and
0 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
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 |
15 changes: 15 additions & 0 deletions
15
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,15 @@ | ||
require_dependency 'enumerations_controller' | ||
|
||
module RedmineTinyFeatures::EnumerationsControllerPatch | ||
|
||
end | ||
|
||
class EnumerationsController | ||
|
||
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 |
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,32 @@ | ||
require_dependency 'issue_priority' | ||
|
||
module RedmineTinyFeatures::IssuePriorityPatch | ||
|
||
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 css_classes | ||
"priority-#{color}" | ||
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
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