Skip to content
Snippets Groups Projects
Select Git revision
  • a3a006b31d3b9f6c6cf0dd9d57b68bf256ab0cbc
  • main default protected
  • ozg-8323-umzug-dependency-track
  • OZG-8252-gitlab-pipelines
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • 2.27.0
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
41 results

user-profile-icon-in-kommentar-error.e2e-spec.ts

Blame
  • aktenzeichen-edit-dialog.component.ts 3.13 KiB
    import { Component, Inject, OnInit } from '@angular/core';
    import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
    import { AktenzeichenEditDialogData } from './aktenzeichen-edit-dialog.data';
    import { AktenzeichenEditDialogFormservice } from './aktenzeichen-edit-dialog.formservice';
    import { VorgangService, VorgangWithEingangResource } from '@alfa-client/vorgang-shared';
    import { COMMAND_ERROR_MESSAGES, CommandResource, hasError, isSuccessfulDone } from '@alfa-client/command-shared';
    import { createEmptyStateResource, hasContent, isClipboardReadSupported, StateResource } from '@alfa-client/tech-shared';
    import { map, Observable, of, startWith, tap } from 'rxjs';
    import { SnackBarService } from '@alfa-client/ui';
    import { AktenzeichenEditDialogMessages } from './aktenzeichen-edit-dialog.message';
    
    @Component({
    	selector: 'alfa-aktenzeichen-edit-dialog',
    	templateUrl: './aktenzeichen-edit-dialog.component.html',
    	styleUrls: ['./aktenzeichen-edit-dialog.component.scss'],
    	providers: [AktenzeichenEditDialogFormservice]
    })
    export class AktenzeichenEditDialogComponent implements OnInit {
    
    	vorgang: VorgangWithEingangResource;
    
    	public setAktenzeichenPending$: Observable<StateResource<CommandResource>> = of(createEmptyStateResource<CommandResource>());
    	public hasAktenzeichen$: Observable<boolean>;
    	public isPasteSupported = false;
    
    	protected readonly AktenzeichenEditDialogFormservice = AktenzeichenEditDialogFormservice;
    
    	constructor(
    		public formService: AktenzeichenEditDialogFormservice,
    		private readonly snackbarService: SnackBarService,
    		private readonly vorgangService: VorgangService,
    		public dialogRef: MatDialogRef<AktenzeichenEditDialogComponent>,
    		@Inject(MAT_DIALOG_DATA) public data: AktenzeichenEditDialogData,
    	) {
    		this.vorgang = data.vorgang;
    	}
    
    	ngOnInit(): void {
    		this.isPasteSupported = isClipboardReadSupported();
    		this.formService.setAktenzeichen(this.vorgang.aktenzeichen);
    		this.hasAktenzeichen$ = this.formService.valueChanges()
    		.pipe(startWith(this.vorgang.aktenzeichen))
    		.pipe(map(hasContent));
    	}
    
    	public onCancel(): void {
    		this.dialogRef.close();
    	}
    
    	public onSubmit(): void {
    		this.formService.setVorgangWithEingangResource(this.vorgang);
    		this.setAktenzeichenPending$ = this.formService.submit()
    		.pipe(startWith(createEmptyStateResource<CommandResource>(true)))
    		.pipe(tap((commandStateResource: StateResource<CommandResource>) => this.onResponse(commandStateResource.resource)));
    	}
    
    	onResponse(commandResource: CommandResource) {
    		if (commandResource && hasError(commandResource)) {
    			this.showSnackbar(commandResource);
    		} else if (isSuccessfulDone(commandResource)) {
    			this.vorgangService.reloadCurrentVorgang();
    			this.dialogRef.close();
    		}
    	}
    
    	private showSnackbar(commandResource: CommandResource): void {
    		if (hasError(commandResource)) {
    			this.snackbarService.showError(this.getErrorMessage(commandResource));
    		}
    	}
    
    	private getErrorMessage(commandResource: CommandResource): string {
    		return COMMAND_ERROR_MESSAGES[commandResource.errorMessage] || AktenzeichenEditDialogMessages.SET_FAILED;
    	}
    
    	paste(clipboardContent: string) {
    		this.formService.setAktenzeichen(clipboardContent);
    	}
    }