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

[#41849] Adapt the style of the attachments section to the new designs

Eric Schubert200d1c712bba
diff --git a/frontend/src/app/core/state/attachments/attachment.model.ts b/frontend/src/app/core/state/attachments/attachment.model.ts
index bc04e5bffe9..ea03f4b5a55 100644
--- a/frontend/src/app/core/state/attachments/attachment.model.ts
+++ b/frontend/src/app/core/state/attachments/attachment.model.ts
@@ -39,6 +39,7 @@ export interface IAttachmentHalResourceLinks extends IHalResourceLinks {
container:IHalResourceLink;
author:IHalResourceLink;
downloadLocation:IHalResourceLink;
+ staticDownloadLocation:IHalResourceLink;
}
export interface IAttachment {
diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.ts
index 4f56cca6c4c..da377a0f54e 100644
--- a/frontend/src/app/core/state/resource-collection.service.ts
+++ b/frontend/src/app/core/state/resource-collection.service.ts
@@ -84,16 +84,11 @@ export abstract class ResourceCollectionService<T> {
}
/**
- * Lookup a single entity from the store
+ * Checks, if the store already has a resource loaded by id.
* @param id
*/
- lookupMultiple(id:ID):Observable<T> {
- return this
- .query
- .selectEntity(id)
- .pipe(
- filter((entity) => entity !== undefined),
- ) as Observable<T>;
+ exists(id:ID):boolean {
+ return this.query.hasEntity(id);
}
/**
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
index 07b6a041416..f09dbc8e4fc 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.component.ts
@@ -27,34 +27,43 @@
//++
import {
- ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output,
+ AfterViewInit,
+ ChangeDetectionStrategy,
+ Component,
+ ElementRef,
+ EventEmitter,
+ Input,
+ OnInit,
+ Output,
+ ViewChild,
} from '@angular/core';
-import { Observable, of } from 'rxjs';
-import { map, switchMap } from 'rxjs/operators';
+import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
+import { distinctUntilChanged, first } from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { IPrincipal } from 'core-app/core/state/principals/principal.model';
import { IAttachment } from 'core-app/core/state/attachments/attachment.model';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { PrincipalsResourceService } from 'core-app/core/state/principals/principals.service';
-import { IUser } from 'core-app/core/state/principals/user.model';
+import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
@Component({
- selector: 'op-attachment-list-item',
+ // eslint-disable-next-line @angular-eslint/component-selector
+ selector: '[op-attachment-list-item]',
templateUrl: './attachment-list-item.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class AttachmentListItemComponent implements OnInit {
- @Input() public resource:HalResource;
-
+export class AttachmentListItemComponent extends UntilDestroyedMixin implements OnInit, AfterViewInit {
@Input() public attachment:IAttachment;
@Input() public index:number;
- @Input() destroyImmediately = true;
-
@Output() public removeAttachment = new EventEmitter<void>();
+ @ViewChild('avatar') avatar:ElementRef;
+
static imageFileExtensions:string[] = ['jpeg', 'jpg', 'gif', 'bmp', 'png'];
public text = {
@@ -67,23 +76,53 @@ export class AttachmentListItemComponent implements OnInit {
return this.text.removeFile({ fileName: this.attachment.fileName });
}
- public author$:Observable<IUser>;
+ public author$:Observable<IPrincipal>;
+
+ public timestampText:string;
+
+ private viewInitialized$ = new BehaviorSubject<boolean>(false);
- constructor(private readonly principalsResourceService:PrincipalsResourceService,
+ constructor(
private readonly I18n:I18nService,
- private readonly pathHelper:PathHelperService) {
+ private readonly pathHelper:PathHelperService,
+ private readonly timezoneService:TimezoneService,
+ private readonly principalsResourceService:PrincipalsResourceService,
+ private readonly principalRendererService:PrincipalRendererService,
+ ) {
+ super();
}
ngOnInit():void {
const authorId = idFromLink(this.attachment._links.author.href);
- this.author$ = this
- .principalsResourceService
- .lookup(authorId)
- .pipe(
- switchMap((user) => (user ? of(user) : this.principalsResourceService.fetchUser(authorId))),
- map((user) => user as IUser),
- );
+ if (!this.principalsResourceService.exists(authorId)) {
+ this.principalsResourceService.fetchUser(authorId).subscribe();
+ }
+
+ this.timestampText = this.timezoneService.parseDatetime(this.attachment.createdAt).fromNow();
+
+ this.author$ = this.principalsResourceService.lookup(authorId).pipe(first());
+
+ combineLatest([
+ this.author$,
+ this.viewInitialized$.pipe(distinctUntilChanged()),
+ ]).pipe(this.untilDestroyed())
+ .subscribe(([user, initialized]) => {
+ if (!initialized) {
+ return;
+ }
+
+ this.principalRendererService.render(
+ this.avatar.nativeElement,
+ user,
+ { hide: true, link: false },
+ { hide: false, size: 'mini' },
+ );
+ });
+ }
+
+ ngAfterViewInit():void {
+ this.viewInitialized$.next(true);
}
/**
@@ -108,29 +147,25 @@ export class AttachmentListItemComponent implements OnInit {
if (this.isImage) {
el = document.createElement('img');
el.src = url;
- el.textContent = this.fileName;
+ el.textContent = this.attachment.fileName;
} else {
el = document.createElement('a');
el.href = url;
- el.textContent = this.fileName;
+ el.textContent = this.attachment.fileName;
}
return el;
}
- public get downloadPath():string {
- return this.pathHelper.attachmentDownloadPath(String(this.attachment.id), this.fileName);
+ private get downloadPath():string {
+ return this.pathHelper.attachmentDownloadPath(String(this.attachment.id), this.attachment.fileName);
}
- public get isImage():boolean {
- const ext = this.fileName.split('.').pop() || '';
+ private get isImage():boolean {
+ const ext = this.attachment.fileName.split('.').pop() || '';
return AttachmentListItemComponent.imageFileExtensions.indexOf(ext.toLowerCase()) > -1;
}
- public get fileName():string {
- return this.attachment.fileName;
- }
-
public confirmRemoveAttachment($event:JQuery.TriggeredEvent):boolean {
if (!window.confirm(this.text.destroyConfirmation)) {
$event.stopImmediatePropagation();
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html
index 5532244719c..a271bcfe5a7 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list-item.html
@@ -1,39 +1,47 @@
-<li
- class="form--selected-value--container work-package--attachments--draggable-item"
- opFocusWithin=".inplace-editing--trigger-icon"
- draggable="true"
- data-qa-selector="op-attachment-list-item"
- (dragstart)="setDragData($event)"
- [title]="text.dragHint"
->
- <span class="form--selected-value">
- <op-icon icon-classes="icon-context icon-attachment"></op-icon>
- <a
- class="work-package--attachments--filename"
- target="_blank"
- rel="noopener"
- [attr.href]="downloadPath || '#'">
+<div class="spot-list--item-floating-wrapper">
+ <a
+ class="spot-list--item-action op-files-tab--file-list-item-action"
+ [href]="attachment._links.staticDownloadLocation.href"
+ target="_blank"
+ (dragstart)="setDragData($event)"
+ >
+ <span
+ class="spot-icon spot-icon_attachment op-files-tab--icon_clip"
+ ></span>
- {{ fileName }}
+ <span
+ [textContent]="attachment.fileName"
+ [title]="attachment.fileName"
+ class="spot-list--item-title op-files-tab--file-list-item-title"
+ ></span>
- <op-authoring
- class="work-package--attachments--info"
- [createdOn]="attachment.createdAt"
- [author]="author$ | async"
- [showAuthorAsLink]="false"
- ></op-authoring>
- </a>
- </span>
- <a
- href=""
- class="form--selected-value--remover work-package--attachments--delete-button"
- *ngIf="!!attachment._links.delete"
- (click)="confirmRemoveAttachment($event)">
- <op-icon
- icon-classes="icon-delete"
- [icon-title]="deleteIconTitle"
- ></op-icon>
+ <span
+ class="op-files-tab--file-list-item-text op-files-tab--color-grey"
+ [textContent]="timestampText"
+ ></span>
+
+ <div
+ #avatar
+ class="op-files-tab--file-list-item-avatar"
+ ></div>
</a>
+ <div class="spot-list--item-floating-actions op-files-tab--file-list-item-floating-actions">
+ <a
+ class="spot-link"
+ [title]="(author$ | async)?.name"
+ [href]="(author$ | async)?._links.showUser.href"
+ >
+ <span class="spot-icon spot-icon_user"></span>
+ </a>
+ <button
+ class="spot-link"
+ [title]="deleteIconTitle"
+ (click)="confirmRemoveAttachment($event)"
+ >
+ <span class="spot-icon spot-icon_delete"></span>
+ </button>
+ </div>
+</div>
- <input type="hidden" name="attachments[{{index}}][id]" value="{{attachment.id}}">
-</li>
+<!-- Needed, if attachment-list-item is used within a form, to provide the added attachment to the serializer. -->
+<input type="hidden" name="attachments[{{index}}][id]" value="{{attachment.id}}">
diff --git a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html
index da5752594d5..e3d1e8eb984 100644
--- a/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html
+++ b/frontend/src/app/shared/components/attachments/attachment-list/attachment-list.html
@@ -1,10 +1,16 @@
-<div class="work-package--attachments--files" *ngIf="resource">
- <ul class="form--selected-value--list"
- *ngFor="let attachment of $attachments | async; trackBy:trackByFileName; let i = index;">
- <op-attachment-list-item [attachment]="attachment"
- [resource]="resource"
- [index]="i"
- (removeAttachment)="removeAttachment(attachment)">
- </op-attachment-list-item>
+<div
+ *ngIf="resource"
+ class="work-package--attachments--files op-attachments-list"
+>
+ <ul class="spot-list spot-list_compact op-files-tab--file-list">
+ <li
+ *ngFor="let attachment of $attachments | async; trackBy:trackByFileName; let i = index;"
+ op-attachment-list-item
+ class="spot-list--item op-files-tab--file-list-item"
+ data-qa-selector="op-attachment-list-item"
+ [attachment]="attachment"
+ [index]="i"
+ (removeAttachment)="removeAttachment(attachment)"
+ ></li>
</ul>
</div>
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
index d57c4aaad52..cd30a87e32b 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
@@ -100,7 +100,7 @@ export class FileLinkListItemComponent implements OnInit, AfterViewInit {
if (this.originData.lastModifiedByName) {
this.principalRendererService.render(
this.avatar.nativeElement,
- { name: this.originData.lastModifiedByName, href: '/users/1' },
+ { name: this.originData.lastModifiedByName, href: '/external_users/1' },
{ hide: true, link: false },
{ hide: false, size: 'mini' },
);
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
index 16ded077feb..2c76141a7b3 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
@@ -11,6 +11,7 @@
<span
[textContent]="fileLink.originData.name"
+ [title]="fileLink.originData.name"
class="spot-list--item-title op-files-tab--file-list-item-title"
></span>
diff --git a/frontend/src/app/shared/components/principal/principal-helper.ts b/frontend/src/app/shared/components/principal/principal-helper.ts
index 4c70b1c991e..4dac9c48672 100644
--- a/frontend/src/app/shared/components/principal/principal-helper.ts
+++ b/frontend/src/app/shared/components/principal/principal-helper.ts
@@ -30,8 +30,7 @@ import { PrincipalLike } from 'core-app/shared/components/principal/principal-ty
import { IPrincipal } from 'core-app/core/state/principals/principal.model';
import { HalSourceLink } from 'core-app/features/hal/resources/hal-resource';
-export type PrincipalType = 'user'|'placeholder_user'|'group';
-export type PrincipalPluralType = 'users'|'placeholder_users'|'groups';
+export type PrincipalType = 'user'|'placeholder_user'|'group'|'external_user';
/*
* This function is a helper that wraps around the old HalResource based principal type and the new interface based one.
@@ -51,7 +50,7 @@ export function hrefFromPrincipal(p:IPrincipal|PrincipalLike):string {
return '';
}
export function typeFromHref(href:string):PrincipalType|null {
- const match = /\/(user|group|placeholder_user)s\/\d+$/.exec(href);
+ const match = /\/(user|group|placeholder_user|external_user)s\/\d+$/.exec(href);
if (!match) {
return null;
diff --git a/frontend/src/global_styles/content/work_packages/tabs/_files.sass b/frontend/src/global_styles/content/work_packages/tabs/_files.sass
index 72a8171d1d2..2c01b947ad9 100644
--- a/frontend/src/global_styles/content/work_packages/tabs/_files.sass
+++ b/frontend/src/global_styles/content/work_packages/tabs/_files.sass
@@ -26,7 +26,8 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-.op-files-tab
+.op-files-tab,
+.op-attachments-list
.op-files-tab--file-list
.op-files-tab--file-list-item
.op-files-tab--file-list-item-action
@@ -128,3 +129,6 @@
&_default
color: #9A9A9A
+
+ &_clip
+ color: #333333