Skip to content

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

Allow project help texts on the rails form

Oliver Güntherc369a71f4da1
diff --git a/app/models/attribute_help_text/project.rb b/app/models/attribute_help_text/project.rb
index d3704a0abc1..f2543d89e00 100644
--- a/app/models/attribute_help_text/project.rb
+++ b/app/models/attribute_help_text/project.rb
@@ -28,7 +28,7 @@
class AttributeHelpText::Project < AttributeHelpText
def self.available_attributes
- skip = %w[_type links _dependencies id]
+ skip = %w[_type links _dependencies id created_at updated_at]
attributes = API::V3::Projects::Schemas::ProjectSchemaRepresenter
.representable_definitions
diff --git a/app/views/customizable/_form.html.erb b/app/views/customizable/_form.html.erb
index 6fab171dc0e..aaa8db2466b 100644
--- a/app/views/customizable/_form.html.erb
+++ b/app/views/customizable/_form.html.erb
@@ -36,7 +36,14 @@ See docs/COPYRIGHT.rdoc for more details.
<% if all_fields || (only_required && required) || (!only_required && !required) %>
<% container_class = value.custom_field.field_format == 'text' ? '-xxwide' : '-wide' %>
<div class="form--field custom_field_<%= value.custom_field.id %> <%= required ? '-required' : '' %>">
- <%= value_form.custom_field(container_class: container_class, required: required) %>
+ <%
+ options = { container_class: container_class, required: required }
+
+ if local_assigns[:help_text]
+ options[:help_text] = local_assigns[:help_text].merge(attribute: "customField#{value.custom_field.id}")
+ end
+ %>
+ <%= value_form.custom_field(options) %>
</div>
<% end %>
<% end %>
diff --git a/app/views/projects/form/_project_attributes.html.erb b/app/views/projects/form/_project_attributes.html.erb
index 1e504653f52..753e97ffdb0 100644
--- a/app/views/projects/form/_project_attributes.html.erb
+++ b/app/views/projects/form/_project_attributes.html.erb
@@ -58,7 +58,7 @@ See docs/COPYRIGHT.rdoc for more details.
locals: { form: form } %>
<% unless all_fields %>
<%= render partial: "customizable/form",
- locals: { form: form, all_fields: false, only_required: false } %>
+ locals: { form: form, help_text: { 'attribute-scope': :Project }, all_fields: false, only_required: false } %>
<% end %>
<% if render_advanced %>
</div>
diff --git a/app/views/projects/form/attributes/_description.html.erb b/app/views/projects/form/attributes/_description.html.erb
index 8e55fdc08c8..69df8cb19c5 100644
--- a/app/views/projects/form/attributes/_description.html.erb
+++ b/app/views/projects/form/attributes/_description.html.erb
@@ -31,6 +31,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= form.text_area :description,
id: :project_description,
with_text_formatting: true,
+ help_text: { attribute: :description, 'attribute-scope': :Project },
macros: false,
container_class: '-xxwide' %>
</div>
diff --git a/app/views/projects/form/attributes/_identifier.html.erb b/app/views/projects/form/attributes/_identifier.html.erb
index 6a653c41860..5a0e4793009 100644
--- a/app/views/projects/form/attributes/_identifier.html.erb
+++ b/app/views/projects/form/attributes/_identifier.html.erb
@@ -36,7 +36,9 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="form--field <%= identifier_editable ? '-required' : '' %>">
<% if identifier_editable %>
- <%= form.text_field :identifier, container_class: '-middle'%>
+ <%= form.text_field :identifier,
+ help_text: { attribute: :identifier, 'attribute-scope': :Project },
+ container_class: '-middle'%>
<%= nonced_javascript_tag do %>
window.projectIdentifierMaxLength = <%= id_max_length %>;
@@ -52,6 +54,10 @@ See docs/COPYRIGHT.rdoc for more details.
<% else %>
<label class="form--label" title="<%= Project.human_attribute_name(:identifier) %>">
<%= Project.human_attribute_name(:identifier) %>
+ <attribute-help-text
+ data-attribute="identifier"
+ data-attribute-scope="Project">
+ </attribute-help-text>
</label>
<span class="form--field-container">
<span id="identifier">
diff --git a/app/views/projects/form/attributes/_name.html.erb b/app/views/projects/form/attributes/_name.html.erb
index dd5f4151673..6723e0e0c58 100644
--- a/app/views/projects/form/attributes/_name.html.erb
+++ b/app/views/projects/form/attributes/_name.html.erb
@@ -28,7 +28,9 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<div class="form--field -required">
- <%= form.text_field :name, required: true,
- autofocus: form.object&.name&.empty?,
- container_class: '-wide' %>
+ <%= form.text_field :name,
+ required: true,
+ help_text: { attribute: :name, 'attribute-scope': :Project },
+ autofocus: form.object&.name&.empty?,
+ container_class: '-wide' %>
</div>
diff --git a/app/views/projects/form/attributes/_parent_id.html.erb b/app/views/projects/form/attributes/_parent_id.html.erb
index e8a2234263b..053cf9a7ff0 100644
--- a/app/views/projects/form/attributes/_parent_id.html.erb
+++ b/app/views/projects/form/attributes/_parent_id.html.erb
@@ -38,6 +38,7 @@ See docs/COPYRIGHT.rdoc for more details.
project_tree_options_for_select(allowed_parents,
selected: project.parent),
include_blank: true,
+ help_text: { attribute: :parent, 'attribute-scope': :Project },
container_class: '-wide' %>
</div>
<% end %>
diff --git a/app/views/projects/form/attributes/_public.html.erb b/app/views/projects/form/attributes/_public.html.erb
index bdedd85296e..6b4a4fe4b5b 100644
--- a/app/views/projects/form/attributes/_public.html.erb
+++ b/app/views/projects/form/attributes/_public.html.erb
@@ -28,5 +28,6 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<div class="form--field">
- <%= form.check_box :public %>
+ <%= form.check_box :public,
+ help_text: { attribute: :public, 'attribute-scope': :Project } %>
</div>
diff --git a/app/views/projects/form/attributes/_status.html.erb b/app/views/projects/form/attributes/_status.html.erb
index 48941dd8207..6a69ae09eb3 100644
--- a/app/views/projects/form/attributes/_status.html.erb
+++ b/app/views/projects/form/attributes/_status.html.erb
@@ -36,6 +36,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="form--field">
<%= status_form.select :code,
project_options_for_status(project),
+ help_text: { attribute: :status, 'attribute-scope': :Project },
include_blank: true,
container_class: '-wide' %>
</div>
@@ -43,6 +44,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= status_form.text_area :explanation,
with_text_formatting: true,
macros: false,
+ help_text: { attribute: :statusExplanation, 'attribute-scope': :Project },
preview_context: project_preview_context(project.status, project),
container_class: '-xxwide' %>
</div>
diff --git a/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts b/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts
index 6af037ea383..493e6712d42 100644
--- a/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts
+++ b/frontend/src/app/modules/common/help-texts/attribute-help-text.component.ts
@@ -75,13 +75,11 @@ export class AttributeHelpTextComponent implements OnInit {
ngOnInit() {
const element:HTMLElement = this.elementRef.nativeElement;
- if (element.dataset.helpTextId) {
- this.helpTextId = element.dataset.helpTextId!;
- this.attribute = element.dataset.attribute!;
- this.attributeScope = element.dataset.attributeScope!;
- this.additionalLabel = element.dataset.additionalLabel!;
- }
-
+ // Fall back to values provided by data
+ this.helpTextId = this.helpTextId || element.dataset.helpTextId!;
+ this.attribute = this.attribute || element.dataset.attribute!;
+ this.attributeScope = this.attributeScope || element.dataset.attributeScope!;
+ this.additionalLabel = this.additionalLabel || element.dataset.additionalLabel!;
if (this.helpTextId) {
this.exists = true;
diff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rb
index 2447a245160..edea38b1be8 100644
--- a/lib/custom_field_form_builder.rb
+++ b/lib/custom_field_form_builder.rb
@@ -39,7 +39,7 @@ class CustomFieldFormBuilder < TabularFormBuilder
if options[:no_label]
input
else
- label = custom_field_label_tag
+ label = custom_field_label_tag(options)
container_options = options.merge(no_label: true)
label + container_wrap_field(input, 'field', container_options)
@@ -111,7 +111,7 @@ class CustomFieldFormBuilder < TabularFormBuilder
end
# Return custom field label tag
- def custom_field_label_tag
+ def custom_field_label_tag(options)
custom_value = object
classes = 'form--label'
@@ -121,7 +121,16 @@ class CustomFieldFormBuilder < TabularFormBuilder
for: custom_field_field_id,
class: classes,
title: custom_value.custom_field.name do
- custom_value.custom_field.name
+ output = ''.html_safe
+ output += custom_value.custom_field.name
+
+
+ # Render a help text icon
+ if options[:help_text]
+ output += content_tag('attribute-help-text', '', data: options[:help_text])
+ end
+
+ output
end
end
end
diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb
index 5a1c9167ae8..dcd5aa21316 100644
--- a/lib/tabular_form_builder.rb
+++ b/lib/tabular_form_builder.rb
@@ -241,6 +241,11 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
label_for_field_for(options, label_options, field)
label_for_field_prefix(content, options)
+ # Render a help text icon
+ if options[:help_text]
+ content << content_tag('attribute-help-text', '', data: options[:help_text])
+ end
+
label_options[:lang] = options[:lang]
label_options.reject! do |_k, v|
v.nil?
@@ -286,7 +291,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder
def extract_from(options)
label_options = options.dup.except(:class)
- input_options = options.dup.except(:for, :label, :no_label, :prefix, :suffix, :label_options)
+ input_options = options.dup.except(:for, :label, :no_label, :prefix, :suffix, :label_options, :help_text)
label_options.merge!(options.delete(:label_options) || {})
diff --git a/spec/features/projects/attribute_help_texts_spec.rb b/spec/features/projects/attribute_help_texts_spec.rb
index e742caa13bd..b8476c41257 100644
--- a/spec/features/projects/attribute_help_texts_spec.rb
+++ b/spec/features/projects/attribute_help_texts_spec.rb
@@ -79,6 +79,21 @@ describe 'Project attribute help texts', type: :feature, js: true do
describe 'as admin' do
let(:user) { FactoryBot.create :admin }
it_behaves_like 'allows to view help texts'
+
+ it 'shows the help text on the project create form' do
+ visit new_project_path
+
+ page.find('.form--fieldset-legend', text: 'ADVANCED SETTINGS').click
+
+ expect(page).to have_selector('.form--label attribute-help-text', wait: 10)
+
+ # Open help text modal
+ modal.open!
+ expect(modal.modal_container).to have_selector('strong', text: 'help text')
+ modal.expect_edit(admin: user.admin?)
+
+ modal.close!
+ end
end
describe 'as regular user' do
diff --git a/spec/lib/tabular_form_builder_spec.rb b/spec/lib/tabular_form_builder_spec.rb
index 00dcc01b417..4b219aa3363 100644
--- a/spec/lib/tabular_form_builder_spec.rb
+++ b/spec/lib/tabular_form_builder_spec.rb
@@ -63,6 +63,23 @@ describe TabularFormBuilder do
}).at_path('input')
end
+ context 'with help text' do
+ let(:options) { { title: 'Name', class: 'custom-class', help_text: { attribute: 'foo', 'attribute-scope': 'bar' } } }
+
+ it 'will output a label with an attribute-help-text tag' do
+ expect(output).to be_html_eql(%{
+ <label class="form--label"
+ for="user_name"
+ title="Name">
+ Name
+ <attribute-help-text data-attribute="foo"
+ data-attribute-scope="bar">
+ </attribute-help-text>
+ </label>
+ }).at_path('label')
+ end
+ end
+
context 'with affixes' do
let(:random_id) { 'random_id' }