|
| 1 | +import { OverlayRef } from '@angular/cdk/overlay'; |
| 2 | +import { Component, Input, OnInit } from '@angular/core'; |
| 3 | +import { EuiLoadingService, EuiSidesheetService } from '@elemental-ui/core'; |
| 4 | +import { PortalAttestationCase } from '@imx-modules/imx-api-att'; |
| 5 | +import { |
| 6 | + CollectionLoadParameters, |
| 7 | + CompareOperator, |
| 8 | + EntitySchema, |
| 9 | + FilterType, |
| 10 | + IClientProperty, |
| 11 | + TypedEntity, |
| 12 | + TypedEntityCollectionData, |
| 13 | +} from '@imx-modules/imx-qbm-dbts'; |
| 14 | +import { TranslateService } from '@ngx-translate/core'; |
| 15 | +import { BusyService, DataSourceToolbarSettings, DataViewInitParameters, DataViewSource } from 'qbm'; |
| 16 | +import { AttestationHistoryCase } from '../../attestation-history/attestation-history-case'; |
| 17 | +import { AttestationHistoryDetailsComponent } from '../../attestation-history/attestation-history-details/attestation-history-details.component'; |
| 18 | +import { AttestationHistoryService } from '../../attestation-history/attestation-history.service'; |
| 19 | +import { Approvers } from '../approvers.interface'; |
| 20 | +import { AttestationCasesService } from '../attestation-cases.service'; |
| 21 | +import { AttestationCaseHistoryService } from './attestation-case-history.service'; |
| 22 | + |
| 23 | +@Component({ |
| 24 | + selector: 'imx-attestation-case-history', |
| 25 | + templateUrl: './attestation-case-history.component.html', |
| 26 | + styleUrls: ['./attestation-case-history.component.scss', '../../attestation-history/attestation-history.component.scss'], |
| 27 | + providers: [DataViewSource], |
| 28 | +}) |
| 29 | +export class AttestationCaseHistoryComponent implements OnInit { |
| 30 | + @Input() case: PortalAttestationCase; |
| 31 | + |
| 32 | + public dstSettings: DataSourceToolbarSettings; |
| 33 | + public busyService = new BusyService(); |
| 34 | + public entitySchema: EntitySchema; |
| 35 | + public navigationState: CollectionLoadParameters = {}; |
| 36 | + public displayedColumns: IClientProperty[]; |
| 37 | + |
| 38 | + constructor( |
| 39 | + private readonly attestationCaseHistoryService: AttestationCaseHistoryService, |
| 40 | + private readonly busyServiceElemental: EuiLoadingService, |
| 41 | + private readonly historyService: AttestationHistoryService, |
| 42 | + private readonly sideSheet: EuiSidesheetService, |
| 43 | + private readonly translator: TranslateService, |
| 44 | + private readonly attestationCaseService: AttestationCasesService, |
| 45 | + public readonly dataSource: DataViewSource<PortalAttestationCase>, |
| 46 | + ) { |
| 47 | + this.entitySchema = PortalAttestationCase.GetEntitySchema(); |
| 48 | + this.displayedColumns = [this.entitySchema.Columns.AttestationState, this.entitySchema.Columns.XDateInserted]; |
| 49 | + this.dstSettings = { |
| 50 | + dataSource: { Data: [], totalCount: 0 }, |
| 51 | + entitySchema: this.entitySchema, |
| 52 | + navigationState: this.navigationState, |
| 53 | + displayedColumns: this.displayedColumns, |
| 54 | + }; |
| 55 | + } |
| 56 | + |
| 57 | + public async ngOnInit(): Promise<void> { |
| 58 | + await this.getData(); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Updates the navigation state and reloads the data. |
| 63 | + * @param navigationState reloads data based on the new navigation state |
| 64 | + */ |
| 65 | + public async onNavigationStateChanged(navigationState: CollectionLoadParameters): Promise<void> { |
| 66 | + this.navigationState = navigationState; |
| 67 | + await this.getData(); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Searches attestation cases based on the provided keywords. |
| 72 | + * @param keywords The search keywords entered by the user |
| 73 | + */ |
| 74 | + public async onSearch(keywords: string): Promise<void> { |
| 75 | + this.navigationState.StartIndex = 0; |
| 76 | + this.navigationState.search = keywords; |
| 77 | + await this.getData(); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Shows the details of the selected attestation case in a side sheet |
| 82 | + * @param selectedItem The item, that was selected from the table |
| 83 | + */ |
| 84 | + public async onHighlightedEntityChanged(selectedItem: TypedEntity): Promise<void> { |
| 85 | + const attestationCase: AttestationHistoryCase = selectedItem as AttestationHistoryCase; |
| 86 | + let attestationCaseWithPolicy: AttestationHistoryCase | undefined; |
| 87 | + let approvers: Approvers | undefined; |
| 88 | + |
| 89 | + let busyIndicator: OverlayRef; |
| 90 | + setTimeout(() => (busyIndicator = this.busyServiceElemental.show())); |
| 91 | + |
| 92 | + try { |
| 93 | + attestationCaseWithPolicy = ( |
| 94 | + await this.historyService.getAttestations({ |
| 95 | + ...{ StartIndex: 0, PageSize: 1 }, |
| 96 | + uidpolicy: attestationCase.UID_AttestationPolicy.value, |
| 97 | + filter: [ |
| 98 | + { |
| 99 | + ColumnName: 'UID_AttestationCase', |
| 100 | + Type: FilterType.Compare, |
| 101 | + CompareOp: CompareOperator.Equal, |
| 102 | + Value1: attestationCase.GetEntity().GetKeys()[0], |
| 103 | + }, |
| 104 | + ], |
| 105 | + }) |
| 106 | + ).Data[0]; |
| 107 | + |
| 108 | + if (attestationCaseWithPolicy && !['approved', 'denied'].includes(attestationCaseWithPolicy.AttestationState.value)) { |
| 109 | + approvers = await this.attestationCaseService.getApprovers(attestationCaseWithPolicy); |
| 110 | + } |
| 111 | + } finally { |
| 112 | + setTimeout(() => this.busyServiceElemental.hide(busyIndicator)); |
| 113 | + } |
| 114 | + |
| 115 | + if (attestationCaseWithPolicy) { |
| 116 | + this.sideSheet.open(AttestationHistoryDetailsComponent, { |
| 117 | + title: await this.translator.get('#LDS#Heading View Attestation Case Details').toPromise(), |
| 118 | + subTitle: attestationCaseWithPolicy.GetEntity().GetDisplay(), |
| 119 | + padding: '0', |
| 120 | + width: '600px', |
| 121 | + testId: 'attestation-history-case-sidesheet', |
| 122 | + data: { |
| 123 | + case: attestationCaseWithPolicy, |
| 124 | + approvers, |
| 125 | + showApprovalActions: false, |
| 126 | + }, |
| 127 | + }); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + private async getData(): Promise<void> { |
| 132 | + const dataViewInitParameters: DataViewInitParameters<PortalAttestationCase> = { |
| 133 | + execute: (params: CollectionLoadParameters, signal: AbortSignal): Promise<TypedEntityCollectionData<PortalAttestationCase>> => { |
| 134 | + return this.attestationCaseHistoryService.getAttestationCasesForDecision({ ...this.navigationState, ...params }, this.case); |
| 135 | + }, |
| 136 | + schema: this.entitySchema, |
| 137 | + columnsToDisplay: this.displayedColumns, |
| 138 | + highlightEntity: (attestationCase: PortalAttestationCase) => { |
| 139 | + this.onHighlightedEntityChanged(attestationCase); |
| 140 | + }, |
| 141 | + }; |
| 142 | + await this.dataSource.init(dataViewInitParameters); |
| 143 | + } |
| 144 | +} |
0 commit comments