Skip to content

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

refactor(frontend:files): optimize task list rendering and status display

johaven0bffc271f3f6
diff --git a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
index 3dec692a..15460f3d 100644
--- a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
+++ b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.html
@@ -18,7 +18,7 @@
</div>
@if (nbTotalTasks) {
<div class="d-flex gap-1">
- @if (hasCancellableTasks()) {
+ @if (hasCancellableTasks) {
<button type="button" (click)="cancelTasks()" [tooltip]="'Stop' | translate:locale.language" class="btn btn-sm btn-default" placement="top">
<fa-icon [icon]="icons.faStop"></fa-icon>
</button>
@@ -34,33 +34,29 @@
<!-- Inner menu: contains the tasks -->
<div appAutoResize>
@for (task of tasks; track task.id) {
- @let pending = isTaskPending(task);
- @let error = isTaskError(task);
- @let cancelled = isTaskCancelled(task);
- @let openable = canOpenTask(task);
- @let cancellable = canCancel(task);
<div class="task-list"
- [class.task-list--cancelled]="cancelled"
- [class.task-list--error]="error"
- [class.task-list--interactive]="openable"
- [class.task-list--pending]="pending"
+ [class.task-list--cancelled]="task.ui.cancelled"
+ [class.task-list--error]="task.ui.error"
+ [class.task-list--interactive]="task.ui.openable"
+ [class.task-list--pending]="task.ui.pending"
+ [class.task-list--queued]="task.ui.queued"
[tooltip]="task.result ? (task.result | translate:locale.language) : ''"
(click)="openTask(task)"
placement="bottom">
<div class="task-list__content">
<div class="task-list__header">
<fa-icon class="task-list__status"
- [class.text-danger]="error"
- [class.text-muted]="cancelled"
- [icon]="iconsStatus[task.status]"
- [animation]="pending ? 'spin-pulse' : null"></fa-icon>
+ [class.text-danger]="task.ui.error"
+ [class.text-muted]="task.ui.cancelled || task.ui.queued"
+ [icon]="task.ui.statusIcon"
+ [animation]="task.ui.pending ? 'spin-pulse' : null"></fa-icon>
<span class="task-list__operation">
- <fa-icon [icon]="iconsOperation[task.type]"></fa-icon>
+ <fa-icon [icon]="task.ui.operationIcon"></fa-icon>
</span>
<span class="task-list__name">{{ task.name }}</span>
</div>
- @if (task.status >= 2 && !cancelled) {
- <div [class.text-danger]="error" class="task-list__result">
+ @if (task.ui.error && task.result) {
+ <div class="text-danger task-list__result">
{{ task.result | translate:locale.language }}
</div>
}
@@ -68,28 +64,41 @@
<div class="task-list__progress-row">
<div class="task-list__progress">
<progressbar [max]="100"
- [value]="task.status > 0 ? 100 : task.props.progress || 100"
- [type]="pending ? 'warning' : error ? 'danger' : null"
- [class.custom-progress-bar--cancelled]="cancelled"
+ [value]="task.ui.progress"
+ [type]="task.ui.progressType"
+ [class.custom-progress-bar--cancelled]="task.ui.cancelled"
class="custom-progress-bar position-relative">
<span class="task-list__progress-label d-flex align-items-center justify-content-center position-absolute w-100">
- @if (task.props.size) {
- <span>{{ task.props.size | toBytes:2 }}&nbsp;•&nbsp;</span>
+ @for (item of task.ui.progressItems; track item.type) {
+ @if (!$first) {
+ <span>&nbsp;•&nbsp;</span>
+ }
+ @if (item.icon) {
+ <fa-icon [icon]="item.icon"></fa-icon>
+ <span>&nbsp;</span>
+ }
+ @switch (item.type) {
+ @case ('currentSize') {
+ <span>{{ item.value | toBytes:2 }}</span>
+ }
+ @case ('totalSize') {
+ <span>{{ item.value | toBytes:2 }}</span>
+ }
+ @case ('size') {
+ <span>{{ item.value | toBytes:2 }}</span>
+ }
+ @case ('endedAt') {
+ <span>{{ item.value | amDateFormat:'L HH:mm' }}</span>
+ }
+ @default {
+ <span>{{ item.value }}</span>
+ }
+ }
}
- @if (task.props.directories) {
- <fa-icon [icon]="icons.faFolderClosed"></fa-icon>
- <span>&nbsp;{{ task.props.directories }}&nbsp;•&nbsp;</span>
- }
- @if (task.props.files) {
- <fa-icon [icon]="icons.faFile"></fa-icon>
- <span>&nbsp;{{ task.props.files }}&nbsp;•&nbsp;</span>
- }
- <fa-icon [icon]="icons.faClock"></fa-icon>
- <span>&nbsp;{{ task.startedAt | amTimeAgo:true }}</span>
</span>
</progressbar>
</div>
- @if (cancellable) {
+ @if (task.ui.cancellable) {
<button type="button"
(click)="cancelTask($event, task)"
[tooltip]="'Stop' | translate:locale.language"
diff --git a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
index b9ef51bc..7f73cdb0 100644
--- a/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
+++ b/frontend/src/app/applications/files/components/sidebar/files-tasks.component.ts
@@ -1,4 +1,4 @@
-import { Component, inject, OnDestroy } from '@angular/core'
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, inject, OnDestroy } from '@angular/core'
import { Router } from '@angular/router'
import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
@@ -23,23 +23,31 @@ import { ProgressbarComponent } from 'ngx-bootstrap/progressbar'
import { TooltipModule } from 'ngx-bootstrap/tooltip'
import { Subscription } from 'rxjs'
import { AutoResizeDirective } from '../../../../common/directives/auto-resize.directive'
-import { TimeAgoPipe } from '../../../../common/pipes/time-ago.pipe'
+import { TimeDateFormatPipe } from '../../../../common/pipes/time-date-format.pipe'
import { ToBytesPipe } from '../../../../common/pipes/to-bytes.pipe'
import { StoreService } from '../../../../store/store.service'
import { SPACES_PATH } from '../../../spaces/spaces.constants'
+import type { FileTaskView, TaskProgressItem } from '../../interfaces/file-task-view.interface'
import { FilesTasksService } from '../../services/files-tasks.service'
import { FilesService } from '../../services/files.service'
@Component({
selector: 'app-files-tasks',
- imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarComponent, TimeAgoPipe, ToBytesPipe],
+ imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarComponent, TimeDateFormatPipe, ToBytesPipe],
+ changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: 'files-tasks.component.html'
})
export class FilesTasksComponent implements OnDestroy {
protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
protected readonly icons = { faTrashAlt, faFlag, faClock, faFile, faFolderClosed, faStop }
- protected readonly iconsStatus: IconDefinition[] = [faSpinner, faCheck, faExclamation, faBan]
- protected readonly iconsOperation = {
+ protected readonly iconsStatus: Record<FileTaskStatus, IconDefinition> = {
+ [FileTaskStatus.PENDING]: faSpinner,
+ [FileTaskStatus.SUCCESS]: faCheck,
+ [FileTaskStatus.ERROR]: faExclamation,
+ [FileTaskStatus.CANCELLED]: faBan,
+ [FileTaskStatus.QUEUED]: faClock
+ }
+ protected readonly iconsOperation: Partial<Record<FILE_OPERATION, IconDefinition>> = {
[FILE_OPERATION.DELETE]: faTrashCan,
[FILE_OPERATION.MOVE]: faArrowsAlt,
[FILE_OPERATION.COPY]: faClone,
@@ -51,11 +59,13 @@ export class FilesTasksComponent implements OnDestroy {
protected nbActiveTasks = 0
protected nbEndedTasks = 0
protected nbTotalTasks = 0
- protected tasks: FileTask[] = []
+ protected hasCancellableTasks = false
+ protected tasks: FileTaskView[] = []
private readonly router = inject(Router)
private readonly store = inject(StoreService)
private readonly filesService = inject(FilesService)
private readonly filesTasksService = inject(FilesTasksService)
+ private readonly cdr = inject(ChangeDetectorRef)
private subscriptions: Subscription[] = []
constructor() {
@@ -67,17 +77,19 @@ export class FilesTasksComponent implements OnDestroy {
this.subscriptions.forEach((s) => s.unsubscribe())
}
- updateTasks(tasks: any[], active = false) {
+ updateTasks(tasks: FileTask[], active = false) {
if (active) {
- this.tasks = [...tasks, ...this.store.filesEndedTasks.getValue()]
+ this.tasks = this.sortTasksForDisplay([...tasks, ...this.store.filesEndedTasks.getValue()])
this.nbActiveTasks = tasks.length
this.nbEndedTasks = this.store.filesEndedTasks.getValue().length
} else {
- this.tasks = [...this.store.filesActiveTasks.getValue(), ...tasks]
+ this.tasks = this.sortTasksForDisplay([...this.store.filesActiveTasks.getValue(), ...tasks])
this.nbEndedTasks = tasks.length
this.nbActiveTasks = this.store.filesActiveTasks.getValue().length
}
this.nbTotalTasks = this.nbActiveTasks + this.nbEndedTasks
+ this.updateHasCancellableTasks()
+ this.cdr.markForCheck()
}
removeTasks() {
@@ -86,43 +98,83 @@ export class FilesTasksComponent implements OnDestroy {
cancelTasks() {
for (const task of this.tasks) {
- if (this.canCancel(task)) {
+ if (task.ui.cancellable) {
this.filesTasksService.cancel(task)
+ task.ui.cancellable = false
}
}
+ this.updateHasCancellableTasks()
}
- cancelTask(event: MouseEvent, task: FileTask) {
+ cancelTask(event: MouseEvent, task: FileTaskView) {
event.stopPropagation()
+ if (!task.ui.cancellable) return
this.filesTasksService.cancel(task)
+ task.ui.cancellable = false
+ this.updateHasCancellableTasks()
}
- canCancel(task: FileTask): boolean {
- return this.filesTasksService.canCancel(task)
- }
-
- hasCancellableTasks(): boolean {
- return this.tasks.some((task: FileTask) => this.canCancel(task))
+ private sortTasksForDisplay(tasks: FileTask[]): FileTaskView[] {
+ return tasks
+ .map((task: FileTask, index: number) => ({ index, task: this.createTaskView(task) }))
+ .sort((a, b) => a.task.ui.displayPriority - b.task.ui.displayPriority || a.index - b.index)
+ .map(({ task }) => task)
}
- canOpenTask(task: FileTask): boolean {
- return task.status === FileTaskStatus.SUCCESS
- }
-
- isTaskPending(task: FileTask): boolean {
- return task.status === FileTaskStatus.PENDING
+ private createTaskView(task: FileTask): FileTaskView {
+ const pending = task.status === FileTaskStatus.PENDING
+ const queued = task.status === FileTaskStatus.QUEUED
+ const error = task.status === FileTaskStatus.ERROR
+ const cancelled = task.status === FileTaskStatus.CANCELLED
+ return {
+ ...task,
+ ui: {
+ cancelled,
+ cancellable: this.filesTasksService.canCancel(task),
+ displayPriority: pending ? 0 : queued ? 1 : 2,
+ error,
+ openable: task.status === FileTaskStatus.SUCCESS,
+ operationIcon: this.iconsOperation[task.type] || this.icons.faFlag,
+ pending,
+ progress: pending ? task.props.progress || 100 : queued ? 0 : 100,
+ progressItems: this.createProgressItems(task, pending, queued),
+ progressType: pending ? 'warning' : error ? 'danger' : null,
+ queued,
+ statusIcon: this.iconsStatus[task.status]
+ }
+ }
}
- isTaskError(task: FileTask): boolean {
- return task.status === FileTaskStatus.ERROR
+ private createProgressItems(task: FileTask, pending: boolean, queued: boolean): TaskProgressItem[] {
+ const items: TaskProgressItem[] = []
+ if (pending && task.props.totalSize) {
+ items.push({ type: 'currentSize', value: task.props.size ?? 0 }, { type: 'totalSize', value: task.props.totalSize })
+ } else if (pending && task.type === FILE_OPERATION.COMPRESS) {
+ items.push({ type: 'currentSize', value: task.props.size ?? 0 })
+ } else {
+ const size = queued ? task.props.totalSize || task.props.size : task.props.size || task.props.totalSize
+ if (size) {
+ items.push({ type: 'size', value: size })
+ }
+ }
+ if (task.props.directories) {
+ items.push({ icon: this.icons.faFolderClosed, type: 'directories', value: task.props.directories })
+ }
+ if (task.props.files) {
+ items.push({ icon: this.icons.faFile, type: 'files', value: task.props.files })
+ }
+ if (!pending && !queued && task.endedAt) {
+ items.push({ icon: this.icons.faClock, type: 'endedAt', value: task.endedAt })
+ }
+ return items
}
- isTaskCancelled(task: FileTask): boolean {
- return task.status === FileTaskStatus.CANCELLED
+ private updateHasCancellableTasks() {
+ this.hasCancellableTasks = this.tasks.some((task: FileTaskView) => task.ui.cancellable)
}
openTask(task: FileTask) {
- if (!this.canOpenTask(task)) return
+ if (task.status !== FileTaskStatus.SUCCESS) return
if (task.type === FILE_OPERATION.COMPRESS && task.props.compressInDirectory === false) {
this.filesService.downloadTaskArchive(task.id)
return
diff --git a/frontend/src/app/applications/files/interfaces/file-task-view.interface.ts b/frontend/src/app/applications/files/interfaces/file-task-view.interface.ts
new file mode 100644
index 00000000..82dbc3ef
--- /dev/null
+++ b/frontend/src/app/applications/files/interfaces/file-task-view.interface.ts
@@ -0,0 +1,28 @@
+import type { IconDefinition } from '@fortawesome/fontawesome-svg-core'
+import type { FileTask } from '@sync-in-server/backend/src/applications/files/models/file-task'
+
+export type TaskProgressbarType = 'warning' | 'danger' | null
+export type TaskProgressItemType = 'currentSize' | 'totalSize' | 'size' | 'directories' | 'files' | 'endedAt'
+
+export interface TaskProgressItem {
+ icon?: IconDefinition
+ type: TaskProgressItemType
+ value: number
+}
+
+export interface FileTaskView extends FileTask {
+ ui: {
+ cancelled: boolean
+ cancellable: boolean
+ displayPriority: number
+ error: boolean
+ openable: boolean
+ operationIcon: IconDefinition
+ pending: boolean
+ progress: number
+ progressItems: TaskProgressItem[]
+ progressType: TaskProgressbarType
+ queued: boolean
+ statusIcon: IconDefinition
+ }
+}
diff --git a/frontend/src/styles/components/_tasks.scss b/frontend/src/styles/components/_tasks.scss
index 6126a125..0f9674b1 100755
--- a/frontend/src/styles/components/_tasks.scss
+++ b/frontend/src/styles/components/_tasks.scss
@@ -3,21 +3,25 @@ $task-progress-height: 1.35rem;
.task-list {
@include no-select-utility;
border-bottom: .5px solid transparent;
- border-left: 3px solid transparent;
+ border-right: 3px solid transparent;
font-size: $font-size-sm;
padding: .3rem .4rem;
- transition: background-color .16s ease, border-left-color .16s ease;
+ transition: background-color .16s ease, border-right-color .16s ease;
&--pending {
- border-left-color: $warning;
+ border-right-color: $warning;
}
&--error {
- border-left-color: $danger;
+ border-right-color: $danger;
}
&--cancelled {
- border-left-color: $secondary;
+ border-right-color: $secondary;
+ }
+
+ &--queued {
+ border-right-color: $secondary;
}
&--interactive {