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

Fix displaying of dates in macros

Oliver Günther99f4a5580c59
diff --git a/frontend/src/app/shared/components/fields/display/display-field.component.ts b/frontend/src/app/shared/components/fields/display/display-field.component.ts
index d6509e3ba8e..4066cf10e7c 100644
--- a/frontend/src/app/shared/components/fields/display/display-field.component.ts
+++ b/frontend/src/app/shared/components/fields/display/display-field.component.ts
@@ -38,7 +38,7 @@ export class DisplayFieldComponent implements OnInit {
.then((schema) => {
const proxied = this.schemaCache.proxied(this.resource, schema);
this.fieldName = this.attributeName(this.fieldName, proxied);
- this.render(proxied[this.fieldName] as IFieldSchema);
+ this.render(proxied.ofProperty(this.fieldName));
});
}
diff --git a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
index 97268e03eaf..a4028886715 100644
--- a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
+++ b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
@@ -49,6 +49,7 @@ import {
SupportedAttributeModels,
} from 'core-app/shared/components/fields/macros/attribute-model-loader.service';
import { firstValueFrom } from 'rxjs';
+import { ISchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
@Component({
templateUrl: './attribute-value-macro.html',
@@ -115,8 +116,9 @@ export class AttributeValueMacroComponent implements OnInit {
}
const schema = await this.schemaCache.ensureLoaded(resource);
- const attribute = schema.attributeFromLocalizedName(attributeName) || attributeName;
- const fieldSchema = schema[attribute] as IFieldSchema|undefined;
+ const proxied = this.schemaCache.proxied(resource, schema);
+ const attribute = schema.attributeFromLocalizedName(attributeName) || this.dateAttribute(resource, proxied, attributeName);
+ const fieldSchema = proxied.ofProperty(attribute) as IFieldSchema|undefined;
if (fieldSchema) {
this.resource = resource;
@@ -132,4 +134,12 @@ export class AttributeValueMacroComponent implements OnInit {
this.error = this.I18n.t('js.editor.macro.error', { message });
this.cdRef.detectChanges();
}
+
+ dateAttribute(resource:HalResource, proxied:ISchemaProxy, attributeName:string):string {
+ if (resource._type === 'WorkPackage' && !proxied.isMilestone && attributeName === 'date') {
+ return 'combinedDate';
+ }
+
+ return proxied.mappedName(attributeName);
+ }
}
diff --git a/spec/features/wysiwyg/macros/attribute_macros_spec.rb b/spec/features/wysiwyg/macros/attribute_macros_spec.rb
index 5bb7d11c4fe..c85aadc7a0b 100644
--- a/spec/features/wysiwyg/macros/attribute_macros_spec.rb
+++ b/spec/features/wysiwyg/macros/attribute_macros_spec.rb
@@ -31,8 +31,32 @@ require "spec_helper"
RSpec.describe "Wysiwyg attribute macros", :js do
shared_let(:admin) { create(:admin) }
let(:user) { admin }
- let!(:project) { create(:project, identifier: "some-project", enabled_module_names: %w[wiki work_package_tracking]) }
- let!(:work_package) { create(:work_package, subject: "Foo Bar", project:) }
+
+ shared_let(:type_milestone) { create(:type_milestone) }
+ shared_let(:type_task) { create(:type_task) }
+
+ shared_let(:project) do
+ create(:project,
+ identifier: "some-project",
+ types: [type_milestone, type_task],
+ enabled_module_names: %w[wiki work_package_tracking])
+ end
+ shared_let(:work_package) do
+ create(:work_package,
+ subject: "Foo Bar",
+ project:,
+ start_date: '2023-01-01',
+ due_date: '2023-01-05',
+ type: type_task)
+ end
+ shared_let(:milestone) do
+ create(:work_package,
+ subject: "Milestone",
+ project:,
+ due_date: '2023-01-10',
+ type: type_milestone)
+ end
+
let(:editor) { Components::WysiwygEditor.new }
let(:markdown) do
@@ -59,6 +83,18 @@ RSpec.describe "Wysiwyg attribute macros", :js do
<td>invalid subject workPackageValue:"Invalid":subject</td>
<td>invalid project projectValue:"does not exist":identifier</td>
</tr>
+
+ <tr>
+ <td>work package start date workPackageValue:"Foo Bar":startDate</td>
+ <td>work package due date workPackageValue:"Foo Bar":dueDate</td>
+ <td>work package date workPackageValue:"Foo Bar":date</td>
+ </tr>
+
+ <tr>
+ <td>milestone start date workPackageValue:"Milestone":startDate</td>
+ <td>milestone due date workPackageValue:"Milestone":dueDate</td>
+ <td>milestone date workPackageValue:"Milestone":date</td>
+ </tr>
</tbody>
</table>
MD
@@ -92,13 +128,21 @@ RSpec.describe "Wysiwyg attribute macros", :js do
expect(page).to have_css("td", text: "invalid subject Cannot expand macro: Requested resource could not be found")
expect(page).to have_css("td", text: "invalid project Cannot expand macro: Requested resource could not be found")
+
+ expect(page).to have_css("td", text: "work package start date 01/01/2023")
+ expect(page).to have_css("td", text: "work package due date 01/05/2023")
+ expect(page).to have_css("td", text: "work package date 01/01/2023 - 01/05/2023")
+
+ expect(page).to have_css("td", text: "milestone start date 01/10/2023")
+ expect(page).to have_css("td", text: "milestone due date 01/10/2023")
+ expect(page).to have_css("td", text: "milestone date 01/10/2023")
end
# Edit page again
click_on "Edit"
editor.in_editor do |container,|
- expect(container).to have_css("tbody td", count: 6)
+ expect(container).to have_css("tbody td", count: 15)
end
end