let shareLinkService: ShareLinkService
- let documentService: DocumentService
- let permissionsService: PermissionsService
let toastService: ToastService
let httpController: HttpTestingController
let clipboard: Clipboard
beforeEach(() => {
TestBed.configureTestingModule({
- declarations: [],
imports: [
- ShareDocumentDropdownComponent,
- IfPermissionsDirective,
+ ShareLinksDropdownComponent,
NgxBootstrapIconsModule.pick(allIcons),
],
providers: [
@@ -46,15 +39,12 @@ describe('ShareDocumentDropdownComponent', () => {
],
})
- fixture = TestBed.createComponent(ShareDocumentDropdownComponent)
+ fixture = TestBed.createComponent(ShareLinksDropdownComponent)
shareLinkService = TestBed.inject(ShareLinkService)
- documentService = TestBed.inject(DocumentService)
- permissionsService = TestBed.inject(PermissionsService)
toastService = TestBed.inject(ToastService)
httpController = TestBed.inject(HttpTestingController)
clipboard = TestBed.inject(Clipboard)
- jest.spyOn(permissionsService, 'currentUserCan').mockReturnValue(true)
component = fixture.componentInstance
fixture.detectChanges()
})
@@ -242,21 +232,4 @@ describe('ShareDocumentDropdownComponent', () => {
]
).toBeTruthy()
})
-
- it('should support sending document via email, showing error if needed', () => {
- const toastErrorSpy = jest.spyOn(toastService, 'showError')
- const toastSuccessSpy = jest.spyOn(toastService, 'showInfo')
- component.emailAddress = 'hello@paperless-ngx.com'
- component.emailSubject = 'Hello'
- component.emailMessage = 'World'
- jest
- .spyOn(documentService, 'emailDocument')
- .mockReturnValue(throwError(() => new Error('Unable to email document')))
- component.emailDocument()
- expect(toastErrorSpy).toHaveBeenCalled()
-
- jest.spyOn(documentService, 'emailDocument').mockReturnValue(of(true))
- component.emailDocument()
- expect(toastSuccessSpy).toHaveBeenCalled()
- })
})
diff --git a/src-ui/src/app/components/common/share-document-dropdown/share-document-dropdown.component.ts b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts
similarity index 65%
rename from src-ui/src/app/components/common/share-document-dropdown/share-document-dropdown.component.ts
rename to src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts
index 3f66436e3..5e65eed73 100644
--- a/src-ui/src/app/components/common/share-document-dropdown/share-document-dropdown.component.ts
+++ b/src-ui/src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts
@@ -5,40 +5,33 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { first } from 'rxjs'
import { FileVersion, ShareLink } from 'src/app/data/share-link'
-import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
-import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
-import { DocumentService } from 'src/app/services/rest/document.service'
import { ShareLinkService } from 'src/app/services/rest/share-link.service'
-import { SettingsService } from 'src/app/services/settings.service'
import { ToastService } from 'src/app/services/toast.service'
import { environment } from 'src/environments/environment'
-import { ComponentWithPermissions } from '../../with-permissions/with-permissions.component'
-
-const EXPIRATION_OPTIONS = [
- { label: $localize`1 day`, value: 1 },
- { label: $localize`7 days`, value: 7 },
- { label: $localize`30 days`, value: 30 },
- { label: $localize`Never`, value: null },
-]
@Component({
- selector: 'pngx-share-document-dropdown',
- templateUrl: './share-document-dropdown.component.html',
- styleUrls: ['./share-document-dropdown.component.scss'],
+ selector: 'pngx-share-links-dropdown',
+ templateUrl: './share-links-dropdown.component.html',
+ styleUrls: ['./share-links-dropdown.component.scss'],
imports: [
- IfPermissionsDirective,
FormsModule,
ReactiveFormsModule,
NgbDropdownModule,
NgxBootstrapIconsModule,
],
})
-export class ShareDocumentDropdownComponent
- extends ComponentWithPermissions
- implements OnInit
-{
- public EXPIRATION_OPTIONS = EXPIRATION_OPTIONS
- private _documentId: number
+export class ShareLinksDropdownComponent implements OnInit {
+ EXPIRATION_OPTIONS = [
+ { label: $localize`1 day`, value: 1 },
+ { label: $localize`7 days`, value: 7 },
+ { label: $localize`30 days`, value: 30 },
+ { label: $localize`Never`, value: null },
+ ]
+
+ @Input()
+ title = $localize`Share Links`
+
+ _documentId: number
@Input()
set documentId(id: number) {
@@ -57,7 +50,6 @@ export class ShareDocumentDropdownComponent
set hasArchiveVersion(value: boolean) {
this._hasArchiveVersion = value
this.useArchiveVersion = value
- this.emailUseArchiveVersion = value
}
get hasArchiveVersion(): boolean {
@@ -74,21 +66,11 @@ export class ShareDocumentDropdownComponent
useArchiveVersion: boolean = true
- emailLoading: boolean = false
- emailAddress: string = ''
- emailSubject: string = ''
- emailMessage: string = ''
- emailUseArchiveVersion: boolean = true
-
constructor(
private shareLinkService: ShareLinkService,
- private documentService: DocumentService,
- private settingsService: SettingsService,
private toastService: ToastService,
private clipboard: Clipboard
- ) {
- super()
- }
+ ) {}
ngOnInit(): void {
if (this._documentId !== undefined) this.refresh()
@@ -187,33 +169,4 @@ export class ShareDocumentDropdownComponent
},
})
}
-
- get emailEnabled(): boolean {
- return this.settingsService.get(SETTINGS_KEYS.EMAIL_ENABLED)
- }
-
- public emailDocument() {
- this.emailLoading = true
- this.documentService
- .emailDocument(
- this._documentId,
- this.emailAddress,
- this.emailSubject,
- this.emailMessage,
- this.emailUseArchiveVersion
- )
- .subscribe({
- next: () => {
- this.emailLoading = false
- this.emailAddress = ''
- this.emailSubject = ''
- this.emailMessage = ''
- this.toastService.showInfo($localize`Email sent`)
- },
- error: (e) => {
- this.emailLoading = false
- this.toastService.showError($localize`Error emailing document`, e)
- },
- })
- }
}
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html
index 556874f9b..9931b491c 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.html
+++ b/src-ui/src/app/components/document-detail/document-detail.component.html
@@ -81,7 +81,10 @@
(added)="addField($event)">
-
+
+
+
+
diff --git a/src-ui/src/app/components/document-detail/document-detail.component.ts b/src-ui/src/app/components/document-detail/document-detail.component.ts
index 9fe0d7294..8a0b9a45c 100644
--- a/src-ui/src/app/components/document-detail/document-detail.component.ts
+++ b/src-ui/src/app/components/document-detail/document-detail.component.ts
@@ -88,6 +88,7 @@ import { CorrespondentEditDialogComponent } from '../common/edit-dialog/correspo
import { DocumentTypeEditDialogComponent } from '../common/edit-dialog/document-type-edit-dialog/document-type-edit-dialog.component'
import { EditDialogMode } from '../common/edit-dialog/edit-dialog.component'
import { StoragePathEditDialogComponent } from '../common/edit-dialog/storage-path-edit-dialog/storage-path-edit-dialog.component'
+import { EmailDocumentDropdownComponent } from '../common/email-document-dropdown/email-document-dropdown.component'
import { CheckComponent } from '../common/input/check/check.component'
import { DateComponent } from '../common/input/date/date.component'
import { DocumentLinkComponent } from '../common/input/document-link/document-link.component'
@@ -99,7 +100,7 @@ import { TagsComponent } from '../common/input/tags/tags.component'
import { TextComponent } from '../common/input/text/text.component'
import { UrlComponent } from '../common/input/url/url.component'
import { PageHeaderComponent } from '../common/page-header/page-header.component'
-import { ShareDocumentDropdownComponent } from '../common/share-document-dropdown/share-document-dropdown.component'
+import { ShareLinksDropdownComponent } from '../common/share-links-dropdown/share-links-dropdown.component'
import { DocumentHistoryComponent } from '../document-history/document-history.component'
import { DocumentNotesComponent } from '../document-notes/document-notes.component'
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
@@ -145,7 +146,8 @@ export enum ZoomSetting {
CustomFieldsDropdownComponent,
DocumentNotesComponent,
DocumentHistoryComponent,
- ShareDocumentDropdownComponent,
+ ShareLinksDropdownComponent,
+ EmailDocumentDropdownComponent,
CheckComponent,
DateComponent,
DocumentLinkComponent,