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

[#43696] rework content class for storage file list items

Eric Schubert7ecf5cf41411
diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts
index 3fe389982d2..f0bf15b91cc 100644
--- a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts
+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.component.ts
@@ -40,6 +40,7 @@ import { take } from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { IHalResourceLink } from 'core-app/core/state/hal-resource';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
import { IFileLink } from 'core-app/core/state/file-links/file-link.model';
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
@@ -48,7 +49,7 @@ import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.servi
import { StorageFilesResourceService } from 'core-app/core/state/storage-files/storage-files.service';
import { Breadcrumb, BreadcrumbsContent } from 'core-app/spot/components/breadcrumbs/breadcrumbs-content';
import {
- IStorageFileListItem,
+ StorageFileListItem,
} from 'core-app/shared/components/file-links/storage-file-list-item/storage-file-list-item';
import { FileLinksResourceService } from 'core-app/core/state/file-links/file-links.service';
import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
@@ -61,7 +62,7 @@ import getIconForStorageType from 'core-app/shared/components/file-links/storage
export class FilePickerModalComponent extends OpModalComponent implements OnInit, OnDestroy {
public loading$ = new BehaviorSubject<boolean>(true);
- public listItems$ = new BehaviorSubject<IStorageFileListItem[]>([]);
+ public listItems$ = new BehaviorSubject<StorageFileListItem[]>([]);
public breadcrumbs:BreadcrumbsContent;
@@ -94,6 +95,7 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
readonly elementRef:ElementRef,
readonly cdRef:ChangeDetectorRef,
private readonly i18n:I18nService,
+ private readonly timezoneService:TimezoneService,
private readonly fileLinksResourceService:FileLinksResourceService,
private readonly storageFilesResourceService:StorageFilesResourceService,
) {
@@ -177,17 +179,9 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
};
}
- private storageFileToListItem(file:IStorageFile, index:number):IStorageFileListItem {
- const listItem:IStorageFileListItem = {
- disabled: this.isAlreadyLinked(file),
- isFirst: index === 0,
- selected: this.selection.has(file.id as string),
- changeSelection: () => { this.changeSelection(file); },
- ...file,
- };
-
- if (isDirectory(file.mimeType)) {
- listItem.enterDirectory = () => {
+ private storageFileToListItem(file:IStorageFile, index:number):StorageFileListItem {
+ const enterDirectoryCallback = isDirectory(file.mimeType)
+ ? () => {
const crumbs = this.breadcrumbs.crumbs;
const end = crumbs.length + 1;
const newCrumb:Breadcrumb = {
@@ -195,9 +189,18 @@ export class FilePickerModalComponent extends OpModalComponent implements OnInit
navigate: () => this.changeLevel(file.location, this.breadcrumbs.crumbs.slice(0, end)),
};
this.changeLevel(file.location, crumbs.concat(newCrumb));
- };
- }
- return listItem;
+ }
+ : undefined;
+
+ return new StorageFileListItem(
+ this.timezoneService,
+ file,
+ this.isAlreadyLinked(file),
+ index === 0,
+ this.selection.has(file.id as string),
+ () => { this.changeSelection(file); },
+ enterDirectoryCallback,
+ );
}
private isAlreadyLinked(file:IStorageFile):boolean {
diff --git a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html
index 5ed24483079..606bbd79ea6 100644
--- a/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html
+++ b/frontend/src/app/shared/components/file-links/file-picker-modal/file-picker-modal.html
@@ -28,7 +28,7 @@
class="spot-list--item op-file-list--item"
data-qa-selector="op-file-list--item"
op-storage-file-list-item
- [fileListItemContent]="file"
+ [content]="file"
></li>
</ul>
</ng-container>
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
index 916393c9e6a..88d40f58be2 100644
--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts
@@ -30,18 +30,11 @@ import {
ChangeDetectionStrategy,
Component,
Input,
- OnInit,
} from '@angular/core';
-import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { IFileIcon } from 'core-app/shared/components/file-links/file-link-icons/icon-mappings';
-import {
- getIconForMimeType,
-} from 'core-app/shared/components/file-links/file-link-icons/file-link-list-item-icon.factory';
-import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
import { PrincipalLike } from 'core-app/shared/components/principal/principal-types';
import {
- IStorageFileListItem,
+ StorageFileListItem,
} from 'core-app/shared/components/file-links/storage-file-list-item/storage-file-list-item';
import SpotDropAlignmentOption from 'core-app/spot/drop-alignment-options';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -52,14 +45,8 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
templateUrl: './storage-file-list-item.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class StorageFileListItemComponent implements OnInit {
- @Input() public fileListItemContent:IStorageFileListItem;
-
- infoTimestampText:string;
-
- fileLinkIcon:IFileIcon;
-
- showDetails:boolean;
+export class StorageFileListItemComponent {
+ @Input() public content:StorageFileListItem;
text = {
alreadyLinkedFile: this.i18n.t('js.storages.file_links.already_linked_file'),
@@ -67,9 +54,9 @@ export class StorageFileListItemComponent implements OnInit {
};
get principal():PrincipalLike {
- return this.fileListItemContent.createdByName
+ return this.content.createdByName
? {
- name: this.fileListItemContent.createdByName,
+ name: this.content.createdByName,
href: '/external_users/1',
}
: {
@@ -79,11 +66,11 @@ export class StorageFileListItemComponent implements OnInit {
}
get tooltip():string {
- return isDirectory(this.fileListItemContent.mimeType) ? this.text.alreadyLinkedDirectory : this.text.alreadyLinkedFile;
+ return this.content.isDirectory ? this.text.alreadyLinkedDirectory : this.text.alreadyLinkedFile;
}
get getTooltipAlignment():SpotDropAlignmentOption {
- if (this.fileListItemContent.isFirst) {
+ if (this.content.isFirst) {
return SpotDropAlignmentOption.BottomLeft;
}
@@ -92,16 +79,5 @@ export class StorageFileListItemComponent implements OnInit {
constructor(
private readonly i18n:I18nService,
- private readonly timezoneService:TimezoneService,
) {}
-
- ngOnInit():void {
- if (this.fileListItemContent.lastModifiedAt) {
- this.infoTimestampText = this.timezoneService.parseDatetime(this.fileListItemContent.lastModifiedAt).fromNow();
- }
-
- this.fileLinkIcon = getIconForMimeType(this.fileListItemContent.mimeType);
-
- this.showDetails = !isDirectory(this.fileListItemContent.mimeType);
- }
}
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
index 05234b94fe5..e812722204e 100644
--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.html
@@ -1,6 +1,6 @@
<spot-tooltip
[alignment]="getTooltipAlignment"
- [disabled]="!fileListItemContent.disabled"
+ [disabled]="!content.disabled"
>
<p
slot="body"
@@ -10,31 +10,31 @@
<label
slot="trigger"
class="spot-list--item-action"
- [ngClass]="{ 'spot-list--item-action_disabled': fileListItemContent.disabled }"
+ [ngClass]="{ 'spot-list--item-action_disabled': content.disabled }"
>
<spot-checkbox
- [checked]="fileListItemContent.disabled || fileListItemContent.selected"
- (checkedChange)="fileListItemContent.changeSelection()"
- [disabled]="fileListItemContent.disabled"
+ [checked]="content.disabled || content.selected"
+ (checkedChange)="content.changeSelection()"
+ [disabled]="content.disabled"
></spot-checkbox>
<span
- class="spot-icon spot-icon_{{fileLinkIcon.icon}} op-files-tab--icon op-files-tab--icon_{{fileLinkIcon.clazz}}"
+ class="spot-icon spot-icon_{{content.icon.icon}} op-files-tab--icon op-files-tab--icon_{{content.icon.clazz}}"
></span>
<span
- [textContent]="fileListItemContent.name"
- [title]="fileListItemContent.name"
+ [textContent]="content.name"
+ [title]="content.name"
class="spot-list--item-title op-file-list--item-title"
></span>
<span
- *ngIf="showDetails"
+ *ngIf="!content.isDirectory"
class="op-file-list--item-text"
- [textContent]="infoTimestampText"
+ [textContent]="content.timestamp"
></span>
<op-principal
- *ngIf="showDetails"
+ *ngIf="!content.isDirectory"
class="op-file-list--item-avatar"
[principal]="principal"
[hideName]="true"
@@ -43,9 +43,9 @@
></op-principal>
<button
- *ngIf="!showDetails"
+ *ngIf="content.isDirectory"
class="spot-link"
- (click)="fileListItemContent.enterDirectory()"
+ (click)="content.enterDirectory()"
>
<span class="spot-icon spot-icon_arrow-right2"></span>
</button>
diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts
index fdc203ea81c..8a51391e251 100644
--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts
+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.ts
@@ -27,11 +27,47 @@
//++
import { IStorageFile } from 'core-app/core/state/storage-files/storage-file.model';
+import { TimezoneService } from 'core-app/core/datetime/timezone.service';
+import {
+ getIconForMimeType,
+} from 'core-app/shared/components/file-links/file-link-icons/file-link-list-item-icon.factory';
+import { IFileIcon } from 'core-app/shared/components/file-links/file-link-icons/icon-mappings';
+import { isDirectory } from 'core-app/shared/components/file-links/file-link-icons/file-icons.helper';
-export interface IStorageFileListItem extends IStorageFile {
- disabled:boolean;
- isFirst:boolean;
- selected:boolean;
- changeSelection:() => void;
- enterDirectory?:() => void;
+export class StorageFileListItem {
+ get name():string {
+ return this.storageFile.name;
+ }
+
+ get mimeType():string|undefined {
+ return this.storageFile.mimeType;
+ }
+
+ get createdByName():string|undefined {
+ return this.storageFile.createdByName;
+ }
+
+ get timestamp():string|undefined {
+ return this.storageFile.lastModifiedAt
+ ? this.timezoneService.parseDatetime(this.storageFile.lastModifiedAt).fromNow()
+ : undefined;
+ }
+
+ get icon():IFileIcon {
+ return getIconForMimeType(this.storageFile.mimeType);
+ }
+
+ get isDirectory():boolean {
+ return isDirectory(this.storageFile.mimeType);
+ }
+
+ constructor(
+ private readonly timezoneService:TimezoneService,
+ private readonly storageFile:IStorageFile,
+ public readonly disabled:boolean,
+ public readonly isFirst:boolean,
+ public readonly selected:boolean,
+ public readonly changeSelection:() => void,
+ public readonly enterDirectory?:() => void,
+ ) {}
}