Skeleton bundle component some more

This commit is contained in:
shamoon
2025-11-04 10:25:57 -08:00
parent 89c061d8cd
commit 2b7af65bce
5 changed files with 143 additions and 88 deletions

View File

@@ -1,11 +1,12 @@
import { CommonModule } from '@angular/common'
import { Component, Input, inject } from '@angular/core'
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { ShareBundleCreatePayload } from 'src/app/data/share-bundle'
import {
FileVersion,
SHARE_LINK_EXPIRATION_OPTIONS,
} from 'src/app/data/share-link'
import { ConfirmDialogComponent } from '../confirm-dialog/confirm-dialog.component'
@Component({
selector: 'pngx-share-bundle-dialog',
@@ -13,12 +14,10 @@ import {
standalone: true,
imports: [CommonModule, ReactiveFormsModule],
})
export class ShareBundleDialogComponent {
private activeModal = inject(NgbActiveModal)
export class ShareBundleDialogComponent extends ConfirmDialogComponent {
private formBuilder = inject(FormBuilder)
private _documentIds: number[] = []
private _documentsWithArchive = 0
selectionCount = 0
documentPreview: number[] = []
@@ -26,73 +25,35 @@ export class ShareBundleDialogComponent {
shareArchiveVersion: [true],
expirationDays: [7],
})
payload: ShareBundleCreatePayload | null = null
readonly expirationOptions = SHARE_LINK_EXPIRATION_OPTIONS
constructor() {
super()
this.loading = false
this.title = $localize`Share Selected Documents`
}
@Input()
set documentIds(ids: number[]) {
this._documentIds = ids ?? []
this.selectionCount = this._documentIds.length
this.documentPreview = this._documentIds.slice(0, 10)
this.syncArchiveOption()
}
get documentIds(): number[] {
return this._documentIds
}
@Input()
set documentsWithArchive(count: number) {
this._documentsWithArchive = count ?? 0
this.syncArchiveOption()
}
get documentsWithArchive(): number {
return this._documentsWithArchive
}
get archiveOptionDisabled(): boolean {
return (
this.selectionCount === 0 ||
this._documentsWithArchive !== this.selectionCount
)
}
get missingArchiveCount(): number {
return Math.max(this.selectionCount - this._documentsWithArchive, 0)
}
close() {
this.activeModal.close()
}
submit() {
// Placeholder until the backend workflow is wired up.
this.activeModal.close({
documentIds: this.documentIds,
options: {
fileVersion: this.form.value.shareArchiveVersion
? FileVersion.Archive
: FileVersion.Original,
expirationDays: this.form.value.expirationDays,
},
})
}
private syncArchiveOption() {
const control = this.form.get('shareArchiveVersion')
if (!control) return
const canUseArchive =
this.selectionCount > 0 &&
this._documentsWithArchive === this.selectionCount
if (canUseArchive) {
control.enable({ emitEvent: false })
control.patchValue(true, { emitEvent: false })
} else {
control.disable({ emitEvent: false })
control.patchValue(false, { emitEvent: false })
this.payload = {
document_ids: this.documentIds,
file_version: this.form.value.shareArchiveVersion
? FileVersion.Archive
: FileVersion.Original,
expiration_days: this.form.value.expirationDays,
}
super.confirm()
}
}