Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

refactor(frontend:files): centralize file location data and rendering

johaven6b418172a0bb
diff --git a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
index 1d2cfeb2..c98900c1 100644
--- a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
+++ b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.html
@@ -18,13 +18,7 @@
</span>
<span class="recent-item-card__content">
<span class="recent-item-card__title">{{ c.content }}</span>
- <span class="recent-item-card__path text-{{c.iconClass}}">
- @if (c.file.inTrash) {
- <fa-icon [icon]="icons.faTrashAlt"></fa-icon>
- }
- <fa-icon [icon]="c.icon" class="me-1"></fa-icon>
- <span>{{ c.showedPath }}</span>
- </span>
+ <app-file-location class="recent-item-card__path" [location]="c"></app-file-location>
</span>
<span class="recent-item-card__time">{{ c.modifiedAt | amLiveTimeAgo }}</span>
</button>
diff --git a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
index 18c1116e..46feed93 100644
--- a/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
+++ b/frontend/src/app/applications/comments/components/widgets/comments-recents-widget.component.ts
@@ -2,26 +2,27 @@ import { Component, computed, inject, Signal } from '@angular/core'
import { Router } from '@angular/router'
import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { faCommentDots } from '@fortawesome/free-regular-svg-icons'
-import { faMagnifyingGlassMinus, faMagnifyingGlassPlus, faTrashAlt } from '@fortawesome/free-solid-svg-icons'
+import { faMagnifyingGlassMinus, faMagnifyingGlassPlus } from '@fortawesome/free-solid-svg-icons'
import { L10nTranslateDirective } from 'angular-l10n'
+import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
import { TAB_MENU } from '../../../../layout/layout.interfaces'
import { LayoutService } from '../../../../layout/layout.service'
import { StoreService } from '../../../../store/store.service'
+import { FileLocationComponent } from '../../../files/components/utils/file-location.component'
import { SPACES_PATH } from '../../../spaces/spaces.constants'
import { UserAvatarComponent } from '../../../users/components/utils/user-avatar.component'
import { CommentRecentModel } from '../../models/comment-recent.model'
import { CommentsService } from '../../services/comments.service'
-import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
@Component({
selector: 'app-comments-recents-widget',
- imports: [L10nTranslateDirective, FaIconComponent, UserAvatarComponent, LiveTimeAgoPipe],
+ imports: [L10nTranslateDirective, FaIconComponent, UserAvatarComponent, LiveTimeAgoPipe, FileLocationComponent],
templateUrl: './comments-recents-widget.component.html',
styleUrl: './comments-recents-widget.component.scss'
})
export class CommentsRecentsWidgetComponent {
protected moreElements = false
- protected readonly icons = { faCommentDots, faMagnifyingGlassPlus, faMagnifyingGlassMinus, faTrashAlt }
+ protected readonly icons = { faCommentDots, faMagnifyingGlassPlus, faMagnifyingGlassMinus }
private readonly router = inject(Router)
private readonly layout = inject(LayoutService)
private readonly store = inject(StoreService)
diff --git a/frontend/src/app/applications/comments/models/comment-recent.model.ts b/frontend/src/app/applications/comments/models/comment-recent.model.ts
index cb34acf8..b2e35342 100644
--- a/frontend/src/app/applications/comments/models/comment-recent.model.ts
+++ b/frontend/src/app/applications/comments/models/comment-recent.model.ts
@@ -20,6 +20,8 @@ export class CommentRecentModel implements CommentRecent {
icon: IconDefinition
iconClass: 'primary' | 'purple'
showedPath: string
+ repositoryTitle: string
+ inTrash: boolean
constructor(props: CommentRecent) {
Object.assign(this, props)
@@ -35,5 +37,7 @@ export class CommentRecentModel implements CommentRecent {
this.icon = location.icon
this.iconClass = location.iconClass
this.showedPath = location.relativePath
+ this.repositoryTitle = location.repositoryTitle
+ this.inTrash = !!this.file.inTrash
}
}
diff --git a/frontend/src/app/applications/files/components/utils/file-location.component.ts b/frontend/src/app/applications/files/components/utils/file-location.component.ts
new file mode 100644
index 00000000..cdccdbd0
--- /dev/null
+++ b/frontend/src/app/applications/files/components/utils/file-location.component.ts
@@ -0,0 +1,107 @@
+import { Component, inject, Input } from '@angular/core'
+import { FaIconComponent } from '@fortawesome/angular-fontawesome'
+import type { IconDefinition } from '@fortawesome/fontawesome-svg-core'
+import { faTrashAlt } from '@fortawesome/free-solid-svg-icons'
+import { L10N_LOCALE, L10nLocale, L10nTranslatePipe } from 'angular-l10n'
+
+export interface FileLocationDisplay {
+ icon?: IconDefinition
+ iconClass: 'primary' | 'purple'
+ showedPath?: string
+ repositoryTitle?: string
+ displayRootName?: string
+ inTrash?: boolean | number
+}
+
+@Component({
+ selector: 'app-file-location',
+ imports: [FaIconComponent, L10nTranslatePipe],
+ template: `
+ @if (location) {
+ <span
+ class="file-location d-flex align-items-center"
+ [class.file-location--repository]="displayAsRepository"
+ [class.overflow-wrap-and-whitespace]="displayAsRepository"
+ [class.text-primary]="!displayAsRepository && location.iconClass === 'primary'"
+ [class.text-purple]="!displayAsRepository && location.iconClass === 'purple'"
+ >
+ @if (displayAsRepository) {
+ @if (displayedIcon) {
+ <fa-icon [icon]="displayedIcon" [class]="displayedIconClass" class="me-2"></fa-icon>
+ }
+ } @else {
+ @if (location.inTrash) {
+ <fa-icon [icon]="faTrashAlt" class="file-location__icon"></fa-icon>
+ }
+ @if (location.icon) {
+ <fa-icon [icon]="location.icon" class="file-location__icon"></fa-icon>
+ }
+ }
+ <span class="file-location__label no-pointer-events" draggable="false">
+ @if (translateLabel) {
+ {{ label | translate: locale.language }}
+ } @else {
+ {{ label }}
+ }
+ </span>
+ </span>
+ }
+ `,
+ styles: [
+ `
+ :host {
+ display: block;
+ min-width: 0;
+ }
+
+ .file-location {
+ column-gap: 0.15rem;
+ line-height: 1.15;
+ min-width: 0;
+ white-space: nowrap;
+ }
+
+ .file-location--repository {
+ column-gap: 0;
+ }
+
+ .file-location__icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex: 0 0 auto;
+ font-size: 1.1em;
+ line-height: 1;
+ }
+
+ .file-location__label {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+ `
+ ]
+})
+export class FileLocationComponent {
+ @Input({ required: true }) location: FileLocationDisplay
+ @Input() displayAsRepository = false
+ protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
+ protected readonly faTrashAlt = faTrashAlt
+
+ protected get displayedIcon(): IconDefinition | undefined {
+ return this.location?.inTrash ? this.faTrashAlt : this.location?.icon
+ }
+
+ protected get displayedIconClass(): string {
+ return this.location?.inTrash ? 'circle-error-icon' : `circle-${this.location?.iconClass || 'primary'}-icon`
+ }
+
+ protected get label(): string {
+ return this.location?.showedPath || this.location?.displayRootName || this.location?.repositoryTitle || ''
+ }
+
+ protected get translateLabel(): boolean {
+ return !this.location?.showedPath && !this.location?.displayRootName && !!this.location?.repositoryTitle
+ }
+}
diff --git a/frontend/src/app/applications/files/components/utils/file-location.utils.ts b/frontend/src/app/applications/files/components/utils/file-location.utils.ts
index da2c246c..36c4e844 100644
--- a/frontend/src/app/applications/files/components/utils/file-location.utils.ts
+++ b/frontend/src/app/applications/files/components/utils/file-location.utils.ts
@@ -3,9 +3,9 @@ import { FILE_REPOSITORY } from '@sync-in-server/backend/src/applications/files/
import { SPACE_ALIAS, SPACE_REPOSITORY } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
import { SPACES_ICON, SPACES_TITLE } from '../../../spaces/spaces.constants'
-type FileLocationRepository = SPACE_ALIAS.PERSONAL | FILE_REPOSITORY.SPACE | FILE_REPOSITORY.SHARE
+export type FileLocationRepository = SPACE_ALIAS.PERSONAL | FILE_REPOSITORY.SPACE | FILE_REPOSITORY.SHARE
-interface FileLocationPresentation {
+export interface FileLocationPresentation {
repository: FileLocationRepository
repositoryTitle: string
relativePath: string
diff --git a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
index eaf2ce6e..9f47e29e 100644
--- a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
+++ b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.html
@@ -18,13 +18,7 @@
</span>
<span class="recent-item-card__content">
<span class="recent-item-card__title">{{ f.name }}</span>
- <span class="recent-item-card__path text-{{f.iconClass}}">
- @if (f.inTrash) {
- <fa-icon [icon]="icons.faTrashAlt"></fa-icon>
- }
- <fa-icon [icon]="f.icon" class="me-1"></fa-icon>
- <span>{{ f.showedPath }}</span>
- </span>
+ <app-file-location class="recent-item-card__path" [location]="f"></app-file-location>
</span>
<span class="recent-item-card__time">{{ f.mtime | amLiveTimeAgo }}</span>
</button>
diff --git a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
index ba3b04aa..da660936 100644
--- a/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
+++ b/frontend/src/app/applications/files/components/widgets/files-recents-widget.component.ts
@@ -2,23 +2,24 @@ import { Component, computed, inject, Signal } from '@angular/core'
import { Router } from '@angular/router'
import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { faFileLines } from '@fortawesome/free-regular-svg-icons'
-import { faMagnifyingGlassMinus, faMagnifyingGlassPlus, faTrashAlt } from '@fortawesome/free-solid-svg-icons'
+import { faMagnifyingGlassMinus, faMagnifyingGlassPlus } from '@fortawesome/free-solid-svg-icons'
import { L10nTranslateDirective } from 'angular-l10n'
+import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
import { StoreService } from '../../../../store/store.service'
import { SPACES_PATH } from '../../../spaces/spaces.constants'
import { FileRecentModel } from '../../models/file-recent.model'
import { FilesService } from '../../services/files.service'
-import { LiveTimeAgoPipe } from '../../../../common/pipes/time-ago-live.pipe'
+import { FileLocationComponent } from '../utils/file-location.component'
@Component({
selector: 'app-files-recents-widget',
- imports: [L10nTranslateDirective, FaIconComponent, LiveTimeAgoPipe],
+ imports: [L10nTranslateDirective, FaIconComponent, LiveTimeAgoPipe, FileLocationComponent],
templateUrl: './files-recents-widget.component.html',
styleUrl: './files-recents-widget.component.scss'
})
export class FilesRecentsWidgetComponent {
protected moreElements = false
- protected readonly icons = { faFileLines, faMagnifyingGlassPlus, faMagnifyingGlassMinus, faTrashAlt }
+ protected readonly icons = { faFileLines, faMagnifyingGlassPlus, faMagnifyingGlassMinus }
private readonly router = inject(Router)
private readonly store = inject(StoreService)
private readonly filesService = inject(FilesService)
diff --git a/frontend/src/app/applications/files/models/file-content.model.ts b/frontend/src/app/applications/files/models/file-content.model.ts
index 05ec8805..80e83418 100644
--- a/frontend/src/app/applications/files/models/file-content.model.ts
+++ b/frontend/src/app/applications/files/models/file-content.model.ts
@@ -1,39 +1,11 @@
-import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import type { FileContent } from '@sync-in-server/backend/src/applications/files/schemas/file-content.interface'
-import { resolveFileLocation } from '../components/utils/file-location.utils'
-import { defaultMimeUrl, getAssetsMimeUrl } from '../files.constants'
+import { FileLocationModel } from './file-location.model'
-export class FileContentModel implements FileContent {
- id: number
- path: string
- name: string
- mime: string
+export class FileContentModel extends FileLocationModel implements FileContent {
size: number
- mtime: number
matches: string[]
- displayRootName?: string
-
- // Computed
- mimeUrl: string
- icon: IconDefinition
- iconClass: 'primary' | 'purple'
- showedPath: string
constructor(props: FileContent) {
- Object.assign(this, props)
- this.mimeUrl = getAssetsMimeUrl(this.mime)
- this.setProperties()
- }
-
- fallBackMimeUrl() {
- this.mimeUrl = defaultMimeUrl
- }
-
- private setProperties() {
- const location = resolveFileLocation(this.path, { displayRootName: this.displayRootName })
- if (!location) return
- this.showedPath = location.relativePath
- this.iconClass = location.iconClass
- this.icon = location.icon
+ super(props)
}
}
diff --git a/frontend/src/app/applications/files/models/file-location.model.ts b/frontend/src/app/applications/files/models/file-location.model.ts
new file mode 100644
index 00000000..6ffcca0c
--- /dev/null
+++ b/frontend/src/app/applications/files/models/file-location.model.ts
@@ -0,0 +1,55 @@
+import type { IconDefinition } from '@fortawesome/fontawesome-svg-core'
+import { FILE_REPOSITORY } from '@sync-in-server/backend/src/applications/files/constants/operations'
+import { SPACE_REPOSITORY } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
+import { type FileLocationRepository, resolveFileLocation } from '../components/utils/file-location.utils'
+import { defaultMimeUrl, getAssetsMimeUrl, mimeDirectory, mimeDirectoryShare } from '../files.constants'
+
+interface FileLocationProps {
+ id: number
+ path: string
+ name: string
+ mime: string
+ mtime: number
+ isDir?: boolean
+ inTrash?: boolean
+ displayRootName?: string
+}
+
+export abstract class FileLocationModel {
+ id: number
+ path: string
+ name: string
+ mime: string
+ mtime: number
+ inTrash = false
+ displayRootName?: string
+ repository?: FileLocationRepository
+ repositoryTitle?: string
+
+ // Computed
+ mimeUrl: string
+ icon: IconDefinition
+ iconClass: 'primary' | 'purple' = 'primary'
+ showedPath: string
+
+ protected constructor(props: Partial<FileLocationProps>, repository?: FileLocationRepository) {
+ Object.assign(this, props)
+ const location = resolveFileLocation(this.path, { repository, displayRootName: this.displayRootName })
+ this.showedPath = location?.relativePath ?? this.path
+ if (location) {
+ this.repository = location.repository
+ this.repositoryTitle = location.repositoryTitle
+ this.iconClass = location.iconClass
+ this.icon = location.icon
+ } else {
+ this.repository = repository
+ }
+ const displayMime = this.repository === FILE_REPOSITORY.SHARE && (props.isDir || this.mime === mimeDirectory) ? mimeDirectoryShare : this.mime
+ this.mimeUrl = getAssetsMimeUrl(displayMime)
+ this.inTrash = props.inTrash ?? this.path?.split('/')[0] === SPACE_REPOSITORY.TRASH
+ }
+
+ fallBackMimeUrl() {
+ this.mimeUrl = defaultMimeUrl
+ }
+}
diff --git a/frontend/src/app/applications/files/models/file-recent.model.ts b/frontend/src/app/applications/files/models/file-recent.model.ts
index 00885418..3b312fbd 100644
--- a/frontend/src/app/applications/files/models/file-recent.model.ts
+++ b/frontend/src/app/applications/files/models/file-recent.model.ts
@@ -1,42 +1,14 @@
-import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import { FILE_REPOSITORY } from '@sync-in-server/backend/src/applications/files/constants/operations'
import type { FileRecent } from '@sync-in-server/backend/src/applications/files/schemas/file-recent.interface'
-import { SPACE_ALIAS, SPACE_REPOSITORY } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
-import { resolveFileLocation } from '../components/utils/file-location.utils'
-import { defaultMimeUrl, getAssetsMimeUrl } from '../files.constants'
+import { SPACE_ALIAS } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
+import { FileLocationModel } from './file-location.model'
-export class FileRecentModel implements FileRecent {
- id: number
- mime: string
- mtime: number
- name: string
+export class FileRecentModel extends FileLocationModel implements FileRecent {
ownerId: number
- path: string
shareId: number
spaceId: number
- displayRootName?: string
-
- // Computed
- mimeUrl: string
- icon: IconDefinition
- iconClass: 'primary' | 'purple'
- showedPath: string
- inTrash = false
constructor(props: Partial<FileRecent>) {
- Object.assign(this, props)
- this.mimeUrl = getAssetsMimeUrl(this.mime)
- const location = resolveFileLocation(this.path, {
- repository: this.shareId ? FILE_REPOSITORY.SHARE : this.spaceId ? FILE_REPOSITORY.SPACE : SPACE_ALIAS.PERSONAL,
- displayRootName: this.displayRootName
- })
- this.iconClass = location.iconClass
- this.icon = location.icon
- this.showedPath = location.relativePath
- this.inTrash = this.path.split('/')[0] === SPACE_REPOSITORY.TRASH
- }
-
- fallBackMimeUrl() {
- this.mimeUrl = defaultMimeUrl
+ super(props, props.shareId ? FILE_REPOSITORY.SHARE : props.spaceId ? FILE_REPOSITORY.SPACE : SPACE_ALIAS.PERSONAL)
}
}
diff --git a/frontend/src/app/applications/search/components/search.component.html b/frontend/src/app/applications/search/components/search.component.html
index 4f0d35f0..8fb444d5 100644
--- a/frontend/src/app/applications/search/components/search.component.html
+++ b/frontend/src/app/applications/search/components/search.component.html
@@ -56,10 +56,7 @@
<img [src]="f.mimeUrl" (error)="f.fallBackMimeUrl()" alt="" draggable="false" class="search-result-mime">
<div class="search-result-meta d-flex flex-column">
<span class="search-result-name text-truncate">{{ f.name }}</span>
- <div class="search-result-path d-flex align-items-center text-{{f.iconClass}}">
- <fa-icon [icon]="f.icon" class="search-result-path-icon"></fa-icon>
- <span class="text-truncate search-result-path-text">{{ f.showedPath }}</span>
- </div>
+ <app-file-location class="search-result-path" [location]="f"></app-file-location>
</div>
</div>
@if (f.matches?.length) {
diff --git a/frontend/src/app/applications/search/components/search.component.ts b/frontend/src/app/applications/search/components/search.component.ts
index 91a995c1..1e05c221 100644
--- a/frontend/src/app/applications/search/components/search.component.ts
+++ b/frontend/src/app/applications/search/components/search.component.ts
@@ -17,6 +17,7 @@ import { SearchFilterPipe } from '../../../common/pipes/search.pipe'
import { filterArray } from '../../../common/utils/functions'
import { LayoutService } from '../../../layout/layout.service'
import { StoreService } from '../../../store/store.service'
+import { FileLocationComponent } from '../../files/components/utils/file-location.component'
import { FileContentModel } from '../../files/models/file-content.model'
import { FilesService } from '../../files/services/files.service'
import { SPACES_PATH } from '../../spaces/spaces.constants'
@@ -35,7 +36,8 @@ import { SEARCH_ICON, SEARCH_PATH } from '../search.constants'
TooltipDirective,
SearchFilterPipe,
L10nTranslateDirective,
- TapDirective
+ TapDirective,
+ FileLocationComponent
],
templateUrl: './search.component.html'
})
diff --git a/frontend/src/styles/components/_search.scss b/frontend/src/styles/components/_search.scss
index c97a36e8..387361a6 100644
--- a/frontend/src/styles/components/_search.scss
+++ b/frontend/src/styles/components/_search.scss
@@ -55,18 +55,7 @@
.search-result-path {
min-width: 0;
line-height: 1.15;
-}
-
-.search-result-path-icon {
font-size: $font-size-sm;
- flex: 0 0 auto;
- margin-right: 0.25rem;
-}
-
-.search-result-path-text {
- font-size: $font-size-sm;
- min-width: 0;
- user-select: none;
}
.search-result-matches {