From ce95e56f0d698b73fb78584faf39f86439351555 Mon Sep 17 00:00:00 2001 From: Yalaeddin Date: Fri, 14 Jun 2024 11:46:31 +0200 Subject: [PATCH] =?UTF-8?q?Colorisation=20des=20demandes=20par=20priorit?= =?UTF-8?q?=C3=A9=20:=20pouvoir=20choisir=20la=20couleur=20pour=20chaque?= =?UTF-8?q?=20priorit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/overrides/enumerations/_form.rb | 4 ++ assets/stylesheets/tiny_features.css | 26 +++++++++++++ db/migrate/006_add_color_to_enumerations.rb | 5 +++ .../enumerations_controller_patch.rb | 15 +++++++ .../enumerations_helper_patch.rb | 12 ++++++ lib/redmine_tiny_features/hooks.rb | 3 ++ .../issue_priority_patch.rb | 32 +++++++++++++++ .../enumerations_controller_spec.rb | 39 +++++++++++++++++++ spec/controllers/issues_controller_spec.rb | 30 ++++++++++++++ 9 files changed, 166 insertions(+) create mode 100644 app/overrides/enumerations/_form.rb create mode 100644 db/migrate/006_add_color_to_enumerations.rb create mode 100644 lib/redmine_tiny_features/enumerations_controller_patch.rb create mode 100644 lib/redmine_tiny_features/enumerations_helper_patch.rb create mode 100644 lib/redmine_tiny_features/issue_priority_patch.rb create mode 100644 spec/controllers/enumerations_controller_spec.rb diff --git a/app/overrides/enumerations/_form.rb b/app/overrides/enumerations/_form.rb new file mode 100644 index 0000000..de0ecc4 --- /dev/null +++ b/app/overrides/enumerations/_form.rb @@ -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' %>

<%= f.select :color, valid_priority_color_list %>

<% end %>" diff --git a/assets/stylesheets/tiny_features.css b/assets/stylesheets/tiny_features.css index 41f96d7..2e54dbd 100644 --- a/assets/stylesheets/tiny_features.css +++ b/assets/stylesheets/tiny_features.css @@ -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; } diff --git a/db/migrate/006_add_color_to_enumerations.rb b/db/migrate/006_add_color_to_enumerations.rb new file mode 100644 index 0000000..3bb94ee --- /dev/null +++ b/db/migrate/006_add_color_to_enumerations.rb @@ -0,0 +1,5 @@ +class AddColorToEnumerations < ActiveRecord::Migration[5.2] + def change + add_column :enumerations, :color, :string, :default => '', :null => false + end +end diff --git a/lib/redmine_tiny_features/enumerations_controller_patch.rb b/lib/redmine_tiny_features/enumerations_controller_patch.rb new file mode 100644 index 0000000..095f00a --- /dev/null +++ b/lib/redmine_tiny_features/enumerations_controller_patch.rb @@ -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 diff --git a/lib/redmine_tiny_features/enumerations_helper_patch.rb b/lib/redmine_tiny_features/enumerations_helper_patch.rb new file mode 100644 index 0000000..52cb7f0 --- /dev/null +++ b/lib/redmine_tiny_features/enumerations_helper_patch.rb @@ -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) diff --git a/lib/redmine_tiny_features/hooks.rb b/lib/redmine_tiny_features/hooks.rb index 36f7aaf..a94cac5 100644 --- a/lib/redmine_tiny_features/hooks.rb +++ b/lib/redmine_tiny_features/hooks.rb @@ -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 diff --git a/lib/redmine_tiny_features/issue_priority_patch.rb b/lib/redmine_tiny_features/issue_priority_patch.rb new file mode 100644 index 0000000..1736f16 --- /dev/null +++ b/lib/redmine_tiny_features/issue_priority_patch.rb @@ -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 diff --git a/spec/controllers/enumerations_controller_spec.rb b/spec/controllers/enumerations_controller_spec.rb new file mode 100644 index 0000000..381bb60 --- /dev/null +++ b/spec/controllers/enumerations_controller_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/controllers/issues_controller_spec.rb b/spec/controllers/issues_controller_spec.rb index 3a4fd46..81406fb 100644 --- a/spec/controllers/issues_controller_spec.rb +++ b/spec/controllers/issues_controller_spec.rb @@ -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