-
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.
Allow admins to select a specific color for each IssuePriority
- Loading branch information
Showing
15 changed files
with
187 additions
and
30 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ jobs: | |
|
||
strategy: | ||
matrix: | ||
ruby: ['3.2'] | ||
ruby: ['3.3'] | ||
db: ['postgres'] | ||
fail-fast: false | ||
|
||
|
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,10 @@ | ||
Deface::Override.new :virtual_path => "enumerations/_form", | ||
:name => "add-color-select-to-issues-Priorities-form", | ||
:insert_after => "p:contains('is_default')", | ||
:text => <<-EOS | ||
<% if @enumeration.type == 'IssuePriority' %> | ||
<p> | ||
<%= f.select :color, priorities_colors_list %> | ||
</p> | ||
<% end %> | ||
EOS |
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,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 | ||
cf_ids = @enumeration.available_custom_fields.map {|c| c.multiple? ? {c.id.to_s => []} : c.id.to_s} | ||
# Add color parameter | ||
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 priorities_colors_list | ||
IssuePriority::COLOR_LIST.collect { |color| [l("label_#{color}"), color] } | ||
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,22 @@ | ||
require_dependency 'issue_priority' | ||
|
||
module RedmineTinyFeatures::IssuePriorityPatch | ||
def css_classes | ||
super.to_s + " priority-#{color}" | ||
end | ||
end | ||
|
||
class IssuePriority < Enumeration | ||
|
||
COLOR_LIST = %w( green orange red grey ) | ||
|
||
validates_inclusion_of :color, :in => COLOR_LIST | ||
|
||
before_validation :set_color | ||
|
||
def set_color | ||
self.color = COLOR_LIST.first if self.color.blank? | ||
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,54 @@ | ||
require 'spec_helper' | ||
|
||
describe EnumerationsController, type: :controller do | ||
include ApplicationHelper | ||
render_views | ||
|
||
fixtures :users, :enumerations | ||
|
||
before do | ||
@request.session[:user_id] = 1 | ||
end | ||
|
||
it "adds a select tag with colors" do | ||
get :new, :params => { :type => "IssuePriority" } | ||
|
||
assert_select "select#enumeration_color" do |element| | ||
assert_select element, "option", 4 | ||
end | ||
end | ||
|
||
it "creates a new priority with a 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 | ||
|
||
it "does not create a new priority with a invalid color" do | ||
expect { | ||
post( | ||
:create, | ||
:params => { | ||
:enumeration => { | ||
:type => "IssuePriority", | ||
:name => "test", | ||
:color => "light-blue", # invalid color | ||
:active => "1", | ||
:is_default => "0" | ||
} | ||
} | ||
) | ||
}.to_not change { Enumeration.count } | ||
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