From 162c356b23e236724c7a46e0e4d1778903d45ee5 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 10 Nov 2024 06:40:07 +0000 Subject: [PATCH 1/8] Switched checked icon in context menu to SVG icon (#23980, #41720). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23224 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/assets/stylesheets/context_menu.css | 5 +++-- app/helpers/context_menus_helper.rb | 6 ++++-- test/functional/context_menus_controller_test.rb | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/context_menu.css b/app/assets/stylesheets/context_menu.css index 1b2b749ee..875564c8f 100644 --- a/app/assets/stylesheets/context_menu.css +++ b/app/assets/stylesheets/context_menu.css @@ -48,11 +48,12 @@ #context-menu li a.submenu { padding-right:16px; background:url("/arrow_right.png") right no-repeat; padding-left: 28px;} #context-menu li:hover { border:1px solid #628db6; background-color:#eef5fd; border-radius:3px; } #context-menu a:hover {color:#2A5685;} -#context-menu li.folder ul li a {padding-left: 20px;} +#context-menu li.folder ul li a:not(.icon) { + padding-left: 28px; +} #context-menu li.folder:hover { z-index:40; } #context-menu ul ul, #context-menu li:hover ul ul { display:none; } #context-menu li:hover ul, #context-menu li:hover li:hover ul { display:block; } -#context-menu a.icon-checked {background-position: 3px 40%;} /* selected element */ .context-menu-selection { background-color:#507AAA !important; color:#f8f8f8 !important; } diff --git a/app/helpers/context_menus_helper.rb b/app/helpers/context_menus_helper.rb index 0f208397c..bfabbbb4e 100644 --- a/app/helpers/context_menus_helper.rb +++ b/app/helpers/context_menus_helper.rb @@ -19,10 +19,12 @@ module ContextMenusHelper def context_menu_link(name, url, options={}) + label = name options[:class] ||= '' if options.delete(:selected) - options[:class] += ' icon icon-checked disabled' + options[:class] += ' icon disabled' options[:disabled] = true + label = sprite_icon('checked', name) end if options.delete(:disabled) options.delete(:method) @@ -31,7 +33,7 @@ module ContextMenusHelper options[:class] += ' disabled' url = '#' end - link_to h(name), url, options + link_to label, url, options end def bulk_update_custom_field_context_menu_link(field, text, value) diff --git a/test/functional/context_menus_controller_test.rb b/test/functional/context_menus_controller_test.rb index c8d4f798d..e10d2309c 100644 --- a/test/functional/context_menus_controller_test.rb +++ b/test/functional/context_menus_controller_test.rb @@ -221,7 +221,7 @@ class ContextMenusControllerTest < Redmine::ControllerTest assert_select 'a[href="#"]', :text => 'List' assert_select 'ul' do assert_select 'a', 3 - assert_select 'a.icon.icon-checked', :text => 'Bar' + assert_select 'a.icon', :text => 'Bar' end end end From 44408dcf1bd6b8fd530240b04145ff5a47d9183f Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 10 Nov 2024 06:43:10 +0000 Subject: [PATCH 2/8] Added tests for context_menu_link helper (#23980, #41720). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23225 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/helpers/context_menus_helper_test.rb | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/helpers/context_menus_helper_test.rb diff --git a/test/helpers/context_menus_helper_test.rb b/test/helpers/context_menus_helper_test.rb new file mode 100644 index 000000000..df9ea3374 --- /dev/null +++ b/test/helpers/context_menus_helper_test.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006- Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require_relative '../test_helper' + +class ContextMenusHelperTest < Redmine::HelperTest + include ContextMenusHelper + + test '#context_menu_link' do + html = context_menu_link('name', 'url', class: 'class-a') + assert_select_in html, 'a.class-a[href=?]', 'url' + + # When :selected is true + html = context_menu_link('name', 'url', selected: true, class: 'class-a class-b') + assert_select_in html, 'a.class-a.class-b.icon.disabled.disabled[href=?]', '#' do + assert_select 'svg.icon-svg' + end + + # When :disabled is true + html = context_menu_link('name', 'url', disabled: true, method: 'patch', data: { key: 'value' }) + assert_select_in html, + 'a.disabled[href=?][onclick=?]:not([method]):not([data-key])', + '#', 'return false;' + end +end From 624f9bf3d107488c67624de636171eeff10886ab Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Sun, 10 Nov 2024 06:45:26 +0000 Subject: [PATCH 3/8] Fixed duplicate "disabled" class in the context_menus_helper result (#23980, #41720). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23226 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/context_menus_helper.rb | 10 +++++++--- test/helpers/context_menus_helper_test.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/helpers/context_menus_helper.rb b/app/helpers/context_menus_helper.rb index bfabbbb4e..cb8153549 100644 --- a/app/helpers/context_menus_helper.rb +++ b/app/helpers/context_menus_helper.rb @@ -20,19 +20,23 @@ module ContextMenusHelper def context_menu_link(name, url, options={}) label = name - options[:class] ||= '' + css_classes = [options[:class]] + if options.delete(:selected) - options[:class] += ' icon disabled' + css_classes << 'icon disabled' options[:disabled] = true label = sprite_icon('checked', name) end + if options.delete(:disabled) options.delete(:method) options.delete(:data) options[:onclick] = 'return false;' - options[:class] += ' disabled' + css_classes << 'disabled' url = '#' end + + options[:class] = class_names(css_classes) link_to label, url, options end diff --git a/test/helpers/context_menus_helper_test.rb b/test/helpers/context_menus_helper_test.rb index df9ea3374..20ad333a3 100644 --- a/test/helpers/context_menus_helper_test.rb +++ b/test/helpers/context_menus_helper_test.rb @@ -28,7 +28,7 @@ class ContextMenusHelperTest < Redmine::HelperTest # When :selected is true html = context_menu_link('name', 'url', selected: true, class: 'class-a class-b') - assert_select_in html, 'a.class-a.class-b.icon.disabled.disabled[href=?]', '#' do + assert_select_in html, 'a.class-a.class-b.icon.disabled[href=?]', '#' do assert_select 'svg.icon-svg' end From ecee8ccabaefc131622638c50035bf77e92b7597 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 11:36:23 +0000 Subject: [PATCH 4/8] Fixes broken @link_to_principal@ helper test caused by r23222 (#41711, #23980). git-svn-id: https://svn.redmine.org/redmine/trunk@23227 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/helpers/application_helper_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index a2c4ac82f..c7e79cb66 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -1868,8 +1868,8 @@ class ApplicationHelperTest < Redmine::HelperTest def test_link_to_principal_should_link_to_group group = Group.find(10) - result = link_to('A Team', '/groups/10', :class => 'group') - assert_equal result, link_to_principal(group) + result = %r{A Team} + assert_match result, link_to_principal(group) end def test_link_to_principal_should_return_string_representation_for_unknown_type_principal From 505981c6824e0133ba2718e4d5e1f4c277a4e900 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 11:37:38 +0000 Subject: [PATCH 5/8] Fixes double-escaping issue for a principal name with special chars (#41721, #23980). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23228 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4a02d8376..806d59da1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -60,23 +60,23 @@ module ApplicationHelper only_path = options[:only_path].nil? ? true : options[:only_path] case principal when User - name = h(principal.name(options[:format])) - name = "@".html_safe + name if options[:mention] + name = principal.name(options[:format]) + name = "@#{name}" if options[:mention] css_classes = '' if principal.active? || (User.current.admin? && principal.logged?) url = user_url(principal, :only_path => only_path) css_classes += principal.css_classes end when Group - name = h(principal.to_s) + name = principal.to_s url = group_url(principal, :only_path => only_path) css_classes = principal.css_classes else - name = h(principal.to_s) + name = principal.to_s end css_classes += " #{options[:class]}" if css_classes && options[:class].present? - url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : name + url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : h(name) end # Displays a link to edit group page if current user is admin From 1af81684260f68c958a04df8adcd4d13b11f143f Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 15:29:42 +0000 Subject: [PATCH 6/8] Use double splat operator for icons methods that are extending @sprite_icon@ (#23980). git-svn-id: https://svn.redmine.org/redmine/trunk@23229 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/icons_helper.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 5654f3a2f..f423a2898 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -36,20 +36,20 @@ module IconsHelper end end - def file_icon(entry, name, size: DEFAULT_ICON_SIZE, css_class: nil) + def file_icon(entry, name, **options) if entry.is_dir? - sprite_icon("folder", name, size: size, css_class: css_class) + sprite_icon("folder", name, **options) else icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(name)) - sprite_icon(icon_name, name, size: size, css_class: css_class) + sprite_icon(icon_name, name, **options) end end - def principal_icon(principal_class, size: DEFAULT_ICON_SIZE, css_class: nil) - sprite_icon('group', size: size, css_class: css_class) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class) + def principal_icon(principal_class, **options) + sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class) end - def activity_event_type_icon(event_type, size: DEFAULT_ICON_SIZE, css_class: nil) + def activity_event_type_icon(event_type, **options) icon_name = case event_type when 'reply' 'comments' @@ -61,7 +61,7 @@ module IconsHelper event_type end - sprite_icon(icon_name, size: size, css_class: css_class) + sprite_icon(icon_name, **options) end private From 6d0eba75e92898c8308a8ed0892d49bd515c45b3 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 15:31:46 +0000 Subject: [PATCH 7/8] @principal_icon@ method should accept a Principal as argument (#23980). git-svn-id: https://svn.redmine.org/redmine/trunk@23230 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/application_helper.rb | 4 ++-- app/helpers/icons_helper.rb | 5 ++++- app/views/projects/settings/_members.html.erb | 2 +- test/helpers/application_helper_test.rb | 2 +- test/helpers/icons_helper_test.rb | 6 ++++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 806d59da1..bac8da266 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -76,7 +76,7 @@ module ApplicationHelper end css_classes += " #{options[:class]}" if css_classes && options[:class].present? - url ? link_to(principal_icon(principal.class.name.downcase).to_s + name, url, :class => css_classes) : h(name) + url ? link_to(principal_icon(principal).to_s + name, url, :class => css_classes) : h(name) end # Displays a link to edit group page if current user is admin @@ -657,7 +657,7 @@ module ApplicationHelper check_box_tag(name, principal.id, false, :id => nil) + (avatar(principal, :size => 16).presence || content_tag( - 'span', principal_icon(principal.class.name.downcase), + 'span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}" ) ) + principal.to_s diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index f423a2898..99006308e 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -45,7 +45,10 @@ module IconsHelper end end - def principal_icon(principal_class, **options) + def principal_icon(principal, **options) + raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal) + + principal_class = principal.class.name.downcase sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class) end diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb index bd953d247..6e13808b6 100644 --- a/app/views/projects/settings/_members.html.erb +++ b/app/views/projects/settings/_members.html.erb @@ -20,7 +20,7 @@ <% next if member.new_record? %> - <%= principal_icon(member.principal.class.name.downcase) %> + <%= principal_icon(member.principal) %> <%= link_to_user member.principal %> diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index c7e79cb66..3ffa24281 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -2027,7 +2027,7 @@ class ApplicationHelperTest < Redmine::HelperTest tags = principals_check_box_tags(name, principals) principals.each_with_index do |principal, i| assert_not_include avatar_tags[i], tags - assert_include content_tag('span', principal_icon(principal.class.name.downcase), :class => "name icon icon-#{principal.class.name.downcase}"), tags + assert_include content_tag('span', principal_icon(principal), :class => "name icon icon-#{principal.class.name.downcase}"), tags end end end diff --git a/test/helpers/icons_helper_test.rb b/test/helpers/icons_helper_test.rb index 688c6dbac..ab3e743fd 100644 --- a/test/helpers/icons_helper_test.rb +++ b/test/helpers/icons_helper_test.rb @@ -22,6 +22,8 @@ require_relative '../test_helper' class IconsHelperTest < Redmine::HelperTest include IconsHelper + fixtures :users + def test_sprite_icon_should_return_svg_with_defaults expected = %r{$} icon = sprite_icon('edit') @@ -98,8 +100,8 @@ class IconsHelperTest < Redmine::HelperTest def test_principal_icon_should_return_group_icon_for_group_classes expected = %r{} - %w(groupanonymous groupnonmember group).each do |principal_class| - assert_match expected, principal_icon(principal_class) + [Principal.find(12), Principal.find(13), Principal.find(10)].each do |principal| + assert_match expected, principal_icon(principal) end end From 0f7e32107811195d16593db28b1d8859890b62f1 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 10 Nov 2024 15:33:27 +0000 Subject: [PATCH 8/8] Fixes missing key icon SVG on Change password button (#23980, #41724). Patch by Katsuya HIDAKA (user:hidakatsuya). git-svn-id: https://svn.redmine.org/redmine/trunk@23231 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/assets/images/icons.svg | 4 ++++ config/icon_source.yml | 2 ++ 2 files changed, 6 insertions(+) diff --git a/app/assets/images/icons.svg b/app/assets/images/icons.svg index c94249ba8..84d68904a 100644 --- a/app/assets/images/icons.svg +++ b/app/assets/images/icons.svg @@ -247,6 +247,10 @@ + + + + diff --git a/config/icon_source.yml b/config/icon_source.yml index 05d024718..a97b4bcb9 100644 --- a/config/icon_source.yml +++ b/config/icon_source.yml @@ -195,3 +195,5 @@ svg: chevrons-right - name: chevrons-left svg: chevrons-left +- name: key + svg: key