Skip to content

Commit

Permalink
Init new feature to choose priorities colors
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Jun 26, 2024
1 parent d9a918e commit 6c0d23a
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 11 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
4 changes: 4 additions & 0 deletions app/overrides/enumerations/_form.rb
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 %>"
26 changes: 26 additions & 0 deletions assets/stylesheets/tiny_features.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ 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
# 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
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 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)
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
40 changes: 40 additions & 0 deletions lib/redmine_tiny_features/issue_priority_patch.rb
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
39 changes: 39 additions & 0 deletions spec/controllers/enumerations_controller_spec.rb
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
35 changes: 29 additions & 6 deletions spec/controllers/issues_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,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 +50,35 @@
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)

priority_low = Enumeration.find_by(:type => "IssuePriority", :name => "Low")
priority_low.update_attribute(:color, "grey")

priority_normal = Enumeration.find_by(:type => "IssuePriority", :name => "Normal")
priority_normal.update_attribute(:color, "green")

priority_high = Enumeration.find_by(:type => "IssuePriority", :name => "High")
priority_high.update_attribute(:color, "orange")

priority_urgent = Enumeration.find_by(:type => "IssuePriority", :name => "Urgent")
priority_urgent.update_attribute(:color, "red")

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 => 6 # 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
13 changes: 13 additions & 0 deletions spec/spec_helper.rb
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

0 comments on commit 6c0d23a

Please sign in to comment.