Skip to content

Commit

Permalink
Merge branch 'dev' into sharing-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Jul 8, 2024
2 parents a6d38f1 + 99b15c6 commit ed3ed76
Show file tree
Hide file tree
Showing 262 changed files with 2,592 additions and 3,196 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rubocop-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
rubocop_extensions: >
rubocop-capybara:gemfile
rubocop-factory_bot:gemfile
rubocop-openproject:gemfile
rubocop-performance:gemfile
rubocop-rails:gemfile
rubocop-rspec:gemfile
Expand Down
4 changes: 1 addition & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
require:
- rubocop-openproject
- rubocop-rails
- rubocop-rspec
- rubocop-rspec_rails
- ./lib_static/rubocop/cop/open_project/add_preview_for_view_component.rb
- ./lib_static/rubocop/cop/open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect.rb
- ./lib_static/rubocop/cop/open_project/use_service_result_factory_methods.rb
- rubocop-capybara
- rubocop-factory_bot
- rubocop-performance
Expand Down
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ group :development, :test do
gem "rubocop", require: false
gem "rubocop-capybara", require: false
gem "rubocop-factory_bot", require: false
gem "rubocop-openproject", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
gem "rubocop-rspec", require: false
Expand Down Expand Up @@ -389,6 +390,6 @@ gemfiles.each do |file|
send(:eval_gemfile, file) if File.readable?(file)
end

gem "openproject-octicons", "~>19.14.1"
gem "openproject-octicons_helper", "~>19.14.1"
gem "openproject-primer_view_components", "~>0.35.2"
gem "openproject-octicons", "~>19.15.0"
gem "openproject-octicons_helper", "~>19.15.0"
gem "openproject-primer_view_components", "~>0.36.0"
23 changes: 13 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ GEM
activerecord (>= 4.0.0, < 7.2)
awrence (1.2.1)
aws-eventstream (1.3.0)
aws-partitions (1.950.0)
aws-sdk-core (3.201.0)
aws-partitions (1.952.0)
aws-sdk-core (3.201.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.8)
Expand Down Expand Up @@ -771,15 +771,15 @@ GEM
validate_email
validate_url
webfinger (~> 2.0)
openproject-octicons (19.14.1)
openproject-octicons_helper (19.14.1)
openproject-octicons (19.15.0)
openproject-octicons_helper (19.15.0)
actionview
openproject-octicons (= 19.14.1)
openproject-octicons (= 19.15.0)
railties
openproject-primer_view_components (0.35.2)
openproject-primer_view_components (0.36.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
openproject-octicons (>= 19.12.0)
openproject-octicons (>= 19.15.0)
view_component (>= 3.1, < 4.0)
openproject-token (4.0.0)
activemodel
Expand Down Expand Up @@ -986,6 +986,8 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-openproject (0.1.0)
rubocop
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
Expand Down Expand Up @@ -1261,10 +1263,10 @@ DEPENDENCIES
openproject-job_status!
openproject-ldap_groups!
openproject-meeting!
openproject-octicons (~> 19.14.1)
openproject-octicons_helper (~> 19.14.1)
openproject-octicons (~> 19.15.0)
openproject-octicons_helper (~> 19.15.0)
openproject-openid_connect!
openproject-primer_view_components (~> 0.35.2)
openproject-primer_view_components (~> 0.36.0)
openproject-recaptcha!
openproject-reporting!
openproject-storages!
Expand Down Expand Up @@ -1312,6 +1314,7 @@ DEPENDENCIES
rubocop
rubocop-capybara
rubocop-factory_bot
rubocop-openproject
rubocop-performance
rubocop-rails
rubocop-rspec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<% end %>

<div class="op-sidebar--body">
<div class="op-sidebar--body" data-test-selector="op-sidebar--body">
<% if top_level_sidebar_menu_items.any? %>
<div class="op-sidemenu">
<ul class="op-sidemenu--items">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ See COPYRIGHT and LICENSE files for more details.
selected: project_custom_field_project_mappings_selected?,
href: project_mappings_admin_settings_project_custom_field_path(@custom_field)
) do |tab|
tab.with_text { I18n.t("projects.settings.project_custom_fields.project_mappings.header") }
tab.with_text { t(:label_project_mappings) }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def render?
private

def title
I18n.t("projects.settings.project_custom_fields.new_project_mapping_form.add_projects")
I18n.t(:label_add_projects)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize(project_mapping:, project_custom_field:)
private

def title
I18n.t("projects.settings.project_custom_fields.new_project_mapping_form.add_projects")
I18n.t(:label_add_projects)
end

def cancel_button_text
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/work_packages/menus_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-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.
#++
module WorkPackages
class MenusController < ApplicationController
before_action :load_and_authorize_in_optional_project

def show
@sidebar_menu_items = WorkPackages::Menu.new(project: @project, params:, request:).menu_items
render layout: nil
end
end
end
127 changes: 94 additions & 33 deletions app/helpers/colors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ def options_for_colors(colored_thing)
options = {}
options[:name] = c.name
options[:value] = c.id
options[:data] = {
color: c.hexcode,
bright: c.bright?,
dark: c.dark?,
background: c.contrasting_color(light_color: "transparent")
}
options[:selected] = true if c.id == colored_thing.color_id

colors.push(options)
Expand All @@ -50,21 +44,13 @@ def selected_color(colored_thing)
colored_thing.color_id
end

def colored_text(color)
background = color.contrasting_color(dark_color: "#333", light_color: "transparent")
style = "background-color: #{background}; color: #{color.hexcode}"
content_tag(:span, color.hexcode, class: "color--text-preview", style:)
end

#
# Styles to display colors itself (e.g. for the colors autocompleter)
##
def color_css
Color.find_each do |color|
concat ".__hl_inline_color_#{color.id}_dot::before { background-color: #{color.hexcode} !important;}"
concat ".__hl_inline_color_#{color.id}_dot::before { border: 1px solid #555555 !important;}" if color.bright?
concat ".__hl_inline_color_#{color.id}_text { color: #{color.hexcode} !important;}"
concat ".__hl_inline_color_#{color.id}_text { -webkit-text-stroke: 0.5px grey; text-stroke: 0.5px grey;}" if color.super_bright?
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
end
end

Expand All @@ -80,27 +66,13 @@ def resource_color_css(name, scope)
next
end

styles = color.color_styles
background_style = styles.map { |k, v| "#{k}:#{v} !important" }.join(";")

if name === "type"
concat ".__hl_inline_#{name}_#{entry.id} { color: #{color.hexcode} !important;}"
concat ".__hl_inline_#{name}_#{entry.id} { -webkit-text-stroke: 0.5px grey;}" if color.super_bright?

border_color = color.super_bright? ? "#555555" : color.hexcode
concat ".__hl_background_#{name}_#{entry.id} { border-color: #{border_color} !important; }"
set_foreground_colors_for class_name: ".__hl_inline_#{name}_#{entry.id}", hexcode: color.hexcode
else
border_color = color.bright? ? "#555555" : color.hexcode
concat ".__hl_inline_#{name}_#{entry.id}::before { #{background_style}; border-color: #{border_color}; }\n"
set_background_colors_for class_name: ".__hl_inline_#{name}_#{entry.id}::before", hexcode: color.hexcode
end

concat ".__hl_background_#{name}_#{entry.id} { #{background_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
set_background_colors_for class_name: ".__hl_background_#{name}_#{entry.id}", hexcode: color.hexcode
end
end

Expand All @@ -117,4 +89,93 @@ def icon_for_color(color, options = {})
def color_by_variable(variable)
DesignColor.find_by(variable:)&.hexcode
end

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

concat "#{class_name} { #{default_color_styles(hexcode)} }"
if mode == "dark"
concat "#{class_name} { #{default_variables_dark} }"
concat "#{class_name} { #{highlighted_background_dark} }"
else
concat "#{class_name} { #{default_variables_light} }"
concat "#{class_name} { #{highlighted_background_light} }"
end
end

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

concat "#{class_name} { #{default_color_styles(hexcode)} }"
if mode == "dark"
concat "#{class_name} { #{default_variables_dark} }"
concat "#{class_name} { #{highlighted_foreground_dark} }"
else
concat "#{class_name} { #{default_variables_light} }"
concat "#{class_name} { #{highlighted_foreground_light} }"
end
end

# rubocop:disable Layout/LineLength
def default_color_styles(hex)
color = ColorConversion::Color.new(hex)
rgb = color.rgb
hsl = color.hsl

"--color-r: #{rgb[:r]};
--color-g: #{rgb[:g]};
--color-b: #{rgb[:b]};
--color-h: #{hsl[:h]};
--color-s: #{hsl[:s]};
--color-l: #{hsl[:l]};
--perceived-lightness: calc( ((var(--color-r) * 0.2126) + (var(--color-g) * 0.7152) + (var(--color-b) * 0.0722)) / 255 );
--lightness-switch: max(0, min(calc((1/(var(--lightness-threshold) - var(--perceived-lightness)))), 1));"
end

def default_variables_dark
"--lightness-threshold: 0.6;
--background-alpha: 0.18;
--lighten-by: calc(((var(--lightness-threshold) - var(--perceived-lightness)) * 100) * var(--lightness-switch));"
end

def default_variables_light
"--lightness-threshold: 0.453;
--border-threshold: 0.75;
--border-alpha: max(0, min(calc((var(--perceived-lightness) - var(--border-threshold)) * 100), 1));"
end

def highlighted_background_dark
"color: hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;
background: rgba(var(--color-r), var(--color-g), var(--color-b), var(--background-alpha)) !important;
border: 1px solid hsl(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%)) !important;"
end

def highlighted_background_light
style = "color: hsl(0deg, 0%, calc(var(--lightness-switch) * 100%)) !important;
background: rgb(var(--color-r), var(--color-g), var(--color-b)) !important;"
mode = User.current.pref.theme

if mode == "light_high_contrast"
style += "border: 1px solid hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 75) * 1%), 1) !important;"
else
style += "border: 1px solid hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - 25) * 1%), var(--border-alpha)) !important;"
end

style
end

def highlighted_foreground_dark
"color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) + var(--lighten-by)) * 1%), 1) !important;"
end

def highlighted_foreground_light
mode = User.current.pref.theme

if mode == "light_high_contrast"
"color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.5)) * 1%), 1); !important;"
else
"color: hsla(var(--color-h), calc(var(--color-s) * 1%), calc((var(--color-l) - (var(--color-l) * 0.22)) * 1%), 1); !important;"
end
end
# rubocop:enable Layout/LineLength
end
2 changes: 1 addition & 1 deletion app/helpers/highlighting_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ def highlight_css_version_tag(max_updated_at = highlight_css_updated_at)
end

def highlight_css_updated_at
ApplicationRecord.most_recently_changed Status, IssuePriority, Type
ApplicationRecord.most_recently_changed Status, IssuePriority, Type, UserPreference
end
end
5 changes: 4 additions & 1 deletion app/menus/submenu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def starred_queries
.where("starred" => "t")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def default_queries
Expand All @@ -61,6 +62,7 @@ def global_queries
.where("public" => "t")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def custom_queries
Expand All @@ -69,6 +71,7 @@ def custom_queries
.where("public" => "f")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def base_query
Expand Down Expand Up @@ -103,7 +106,7 @@ def selected?(query_params)
end
end

if query_params.empty? && params[:filters].present?
if query_params.empty? && (%i[filters query_props query_id name].any? { |k| params.key? k })
return false
end

Expand Down
Loading

0 comments on commit ed3ed76

Please sign in to comment.