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/36049 ## references not displayed correctly (#9013)

Aleix Suaucd628b5c7506
diff --git a/frontend/src/app/components/wp-activity/user/user-activity.component.html b/frontend/src/app/components/wp-activity/user/user-activity.component.html
index b348ef23937..5fdcbd55893 100644
--- a/frontend/src/app/components/wp-activity/user/user-activity.component.html
+++ b/frontend/src/app/components/wp-activity/user/user-activity.component.html
@@ -46,10 +46,10 @@
</edit-form-portal>
</div>
</div>
- <div *ngIf="!active && (isComment || isBcfComment)"
- class="message wiki op-uc-container"
- [innerHtml]="postedComment">
- </div>
+ <op-dynamic-bootstrap *ngIf="!active && (isComment || isBcfComment)"
+ [HTML]="postedComment"
+ class="message wiki op-uc-container">
+ </op-dynamic-bootstrap>
<ul class="work-package-details-activities-messages" *ngIf="!isInitial">
<li *ngFor="let detail of details">
<span class="message" [innerHtml]="detail"></span>
diff --git a/frontend/src/app/components/wp-activity/user/user-activity.component.ts b/frontend/src/app/components/wp-activity/user/user-activity.component.ts
index e1b84858eee..9cbf3d75dbc 100644
--- a/frontend/src/app/components/wp-activity/user/user-activity.component.ts
+++ b/frontend/src/app/components/wp-activity/user/user-activity.component.ts
@@ -32,6 +32,7 @@ import {ConfigurationService} from 'core-app/modules/common/config/configuration
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';
import {
+ ApplicationRef,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
@@ -91,7 +92,8 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem
readonly apiV3Service:APIV3Service,
readonly cdRef:ChangeDetectorRef,
readonly I18n:I18nService,
- readonly ngZone:NgZone) {
+ readonly ngZone:NgZone,
+ protected appRef:ApplicationRef) {
super(elementRef, injector);
}
@@ -227,6 +229,6 @@ export class UserActivityComponent extends WorkPackageCommentFieldHandler implem
}
private updateCommentText() {
- this.postedComment = this.sanitization.bypassSecurityTrustHtml(this.activity.comment.html);
+ this.postedComment = this.activity.comment.html;
}
}
diff --git a/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.html b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.html
new file mode 100644
index 00000000000..9d072e99c19
--- /dev/null
+++ b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.html
@@ -0,0 +1 @@
+<div [innerHtml]="innerHtml"></div>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.spec.ts b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.spec.ts
new file mode 100644
index 00000000000..e165ea4205f
--- /dev/null
+++ b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.spec.ts
@@ -0,0 +1,62 @@
+import {
+ ComponentFixture,
+ fakeAsync,
+ TestBed,
+ tick,
+} from '@angular/core/testing';
+import {DynamicBootstrapComponent} from './dynamic-bootstrap.component';
+import {ApplicationRef, Component, DebugElement} from '@angular/core';
+import {DynamicBootstrapper} from 'core-app/globals/dynamic-bootstrapper';
+
+// Stub component to bootstrap dynamically
+@Component({
+ selector: 'op-test',
+ template: `<div class="dynamic-component-div"></div>`,
+})
+export class TestComponent {}
+
+// Stub DynamicBootstrapper so we can pass the stub component definition
+class TestDynamicBootstrapper extends DynamicBootstrapper {
+ static bootstrapOptionalEmbeddable(appRef:ApplicationRef, element:HTMLElement) {
+ DynamicBootstrapper.bootstrapOptionalEmbeddable(appRef, element, [{ selector: 'op-test', cls: TestComponent, embeddable: true }]);
+ }
+}
+
+describe('DynamicBootstrapComponent', () => {
+ let component:DynamicBootstrapComponent;
+ let fixture:ComponentFixture<DynamicBootstrapComponent>;
+ let element:DebugElement;
+
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ declarations: [
+ DynamicBootstrapComponent,
+ TestComponent,
+ ]
+ })
+ .compileComponents();
+ });
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DynamicBootstrapComponent);
+ component = fixture.componentInstance;
+ element = fixture.debugElement;
+
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+
+ it('should render HTML strings and bootstrap Angular directives', fakeAsync(() => {
+ // Overwrite with the stub dynamicBootstrapper
+ component.dynamicBootstrapper = TestDynamicBootstrapper;
+ component.HTML = '<op-test></op-test>';
+
+ fixture.detectChanges();
+ tick();
+
+ expect(element.nativeElement.querySelector('.dynamic-component-div')).toBeTruthy();
+ }));
+});
diff --git a/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.ts b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.ts
new file mode 100644
index 00000000000..9f5ae3004a7
--- /dev/null
+++ b/frontend/src/app/modules/common/dynamic-bootstrap/component/dynamic-bootstrap/dynamic-bootstrap.component.ts
@@ -0,0 +1,38 @@
+/**
+ * Allows to dynamically render an HTML string into any HTML node, dynamically
+ * bootstrapping all its Angular components and directives.
+ *
+ * ```
+ * <op-dynamic-bootstrap HTML="<macro data-id="1" data-detailed="false" title="Macro nº1"></macro>">
+ * </op-dynamic-bootstrap>
+ * ```
+ * @module
+ * @public
+ */
+import {ApplicationRef, Component, ElementRef, Input} from '@angular/core';
+import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
+import {DynamicBootstrapper} from 'core-app/globals/dynamic-bootstrapper';
+
+@Component({
+ selector: 'op-dynamic-bootstrap',
+ templateUrl: './dynamic-bootstrap.component.html',
+})
+export class DynamicBootstrapComponent {
+ /*
+ * HTML string to be rendered.
+ */
+ @Input()
+ set HTML(templateString:string) {
+ this.innerHtml = this.domSanitizer.bypassSecurityTrustHtml(templateString);
+ this.dynamicBootstrapper.bootstrapOptionalEmbeddable(this.appRef, this.elementRef.nativeElement);
+ }
+
+ innerHtml:SafeHtml;
+ dynamicBootstrapper = DynamicBootstrapper;
+
+ constructor(
+ readonly domSanitizer:DomSanitizer,
+ readonly elementRef:ElementRef,
+ readonly appRef:ApplicationRef,
+ ) { }
+}
diff --git a/frontend/src/app/modules/common/dynamic-bootstrap/dynamic-bootstrap.module.ts b/frontend/src/app/modules/common/dynamic-bootstrap/dynamic-bootstrap.module.ts
new file mode 100644
index 00000000000..97d4745fbcd
--- /dev/null
+++ b/frontend/src/app/modules/common/dynamic-bootstrap/dynamic-bootstrap.module.ts
@@ -0,0 +1,8 @@
+import { NgModule } from '@angular/core';
+import { DynamicBootstrapComponent } from './component/dynamic-bootstrap/dynamic-bootstrap.component';
+
+@NgModule({
+ declarations: [DynamicBootstrapComponent],
+ exports: [DynamicBootstrapComponent],
+})
+export class DynamicBootstrapModule { }
diff --git a/frontend/src/app/modules/common/openproject-common.module.ts b/frontend/src/app/modules/common/openproject-common.module.ts
index 374f7e7bd1e..359e82419cb 100644
--- a/frontend/src/app/modules/common/openproject-common.module.ts
+++ b/frontend/src/app/modules/common/openproject-common.module.ts
@@ -26,8 +26,8 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {FormsModule} from "@angular/forms";
-import {Injector, NgModule} from "@angular/core";
+import {FormsModule} from '@angular/forms';
+import {Injector, NgModule} from '@angular/core';
import {AuthoringComponent} from 'core-app/modules/common/authoring/authoring.component';
import {OpDateTimeComponent} from 'core-app/modules/common/date/op-date-time.component';
@@ -35,55 +35,56 @@ import {OpIcon} from 'core-app/modules/common/icon/op-icon';
import {NotificationComponent} from 'core-app/modules/common/notifications/notification.component';
import {NotificationsContainerComponent} from 'core-app/modules/common/notifications/notifications-container.component';
import {UploadProgressComponent} from 'core-app/modules/common/notifications/upload-progress.component';
-import {OpDatePickerComponent} from "core-app/modules/common/op-date-picker/op-date-picker.component";
-import {FocusWithinDirective} from "core-app/modules/common/focus/focus-within.directive";
-import {OpenprojectAccessibilityModule} from "core-app/modules/a11y/openproject-a11y.module";
-import {FocusDirective} from "core-app/modules/common/focus/focus.directive";
-import {HighlightColDirective} from "core-app/modules/common/highlight-col/highlight-col.directive";
-import {CopyToClipboardDirective} from "core-app/modules/common/copy-to-clipboard/copy-to-clipboard.directive";
-import {highlightColBootstrap} from "./highlight-col/highlight-col.directive";
-import {HookService} from "../plugins/hook-service";
-import {ColorsAutocompleter} from "core-app/modules/common/colors/colors-autocompleter.component";
-import {ResizerComponent} from "core-app/modules/common/resizer/resizer.component";
+import {OpDatePickerComponent} from 'core-app/modules/common/op-date-picker/op-date-picker.component';
+import {FocusWithinDirective} from 'core-app/modules/common/focus/focus-within.directive';
+import {OpenprojectAccessibilityModule} from 'core-app/modules/a11y/openproject-a11y.module';
+import {FocusDirective} from 'core-app/modules/common/focus/focus.directive';
+import {HighlightColDirective} from 'core-app/modules/common/highlight-col/highlight-col.directive';
+import {CopyToClipboardDirective} from 'core-app/modules/common/copy-to-clipboard/copy-to-clipboard.directive';
+import {highlightColBootstrap} from './highlight-col/highlight-col.directive';
+import {HookService} from '../plugins/hook-service';
+import {ColorsAutocompleter} from 'core-app/modules/common/colors/colors-autocompleter.component';
+import {ResizerComponent} from 'core-app/modules/common/resizer/resizer.component';
import {TablePaginationComponent} from 'core-components/table-pagination/table-pagination.component';
import {SortHeaderDirective} from 'core-components/wp-table/sort-header/sort-header.directive';
import {ZenModeButtonComponent} from 'core-components/wp-buttons/zen-mode-toggle-button/zen-mode-toggle-button.component';
import {OPContextMenuComponent} from 'core-components/op-context-menu/op-context-menu.component';
-import {StateService, UIRouterModule} from "@uirouter/angular";
-import {PortalModule} from "@angular/cdk/portal";
-import {CommonModule} from "@angular/common";
-import {CollapsibleSectionComponent} from "core-app/modules/common/collapsible-section/collapsible-section.component";
-import {NoResultsComponent} from "core-app/modules/common/no-results/no-results.component";
-import {DragDropModule} from "@angular/cdk/drag-drop";
-import {UserAutocompleterComponent} from "app/modules/common/autocomplete/user-autocompleter.component";
-import {ScrollableTabsComponent} from "core-app/modules/common/tabs/scrollable-tabs/scrollable-tabs.component";
-import {ContentTabsComponent} from "core-app/modules/common/tabs/content-tabs/content-tabs.component";
-import {EditableToolbarTitleComponent} from "core-app/modules/common/editable-toolbar-title/editable-toolbar-title.component";
-import {UserAvatarComponent} from "core-components/user/user-avatar/user-avatar.component";
-import {EnterpriseBannerComponent} from "core-components/enterprise-banner/enterprise-banner.component";
-import {EnterpriseBannerBootstrapComponent} from "core-components/enterprise-banner/enterprise-banner-bootstrap.component";
-import {DynamicModule} from "ng-dynamic-component";
-import {VersionAutocompleterComponent} from "core-app/modules/common/autocomplete/version-autocompleter.component";
-import {CreateAutocompleterComponent} from "core-app/modules/common/autocomplete/create-autocompleter.component";
-import {HomescreenNewFeaturesBlockComponent} from "core-components/homescreen/blocks/new-features.component";
-import {BoardVideoTeaserModalComponent} from "core-app/modules/boards/board/board-video-teaser-modal/board-video-teaser-modal.component";
-import {PersistentToggleComponent} from "core-app/modules/common/persistent-toggle/persistent-toggle.component";
-import {AutocompleteSelectDecorationComponent} from "core-app/modules/common/autocomplete/autocomplete-select-decoration.component";
-import {AddSectionDropdownComponent} from "core-app/modules/common/hide-section/add-section-dropdown/add-section-dropdown.component";
-import {HideSectionLinkComponent} from "core-app/modules/common/hide-section/hide-section-link/hide-section-link.component";
+import {StateService, UIRouterModule} from '@uirouter/angular';
+import {PortalModule} from '@angular/cdk/portal';
+import {CommonModule} from '@angular/common';
+import {CollapsibleSectionComponent} from 'core-app/modules/common/collapsible-section/collapsible-section.component';
+import {NoResultsComponent} from 'core-app/modules/common/no-results/no-results.component';
+import {DragDropModule} from '@angular/cdk/drag-drop';
+import {UserAutocompleterComponent} from 'app/modules/common/autocomplete/user-autocompleter.component';
+import {ScrollableTabsComponent} from 'core-app/modules/common/tabs/scrollable-tabs/scrollable-tabs.component';
+import {ContentTabsComponent} from 'core-app/modules/common/tabs/content-tabs/content-tabs.component';
+import {EditableToolbarTitleComponent} from 'core-app/modules/common/editable-toolbar-title/editable-toolbar-title.component';
+import {UserAvatarComponent} from 'core-components/user/user-avatar/user-avatar.component';
+import {EnterpriseBannerComponent} from 'core-components/enterprise-banner/enterprise-banner.component';
+import {EnterpriseBannerBootstrapComponent} from 'core-components/enterprise-banner/enterprise-banner-bootstrap.component';
+import {DynamicModule} from 'ng-dynamic-component';
+import {VersionAutocompleterComponent} from 'core-app/modules/common/autocomplete/version-autocompleter.component';
+import {CreateAutocompleterComponent} from 'core-app/modules/common/autocomplete/create-autocompleter.component';
+import {HomescreenNewFeaturesBlockComponent} from 'core-components/homescreen/blocks/new-features.component';
+import {BoardVideoTeaserModalComponent} from 'core-app/modules/boards/board/board-video-teaser-modal/board-video-teaser-modal.component';
+import {PersistentToggleComponent} from 'core-app/modules/common/persistent-toggle/persistent-toggle.component';
+import {AutocompleteSelectDecorationComponent} from 'core-app/modules/common/autocomplete/autocomplete-select-decoration.component';
+import {AddSectionDropdownComponent} from 'core-app/modules/common/hide-section/add-section-dropdown/add-section-dropdown.component';
+import {HideSectionLinkComponent} from 'core-app/modules/common/hide-section/hide-section-link/hide-section-link.component';
import {RemoteFieldUpdaterComponent} from 'core-app/modules/common/remote-field-updater/remote-field-updater.component';
-import {AutofocusDirective} from "core-app/modules/common/autofocus/autofocus.directive";
-import {ShowSectionDropdownComponent} from "core-app/modules/common/hide-section/show-section-dropdown.component";
-import {IconTriggeredContextMenuComponent} from "core-components/op-context-menu/icon-triggered-context-menu/icon-triggered-context-menu.component";
-import {NgSelectModule} from "@ng-select/ng-select";
-import {NgOptionHighlightModule} from "@ng-select/ng-option-highlight";
-import {CurrentProjectService} from "core-components/projects/current-project.service";
-import {CurrentUserService} from "core-components/user/current-user.service";
-import {WorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/wp-autocompleter.component";
-import {TimeEntryWorkPackageAutocompleterComponent} from "core-app/modules/common/autocomplete/te-work-package-autocompleter.component";
-import {DraggableAutocompleteComponent} from "core-app/modules/common/draggable-autocomplete/draggable-autocomplete.component";
-import {DragulaModule} from "ng2-dragula";
-import {SlideToggleComponent} from "core-app/modules/common/slide-toggle/slide-toggle.component";
+import {AutofocusDirective} from 'core-app/modules/common/autofocus/autofocus.directive';
+import {ShowSectionDropdownComponent} from 'core-app/modules/common/hide-section/show-section-dropdown.component';
+import {IconTriggeredContextMenuComponent} from 'core-components/op-context-menu/icon-triggered-context-menu/icon-triggered-context-menu.component';
+import {NgSelectModule} from '@ng-select/ng-select';
+import {NgOptionHighlightModule} from '@ng-select/ng-option-highlight';
+import {CurrentProjectService} from 'core-components/projects/current-project.service';
+import {CurrentUserService} from 'core-components/user/current-user.service';
+import {WorkPackageAutocompleterComponent} from 'core-app/modules/common/autocomplete/wp-autocompleter.component';
+import {TimeEntryWorkPackageAutocompleterComponent} from 'core-app/modules/common/autocomplete/te-work-package-autocompleter.component';
+import {DraggableAutocompleteComponent} from 'core-app/modules/common/draggable-autocomplete/draggable-autocomplete.component';
+import {DragulaModule} from 'ng2-dragula';
+import {SlideToggleComponent} from 'core-app/modules/common/slide-toggle/slide-toggle.component';
+import {DynamicBootstrapModule} from 'core-app/modules/common/dynamic-bootstrap/dynamic-bootstrap.module';
import {PrincipalRendererService} from "core-app/modules/common/principal/principal-renderer.service";
import {OpPrincipalComponent} from "core-app/modules/common/principal/op-principal.component";
@@ -135,6 +136,8 @@ export function bootstrapModule(injector:Injector) {
WorkPackageAutocompleterComponent,
TimeEntryWorkPackageAutocompleterComponent,
CreateAutocompleterComponent]),
+
+ DynamicBootstrapModule,
],
exports: [
// Re-export all commonly used
@@ -147,6 +150,7 @@ export function bootstrapModule(injector:Injector) {
OpenprojectAccessibilityModule,
NgSelectModule,
NgOptionHighlightModule,
+ DynamicBootstrapModule,
OpDatePickerComponent,
OpDateTimeComponent,