|
| 1 | +import { HttpErrorResponse } from '@angular/common/http'; |
| 2 | +import {ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit, Output} from '@angular/core'; |
| 3 | +import { ActivatedRoute } from '@angular/router'; |
| 4 | +import {EMPTY, Observable} from 'rxjs'; |
| 5 | +import {catchError, concatMap, filter, map, tap} from 'rxjs/operators'; |
| 6 | +import { UtmToastService } from 'src/app/shared/alert/utm-toast.service'; |
| 7 | +import {TimezoneFormatService} from '../../../../shared/services/utm-timezone.service'; |
| 8 | +import {DatePipeDefaultOptions} from '../../../../shared/types/date-pipe-default-options'; |
| 9 | +import {CpControlConfigService} from '../../../shared/services/cp-control-config.service'; |
| 10 | +import {ComplianceControlLatestEvaluationType} from '../../../shared/type/compliance-control-latest-evaluation.type'; |
| 11 | + |
| 12 | + |
| 13 | +@Component({ |
| 14 | + selector: 'app-compliance-latest-eval-print-view', |
| 15 | + templateUrl: './compliance-latest-eval-print-view.component.html', |
| 16 | + styleUrls: ['./compliance-latest-eval-print-view.component.css'], |
| 17 | + changeDetection: ChangeDetectionStrategy.OnPush |
| 18 | +}) |
| 19 | +export class ComplianceLatestEvalPrintViewComponent implements OnInit, OnDestroy { |
| 20 | + controls$: Observable<ComplianceControlLatestEvaluationType[]>; |
| 21 | + dateFormat$: Observable<DatePipeDefaultOptions>; |
| 22 | + |
| 23 | + constructor(private controlsService: CpControlConfigService, |
| 24 | + private toastService: UtmToastService, |
| 25 | + private route: ActivatedRoute, |
| 26 | + private timezoneFormatService: TimezoneFormatService) { } |
| 27 | + |
| 28 | + ngOnInit() { |
| 29 | + this.dateFormat$ = this.timezoneFormatService.getDateFormatSubject(); |
| 30 | + this.controls$ = this.route.queryParams |
| 31 | + .pipe( |
| 32 | + filter((params) => !!params.section), |
| 33 | + map((params) => JSON.parse(decodeURIComponent(params.section))), |
| 34 | + concatMap((params) => this.controlsService.fetchData({ |
| 35 | + page: params.page, |
| 36 | + size: params.size, |
| 37 | + sectionId: params.id, |
| 38 | + sort: params.sort, |
| 39 | + })), |
| 40 | + map((res) => { |
| 41 | + return res.body.map((r, index) => { |
| 42 | + return { |
| 43 | + ...r, |
| 44 | + }; |
| 45 | + }); |
| 46 | + }), |
| 47 | + catchError((err: HttpErrorResponse) => { |
| 48 | + this.toastService.showError('Error', |
| 49 | + 'Unable to retrieve the list of reports. Please try again or contact support.'); |
| 50 | + return EMPTY; |
| 51 | + })); |
| 52 | + } |
| 53 | + |
| 54 | + ngOnDestroy(): void { |
| 55 | + throw new Error('Method not implemented.'); |
| 56 | + } |
| 57 | +} |
0 commit comments