diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts index e0da72cebbd87689172262fba7a0393652b18302..2a984d4ddbdc07d828802be92d46d770002a6fdf 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.model.ts @@ -62,7 +62,8 @@ export interface CreatePostfachMailCommand extends CreateCommand { export interface PostfachMailResource extends Resource, PostfachMail {} export interface PostfachMailListResource extends ListResource { - features: Features; + features: PostfachFeatures; + settings: PostfachSettings; } export enum PostfachNachrichtenCount { @@ -80,7 +81,10 @@ export interface PostfachMailFormDialogData extends FixedDialogData { postfachNachricht?: PostfachMailResource; } -export interface Features { - //TODO Rename to PostfachFeatures +export interface PostfachFeatures { reply: boolean; } + +export interface PostfachSettings { + signatur: string; +} diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts index 1d00b7d41af9f9851a34f07c3035251d140eeb2c..3d23e1126c898d3b4d1df1ce5da9edad93b8d477 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.spec.ts @@ -21,7 +21,6 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { MatDialog } from '@angular/material/dialog'; import { BinaryFileListResource, BinaryFileResource, @@ -37,6 +36,7 @@ import { import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; import { SnackBarService } from '@alfa-client/ui'; import { VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared'; +import { MatDialog } from '@angular/material/dialog'; import { createBinaryFileListResource, createBinaryFileResource, @@ -49,9 +49,11 @@ import { import { createVorgangWithEingangResource } from 'libs/vorgang-shared/test/vorgang'; import { BehaviorSubject, of } from 'rxjs'; import { + createPostfachFeatures, createPostfachMail, createPostfachMailListResource, createPostfachMailResource, + createPostfachSettings, } from '../../test/postfach'; import { PostfachFacade } from './+state/postfach.facade'; import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel'; @@ -630,7 +632,20 @@ describe('PostfachService', () => { ); service.getFeatures().subscribe((features) => { - expect(features).toEqual({ reply: true }); + expect(features).toEqual(createPostfachFeatures()); + done(); + }); + }); + }); + + describe('getSettings', () => { + it('should return settings by list stateResource', (done) => { + service.postfachMailList$ = new BehaviorSubject( + createStateResource(createPostfachMailListResource()), + ); + + service.getSettings().subscribe((settings) => { + expect(settings).toEqual(createPostfachSettings()); done(); }); }); diff --git a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts index f4bc26e4687c2ce05b1cc7b3d36560b76a5a21df..4fda384295d5f2cf511064bccd84941fd78d3a8c 100644 --- a/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts +++ b/alfa-client/libs/postfach-shared/src/lib/postfach.service.ts @@ -58,10 +58,11 @@ import { PostfachMailLinkRel, PostfachMailListLinkRel } from './postfach.linkrel import { PostfachMessages } from './postfach.message'; import { CreatePostfachMailCommand, - Features, + PostfachFeatures, PostfachMail, PostfachMailListResource, PostfachMailResource, + PostfachSettings, } from './postfach.model'; import { PostfachRepository } from './postfach.repository'; import { createResendPostfachMailCommand, createSendPostfachMailCommand } from './postfach.util'; @@ -372,7 +373,7 @@ export class PostfachService { this.postfachFacade.clearAttachmentList(); } - public getFeatures(): Observable<Features> { + public getFeatures(): Observable<PostfachFeatures> { return this.getPostfachMailListByVorgang().pipe( map( (listStateResource: StateResource<PostfachMailListResource>) => @@ -380,4 +381,13 @@ export class PostfachService { ), ); } + + public getSettings(): Observable<PostfachSettings> { + return this.getPostfachMailListByVorgang().pipe( + map( + (listStateResource: StateResource<PostfachMailListResource>) => + listStateResource.resource.settings, + ), + ); + } } diff --git a/alfa-client/libs/postfach-shared/test/postfach.ts b/alfa-client/libs/postfach-shared/test/postfach.ts index fb0fa71451c5d4409d18ba8c879e592eae198030..4127e34f9369670e4656a63bef0f7cf56dad0fef 100644 --- a/alfa-client/libs/postfach-shared/test/postfach.ts +++ b/alfa-client/libs/postfach-shared/test/postfach.ts @@ -21,8 +21,8 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { faker } from '@faker-js/faker'; import { EMPTY_ARRAY, createStateResource } from '@alfa-client/tech-shared'; +import { faker } from '@faker-js/faker'; import { Resource } from '@ngxp/rest'; import { toResource } from 'libs/tech-shared/test/resource'; import { times } from 'lodash-es'; @@ -30,10 +30,12 @@ import { PostfachMailListLinkRel } from '../src/lib/postfach.linkrel'; import { PostfachNachrichtMessageCode } from '../src/lib/postfach.message-code'; import { Direction, + PostfachFeatures, PostfachMail, PostfachMailFormDialogData, PostfachMailListResource, PostfachMailResource, + PostfachSettings, ReplyOption, } from '../src/lib/postfach.model'; @@ -62,13 +64,23 @@ export function createPostfachMailResources(linkRelations: string[] = []): Postf export function createPostfachMailListResource( linkRelations: string[] = [], ): PostfachMailListResource { - return toResource(createPostfachMailListWithAllowedReplyFeature(), [...linkRelations], { + return toResource(createPostfachMailList(), [...linkRelations], { [PostfachMailListLinkRel.POSTFACH_MAIL_LIST]: createPostfachMailResources(), }); } -function createPostfachMailListWithAllowedReplyFeature(): Resource { - return toResource({ features: { reply: true } }, ['sendPostfachMail']); +function createPostfachMailList(): Resource { + return toResource({ features: createPostfachFeatures(), settings: createPostfachSettings() }, [ + 'sendPostfachMail', + ]); +} + +export function createPostfachFeatures(): PostfachFeatures { + return { reply: true }; +} + +export function createPostfachSettings(): PostfachSettings { + return { signatur: 'Best regards' }; } export class PostfachTestFactory { diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html index cea292daf1e3bfe942599923ec2cba8083a7c3ce..f9051a515a935c512c5e6660db737afac2114d72 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.html @@ -40,6 +40,7 @@ [formControlName]="formServiceClass.FIELD_MAIL_BODY" label="Text" class="message-editor mt-3" + [value]="signatur" [autoFocus]="true" [required]="true" > diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts index 40d4bc90cda99e87336563376dd405d63298d575..466c580e54dc255424203fa32e167954a5a94131 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.spec.ts @@ -21,12 +21,6 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; -import { MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatInputModule } from '@angular/material/input'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { PostfachService } from '@alfa-client/postfach-shared'; import { createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; @@ -39,8 +33,14 @@ import { TextAreaEditorComponent, TextEditorComponent, } from '@alfa-client/ui'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { createCommandResource } from 'libs/command-shared/test/command'; -import { PostfachTestFactory } from 'libs/postfach-shared/test/postfach'; +import { PostfachTestFactory, createPostfachSettings } from 'libs/postfach-shared/test/postfach'; import { MockComponent } from 'ng-mocks'; import { of } from 'rxjs'; import { PostfachMailFormComponent } from './postfach-mail-form.component'; @@ -55,6 +55,9 @@ describe('PostfachMailFormComponent', () => { let fixture: ComponentFixture<PostfachMailFormComponent>; const postfachService: Mock<PostfachService> = mock(PostfachService); + const postfachSettings = createPostfachSettings(); + postfachService.getSettings.mockReturnValue(of(postfachSettings)); + const formService: PostfachMailFormservice = new PostfachMailFormservice( new FormBuilder(), useFromMock(postfachService), @@ -122,6 +125,20 @@ describe('PostfachMailFormComponent', () => { expect(component.patchPostfachNachricht).toHaveBeenCalled(); }); }); + + describe('on setting signatur', () => { + it('should call postfachService', () => { + component.ngOnInit(); + + expect(postfachService.getSettings).toHaveBeenCalled(); + }); + + it('should set signatur', () => { + component.ngOnInit(); + + expect(component.signatur).toBe(postfachSettings.signatur); + }); + }); }); describe('patchPostfachNachricht', () => { diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts index 6335536d0fd0d2f8e03c413cad7f304c9e06cfae..f49b402a431bc3150e5b6948739db2147570e4b6 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail-form.component.ts @@ -40,6 +40,7 @@ import * as CommandUtil from '../../../../command-shared/src/lib/command.util'; }) export class PostfachMailFormComponent implements OnInit { public readonly formServiceClass = PostfachMailFormservice; + public signatur = ''; public sendInProgress$: Observable<StateResource<CommandResource>> = of( createEmptyStateResource<CommandResource>(), @@ -55,6 +56,10 @@ export class PostfachMailFormComponent implements OnInit { if (isNotNil(this.dialogData.postfachNachricht)) { this.patchPostfachNachricht(); } + + this.formService.getSignatur().subscribe((signatur: string) => { + this.signatur = signatur; + }); } patchPostfachNachricht(): void { diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts index 0825838a83338418ca10cc5a43bbbd001c23987a..ac21899898805e073c303f03f79285dbc08722ae 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.spec.ts @@ -21,13 +21,16 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { UntypedFormBuilder } from '@angular/forms'; import { CommandResource } from '@alfa-client/command-shared'; import { PostfachService } from '@alfa-client/postfach-shared'; import { StateResource, createStateResource } from '@alfa-client/tech-shared'; import { Mock, mock, useFromMock } from '@alfa-client/test-utils'; +import { UntypedFormBuilder } from '@angular/forms'; import { createCommandResource } from 'libs/command-shared/test/command'; -import { createPostfachMailResource } from 'libs/postfach-shared/test/postfach'; +import { + createPostfachMailResource, + createPostfachSettings, +} from 'libs/postfach-shared/test/postfach'; import { of } from 'rxjs'; import { PostfachMailFormservice } from './postfach-mail.formservice'; @@ -84,4 +87,24 @@ describe('PostfachMailFormservice', () => { }); }); }); + + describe('get signatur', () => { + const postfachSettings = createPostfachSettings(); + + beforeEach(() => { + service.getSettings.mockReturnValue(of(postfachSettings)); + }); + + it('should call service', () => { + formService.getSignatur().subscribe(() => { + expect(service.getSettings).toHaveBeenCalled(); + }); + }); + + it('should return signatur', () => { + formService.getSignatur().subscribe((signatur) => { + expect(signatur).toBe(postfachSettings.signatur); + }); + }); + }); }); diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts index 3e7de900cdaa45e7ebfbbdc66994fb9b874ae594..51293968c42a54ca013d876c669d83fe7937cfef 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-mail.formservice.ts @@ -21,6 +21,9 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ +import { CommandResource } from '@alfa-client/command-shared'; +import { PostfachService, PostfachSettings } from '@alfa-client/postfach-shared'; +import { AbstractFormService, StateResource } from '@alfa-client/tech-shared'; import { Injectable } from '@angular/core'; import { UntypedFormArray, @@ -28,11 +31,8 @@ import { UntypedFormControl, UntypedFormGroup, } from '@angular/forms'; -import { CommandResource } from '@alfa-client/command-shared'; -import { PostfachService } from '@alfa-client/postfach-shared'; -import { AbstractFormService, StateResource } from '@alfa-client/tech-shared'; import { ReplyOption } from 'libs/postfach-shared/src/lib/postfach.model'; -import { Observable } from 'rxjs'; +import { Observable, map } from 'rxjs'; @Injectable() export class PostfachMailFormservice extends AbstractFormService { @@ -70,4 +70,10 @@ export class PostfachMailFormservice extends AbstractFormService { return this.postfachService.sendMail(this.getFormValue()); } } + + public getSignatur(): Observable<string> { + return this.postfachService + .getSettings() + .pipe(map((settings: PostfachSettings) => settings.signatur)); + } } diff --git a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts index 1e6ae6bea4559a733a50f29c4411aedc738c8e1c..71a0fc57deeb55ffbadac5d10f4a9cf49ddecd71 100644 --- a/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts +++ b/alfa-client/libs/postfach/src/lib/postfach-mail-form/postfach-nachricht-reply-editor-container/postfach-nachricht-reply-editor-container.component.ts @@ -1,12 +1,12 @@ -import { Component, OnInit } from '@angular/core'; import { - Features, FORBIDDEN_REPLY_OPTION_ITEM, POSSIBLE_REPLY_OPTION_ITEM, + PostfachFeatures, PostfachService, } from '@alfa-client/postfach-shared'; import { FormProvider } from '@alfa-client/tech-shared'; import { CheckboxEnumEditorItem } from '@alfa-client/ui'; +import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { PostfachMailFormservice } from '../postfach-mail.formservice'; @@ -19,7 +19,7 @@ import { PostfachMailFormservice } from '../postfach-mail.formservice'; export class PostfachNachrichtReplyEditorContainerComponent implements OnInit { public readonly formServiceClass = PostfachMailFormservice; - public postfachFeatures$: Observable<Features>; + public postfachFeatures$: Observable<PostfachFeatures>; public checkedItem: CheckboxEnumEditorItem = POSSIBLE_REPLY_OPTION_ITEM; public uncheckedItem: CheckboxEnumEditorItem = FORBIDDEN_REPLY_OPTION_ITEM; diff --git a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html index 14034ce169db28951cd062e19343976a81ca8d7b..67f8f93bac0e98c7fa87bce829a716a2a0a2c0e3 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html +++ b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.html @@ -29,6 +29,7 @@ <textarea #autosize="cdkTextareaAutosize" placeholder="{{ placeholder }}" + value="{{ value }}" matInput cdkTextareaAutosize [formControl]="fieldControl" diff --git a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts index 12d1e2d4906205137a55508042d63b95c9a7e857..b6ae8c8bb3830fa99e199c88b5eb55a181e469b1 100644 --- a/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts +++ b/alfa-client/libs/ui/src/lib/ui/editor/textarea-editor/textarea-editor.component.ts @@ -37,6 +37,7 @@ export class TextAreaEditorComponent @ViewChild('autosize') autosize: CdkTextareaAutosize; @Input() placeholder: string; + @Input() value: string = ''; @Input() label: string = ''; @Input() appearance: 'outline' | 'fill' = 'fill'; @Input() required: boolean = false;