Skip to content

Commit

Permalink
Allow admins to select a specific color for each IssuePriority
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Jun 26, 2024
1 parent d9a918e commit 9b0a1a4
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/4_2_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
sed -i '/rubocop/d' Gemfile
rm -f .rubocop*
cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml
echo 'gem "builder", "~> 3.2.4"' >> Gemfile
- name: Install Ruby dependencies
working-directory: redmine
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/5_1_2.yml → .github/workflows/5_1_3.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Tests 5.1.2
name: Tests 5.1.3

env:
PLUGIN_NAME: redmine_tiny_features
REDMINE_VERSION: 5.1.2
REDMINE_VERSION: 5.1.3
RAILS_ENV: test

on:
Expand All @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
ruby: ['3.1']
ruby: ['3.2']
db: ['postgres']
fail-fast: false

Expand Down Expand Up @@ -90,8 +90,6 @@ jobs:
working-directory: redmine
run: |
rm -f test/integration/routing/plugins_test.rb # Fix routing tests # TODO Remove this line when https://www.redmine.org/issues/38707 is fixed
# TODO Remove the following line when https://www.redmine.org/issues/40551 is fixed
sed -i -e 's/.*mocha.*/ gem "mocha", "2.1.0"/' Gemfile # Fix core tests not compatible with Mocha 2.2.0
sed -i '/rubocop/d' Gemfile
rm -f .rubocop*
cp plugins/redmine_base_rspec/spec/support/database-${{ matrix.db }}.yml config/database.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
ruby: ['3.2']
ruby: ['3.3']
db: ['postgres']
fail-fast: false

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Here is a complete list of the features:
| Plugin branch | Redmine Version | Test Status |
|---------------|-----------------|-------------------|
| master | 4.2.11 | [![4.2.11][1]][5] |
| master | 5.1.2 | [![5.1.2][2]][5] |
| master | 5.1.3 | [![5.1.3][2]][5] |
| master | master | [![master][3]][5] |

[1]: https://github.com/nanego/redmine_tiny_features/actions/workflows/4_2_11.yml/badge.svg
[2]: https://github.com/nanego/redmine_tiny_features/actions/workflows/5_1_2.yml/badge.svg
[2]: https://github.com/nanego/redmine_tiny_features/actions/workflows/5_1_3.yml/badge.svg
[3]: https://github.com/nanego/redmine_tiny_features/actions/workflows/master.yml/badge.svg
[5]: https://github.com/nanego/redmine_tiny_features/actions
10 changes: 10 additions & 0 deletions app/overrides/enumerations/_form.rb
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
2 changes: 1 addition & 1 deletion app/overrides/projects/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:name => 'hide-members-on-project-overview',
:surround => "erb[loud]:contains('members_box')",
:text => <<-EOS
<% if !Setting["plugin_redmine_tiny_features"]["hide_members_section_on_project_overview"].present? %>
<% unless Setting["plugin_redmine_tiny_features"]["hide_members_section_on_project_overview"] == '1' %>
<%= render_original %>
<% end %>
EOS
25 changes: 25 additions & 0 deletions assets/stylesheets/tiny_features.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ table.trackers-permissions td.role {color:#999;font-size:90%;font-weight:normal
top: auto;
}

/* priorities */
tr.priority-red, table.list tbody tr.priority-red:hover { color:#c00; }
tr.priority-red a, tr.priority-red:hover a { color:#c00; }
tr.priority-red, table.list:not(.odd-even) tbody tr:nth-child(odd).priority-red,
table.list:not(.odd-even) tbody tr:nth-child(even).priority-red { background:#ffe3e3; }
tr.priority-red:hover td, tr.priority-red:hover a, tr.priority-red:hover a:hover, tr.priority-red:hover span.status, tr.priority-red:hover p.extra-fields, td.priority-red { color:#ffe3e3; background:#c00; }

tr.priority-orange, table.list tbody tr.priority-orange:hover { color:#b36d00; font-weight:normal; }
tr.priority-orange a, tr.priority-orange:hover a { color:#b36d00; }
tr.priority-orange, table.list:not(.odd-even) tbody tr:nth-child(odd).priority-orange,
table.list:not(.odd-even) tbody tr:nth-child(even).priority-orange { background:#fadcb3; }
tr.priority-orange:hover td, tr.priority-orange:hover a, tr.priority-orange:hover a:hover, tr.priority-orange:hover span.status, tr.priority-orange:hover p.extra-fields, td.priority-orange { color:#fadcb3; background:#b36d00; }

tr.priority-green, table.list tbody tr.priority-green:hover { color:#229e43; }
tr.priority-green a, tr.priority-green:hover a { color:#229e43; }
tr.priority-green, table.list:not(.odd-even) tbody tr:nth-child(odd).priority-green,
table.list:not(.odd-even) tbody tr:nth-child(even).priority-green { background:#f9ffef; }
tr.priority-green:hover td, tr.priority-green:hover a, tr.priority-green:hover a:hover, tr.priority-green:hover span.status, tr.priority-green:hover p.extra-fields, td.priority-green { color:#f9ffef; background:#229e43; }

tr.priority-grey, table.list tbody tr.priority-grey:hover { color:#888; }
tr.priority-grey a, tr.priority-grey:hover a { color:#888; }
tr.priority-grey, table.list:not(.odd-even) tbody tr:nth-child(odd).priority-grey,
table.list:not(.odd-even) tbody tr:nth-child(even).priority-grey { background:#ffffff; }
tr.priority-grey:hover td, tr.priority-grey:hover a, tr.priority-grey:hover a:hover, tr.priority-grey:hover span.status, tr.priority-grey:hover p.extra-fields, td.priority-grey { color:#ffffff; background:#bbb; }

/* issue_statuses */
tr.status-red, table.list tbody tr.priority-3:hover { color:#c00; }
tr.status-red a, tr.priority-3:hover a { color:#c00; }
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/006_add_color_to_enumerations.rb
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 lib/redmine_tiny_features/enumerations_controller_patch.rb
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
12 changes: 12 additions & 0 deletions lib/redmine_tiny_features/enumerations_helper_patch.rb
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)
3 changes: 3 additions & 0 deletions lib/redmine_tiny_features/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def after_plugins_loaded(_context = {})
require_relative 'users_helper_patch'
require_relative 'user_preference_patch'
require_relative 'issues_pdf_helper_patch'
require_relative 'issue_priority_patch'
require_relative 'enumerations_helper_patch'
require_relative 'enumerations_controller_patch'
end
end
end
22 changes: 22 additions & 0 deletions lib/redmine_tiny_features/issue_priority_patch.rb
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
54 changes: 54 additions & 0 deletions spec/controllers/enumerations_controller_spec.rb
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
33 changes: 27 additions & 6 deletions spec/controllers/issues_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@
:trackers, :issue_statuses, :enumerations, :custom_fields,
:custom_values, :custom_fields_projects, :projects_trackers, :workflows

let!(:priority_normal) { Enumeration.find_by(:type => "IssuePriority", :name => "Low") }
let!(:priority_low) { Enumeration.find_by(:type => "IssuePriority", :name => "Normal") }
let!(:priority_high) { Enumeration.find_by(:type => "IssuePriority", :name => "High") }
let!(:priority_urgent) { Enumeration.find_by(:type => "IssuePriority", :name => "Urgent") }

before do
User.current = User.find(1)
@request.session[:user_id] = 1 # admin

priority_low.update_attribute(:color, "grey")
priority_normal.update_attribute(:color, "green")
priority_high.update_attribute(:color, "orange")
priority_urgent.update_attribute(:color, "red")
end

describe "range custom-field format" do
Expand All @@ -27,12 +37,6 @@
end
end

before do
@controller = IssuesController.new
@request = ActionDispatch::TestRequest.create
@request.session[:user_id] = 1
end

describe "colorization of issues" do

it "should show the colorization of issues by status if the user selects this mode" do
Expand All @@ -56,6 +60,23 @@
assert_select "table tbody tr.status-red", :count => Issue.where(status_id: 6).count
end

it "displays issues colorized by priority if the user selects this mode" do
User.find(1).update_attribute(:issue_display_mode, User::BY_PRIORITY)

columns = ['project', 'status', 'priority']
get :index, :params => { :set_filter => 1,
:f => ["status_id" => ""],
:op => { "status_id" => "o" },
:c => columns }

expect(Issue.count).to eq 14
assert_select "table tbody tr", :count => 14
assert_select "tr.priority-grey", :count => Issue.where(priority_id: priority_low.id).count
assert_select "table tbody tr.priority-green", :count => Issue.where(priority_id: priority_normal.id).count
assert_select "table tbody tr.priority-orange", :count => Issue.where(priority_id: priority_high.id).count
assert_select "table tbody tr.priority-red", :count => Issue.where(priority_id: priority_urgent.id).count
end

it "should switch the display mode of issue for user in project/issue index" do
post :switch_display_mode, :params => { :path => "http://localhost:3000/projects/ecookbook/issues" }
expect(User.find(1).issue_display_mode).to eq User::BY_STATUS
Expand Down
23 changes: 8 additions & 15 deletions spec/system/projects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@
let(:project_test) { Project.find(1) }

it "hides members section when the option is activated" do

Setting.send "plugin_redmine_tiny_features=", {
"hide_members_section_on_project_overview" => "1",
}

visit "/projects/#{project_test.identifier}"
expect(page).to_not have_selector('div.members')

with_settings :plugin_redmine_tiny_features => { 'hide_members_section_on_project_overview' => '1' } do
visit "/projects/#{project_test.identifier}"
expect(page).to_not have_selector('div.members')
end
end

it "displays members section when the option is deactivated" do

Setting.send "plugin_redmine_tiny_features=", {
"hide_members_section_on_project_overview" => "",
}

visit "/projects/#{project_test.identifier}"
expect(page).to have_selector('div.members')
with_settings :plugin_redmine_tiny_features => { 'hide_members_section_on_project_overview' => '' } do
visit "/projects/#{project_test.identifier}"
expect(page).to have_selector('div.members')
end
end

end
Expand Down

0 comments on commit 9b0a1a4

Please sign in to comment.