Skip to content

Commit

Permalink
Merge branch 'dev' into 53810-update-pageheaders-subheaders-in-the-ra…
Browse files Browse the repository at this point in the history
…ils-project-pages
  • Loading branch information
HDinger authored Nov 28, 2024
2 parents a7c0b0a + 0c16d9e commit 9024b58
Show file tree
Hide file tree
Showing 128 changed files with 4,562 additions and 306 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/citizensadvice/capybara_accessible_selectors
revision: 347bbe06cb420416855e80bb4e3a3016b2d5872c
revision: aed2860e5b5df7f39284fdc35a5bf57bda7e1ad9
branch: main
specs:
capybara_accessible_selectors (0.11.0)
Expand Down Expand Up @@ -1012,17 +1012,17 @@ GEM
rspec-support (3.13.1)
rspec-wait (1.0.1)
rspec (>= 3.4)
rubocop (1.68.0)
rubocop (1.69.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
rubocop-ast (>= 1.36.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.36.1)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand Down Expand Up @@ -1065,7 +1065,7 @@ GEM
nokogiri (>= 1.12.0)
secure_headers (7.0.0)
securerandom (0.3.2)
selenium-devtools (0.130.0)
selenium-devtools (0.131.0)
selenium-webdriver (~> 4.2)
selenium-webdriver (4.26.0)
base64 (~> 0.2)
Expand Down Expand Up @@ -1152,7 +1152,7 @@ GEM
public_suffix
vcr (6.3.1)
base64
vernier (1.3.1)
vernier (1.4.0)
view_component (3.20.0)
activesupport (>= 5.2.0, < 8.1)
concurrent-ruby (~> 1.0)
Expand Down
3 changes: 2 additions & 1 deletion app/components/op_primer/border_box_row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def visible_on_mobile?(column)
def grid_column_classes(column)
classes = ["op-border-box-grid--row-item"]
classes << column_css_class(column)
classes << "op-border-box-grid--wide-column" if table.wide_column?(column)
classes << "op-border-box-grid--main-column" if table.main_column?(column)
classes << "ellipsis" unless table.main_column?(column)
classes << "op-border-box-grid--no-mobile" unless visible_on_mobile?(column)

classes.compact.join(" ")
Expand Down
5 changes: 3 additions & 2 deletions app/components/op_primer/border_box_table_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ See COPYRIGHT and LICENSE files for more details.
test_selector:,
)) do |component|
component.with_header(classes: grid_class, color: :muted) do
concat render(Primer::Beta::Text.new(classes: "op-border-box-grid--mobile-heading",
font_weight: :semibold)) { mobile_title }
headers.each do |name, args|
concat render(Primer::Beta::Text.new(classes: header_classes(name),
font_weight: :semibold,
**header_args(name))) { args[:caption] }
end

concat render(Primer::Beta::Text.new(classes: "op-border-box-grid--mobile-heading",
font_weight: :semibold)) { mobile_title }

if has_actions?
concat render(Primer::BaseComponent.new(classes: heading_class,
tag: :div))
Expand Down
14 changes: 7 additions & 7 deletions app/components/op_primer/border_box_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ def mobile_labels(*names)
@mobile_labels = names.map(&:to_sym)
end

# Declare wide columns, that will result in a grid column span of 3
# Declare main columns, that will result in a grid column span of 2 and not truncate text
#
# column_grid_span :title
#
def wide_columns(*names)
return Array(@wide_columns) if names.empty?
def main_column(*names)
return Array(@main_columns) if names.empty?

@wide_columns = names.map(&:to_sym)
@main_columns = names.map(&:to_sym)
end
end

delegate :mobile_columns, :mobile_labels,
to: :class

def wide_column?(column)
self.class.wide_columns.include?(column)
def main_column?(column)
self.class.main_column.include?(column)
end

def header_args(_column)
Expand All @@ -88,7 +88,7 @@ def column_title(name)

def header_classes(column)
classes = [heading_class]
classes << "op-border-box-grid--wide-column" if wide_column?(column)
classes << "op-border-box-grid--main-column" if main_column?(column)

classes.join(" ")
end
Expand Down
12 changes: 10 additions & 2 deletions app/components/op_primer/border_box_table_component.sass
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
justify-content: flex-start
align-items: center

&--heading,
&--row-item
&:not(:first-child)
padding-left: 6px

&:not(:last-child)
padding-right: 6px

&--mobile-heading,
&--row-label
display: none

&--wide-column
grid-column: span 3
&--main-column
grid-column: span 2

@media screen and (max-width: $breakpoint-md)
.op-border-box-grid
Expand Down
6 changes: 0 additions & 6 deletions app/forms/custom_fields/details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ class DetailsForm < ApplicationForm
caption: I18n.t("custom_fields.instructions.is_filter")
)

details_form.check_box(
name: :searchable,
label: I18n.t("activerecord.attributes.custom_field.searchable"),
caption: I18n.t("custom_fields.instructions.searchable")
)

details_form.submit(name: :submit, label: I18n.t(:button_save), scheme: :default)
end
end
Expand Down
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
2 changes: 2 additions & 0 deletions app/models/custom_value/hierarchy_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def ar_object(value)
item = CustomField::Hierarchy::Item.find_by(id: value.to_s)
if item.nil?
"#{value} #{I18n.t(:label_not_found)}"
elsif item.short.present?
"#{item.label} (#{item.short})"
else
item.label
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/queries/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module Queries::Filters
search: Queries::Filters::Strategies::Search,
float: Queries::Filters::Strategies::Float,
inexistent: Queries::Filters::Strategies::Inexistent,
empty_value: Queries::Filters::Strategies::EmptyValue
empty_value: Queries::Filters::Strategies::EmptyValue,
hierarchy: Queries::Filters::Strategies::Hierarchy
}.freeze

##
Expand Down
36 changes: 18 additions & 18 deletions app/models/queries/filters/shared/custom_field_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,12 @@ def create!(name:, **)
##
# Create a filter instance for the given custom field
def from_custom_field!(custom_field:, **)
constant_name = subfilter_module(custom_field)
clazz = "::Queries::Filters::Shared::CustomFields::#{constant_name}".constantize
clazz.create!(custom_field:, custom_field_context:, **)
subfilter_class(custom_field).create!(custom_field:, custom_field_context:, **)
rescue NameError => e
Rails.logger.error "Failed to constantize custom field filter for #{name}. #{e}"
raise ::Queries::Filters::InvalidError
end

##
# Get the subfilter class name for the given custom field
def subfilter_module(custom_field)
case custom_field.field_format
when "user"
:User
when "list", "version"
:ListOptional
when "bool"
:Bool
else
:Base
end
end

def all_custom_fields
key = ["Queries::Filters::Shared::CustomFieldFilter",
custom_field_context.custom_field_class,
Expand All @@ -102,5 +85,22 @@ def all_custom_fields
custom_field_context.custom_field_class.all.to_a
end
end

private

def subfilter_class(custom_field)
case custom_field.field_format
when "user"
::Queries::Filters::Shared::CustomFields::User
when "list", "version"
::Queries::Filters::Shared::CustomFields::ListOptional
when "hierarchy"
::Queries::Filters::Shared::CustomFields::Hierarchy
when "bool"
::Queries::Filters::Shared::CustomFields::Bool
else
::Queries::Filters::Shared::CustomFields::Base
end
end
end
end
2 changes: 2 additions & 0 deletions app/models/queries/filters/shared/custom_fields/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def type
:text
when "date"
:date
when "hierarchy"
:hierarchy
else
:string
end
Expand Down
64 changes: 64 additions & 0 deletions app/models/queries/filters/shared/custom_fields/hierarchy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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 Queries
module Filters
module Shared
module CustomFields
class Hierarchy < Base
def ar_object_filter?
true
end

def value_objects
CustomField::Hierarchy::Item
.where(id: @values)
.map { |item| HierarchyItemFilterAdapter.new(item:) }
end
end

class HierarchyItemFilterAdapter
attr_reader :name

delegate :id, to: :item

def initialize(item:)
@item = item
@name = item.label
end

private

attr_accessor :item
end
end
end
end
end
Loading

0 comments on commit 9024b58

Please sign in to comment.