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

user-link component handles having no show link correctly

ulfertsa4b705ac0bdc
diff --git a/frontend/src/app/components/user/user-link/user-link.component.ts b/frontend/src/app/components/user/user-link/user-link.component.ts
index 3d3695dd4ef..68612f38a6f 100644
--- a/frontend/src/app/components/user/user-link/user-link.component.ts
+++ b/frontend/src/app/components/user/user-link/user-link.component.ts
@@ -26,7 +26,7 @@
// See docs/COPYRIGHT.rdoc for more details.
//++
-import {Component, Inject, Input} from '@angular/core';
+import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
import {UserResource} from 'core-app/modules/hal/resources/user-resource';
import {I18nService} from 'core-app/modules/common/i18n/i18n.service';
import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
@@ -34,26 +34,33 @@ import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper
@Component({
selector: 'user-link',
template: `
- <a [attr.href]="href"
+ <a *ngIf="href"
+ [attr.href]="href"
[attr.title]="label"
- [textContent]="user.name">
+ [textContent]="name">
</a>
- `
+ <ng-container *ngIf="!href">
+ {{ name }}
+ <ng-container>
+ `,
+ changeDetection: ChangeDetectionStrategy.OnPush
})
export class UserLinkComponent {
@Input() user:UserResource;
- public href:string;
- public label:string;
- public name:string;
-
constructor(readonly pathHelper:PathHelperService,
readonly I18n:I18nService) {
}
- ngOnInit() {
- this.href = this.pathHelper.userPath(this.user.idFromLink);
- this.name = this.user.name;
- this.label = this.I18n.t('js.label_author', { user: this.name });
+ public get href() {
+ return this.user && this.user.showUserPath;
+ }
+
+ public get name() {
+ return this.user && this.user.name;
+ }
+
+ public get label() {
+ return this.I18n.t('js.label_author', { user: this.name });
}
}
diff --git a/frontend/src/app/modules/hal/resources/user-resource.ts b/frontend/src/app/modules/hal/resources/user-resource.ts
index 669284d7a09..ea7eb2d6763 100644
--- a/frontend/src/app/modules/hal/resources/user-resource.ts
+++ b/frontend/src/app/modules/hal/resources/user-resource.ts
@@ -55,7 +55,7 @@ export class UserResource extends HalResource {
}
public get showUserPath() {
- return this.showUser.$link.href;
+ return this.showUser ? this.showUser.$link.href : null;
}
public get isActive() {