Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
refactor(frontend): migrate to Angular signals, replace ProgressbarModule with ProgressbarComponent, and enhance quota input handling
johaven3ea9a653fb1a
diff --git a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.tsindex 20e9cabf..cccae95e 100644--- a/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts+++ b/frontend/src/app/applications/admin/components/dialogs/admin-user-dialog.component.ts@@ -166,6 +166,7 @@ export class AdminUserDialogComponent implements OnInit {updateQuota(quota: number) {this.userForm.controls.storageQuota.setValue(quota)this.userForm.controls.storageQuota.markAsDirty()+ this.user.storageQuota = quota}onCancel() {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.htmlindex d252565f..a08791cc 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@@ -44,25 +44,26 @@}</span><div class="fs-xxxs">- <div>- <progressbar [max]="100"- [value]="task.status > 0 ? 100 : task.props.progress || 100"- [type]="task.status < 1 ? 'warning' : task.status === 2 ? 'danger' : null"- class="custom-progress-bar position-relative">+ <progressbar [max]="100"+ [value]="task.status > 0 ? 100 : task.props.progress || 100"+ [type]="task.status < 1 ? 'warning' : task.status === 2 ? 'danger' : null"+ class="custom-progress-bar position-relative"><span class="d-flex align-items-center justify-content-center position-absolute mx-1 w-100">@if (task.props.size) {<span>{{ task.props.size | toBytes:2 }} • </span>}@if (task.props.directories) {- <span><fa-icon [icon]="icons.faFolderClosed" [fixedWidth]="false"></fa-icon> {{ task.props.directories }} • </span>+ <fa-icon [icon]="icons.faFolderClosed"></fa-icon>+ <span> {{ task.props.directories }} • </span>}@if (task.props.files) {- <span><fa-icon [icon]="icons.faFile" [fixedWidth]="false"></fa-icon> {{ task.props.files }} • </span>+ <fa-icon [icon]="icons.faFile"></fa-icon>+ <span> {{ task.props.files }} • </span>}- <span><fa-icon [icon]="icons.faClock" [fixedWidth]="false"></fa-icon> {{ task.startedAt | amTimeAgo:true }}</span>+ <fa-icon [icon]="icons.faClock"></fa-icon>+ <span> {{ task.startedAt | amTimeAgo:true }}</span></span>- </progressbar>- </div>+ </progressbar></div></div></div>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.tsindex df769143..bfe04d43 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@@ -23,7 +23,7 @@ import {import { FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'import { FileTask } from '@sync-in-server/backend/src/applications/files/models/file-task'import { L10N_LOCALE, L10nLocale, L10nTranslatePipe } from 'angular-l10n'-import { ProgressbarModule } from 'ngx-bootstrap/progressbar'+import { ProgressbarComponent } from 'ngx-bootstrap/progressbar'import { TooltipModule } from 'ngx-bootstrap/tooltip'import { Subscription } from 'rxjs'import { AutoResizeDirective } from '../../../../common/directives/auto-resize.directive'@@ -36,7 +36,7 @@ import { FilesService } from '../../services/files.service'@Component({selector: 'app-files-tasks',- imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarModule, TimeAgoPipe, ToBytesPipe],+ imports: [FaIconComponent, L10nTranslatePipe, AutoResizeDirective, TooltipModule, ProgressbarComponent, TimeAgoPipe, ToBytesPipe],templateUrl: 'files-tasks.component.html'})export class FilesTasksComponent implements OnDestroy {diff --git a/frontend/src/app/applications/users/components/user-account.component.ts b/frontend/src/app/applications/users/components/user-account.component.tsindex 06c86cb8..2d3f801b 100644--- a/frontend/src/app/applications/users/components/user-account.component.ts+++ b/frontend/src/app/applications/users/components/user-account.component.ts@@ -20,7 +20,6 @@ import { TWO_FA_HEADER_CODE, TWO_FA_HEADER_PASSWORD } from '@sync-in-server/backimport { TwoFaSetup } from '@sync-in-server/backend/src/authentication/interfaces/two-fa-setup.interface'import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'import { BsModalRef } from 'ngx-bootstrap/modal'-import { ProgressbarModule } from 'ngx-bootstrap/progressbar'import { ClipboardService } from 'ngx-clipboard'import { Subscription } from 'rxjs'import { filter, take } from 'rxjs/operators'@@ -48,7 +47,6 @@ import { UserAuthManageAppPasswordsDialogComponent } from './dialogs/user-auth-mL10nTranslatePipe,TimeDateFormatPipe,TimeAgoPipe,- ProgressbarModule,PasswordStrengthBarComponent,L10nTranslateDirective,FaIconComponent,diff --git a/frontend/src/app/common/components/storage-quota.component.ts b/frontend/src/app/common/components/storage-quota.component.tsindex 0279eea9..cc4e263a 100644--- a/frontend/src/app/common/components/storage-quota.component.ts+++ b/frontend/src/app/common/components/storage-quota.component.ts@@ -4,7 +4,7 @@* See the LICENSE file for licensing details*/-import { Component, EventEmitter, inject, Input, OnInit, Output } from '@angular/core'+import { Component, computed, inject, input, model, OnInit, signal } from '@angular/core'import { FormsModule } from '@angular/forms'import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'import { TooltipModule } from 'ngx-bootstrap/tooltip'@@ -14,59 +14,81 @@ import { quotaRegexp } from '../utils/regexp'@Component({selector: 'app-storage-quota',imports: [L10nTranslatePipe, TooltipModule, FormsModule, L10nTranslateDirective],- template: ` <label for="storageQuota" l10nTranslate>Storage Quota</label>+ template: `+ <label for="storageQuota" l10nTranslate>Storage Quota</label><div id="storageQuota"><inputid="quota"- [(ngModel)]="quotaText"- (ngModelChange)="validateQuota()"+ [ngModel]="quotaText()"+ (ngModelChange)="onQuotaInput($event)"(blur)="onQuotaBlur()"[placeholder]="'Unlimited' | translate: locale.language"- class="form-control form-control-sm {{ invalid ? 'is-invalid' : '' }}"- [class.w-100]="fullWidth"- [style.max-width.%]="maxWidthPercent"+ class="form-control form-control-sm {{ invalid() ? 'is-invalid' : '' }}"+ [class.w-100]="fullWidth()"+ [style.max-width.%]="displayMaxWidth()"placement="top"tooltip='"512 MB" "12 GB" "2 TB" ...'triggers="focus"type="text"/>- </div>`+ </div>+ `})export class StorageQuotaComponent implements OnInit {- @Input() quota: number- @Output() quotaChange = new EventEmitter<number>()- @Input() maxWidthPercent = 75- @Input() fullWidth = false+ // two-way binding via banana in parent: [(quota)]="..."+ quota = model<number | null>(null)++ // plain inputs converted to signals+ maxWidthPercent = input<number>(75)+ fullWidth = input<boolean>(false)++ // derived: what we actually apply in the template+ displayMaxWidth = computed(() => (this.fullWidth() ? 100 : this.maxWidthPercent()))++ // locale as beforeprotected locale = inject<L10nLocale>(L10N_LOCALE)- protected quotaText: string- protected invalid = false++ // internal state as signals+ protected quotaText = signal<string>('') // text shown/edited in the input+ protected invalid = signal<boolean>(false)ngOnInit() {- if (this.fullWidth) {- this.maxWidthPercent = 100- }- if (this.quota !== null) {- this.quotaText = this.quota === 0 ? '0' : convertBytesToText(this.quota)+ // initialize text from initial quota value (one-time on init)+ const q = this.quota()+ if (q !== null && q !== undefined) {+ this.quotaText.set(q === 0 ? '0' : convertBytesToText(q))}+ // keep initial max width behavior but via computed (no mutation of inputs)+ // -> handled by displayMaxWidth()+ }++ // called on each keystroke+ onQuotaInput(value: string) {+ this.quotaText.set(value)+ this.validateQuota()}+ // called on blur (commit the numeric value back to the model)onQuotaBlur() {- if (this.quotaText) {- if (this.quotaText === '0') {- this.quotaChange.emit(0)+ const t = this.quotaText()+ if (t) {+ if (t === '0') {+ this.quota.set(0)return}- const b = quotaRegexp.exec(this.quotaText)+ const b = quotaRegexp.exec(t)if (b) {- this.quotaText = `${b[1]} ${b[2].toUpperCase()}`- this.quotaChange.emit(convertTextToBytes(parseInt(b[1]), b[2]))+ const pretty = `${b[1]} ${b[2].toUpperCase()}`+ this.quotaText.set(pretty)+ this.quota.set(convertTextToBytes(parseInt(b[1], 10), b[2]))return}}- this.quotaChange.emit(null)+ this.quota.set(null)}validateQuota() {- this.invalid = this.quotaText && this.quotaText !== '0' && !quotaRegexp.test(this.quotaText)+ const t = this.quotaText()+ this.invalid.set(!!t && t !== '0' && !quotaRegexp.test(t))}}diff --git a/frontend/src/app/common/components/storage-usage.component.ts b/frontend/src/app/common/components/storage-usage.component.tsindex fe567699..ea10a5dd 100644--- a/frontend/src/app/common/components/storage-usage.component.ts+++ b/frontend/src/app/common/components/storage-usage.component.ts@@ -4,23 +4,61 @@* See the LICENSE file for licensing details*/-import { Component, Input } from '@angular/core'-import { ProgressbarModule } from 'ngx-bootstrap/progressbar'+import { afterNextRender, ChangeDetectorRef, Component, DestroyRef, ElementRef, inject, input } from '@angular/core'+import type { StorageQuota } from '@sync-in-server/backend/src/common/interfaces'+import { ProgressbarComponent } from 'ngx-bootstrap/progressbar'import { ToBytesPipe } from '../pipes/to-bytes.pipe'@Component({selector: 'app-storage-usage',- imports: [ProgressbarModule, ToBytesPipe],- template: `@if (item.storageQuota > 0) {- <progressbar [max]="item.storageQuota" [value]="item.storageUsage" class="bg-black" [type]="null">- <span class="ms-1 me-1">{{ item.storageUsage | toBytes: 2 : true }} / {{ item.storageQuota | toBytes }}</span>+ imports: [ProgressbarComponent, ToBytesPipe],+ template: `@if (item().storageQuota && item().storageQuota > 0) {+ <progressbar+ [max]="item().storageQuota"+ [value]="item().storageUsage"+ class="bg-black"+ [type]="this.item().storageUsage >= this.item().storageQuota ? 'danger' : null"+ >+ <span [style.width.px]="labelWidth ?? null" class="ms-1 me-1">+ {{ item().storageUsage | toBytes: 2 : true }} / {{ item().storageQuota | toBytes }}+ </span></progressbar>} @else {- <progressbar [max]="item.storageUsage" [value]="item.storageUsage" class="bg-black" [type]="null">- <span class="ms-1 me-1">{{ item.storageUsage | toBytes: 2 : true }}</span>+ <progressbar [max]="1" [value]="1" class="bg-black" [type]="null">+ <span class="ms-1 me-1">+ {{ item().storageUsage | toBytes: 2 : true }}+ </span></progressbar>}`})export class StorageUsageComponent {- @Input() item: { storageUsage: number; storageQuota: number } & any = { storageUsage: 0, storageQuota: null }+ item = input<StorageQuota>({ storageUsage: 0, storageQuota: null })+ labelWidth: number | null = null+ protected readonly elRef = inject(ElementRef)+ // helpers for safe updates+ private readonly cdr = inject(ChangeDetectorRef)+ private readonly destroyRef = inject(DestroyRef)++ constructor() {+ // measure after the initial render to avoid NG0100+ afterNextRender(() => {+ const host = this.elRef.nativeElement as HTMLElement++ const measure = () => {+ const w = host.offsetWidth+ if (w !== this.labelWidth) {+ this.labelWidth = w+ // force CD since we update after first check+ this.cdr.detectChanges()+ }+ }++ measure()++ const ro = new ResizeObserver(() => measure())+ ro.observe(host)+ // cleanup+ this.destroyRef.onDestroy(() => ro.disconnect())+ })+ }}