diff --git a/goofy-client/libs/postfach-shared/src/index.ts b/goofy-client/libs/postfach-shared/src/index.ts index 68b5a581b61c86db9e2d6138b5eb1c6d6af407bd..7becfc72b51bb988f11d1e1f15370caafc94c752 100644 --- a/goofy-client/libs/postfach-shared/src/index.ts +++ b/goofy-client/libs/postfach-shared/src/index.ts @@ -1,7 +1,10 @@ +export * from './lib/+state/postfach.actions'; +export * from './lib/+state/postfach.facade'; +export * from './lib/+state/postfach.reducer'; export * from './lib/postfach-shared.module'; -export * from './lib/postfach.facade'; export * from './lib/postfach.linkrel'; export * from './lib/postfach.model'; export * from './lib/postfach.service'; export * from './lib/postfach.tokens'; export * from './lib/postfach.util'; + diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.actions.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.actions.ts new file mode 100644 index 0000000000000000000000000000000000000000..6dfc6e034d40d994b0a29c81fedc1d3ac1121c8d --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.actions.ts @@ -0,0 +1,6 @@ +import { ApiErrorAction, TypedActionCreator, TypedActionCreatorWithProps } from '@goofy-client/tech-shared'; +import { createAction, props } from '@ngrx/store'; + +export const startDownloadAsPdf: TypedActionCreator = createAction('[Postfach] Start Download Nachrichten as pdf'); +export const downloadAsPdfSuccess: TypedActionCreator = createAction('[Postfach/API] Download Nachrichten as pdf Success'); +export const downloadAsPdfFailed: TypedActionCreatorWithProps<ApiErrorAction> = createAction('[Postfach/API] Download Nachrichten as pdf Failure', props<ApiErrorAction>()); \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.spec.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..e9d751bb77c925d391fc8fb40dd5a78dd0a5ee5d --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.spec.ts @@ -0,0 +1,111 @@ + +import { formatDate, registerLocaleData } from '@angular/common'; +import localeDe from '@angular/common/locales/de'; +import { DownloadBinaryFileAsPdfAction } from '@goofy-client/binary-file-shared'; +import { Mock, mock, useFromMock } from '@goofy-client/test-utils'; +import { VorgangHeaderLinkRel, VorgangWithEingangResource } from '@goofy-client/vorgang-shared'; +import { Store } from '@ngrx/store'; +import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; +import { Subject } from 'rxjs'; +import { PostfachFacade } from './postfach.facade'; + +import * as BinaryFileActions from '@goofy-client/binary-file-shared'; +import { getUrl } from '@ngxp/rest'; +import * as PostfachActions from './postfach.actions'; + +registerLocaleData(localeDe); + +describe('PostfachFacade', () => { + + let facade: PostfachFacade; + let store: Mock<Store>; + + let selectionSubject: Subject<any>; + + beforeEach(() => { + store = mock(Store); + + selectionSubject = new Subject(); + + store.select.mockReturnValue(selectionSubject); + store.dispatch = jest.fn(); + + facade = new PostfachFacade(useFromMock(<any>store)); + }) + + it('is initialized', () => { + expect(facade).toBeTruthy(); + }) + + describe('startDownloadPdf', () => { + + it('should dispatch "startDownloadAsPdf" action', () => { + facade.startDownloadPdf(); + + expect(store.dispatch).toHaveBeenCalledWith(PostfachActions.startDownloadAsPdf()); + }); + }) + + describe('isDownloadPdfInProgress', () => { + + it('should return value', (done) => { + facade.isDownloadPdfInProgress().subscribe(isInProgress => { + expect(isInProgress).toBeTruthy(); + done(); + }); + + selectionSubject.next(true); + }); + }) + + describe('downloadPdf', () => { + + const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource(); + const downloadAction: DownloadBinaryFileAsPdfAction = <any>{}; + + beforeEach(() => { + facade.createDownloadPdfProps = jest.fn().mockReturnValue(downloadAction); + }) + + it('should dispatch "downloadPdf" action', () => { + facade.downloadPdf(vorgang); + + expect(store.dispatch).toHaveBeenCalledWith(BinaryFileActions.downloadPdf(downloadAction)); + }) + + it('should create props', () => { + facade.downloadPdf(vorgang); + + expect(facade.createDownloadPdfProps).toHaveBeenCalledWith(vorgang); + }) + }) + + describe('createDownloadPdfProps', () => { + + const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource([VorgangHeaderLinkRel.POSTFACH_MAILS]); + + it('should have uri', () => { + const props: DownloadBinaryFileAsPdfAction = facade.createDownloadPdfProps(vorgang); + + expect(props.uri).toBe(getUrl(vorgang, VorgangHeaderLinkRel.POSTFACH_MAILS)); + }) + + it('should have fileName', () => { + const props: DownloadBinaryFileAsPdfAction = facade.createDownloadPdfProps(vorgang); + + expect(props.fileName).toBe(`${vorgang.nummer}_${formatDate(new Date(), 'yyyyMMdd', 'de')}_Nachrichten.pdf`); + }) + + it('should have "downloadAsPdfSuccess" as success action', () => { + const props: DownloadBinaryFileAsPdfAction = facade.createDownloadPdfProps(vorgang); + + expect(props.successAction).toBe(PostfachActions.downloadAsPdfSuccess); + }) + + it('should have "downloadAsPdfFailed" as failure action', () => { + const props: DownloadBinaryFileAsPdfAction = facade.createDownloadPdfProps(vorgang); + + expect(props.failureAction).toBe(facade.createFailureAction); + }) + }) +}); diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.ts new file mode 100644 index 0000000000000000000000000000000000000000..8abaeb9d0008775381eeb7147b77992cbbccc2c6 --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.facade.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; +import { DownloadBinaryFileAsPdfAction } from '@goofy-client/binary-file-shared'; +import { ApiError, ApiErrorAction, formatFullDateWithoutSeperator } from '@goofy-client/tech-shared'; +import { VorgangHeaderLinkRel, VorgangWithEingangResource } from '@goofy-client/vorgang-shared'; +import { Store } from '@ngrx/store'; +import { TypedAction } from '@ngrx/store/src/models'; +import { Observable } from 'rxjs'; + +import * as BinaryFileActions from '@goofy-client/binary-file-shared'; +import { getUrl } from '@ngxp/rest'; +import * as PostfachActions from './postfach.actions'; +import * as PostfachSelectors from './postfach.selectors'; + +@Injectable() +export class PostfachFacade { + + constructor(private readonly store: Store) { } + + public startDownloadPdf(): void { + this.store.dispatch(PostfachActions.startDownloadAsPdf()); + } + + public isDownloadPdfInProgress(): Observable<boolean> { + return this.store.select(PostfachSelectors.isDownloadPdfInProgress); + } + + public downloadPdf(vorgangWithEingang: VorgangWithEingangResource): void { + this.store.dispatch(BinaryFileActions.downloadPdf(this.createDownloadPdfProps(vorgangWithEingang))); + } + + createDownloadPdfProps(vorgangWithEingang: VorgangWithEingangResource): DownloadBinaryFileAsPdfAction { + return { + uri: getUrl(vorgangWithEingang, VorgangHeaderLinkRel.POSTFACH_MAILS), + fileName: this.buildFileName(vorgangWithEingang), + successAction: PostfachActions.downloadAsPdfSuccess, + failureAction: this.createFailureAction + } + } + + buildFileName(vorgangWithEingang: VorgangWithEingangResource): string { + return `${vorgangWithEingang.nummer}_${formatFullDateWithoutSeperator(new Date())}_Nachrichten.pdf`; + } + + createFailureAction(apiError: ApiError): ApiErrorAction & TypedAction<string> { + return PostfachActions.downloadAsPdfFailed({ apiError }); + } +} \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.spec.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..723504c033acc93310c563fa9634a96ac736d798 --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.spec.ts @@ -0,0 +1,40 @@ +import { Action } from '@ngrx/store'; +import { initialPostfachState, postfachReducer, PostfachState } from './postfach.reducer'; + +import * as PostfachActions from './postfach.actions'; + +describe('Postfach Reducer', () => { + + describe('unknown action', () => { + + it('should return current state', () => { + const action = {} as Action; + + const result = postfachReducer(initialPostfachState, action); + + expect(result).toBe(initialPostfachState); + }) + }) + + describe('on "startDownloadAsPdf" action', () => { + + it('should set isDownloadPdfInProgress to true', () => { + const action = PostfachActions.startDownloadAsPdf(); + + const state: PostfachState = postfachReducer(initialPostfachState, action); + + expect(state.isDownloadPdfInProgress).toBeTruthy(); + }) + }) + + describe('on "downloadAsPdfSuccess" action', () => { + + it('should set isDownloadPdfInProgress to false', () => { + const action = PostfachActions.downloadAsPdfSuccess(); + + const state: PostfachState = postfachReducer(initialPostfachState, action); + + expect(state.isDownloadPdfInProgress).toBeFalsy(); + }) + }) +}); diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.ts new file mode 100644 index 0000000000000000000000000000000000000000..10160534f82b4f6b453fc252bafe6f3f10d2ffd5 --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.reducer.ts @@ -0,0 +1,32 @@ +import { Action, ActionReducer, createReducer, on } from '@ngrx/store'; + +import * as PostfachActions from './postfach.actions'; + +export const POSTFACH_FEATURE_KEY = 'PostfachState'; + +export interface PostfachPartialState { + readonly [POSTFACH_FEATURE_KEY]: PostfachState; +} +export interface PostfachState { + isDownloadPdfInProgress: boolean; +} + +export const initialPostfachState: PostfachState = { + isDownloadPdfInProgress: false +}; + +const reducer: ActionReducer<PostfachState, Action> = createReducer( + initialPostfachState, + on(PostfachActions.startDownloadAsPdf, (state: PostfachState) => ({ + ...state, + isDownloadPdfInProgress: true + })), + on(PostfachActions.downloadAsPdfSuccess, (state: PostfachState) => ({ + ...state, + isDownloadPdfInProgress: false + })) +); + +export function postfachReducer(state: PostfachState, action: Action) { + return reducer(state, action); +} \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.spec.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f9d61b2e3cc58e283dfe2dbecf6a2d7ac570b196 --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.spec.ts @@ -0,0 +1,22 @@ +import { initialPostfachState, PostfachPartialState } from './postfach.reducer'; + +import * as PostfachSelectors from './postfach.selectors'; + +describe('Postfach Selectors', () => { + let state: PostfachPartialState; + + const isDownloadPdfInProgress: boolean = true; + + beforeEach(() => { + state = { + PostfachState: { + ...initialPostfachState, + isDownloadPdfInProgress: isDownloadPdfInProgress + } + }; + }); + + it('should return isDownloadPdfInProgress', () => { + expect(PostfachSelectors.isDownloadPdfInProgress.projector(state.PostfachState)).toBe(isDownloadPdfInProgress); + }) +}); \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.ts b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.ts new file mode 100644 index 0000000000000000000000000000000000000000..66649e937cd8f694d4155207b6df0d19d2e033e8 --- /dev/null +++ b/goofy-client/libs/postfach-shared/src/lib/+state/postfach.selectors.ts @@ -0,0 +1,6 @@ +import { createFeatureSelector, createSelector, MemoizedSelector } from '@ngrx/store'; +import { PostfachState, POSTFACH_FEATURE_KEY } from './postfach.reducer'; + +export const getPostfachState: MemoizedSelector<object, PostfachState> = createFeatureSelector<PostfachState>(POSTFACH_FEATURE_KEY); + +export const isDownloadPdfInProgress: MemoizedSelector<PostfachState, boolean> = createSelector(getPostfachState, (state: PostfachState) => state.isDownloadPdfInProgress); \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach-shared.module.ts b/goofy-client/libs/postfach-shared/src/lib/postfach-shared.module.ts index 25952514e7115e4f304144d3cde68c47307da221..cc6c91605ff9acf27ff26a0d0e0cffdbb1939192 100644 --- a/goofy-client/libs/postfach-shared/src/lib/postfach-shared.module.ts +++ b/goofy-client/libs/postfach-shared/src/lib/postfach-shared.module.ts @@ -1,11 +1,19 @@ import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { CommandSharedModule } from '@goofy-client/command-shared'; +import { StoreModule } from '@ngrx/store'; +import { PostfachFacade } from './+state/postfach.facade'; +import * as fromPostfach from './+state/postfach.reducer'; @NgModule({ imports: [ CommonModule, - CommandSharedModule - ] + CommandSharedModule, + StoreModule.forFeature( + fromPostfach.POSTFACH_FEATURE_KEY, + fromPostfach.postfachReducer + ) + ], + providers: [PostfachFacade], }) export class PostfachSharedModule { } diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.facade.spec.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.facade.spec.ts deleted file mode 100644 index 5d9805ba4da46930954d66a5df02d39ca0fbf802..0000000000000000000000000000000000000000 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.facade.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { createEmptyStateResource } from '@goofy-client/tech-shared'; -import { Mock, mock, useFromMock } from '@goofy-client/test-utils'; -import { createPostfachMailResource } from 'libs/postfach-shared/test/postfach'; -import { of } from 'rxjs'; -import { PostfachMailResource, PostfachService } from '..'; -import { PostfachFacade } from './postfach.facade'; -import { PostfachReducer } from './postfach.reducer'; - -describe('PostfachFacade', () => { - let facade: PostfachFacade; - - const service: Mock<PostfachService> = mock(PostfachService); - const reducer: Mock<PostfachReducer> = mock(PostfachReducer); - - beforeEach(() => { - facade = new PostfachFacade(useFromMock(service), useFromMock(reducer)); - }); - - it('should be created', () => { - expect(facade).toBeTruthy(); - }); - - describe('getAttachments', () => { - - const postfachNachricht: PostfachMailResource = createPostfachMailResource(); - - beforeEach(() => { - reducer.getAttachments.mockReturnValue(of(createEmptyStateResource())); - }) - - it('should call reducer', () => { - facade.getAttachments(postfachNachricht); - - expect(reducer.getAttachments).toHaveBeenCalled(); - }) - }) -}) \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.facade.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.facade.ts deleted file mode 100644 index c6cd3f87bf2ac866d25b0e5ca257c44e7c39c9b7..0000000000000000000000000000000000000000 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.facade.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BinaryFileListLinkRel, BinaryFileListResource, BinaryFileResource } from '@goofy-client/binary-file-shared'; -import { createStateResource, doIfLoadingRequired, StateResource } from '@goofy-client/tech-shared'; -import { getEmbeddedResource } from '@ngxp/rest'; -import { Observable } from 'rxjs'; -import { map, tap } from 'rxjs/operators'; -import { PostfachMailResource } from './postfach.model'; -import { PostfachReducer } from './postfach.reducer'; -import { PostfachService } from './postfach.service'; - -@Injectable({ providedIn: 'root' }) -export class PostfachFacade { - - constructor(private postfachService: PostfachService, private postfachReducer: PostfachReducer) { } - - public getAttachments(postfachNachricht: PostfachMailResource): Observable<StateResource<BinaryFileResource[]>> { - return this.postfachReducer.getAttachments().pipe( - tap(attachments => doIfLoadingRequired(attachments, () => this.postfachService.loadAttachments(postfachNachricht))), - map((attachments: StateResource<BinaryFileListResource>) => createStateResource(getEmbeddedResource<BinaryFileResource[]>(attachments.resource, BinaryFileListLinkRel.FILE_LIST))) - ); - } -} \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.spec.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.spec.ts deleted file mode 100644 index b74fccd214cfc674b3f198485edb0e6c3fbc88a8..0000000000000000000000000000000000000000 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.spec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PostfachReducer } from "./postfach.reducer"; - -describe('PostfachReducer', () => { - let reducer: PostfachReducer; - - beforeEach(() => { - reducer = new PostfachReducer(); - }); - - it('should be created', () => { - expect(reducer).toBeTruthy(); - }); -}) \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.ts deleted file mode 100644 index d543797aa41952c1daf9540398962a6792659001..0000000000000000000000000000000000000000 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.reducer.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BinaryFileListResource } from '@goofy-client/binary-file-shared'; -import { createEmptyStateResource, createStateResource, StateResource } from '@goofy-client/tech-shared'; -import { BehaviorSubject, Observable } from 'rxjs'; - -@Injectable({ providedIn: 'root' }) -export class PostfachReducer { - - private readonly attachments$: BehaviorSubject<StateResource<BinaryFileListResource>> = new BehaviorSubject<StateResource<BinaryFileListResource>>(createEmptyStateResource<BinaryFileListResource>()); - - setAttachmentsLoading(): void { - this.attachments$.next({ ...this.attachments$.value, loading: true }); - } - - setAttachments(listResource: BinaryFileListResource): void { - this.attachments$.next(createStateResource(listResource)) - } - - getAttachments(): Observable<StateResource<BinaryFileListResource>> { - return this.attachments$.asObservable(); - } -} \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.service.spec.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.service.spec.ts index a5e6f96068380b56e6a19e6a579578391fefeb4a..c8da9eaea5de6a595b67d4afd9551189365802c0 100644 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.service.spec.ts +++ b/goofy-client/libs/postfach-shared/src/lib/postfach.service.spec.ts @@ -4,13 +4,14 @@ import { CommandResource, CommandService } from '@goofy-client/command-shared'; import { createEmptyStateResource, createStateResource, NavigationService, StateResource } from '@goofy-client/tech-shared'; import { Mock, mock, useFromMock } from '@goofy-client/test-utils'; import { SnackBarService } from '@goofy-client/ui'; -import { VorgangService } from '@goofy-client/vorgang-shared'; +import { VorgangService, VorgangWithEingangResource } from '@goofy-client/vorgang-shared'; import { createBinaryFileListResource } from 'libs/binary-file-shared/test/binary-file'; import { CommandLinkRel } from 'libs/command-shared/src/lib/command.linkrel'; import { createCommandResource } from 'libs/command-shared/test/command'; import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { of } from 'rxjs'; import { createPostfachMail, createPostfachMailListResource, createPostfachMailResource } from '../../test/postfach'; +import { PostfachFacade } from './+state/postfach.facade'; import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel'; import { PostfachMessages } from './postfach.message'; import { PostfachMail, PostfachMailListResource, PostfachMailResource } from './postfach.model'; @@ -27,6 +28,7 @@ describe('PostfachService', () => { const snackbarService: Mock<SnackBarService> = mock(SnackBarService); const dialog: Mock<MatDialog> = <Mock<MatDialog>>{ closeAll: jest.fn() }; const binaryFileService: Mock<BinaryFileService> = mock(BinaryFileService); + const postfachFacade: Mock<PostfachFacade> = mock(PostfachFacade); const urlChangedParams = {}; @@ -43,7 +45,8 @@ describe('PostfachService', () => { useFromMock(vorgangService), useFromMock(snackbarService), useFromMock(dialog), - useFromMock(binaryFileService)); + useFromMock(binaryFileService), + useFromMock(postfachFacade)); }); it('should be created', () => { @@ -444,4 +447,48 @@ describe('PostfachService', () => { expect(binaryFileService.getFiles).toHaveBeenCalledWith(postfachNachricht, PostfachMailLinkRel.ATTACHMENTS); }) }) + + describe('isDownloadPdfInProgress', () => { + + const vorgang: VorgangWithEingangResource = createVorgangWithEingangResource(); + + it('should call facade to download pdf', (done) => { + vorgangService.getVorgangWithEingang.mockReturnValue(of(createStateResource(vorgang))); + postfachFacade.isDownloadPdfInProgress.mockReturnValue(of(true)); + + service.isDownloadPdfInProgress().subscribe(() => { + expect(postfachFacade.downloadPdf).toHaveBeenCalledWith(vorgang); + done(); + }); + }); + + describe('combine latest', () => { + + beforeEach(() => { + vorgangService.getVorgangWithEingang.mockReturnValue(of(vorgang)); + postfachFacade.isDownloadPdfInProgress = jest.fn().mockReturnValue((true)); + }) + + it('should call facade to get isDownloadPdfInProgress', () => { + service.isDownloadPdfInProgress(); + + expect(postfachFacade.isDownloadPdfInProgress).toHaveBeenCalled(); + }) + + it('should call vorgang service to get vorgang', () => { + service.isDownloadPdfInProgress(); + + expect(vorgangService.getVorgangWithEingang).toHaveBeenCalled(); + }) + }) + }) + + describe('downloadPdf', () => { + + it('should call facade', () => { + service.downloadPdf(); + + expect(postfachFacade.startDownloadPdf).toHaveBeenCalled(); + }) + }) }); \ No newline at end of file diff --git a/goofy-client/libs/postfach-shared/src/lib/postfach.service.ts b/goofy-client/libs/postfach-shared/src/lib/postfach.service.ts index 0ad7e8fea4efbd91f0d5278855c39ffbadd91fc8..02bd7b49233d4ce734bc0d198c9730738f4400a7 100644 --- a/goofy-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/goofy-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -8,8 +8,9 @@ import { SnackBarService } from '@goofy-client/ui'; import { VorgangResource, VorgangService } from '@goofy-client/vorgang-shared'; import { hasLink, Resource } from '@ngxp/rest'; import { isNil, isNull } from 'lodash-es'; -import { BehaviorSubject, Observable, Subscription } from 'rxjs'; -import { first, map, take } from 'rxjs/operators'; +import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs'; +import { first, map, take, tap } from 'rxjs/operators'; +import { PostfachFacade } from './+state/postfach.facade'; import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel'; import { PostfachMessages } from './postfach.message'; import { CreatePostfachMailCommand, PostfachMail, PostfachMailListResource, PostfachMailResource } from './postfach.model'; @@ -36,7 +37,8 @@ export class PostfachService { private vorgangService: VorgangService, private snackbarService: SnackBarService, private dialog: MatDialog, - private binaryFileService: BinaryFileService + private binaryFileService: BinaryFileService, + private postfachFacade: PostfachFacade ) { this.listenToNavigation(); } @@ -224,4 +226,18 @@ export class PostfachService { public loadAttachments(postfachNachricht: PostfachMailResource): Observable<StateResource<BinaryFileListResource>> { return this.binaryFileService.getFiles(postfachNachricht, PostfachMailLinkRel.ATTACHMENTS); } + + public isDownloadPdfInProgress(): Observable<boolean> { + return combineLatest([this.vorgangService.getVorgangWithEingang(), this.postfachFacade.isDownloadPdfInProgress()]).pipe( + tap(([vorgang, isDownloadInProgress]) => { + if (isDownloadInProgress && vorgang.resource) { + this.postfachFacade.downloadPdf(vorgang.resource); + } + }), + map(([, isDownloadInProgress]) => isDownloadInProgress)); + } + + public downloadPdf(): void { + this.postfachFacade.startDownloadPdf(); + } } \ No newline at end of file diff --git a/goofy-client/libs/postfach/src/lib/postfach.module.ts b/goofy-client/libs/postfach/src/lib/postfach.module.ts index 51873ed48f38cdce082bd9ff7acd6df11c9c46e0..6d6027fb6c3e8d588497c9013db37d4f5786afd1 100644 --- a/goofy-client/libs/postfach/src/lib/postfach.module.ts +++ b/goofy-client/libs/postfach/src/lib/postfach.module.ts @@ -19,6 +19,7 @@ import { OutgoingMailComponent } from './postfach-mail-list-container/postfach-m import { PostfachMailDateComponent } from './postfach-mail-list-container/postfach-mail-list/postfach-mail/postfach-mail-date/postfach-mail-date.component'; import { PostfachMailComponent } from './postfach-mail-list-container/postfach-mail-list/postfach-mail/postfach-mail.component'; import { PostfachNachrichtAttachmentsComponent } from './postfach-mail-list-container/postfach-mail-list/postfach-mail/postfach-nachricht-attachments/postfach-nachricht-attachments.component'; +import { PostfachMailPdfButtonContainerComponent } from './postfach-mail-pdf-button-container/postfach-mail-pdf-button-container.component'; import { PostfachPageContainerComponent } from './postfach-page-container/postfach-page-container.component'; import { PostfachPageMailListComponent } from './postfach-page-container/postfach-page/postfach-page-mail-list/postfach-page-mail-list.component'; import { PostfachPageComponent } from './postfach-page-container/postfach-page/postfach-page.component'; @@ -57,8 +58,8 @@ const routes: Routes = [ PostfachMailDateComponent, OutgoingMailErrorContainerComponent, PostfachNachrichtAttachmentsComponent, - PostfachMailButtonComponent - + PostfachMailButtonComponent, + PostfachMailPdfButtonContainerComponent ], exports: [ PostfachMailListContainerComponent, diff --git a/goofy-client/libs/postfach/src/test-setup.ts b/goofy-client/libs/postfach/src/test-setup.ts index 08ef82b5d5efa87cb27257314075f6a16eb7a63e..82178098b34faeb3a94a8268bd072d4db95371a3 100644 --- a/goofy-client/libs/postfach/src/test-setup.ts +++ b/goofy-client/libs/postfach/src/test-setup.ts @@ -1,9 +1,10 @@ +import '@testing-library/jest-dom'; import 'jest-preset-angular/setup-jest'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, - platformBrowserDynamicTesting, + platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; getTestBed().resetTestEnvironment();