OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
consider only the first child when calculating the preview
ulferts4bdba9a79290
diff --git a/app/components/open_project/common/attribute_component.html.erb b/app/components/open_project/common/attribute_component.html.erbindex b8b7e98eb60..3db882cd538 100644--- a/app/components/open_project/common/attribute_component.html.erb+++ b/app/components/open_project/common/attribute_component.html.erb@@ -4,12 +4,12 @@class="op-long-text-attribute"><%= render(- Primer::Beta::Text.new(tag: :p,- classes: "op-long-text-attribute--text",+ Primer::Beta::Text.new(tag: :div,+ classes: ['op-long-text-attribute--text', PARAGRAPH_CSS_CLASS],color: text_color,data: {'attribute-target': "descriptionText"- })) { text } %>+ })) { short_text } %><%= render(Primer::Alpha::Dialog.new(id: id,@@ -17,9 +17,10 @@size: :large)) do |component|component.with_show_button(scheme: :link,display: display_expand_button_value,+ ml: 1,data: { 'attribute-target': 'expandButton' }) { I18n.t('js.label_expand') }- component.with_body(mt: 2) { modal_body }- component.with_header+ component.with_body(mt: 2) { full_text }+ component.with_header(variant: :large)end%></div>diff --git a/app/components/open_project/common/attribute_component.rb b/app/components/open_project/common/attribute_component.rbindex 537b3ca2b64..12d1584a7b6 100644--- a/app/components/open_project/common/attribute_component.rb+++ b/app/components/open_project/common/attribute_component.rb@@ -34,6 +34,8 @@ module OpenProject:name,:description+ PARAGRAPH_CSS_CLASS = 'op-uc-p'.freeze+def initialize(id, name, description, **args)super@id = id@@ -42,26 +44,43 @@ module OpenProject@system_arguments = argsend- def text- is_multi_type(description) ? I18n.t(:label_preview_not_available) : Nokogiri::HTML(description).text+ def short_text+ if multi_type?+ I18n.t(:label_preview_not_available)+ else+ first_paragraph+ endend- def modal_body- helpers.format_text(description)+ def full_text+ @full_text ||= helpers.format_text(description)enddef display_expand_button_value- is_multi_type(description) ? :block : :none+ multi_type? || text_ast.xpath('html/body').children.length > 1 ? :block : :noneenddef text_color- :muted if is_multi_type(description)+ :muted if multi_type?endprivate- def is_multi_type(text)- text.to_s.include?('figure') || text.to_s.include?('macro')+ def first_paragraph+ @first_paragraph ||= text_ast+ .xpath('html/body')+ .children+ .first+ .inner_html+ .html_safe # rubocop:disable Rails/OutputSafety+ end++ def text_ast+ @text_ast ||= Nokogiri::HTML(full_text)+ end++ def multi_type?+ first_paragraph.include?('figure') || first_paragraph.include?('macro')endendend