Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add life cycle steps into styles.css #17277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions app/helpers/colors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,41 @@ def selected_color(colored_thing)
##
def color_css
Color.find_each do |color|
set_background_colors_for class_name: ".__hl_inline_color_#{color.id}_dot::before", hexcode: color.hexcode
set_foreground_colors_for class_name: ".__hl_inline_color_#{color.id}_text", hexcode: color.hexcode
set_background_colors_for(class_name: ".#{hl_inline_class('color', color)}_dot::before", color:)
set_foreground_colors_for(class_name: ".#{hl_inline_class('color', color)}_text", color:)
end
end

#
# Styles to display the color of attributes (type, status etc.) for example in the WP view
##
def resource_color_css(name, scope)
def resource_color_css(name, scope, inline_foreground: false)
scope.includes(:color).find_each do |entry|
color = entry.color

if color.nil?
concat ".__hl_inline_#{name}_#{entry.id}::before { display: none }\n"
concat ".#{hl_inline_class(name, entry)}::before { display: none }\n"
next
end

if name === "type"
set_foreground_colors_for class_name: ".__hl_inline_#{name}_#{entry.id}", hexcode: color.hexcode
if inline_foreground
set_foreground_colors_for(class_name: ".#{hl_inline_class(name, entry)}", color:)
else
set_background_colors_for class_name: ".__hl_inline_#{name}_#{entry.id}::before", hexcode: color.hexcode
set_background_colors_for(class_name: ".#{hl_inline_class(name, entry)}::before", color:)
end

set_background_colors_for class_name: ".__hl_background_#{name}_#{entry.id}", hexcode: color.hexcode
set_background_colors_for(class_name: ".#{hl_background_class(name, entry)}", color:)
end
end

def hl_inline_class(name, model)
"__hl_inline_#{name}_#{model.id}"
end

def hl_background_class(name, model)
"__hl_background_#{name}_#{model.id}"
end

def icon_for_color(color, options = {})
return unless color

Expand All @@ -90,10 +98,10 @@ def color_by_variable(variable)
DesignColor.find_by(variable:)&.hexcode
end

def set_background_colors_for(class_name:, hexcode:)
def set_background_colors_for(class_name:, color:)
mode = User.current.pref.theme.split("_", 2)[0]

concat "#{class_name} { #{default_color_styles(hexcode)} }"
concat "#{class_name} { #{default_color_styles(color.hexcode)} }"
if mode == "dark"
concat "#{class_name} { #{default_variables_dark} }"
concat "#{class_name} { #{highlighted_background_dark} }"
Expand All @@ -103,10 +111,10 @@ def set_background_colors_for(class_name:, hexcode:)
end
end

def set_foreground_colors_for(class_name:, hexcode:)
def set_foreground_colors_for(class_name:, color:)
mode = User.current.pref.theme.split("_", 2)[0]

concat "#{class_name} { #{default_color_styles(hexcode)} }"
concat "#{class_name} { #{default_color_styles(color.hexcode)} }"
if mode == "dark"
concat "#{class_name} { #{default_variables_dark} }"
concat "#{class_name} { #{highlighted_foreground_dark} }"
Expand Down
5 changes: 4 additions & 1 deletion app/views/highlighting/styles.css.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%# Highlightable resources %>
<%= resource_color_css('status', ::Status) %>
<%= resource_color_css('priority', ::IssuePriority) %>
<%= resource_color_css('type', ::Type) %>
<%= resource_color_css('type', ::Type, inline_foreground: true) %>
<%# Color coded icons %>
<%= resource_color_css('life_cycle_step_definition', Project::LifeCycleStepDefinition, inline_foreground: true) %>

<%= color_css() %>

<%# Overdue tasks %>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/global_styles/layout/_colors.sass
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
font-weight: var(--base-text-weight-bold)

// Inline: all except type
[class^='__hl_inline_']:not([class^='__hl_inline_type']),
[class*=' __hl_inline_']:not([class*='__hl_inline_type'])
[class^='__hl_inline_']:not([class^='__hl_inline_type'], [class^='__hl_inline_life_cycle_step_definition']),
[class*=' __hl_inline_']:not([class*='__hl_inline_type'], [class*='__hl_inline_life_cycle_step_definition'])
&::before
content: ''
display: inline-block
Expand Down
45 changes: 45 additions & 0 deletions spec/helpers/colors_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2024 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

require "spec_helper"

RSpec.describe ColorsHelper do
let(:model) { Data.define(:id).new(5) }

describe "#hl_inline_class" do
it "returns the correct class name" do
expect(helper.hl_inline_class("foo_bar", model)).to eq("__hl_inline_foo_bar_5")
end
end

describe "#hl_background_class" do
it "returns the correct class name" do
expect(helper.hl_background_class("foo_bar", model)).to eq("__hl_background_foo_bar_5")
end
end
end
Loading