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
Convert attribute help text to datset inputs
Oliver Günther98f46ee7bdfd
diff --git a/app/helpers/angular_helper.rb b/app/helpers/angular_helper.rbindex 2aada29a212..ef691608a81 100644--- a/app/helpers/angular_helper.rb+++ b/app/helpers/angular_helper.rb@@ -31,8 +31,17 @@module AngularHelper### Create a component element tag with the given attributes+ #+ # Allow setting dynamic inputs for components with the @DatasetInputs decorator+ # by using inputs: { inputName: value }def angular_component_tag(component, options = {})- options[:class] = options.fetch(:class, '') + ' op-angular-component'- tag(component, options)+ inputs = (options.delete(:inputs) || {})+ .transform_keys { |k| k.to_s.underscore.dasherize }+ .transform_values(&:to_json)++ options[:data] = options.fetch(:data, {}).merge(inputs)+ options[:class] ||= "#{options.fetch(:class, '')} op-angular-component"++ content_tag(component, '', options)endenddiff --git a/app/views/attribute_help_texts/_tab.html.erb b/app/views/attribute_help_texts/_tab.html.erbindex e616a5129ff..edc64251d14 100644--- a/app/views/attribute_help_texts/_tab.html.erb+++ b/app/views/attribute_help_texts/_tab.html.erb@@ -42,12 +42,14 @@edit_attribute_help_text_path(attribute_help_text) %></td><td>- <attribute-help-text- data-help-text-id="<%= attribute_help_text.id %>"- data-attribute="<%= attribute_help_text.attribute_name %>"- data-attribute-scope="'<%= attribute_help_text.attribute_scope %>'"- data-additional-label="<%= t(:'attribute_help_texts.show_preview') %>">- </attribute-help-text>+ <%= angular_component_tag 'attribute-help-text',+ inputs: {+ helpTextId: attribute_help_text.id,+ attribute: attribute_help_text.attribute_name,+ attributeScope: attribute_help_text.attribute_scope,+ additionalLabel: t(:'attribute_help_texts.show_preview')+ }+ %></td><td class="buttons"><%= link_to(diff --git a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.component.ts b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.component.tsindex 00bfbefc6fc..e36c9270512 100644--- a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.component.ts+++ b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.component.ts@@ -39,9 +39,11 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';import { OpModalService } from 'core-app/shared/components/modal/modal.service';import { AttributeHelpTextsService } from './attribute-help-text.service';import { AttributeHelpTextModalComponent } from './attribute-help-text.modal';+import { DatasetInputs } from 'core-app/shared/components/dataset-inputs.decorator';export const attributeHelpTextSelector = 'attribute-help-text';+@DatasetInputs@Component({selector: attributeHelpTextSelector,changeDetection: ChangeDetectionStrategy.OnPush,@@ -57,7 +59,7 @@ export class AttributeHelpTextComponent implements OnInit {@Input() public attributeScope:string;// Load single id entry if given- @Input() public helpTextId?:string;+ @Input() public helpTextId?:string|number;public exists = false;@@ -67,22 +69,17 @@ export class AttributeHelpTextComponent implements OnInit {close: this.I18n.t('js.button_close'),};- constructor(protected elementRef:ElementRef,+ constructor(+ readonly elementRef:ElementRef,protected attributeHelpTexts:AttributeHelpTextsService,protected opModalService:OpModalService,protected cdRef:ChangeDetectorRef,protected injector:Injector,- protected I18n:I18nService) {+ protected I18n:I18nService,+ ) {}ngOnInit() {- const element:HTMLElement = this.elementRef.nativeElement;- // 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;} else {diff --git a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.service.ts b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.service.tsindex e62b5cce6ea..1f164893afd 100644--- a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.service.ts+++ b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.service.ts@@ -60,7 +60,7 @@ export class AttributeHelpTextsService {* Search for a given attribute help text**/- public requireById(id:string):Promise<HelpTextResource|undefined> {+ public requireById(id:string|number):Promise<HelpTextResource|undefined> {this.load();return this@@ -72,7 +72,7 @@ export class AttributeHelpTextsService {.toPromise().then(() => {const value = this.helpTexts.getValueOr([]);- return _.find(value, (element) => element.id?.toString() === id);+ return _.find(value, (element) => element.id?.toString() === id.toString());});}diff --git a/spec/helpers/angular_helper_spec.rb b/spec/helpers/angular_helper_spec.rbnew file mode 100644index 00000000000..f3bc080e7e4--- /dev/null+++ b/spec/helpers/angular_helper_spec.rb@@ -0,0 +1,75 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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'++describe AngularHelper, type: :helper do+ let(:tag_name) { 'op-test' }+ let(:options) do+ {+ class: 'op-classname',+ inputs: inputs,+ data: data+ }+ end+ let(:data) do+ {+ 'qa-selector': 'foo'+ }+ end++ subject { helper.angular_component_tag tag_name, options }++ describe 'inputs transformations' do+ let(:inputs) do+ {+ key: 'value',+ number: 1,+ anArray: [1, 2, 3],+ someRandomObject: { complex: true, foo: 'bar' }+ }+ end++ let(:expected) do+ <<~HTML.squish+ <op-test+ class="op-classname"+ data-key=""value""+ data-number="1"+ data-an-array="[1,2,3]"+ data-some-random-object="{"complex":true,"foo":"bar"}"+ data-qa-selector="foo"+ /></op-test>+ HTML+ end++ it 'converts the inputs' do+ expect(subject).to be_html_eql(expected)+ end+ end+end