mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix: disable toggle for share link creation without archive version, fix auto-copy in Safari (#4885)
* Fix: disable share link archive switch if archive version doesnt exist * Fix: Add brief timeout before copy after share link creation for Safari, only show if succeeded * Update messages.xlf
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
<li class="list-group-item pt-3 pb-2">
|
||||
<div class="input-group input-group-sm w-100">
|
||||
<div class="form-check form-switch ms-auto">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [(ngModel)]="archiveVersion">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
|
||||
<label class="form-check-label small" for="versionSwitch" i18n>Share archive version</label>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -19,6 +19,7 @@ import { ToastService } from 'src/app/services/toast.service'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { ShareLinksDropdownComponent } from './share-links-dropdown.component'
|
||||
import { Clipboard } from '@angular/cdk/clipboard'
|
||||
import { By } from '@angular/platform-browser'
|
||||
|
||||
describe('ShareLinksDropdownComponent', () => {
|
||||
let component: ShareLinksDropdownComponent
|
||||
@@ -88,7 +89,7 @@ describe('ShareLinksDropdownComponent', () => {
|
||||
.mockReturnValueOnce(throwError(() => new Error('Unable to get links')))
|
||||
component.documentId = 99
|
||||
|
||||
component.refresh()
|
||||
component.ngOnInit()
|
||||
fixture.detectChanges()
|
||||
expect(toastSpy).toHaveBeenCalled()
|
||||
})
|
||||
@@ -97,12 +98,13 @@ describe('ShareLinksDropdownComponent', () => {
|
||||
const createSpy = jest.spyOn(shareLinkService, 'createLinkForDocument')
|
||||
component.documentId = 99
|
||||
component.expirationDays = 7
|
||||
component.archiveVersion = false
|
||||
component.useArchiveVersion = false
|
||||
|
||||
const expiration = new Date()
|
||||
expiration.setDate(expiration.getDate() + 7)
|
||||
|
||||
const copySpy = jest.spyOn(clipboard, 'copy')
|
||||
copySpy.mockReturnValue(true)
|
||||
const refreshSpy = jest.spyOn(component, 'refresh')
|
||||
|
||||
component.createLink()
|
||||
@@ -117,8 +119,10 @@ describe('ShareLinksDropdownComponent', () => {
|
||||
fixture.detectChanges()
|
||||
tick(3000)
|
||||
|
||||
expect(copySpy).toHaveBeenCalled()
|
||||
expect(refreshSpy).toHaveBeenCalled()
|
||||
expect(copySpy).toHaveBeenCalled()
|
||||
expect(component.copied).toEqual(1)
|
||||
tick(100) // copy timeout
|
||||
}))
|
||||
|
||||
it('should show error on link creation if needed', () => {
|
||||
@@ -212,4 +216,16 @@ describe('ShareLinksDropdownComponent', () => {
|
||||
'http://example.domainwithapiinit.com:1234/subpath/share/123abc123'
|
||||
)
|
||||
})
|
||||
|
||||
it('should disable archive switch & option if no archive available', () => {
|
||||
component.hasArchiveVersion = false
|
||||
component.ngOnInit()
|
||||
fixture.detectChanges()
|
||||
expect(component.useArchiveVersion).toBeFalsy()
|
||||
expect(
|
||||
fixture.debugElement.query(By.css("input[type='checkbox']")).attributes[
|
||||
'ng-reflect-is-disabled'
|
||||
]
|
||||
).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
@@ -38,6 +38,9 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
@Input()
|
||||
disabled: boolean = false
|
||||
|
||||
@Input()
|
||||
hasArchiveVersion: boolean = true
|
||||
|
||||
shareLinks: PaperlessShareLink[]
|
||||
|
||||
loading: boolean = false
|
||||
@@ -46,7 +49,7 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
|
||||
expirationDays: number = 7
|
||||
|
||||
archiveVersion: boolean = true
|
||||
useArchiveVersion: boolean = true
|
||||
|
||||
constructor(
|
||||
private shareLinkService: ShareLinkService,
|
||||
@@ -56,6 +59,7 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this._documentId !== undefined) this.refresh()
|
||||
this.useArchiveVersion = this.hasArchiveVersion
|
||||
}
|
||||
|
||||
refresh() {
|
||||
@@ -94,11 +98,13 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
}
|
||||
|
||||
copy(link: PaperlessShareLink) {
|
||||
this.clipboard.copy(this.getShareUrl(link))
|
||||
this.copied = link.id
|
||||
setTimeout(() => {
|
||||
this.copied = null
|
||||
}, 3000)
|
||||
const success = this.clipboard.copy(this.getShareUrl(link))
|
||||
if (success) {
|
||||
this.copied = link.id
|
||||
setTimeout(() => {
|
||||
this.copied = null
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
canShare(link: PaperlessShareLink): boolean {
|
||||
@@ -132,7 +138,7 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
this.shareLinkService
|
||||
.createLinkForDocument(
|
||||
this._documentId,
|
||||
this.archiveVersion
|
||||
this.useArchiveVersion
|
||||
? PaperlessFileVersion.Archive
|
||||
: PaperlessFileVersion.Original,
|
||||
expiration
|
||||
@@ -140,7 +146,9 @@ export class ShareLinksDropdownComponent implements OnInit {
|
||||
.subscribe({
|
||||
next: (result) => {
|
||||
this.loading = false
|
||||
this.copy(result)
|
||||
setTimeout(() => {
|
||||
this.copy(result)
|
||||
}, 10)
|
||||
this.refresh()
|
||||
},
|
||||
error: (e) => {
|
||||
|
@@ -69,7 +69,7 @@
|
||||
(added)="addField($event)">
|
||||
</pngx-custom-fields-dropdown>
|
||||
|
||||
<pngx-share-links-dropdown [documentId]="documentId" [disabled]="!userIsOwner" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }"></pngx-share-links-dropdown>
|
||||
<pngx-share-links-dropdown [documentId]="documentId" [hasArchiveVersion]="!!document?.archived_file_name" [disabled]="!userIsOwner" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }"></pngx-share-links-dropdown>
|
||||
</pngx-page-header>
|
||||
|
||||
<div class="row">
|
||||
|
Reference in New Issue
Block a user