From e9f854fa7cf855f10d92f1bfec29dd2f60cb522f Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 17 Sep 2018 10:22:29 +0200 Subject: [PATCH 1/2] fix color css rendering on non existing color For instances already/still having entries (priorities, status, ...) with color_id = 0, we need to check explicitly if the color exists --- app/views/highlighting/styles.css.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/highlighting/styles.css.erb b/app/views/highlighting/styles.css.erb index 7a9a23f0db..fba32156c5 100644 --- a/app/views/highlighting/styles.css.erb +++ b/app/views/highlighting/styles.css.erb @@ -1,12 +1,13 @@ <% colored_resource = Proc.new do |name, scope| scope.includes(:color).find_each do |entry| - if entry.color_id.nil? + color = entry.color + + if color.nil? concat ".__hl_dot_#{name}_#{entry.id}::before { display: none }\n" next end - color = entry.color styles = color.color_styles inline_style = styles.map{|k,v| "#{k}:#{v} !important"}.join(';') From 269bfb32e543fcb090cc76d1a20ab8cf774cd91f Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 17 Sep 2018 10:27:49 +0200 Subject: [PATCH 2/2] extract in template code into helper method --- app/helpers/colors_helper.rb | 27 ++++++++++++++++++++ app/views/highlighting/styles.css.erb | 36 +++------------------------ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/app/helpers/colors_helper.rb b/app/helpers/colors_helper.rb index 0036572a07..dfdcd43cce 100644 --- a/app/helpers/colors_helper.rb +++ b/app/helpers/colors_helper.rb @@ -61,6 +61,33 @@ module ColorsHelper content_tag(:span, color.hexcode, class: 'color--text-preview', style: style) end + def resource_color_css(name, scope) + scope.includes(:color).find_each do |entry| + color = entry.color + + if color.nil? + concat ".__hl_dot_#{name}_#{entry.id}::before { display: none }\n" + next + end + + styles = color.color_styles + + inline_style = styles.map { |k,v| "#{k}:#{v} !important"}.join(';') + row_style = "background-color: #{color.hexcode} !important;" + + border_color = color.bright? ? '#555555' : color.hexcode + + concat ".__hl_inl_#{name}_#{entry.id} { #{inline_style}; }\n" + concat ".__hl_dot_#{name}_#{entry.id}::before { #{inline_style}; border-color: #{border_color}; }\n" + concat ".__hl_row_#{name}_#{entry.id} { #{row_style}; }\n" + + # Mark color as bright through CSS variable + # so it can be used to add a separate -bright class + unless color.bright? + concat ":root { --hl-#{name}-#{entry.id}-dark: #{styles[:color]} }\n" + end + end + end def icon_for_color(color, options = {}) return unless color diff --git a/app/views/highlighting/styles.css.erb b/app/views/highlighting/styles.css.erb index fba32156c5..077126b3e8 100644 --- a/app/views/highlighting/styles.css.erb +++ b/app/views/highlighting/styles.css.erb @@ -1,37 +1,7 @@ -<% - colored_resource = Proc.new do |name, scope| - scope.includes(:color).find_each do |entry| - color = entry.color - - if color.nil? - concat ".__hl_dot_#{name}_#{entry.id}::before { display: none }\n" - next - end - - styles = color.color_styles - - inline_style = styles.map{|k,v| "#{k}:#{v} !important"}.join(';') - row_style = "background-color: #{color.hexcode} !important;" - - border_color = color.bright? ? '#555555' : color.hexcode - - concat ".__hl_inl_#{name}_#{entry.id} { #{inline_style}; }\n" - concat ".__hl_dot_#{name}_#{entry.id}::before { #{inline_style}; border-color: #{border_color}; }\n" - concat ".__hl_row_#{name}_#{entry.id} { #{row_style}; }\n" - - # Mark color as bright through CSS variable - # so it can be used to add a separate -bright class - unless color.bright? - concat ":root { --hl-#{name}-#{entry.id}-dark: #{styles[:color]} }\n" - end - end - end - %> - <%# Highlightable resources %> -<%= colored_resource.call('status', ::Status) %> -<%= colored_resource.call('priority', ::IssuePriority) %> -<%= colored_resource.call('type', ::Type) %> +<%= resource_color_css('status', ::Status) %> +<%= resource_color_css('priority', ::IssuePriority) %> +<%= resource_color_css('type', ::Type) %> <%# Overdue tasks %> .__hl_date_due_today { color: #F76707 !important; }