Skip to content

Commit

Permalink
Colorisation des demandes par priorité : pouvoir choisir la couleur p…
Browse files Browse the repository at this point in the history
…our chaque priorité
  • Loading branch information
Yalaeddin committed Jun 14, 2024
1 parent d9a918e commit ce95e56
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 0 deletions.
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
15 changes: 15 additions & 0 deletions lib/redmine_tiny_features/enumerations_controller_patch.rb
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
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
32 changes: 32 additions & 0 deletions lib/redmine_tiny_features/issue_priority_patch.rb
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
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
30 changes: 30 additions & 0 deletions spec/controllers/issues_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@
assert_select "table tbody tr.status-red", :count => Issue.where(status_id: 6).count
end

it "should show the colorization of issues by priority if the user selects this mode" do
User.find(1).update_attribute(:issue_display_mode, User::BY_PRIORITY)

priority_low = Enumeration.where(:type => "IssuePriority")[0]
priority_low.update_attribute(:color, "green")

priority_default = Enumeration.where(:type => "IssuePriority")[1]
priority_default.update_attribute(:color, "grey")

priority_high3 = Enumeration.where(:type => "IssuePriority")[2]
priority_high3.update_attribute(:color, "orange")


priority_urgent = Enumeration.where(:type => "IssuePriority")[3]
priority_urgent.update_attribute(:color, "red")

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

expect(Issue.count).to eq 14
assert_select "table tbody tr", :count => 14
assert_select "table tbody tr.priority-green", :count => Issue.where(priority_id: priority_low.id).count
assert_select "table tbody tr.priority-grey", :count => Issue.where(priority_id: priority_default.id).count
assert_select "table tbody tr.priority-orange", :count => Issue.where(priority_id: priority_high3.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

0 comments on commit ce95e56

Please sign in to comment.