From 5340a5477a882949e0aafa5976f0ed2ff5b0e287 Mon Sep 17 00:00:00 2001 From: simvalery Date: Fri, 17 Jan 2025 16:12:48 +0400 Subject: [PATCH] fix build Signed-off-by: simvalery Signed-off-by: simvalery --- .../messages-report-block.component.ts | 185 +++++------------ .../report-block/report-block.component.ts | 194 +----------------- 2 files changed, 55 insertions(+), 324 deletions(-) diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts index 11c6716515..a9c4754ed7 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/messages-report-block/messages-report-block.component.ts @@ -1,17 +1,10 @@ -import { DatePipe } from '@angular/common'; -import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { HttpErrorResponse } from '@angular/common/http'; import { Component, ElementRef, HostListener, Input, OnInit } from '@angular/core'; import { UntypedFormBuilder, Validators } from '@angular/forms'; -import { MatIconRegistry } from '@angular/material/icon'; -import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog'; import { DomSanitizer } from '@angular/platform-browser'; -import { ContractType } from '@guardian/interfaces'; -import * as moment from 'moment'; +import moment from 'moment'; import { DialogService } from 'primeng/dynamicdialog'; -import { forkJoin, Observable } from 'rxjs'; import { VCViewerDialog } from 'src/app/modules/schema-engine/vc-dialog/vc-dialog.component'; -import { AnalyticsService } from 'src/app/services/analytics.service'; -import { ContractService } from 'src/app/services/contract.service'; import { PolicyEngineService } from 'src/app/services/policy-engine.service'; import { PolicyHelper } from 'src/app/services/policy-helper.service'; import { WebSocketService } from 'src/app/services/web-socket.service'; @@ -226,12 +219,6 @@ export class MessagesReportBlockComponent implements OnInit { public searchForm = this.fb.group({ value: ['', Validators.required] }); - gridSize: number = 0; - mintTokenId: string; - mintTokenSerials: string[] = []; - groupedByContractRetirements: any = []; - indexerAvailable: boolean = false; - retirementMessages: any[] = []; constructor( private element: ElementRef, @@ -239,19 +226,9 @@ export class MessagesReportBlockComponent implements OnInit { private policyEngineService: PolicyEngineService, private wsService: WebSocketService, private policyHelper: PolicyHelper, - private dialog: MatDialog, private dialogService: DialogService, - private iconRegistry: MatIconRegistry, - private sanitizer: DomSanitizer, - private contractService: ContractService, - private analyticsService: AnalyticsService, - private datePipe: DatePipe + private sanitizer: DomSanitizer ) { - iconRegistry.addSvgIconLiteral('token', sanitizer.bypassSecurityTrustHtml(` - - - - `)); } public get topics(): any[] { @@ -344,7 +321,6 @@ export class MessagesReportBlockComponent implements OnInit { if (this.report) { this.createReport(this.report); this.createSmallReport(); - this.loadRetirementMessages(); } } this.removeLines(); @@ -354,94 +330,10 @@ export class MessagesReportBlockComponent implements OnInit { }, 100); } - private loadRetirementMessages() { - this._messages2.forEach(message => { - if (message.__ifMintMessage) { - this.mintTokenId = message.__tokenId; - } - }); - - this.contractService - .getContracts({ - type: ContractType.RETIRE - }) - .subscribe( - (policiesResponse) => { - const contracts = policiesResponse.body || []; - const tokenContractTopicIds: string[] = []; - - if (contracts && contracts.length > 0) { - contracts.forEach(contract => { - if (contract.wipeTokenIds && contract.wipeTokenIds.length > 0 && - contract.wipeTokenIds.some((tokenId: string) => tokenId == this.mintTokenId)) { - tokenContractTopicIds.push(contract.topicId); - } - }); - } - - this.analyticsService.checkIndexer().subscribe(indexerAvailable => { - this.indexerAvailable = indexerAvailable; - if (indexerAvailable && tokenContractTopicIds.length > 0) { - const indexerCalls: Observable>[] = []; - tokenContractTopicIds.forEach(id => { - indexerCalls.push(this.contractService.getRetireVCsFromIndexer(id)) - }) - - this.loading = true; - forkJoin(indexerCalls).subscribe((results: any) => { - this.loading = false; - const retires = results.map((item: any) => item.body) - - let allRetireMessages: any = []; - retires.forEach((retirements: any[]) => { - retirements.forEach((item: any) => { - if (item.documents[0].credentialSubject[0].tokens.some((token: any) => token.tokenId === this.mintTokenId)) { - item.id = item.consensusTimestamp; - item.__ifRetireMessage = true; - item.__timestamp = this.datePipe.transform(new Date(item.documents[0].issuanceDate), 'yyyy-MM-dd, hh:mm:ss'); - allRetireMessages.push(item); - } - }); - }); - - allRetireMessages.sort((a: any, b: any) => new Date(a.documents[0].issuanceDate).getTime() - new Date(b.documents[0].issuanceDate).getTime()); - - // For different topics different ordering - let lastOrderMessageTopic1 = this._topics1?.[this._topics1.length - 1]?.messages.reduce((acc: number, item: any) => item.__order > acc ? item.__order : acc, 0) + 1; - allRetireMessages.forEach((element: any) => { - var newElement = {...element, __order: lastOrderMessageTopic1} - this._messages1.push(newElement); - this._topics1[this._topics1.length - 1].messages.push(newElement); - - lastOrderMessageTopic1++; - }); - let lastOrderMessageTopic2 = this._topics2?.[0]?.messages.reduce((acc: number, item: any) => item.__order > acc ? item.__order : acc, 0) + 1; - allRetireMessages.forEach((element: any) => { - var newElement = {...element, __order: lastOrderMessageTopic2} - this._messages2.push(newElement); - this._topics2[0].messages.push(newElement); - lastOrderMessageTopic2++; - }); - - // Todo: Need filtration by serials and token user - this.retirementMessages = [...allRetireMessages]; - - this._gridTemplateColumns1 = 'repeat(' + (this.gridSize + this.retirementMessages.length + 1) + ', 230px)'; - this._gridTemplateColumns2 = 'repeat(' + (this.gridSize + this.retirementMessages.length) + ', 230px)'; - }) - } - }) - }, - (e) => { - this.loading = false; - } - ); - } - private createSmallReport() { for (const topic of this._topics1) { if (topic.message?.messageType === 'INSTANCE_POLICY_TOPIC') { - const t = { ...topic }; + const t = {...topic}; t.__parent = null; t.__offset = 20; t.__order = this._topics2.length + 1; @@ -454,22 +346,21 @@ export class MessagesReportBlockComponent implements OnInit { this._messages2.push(message); } } - - this.gridSize = 0; + let gridSize = 0; this._messages2.sort((a, b) => a.__order > b.__order ? 1 : -1); for (let index = 0; index < this._messages2.length; index++) { const message = this._messages2[index]; message.__order = index + 1; - this.gridSize = Math.max(this.gridSize, message.__order); + gridSize = Math.max(gridSize, message.__order); } - this._gridTemplateColumns2 = 'repeat(' + this.gridSize + ', 230px)'; + this._gridTemplateColumns2 = 'repeat(' + gridSize + ', 230px)'; this._gridTemplateRows2 = 'repeat(' + this._topics2.length + ', 100px) 30px'; } private getAllMessages(topic: any, messages: any[]): any[] { if (topic.messages) { for (const message of topic.messages) { - messages.push({ ...message }); + messages.push({...message}); } } if (topic.children) { @@ -508,7 +399,7 @@ export class MessagesReportBlockComponent implements OnInit { } private parseMessages() { - this.gridSize = 0; + let gridSize = 0; for (const topic of this._topics1) { if (topic.message) { this.parseMessage(topic, topic.message); @@ -516,7 +407,7 @@ export class MessagesReportBlockComponent implements OnInit { for (const message of topic.messages) { this.parseMessage(topic, message); this._messages1.push(message); - this.gridSize = Math.max(this.gridSize, message.__order); + gridSize = Math.max(gridSize, message.__order); } if (topic.__parent) { topic.__start = 100 * topic.__parent.__order; @@ -539,7 +430,7 @@ export class MessagesReportBlockComponent implements OnInit { topic.message.__rationale = topic.__rationale; } } - this._gridTemplateColumns1 = 'repeat(' + this.gridSize + ', 230px)'; + this._gridTemplateColumns1 = 'repeat(' + gridSize + ', 230px)'; this._gridTemplateRows1 = 'repeat(' + this._topics1.length + ', 100px) 30px'; } @@ -685,13 +576,20 @@ export class MessagesReportBlockComponent implements OnInit { private getStatusLabel(message: any) { switch (message.documentStatus) { - case 'NEW': return 'Create document'; - case 'ISSUE': return 'Create document'; - case 'REVOKE': return 'Revoke document'; - case 'SUSPEND': return 'Suspend document'; - case 'RESUME': return 'Resume document'; - case 'FAILED': return 'Failed'; - default: return message.documentStatus || 'Create document'; + case 'NEW': + return 'Create document'; + case 'ISSUE': + return 'Create document'; + case 'REVOKE': + return 'Revoke document'; + case 'SUSPEND': + return 'Suspend document'; + case 'RESUME': + return 'Resume document'; + case 'FAILED': + return 'Failed'; + default: + return message.documentStatus || 'Create document'; } } @@ -761,7 +659,7 @@ export class MessagesReportBlockComponent implements OnInit { const documents: any[] = []; if (message.document && message.document.verifiableCredential) { for (const vc of message.document.verifiableCredential) { - const item: any = { document: vc }; + const item: any = {document: vc}; item.__schema = this.searchSchema(item); item.__issuer = this.getIssuer(item); if (item.__schema) { @@ -907,11 +805,14 @@ export class MessagesReportBlockComponent implements OnInit { public getTopicHeader(message: any): string { if (message) { switch (message.messageType) { - case 'USER_TOPIC': return 'Standard Registry'; - case 'POLICY_TOPIC': return 'Policy'; + case 'USER_TOPIC': + return 'Standard Registry'; + case 'POLICY_TOPIC': + return 'Policy'; case 'INSTANCE_POLICY_TOPIC': return this.dashboardType === DashboardType.Advanced ? 'Policy instance' : message.name; - case 'DYNAMIC_TOPIC': return 'User defined'; + case 'DYNAMIC_TOPIC': + return 'User defined'; } } return 'Global'; @@ -920,10 +821,14 @@ export class MessagesReportBlockComponent implements OnInit { public getTopicName(topic: any): string { if (topic.message) { switch (topic.message.messageType) { - case 'USER_TOPIC': return ''; - case 'POLICY_TOPIC': return topic.message.name; - case 'INSTANCE_POLICY_TOPIC': return 'Version: ' + (topic.__rationale?.version || 'N/A'); - case 'DYNAMIC_TOPIC': return topic.message.name; + case 'USER_TOPIC': + return ''; + case 'POLICY_TOPIC': + return topic.message.name; + case 'INSTANCE_POLICY_TOPIC': + return 'Version: ' + (topic.__rationale?.version || 'N/A'); + case 'DYNAMIC_TOPIC': + return topic.message.name; } } return ''; @@ -946,7 +851,7 @@ export class MessagesReportBlockComponent implements OnInit { this.loading = true; let filterValue = this.searchForm.value.value || ''; filterValue = filterValue.trim(); - this.policyEngineService.setBlockData(this.id, this.policyId, { filterValue }).subscribe(() => { + this.policyEngineService.setBlockData(this.id, this.policyId, {filterValue}).subscribe(() => { this.loadData(); }, (e) => { console.error(e.error); @@ -981,7 +886,8 @@ export class MessagesReportBlockComponent implements OnInit { viewDocument: false } }); - dialogRef.onClose.subscribe(async (result) => { }); + dialogRef.onClose.subscribe(async (result) => { + }); } else { const dialogRef = this.dialogService.open(VCViewerDialog, { @@ -990,14 +896,15 @@ export class MessagesReportBlockComponent implements OnInit { styleClass: 'guardian-dialog', data: { row: null, - document: message.document || message.documents?.[0], + document: message.document, title: 'VC Document', type: 'VC', viewDocument: true, schema: message.__schema, } }); - dialogRef.onClose.subscribe(async (result) => { }); + dialogRef.onClose.subscribe(async (result) => { + }); } } diff --git a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/report-block/report-block.component.ts b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/report-block/report-block.component.ts index bf6737cd00..e8d5cc4b77 100644 --- a/frontend/src/app/modules/policy-engine/policy-viewer/blocks/report-block/report-block.component.ts +++ b/frontend/src/app/modules/policy-engine/policy-viewer/blocks/report-block/report-block.component.ts @@ -1,19 +1,12 @@ -import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { HttpErrorResponse } from '@angular/common/http'; import { Component, Input, OnInit } from '@angular/core'; import { UntypedFormBuilder, Validators } from '@angular/forms'; -import { MatIconRegistry } from '@angular/material/icon'; -import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog'; -import { DomSanitizer } from '@angular/platform-browser'; -import { ContractType, IconType, IImpactReport, IPolicyReport, IReport, IReportItem, IRetirementMessage, ITokenReport, IVC, IVCReport, IVPReport } from '@guardian/interfaces'; +import { IconType, IImpactReport, IPolicyReport, IReport, IReportItem, ITokenReport, IVCReport, IVPReport } from '@guardian/interfaces'; import { DialogService } from 'primeng/dynamicdialog'; -import { forkJoin, Observable } from 'rxjs'; import { VCViewerDialog } from 'src/app/modules/schema-engine/vc-dialog/vc-dialog.component'; -import { AnalyticsService } from 'src/app/services/analytics.service'; -import { ContractService } from 'src/app/services/contract.service'; import { IPFSService } from 'src/app/services/ipfs.service'; import { PolicyEngineService } from 'src/app/services/policy-engine.service'; import { WebSocketService } from 'src/app/services/web-socket.service'; -import { IconsArray } from './iconsArray'; interface IAdditionalDocument { vpDocument?: IVPReport | undefined; @@ -49,31 +42,13 @@ export class ReportBlockComponent implements OnInit { value: ['', Validators.required] }); - vpDocument: any; - mintTokenId: string; - mintTokenSerials: string[] = []; - groupedByContractRetirements: any = []; - indexerAvailable: boolean = false; - constructor( private policyEngineService: PolicyEngineService, private wsService: WebSocketService, private fb: UntypedFormBuilder, - public dialog: MatDialog, private dialogService: DialogService, - iconRegistry: MatIconRegistry, - sanitizer: DomSanitizer, - private ipfs: IPFSService, - private contractService: ContractService, - private analyticsService: AnalyticsService + private ipfs: IPFSService ) { - for (let i = 0; i < IconsArray.length; i++) { - const element = IconsArray[i]; - iconRegistry.addSvgIconLiteral( - element.name, - sanitizer.bypassSecurityTrustHtml(element.icon) - ); - } } private _onSuccess(data: any) { @@ -113,134 +88,6 @@ export class ReportBlockComponent implements OnInit { } } - loadRetireData() { - this.loading = true; - - this.contractService - .getContracts({ - type: ContractType.RETIRE - }) - .subscribe( - (policiesResponse) => { - const contracts = policiesResponse.body || []; - const tokenContractTopicIds: string[] = []; - - if (contracts && contracts.length > 0) { - contracts.forEach(contract => { - if (contract.wipeTokenIds && contract.wipeTokenIds.length > 0 && - contract.wipeTokenIds.some((tokenId: string) => tokenId == this.mintTokenId)) { - tokenContractTopicIds.push(contract.topicId); - } - }); - } - - this.analyticsService.checkIndexer().subscribe(indexerAvailable => { - this.indexerAvailable = indexerAvailable; - if (indexerAvailable && tokenContractTopicIds.length > 0) { - const indexerCalls: Observable>[] = []; - tokenContractTopicIds.forEach(id => { - indexerCalls.push(this.contractService.getRetireVCsFromIndexer(id)) - }) - - this.loading = true; - forkJoin([this.contractService.getRetireVCs(), ...indexerCalls]).subscribe((results: any) => { - this.loading = false; - const retires = results.map((item: any) => item.body) - - const [retiresDb, ...retiresIndexer] = retires; - const retiresDbMapped = retiresDb - .filter((item: any) => item.type == 'RETIRE') - .map((item: any) => item.document); - - const combinedRetirements = [...retiresDbMapped]; - retiresIndexer.forEach((retirements: IRetirementMessage[]) => { - retirements.forEach((item: IRetirementMessage) => { - const existInGuardianDocument = retiresDbMapped.find((retire: IVC) => retire.id === item.documents[0].id); - if (!existInGuardianDocument) { - item.documents[0].topicId = item.topicId; - item.documents[0].timestamp = item.consensusTimestamp; - item.documents[0].sequenceNumber = item.sequenceNumber; - item.documents[0].owner = item.owner; - combinedRetirements.push(item.documents[0]); - } - else { - existInGuardianDocument.topicId = item.topicId; - existInGuardianDocument.timestamp = item.consensusTimestamp; - existInGuardianDocument.sequenceNumber = item.sequenceNumber; - existInGuardianDocument.owner = item.owner; - } - }); - }); - - const tokenRetirementDocuments = combinedRetirements - .filter((item: any) => item.credentialSubject.some((subject: any) => - subject.user === this.vpDocument.document.target - && subject.tokens.some((token: any) => - token.tokenId === this.mintTokenId - && this.mintTokenSerials.length <= 0 || token.serials.some((serial: string) => this.mintTokenSerials.includes(serial) - )))); - - this.groupedByContractRetirements = Array.from( - new Map(tokenRetirementDocuments - .map((item: any) => [item.credentialSubject[0].contractId, []]) - )).map(([contractId]) => ({ - contractId, - selectedItemIndex: 0, - documents: tokenRetirementDocuments.filter((item: any) => item.credentialSubject[0].contractId === contractId) - })) - }) - } else { - this.contractService - .getRetireVCs() - .subscribe( - (policiesResponse) => { - const tokenRetirementDocuments = (policiesResponse.body || []) - .filter((item: any) => item.type == 'RETIRE' - && item.document.credentialSubject.some((subject: any) => - subject.user === this.vpDocument.document.target - && subject.tokens.some((token: any) => - token.tokenId === this.mintTokenId - && this.mintTokenSerials.length <= 0 || token.serials.some((serial: string) => this.mintTokenSerials.includes(serial) - )))).map((vc: any) => vc.document); - - this.groupedByContractRetirements = Array.from( - new Map(tokenRetirementDocuments - .map((item: any) => [item.credentialSubject[0].contractId, []]) - )).map(([contractId]) => ({ - contractId, - selectedItemIndex: 0, - documents: tokenRetirementDocuments.filter((item: any) => item.credentialSubject[0].contractId === contractId) - })) - - this.loading = false; - }, - (e) => { - this.loading = false; - } - ); - } - }) - }, - (e) => { - this.loading = false; - } - ); - } - - getSelectedRetirementVC(group: any): any { - return group.documents[group.selectedItemIndex]; - } - - onNextRetirementClick(event: any, group: any) { - event.stopPropagation(); - group.selectedItemIndex = group.documents.length > (group.selectedItemIndex + 1) ? group.selectedItemIndex + 1 : 0; - } - - onPrevRetirementClick(event: any, group: any) { - event.stopPropagation(); - group.selectedItemIndex = (group.selectedItemIndex - 1) >= 0 ? (group.selectedItemIndex - 1) : (group.documents.length - 1); - } - loadData() { this.loading = true; if (this.static) { @@ -280,11 +127,6 @@ export class ReportBlockComponent implements OnInit { this.policyCreatorDocument = report.policyCreatorDocument; this.documents = report.documents || []; - this.mintTokenId = report.mintDocument?.tokenId || ''; - this.mintTokenSerials = (report.vpDocument?.document as any).serials.map((serialItem: any) => serialItem.serial); - this.vpDocument = report.vpDocument; - this.loadRetireData(); - const mainDocument = this.createAdditionalDocument(report); if (mainDocument) { this.mainDocuments = [mainDocument]; @@ -384,7 +226,8 @@ export class ReportBlockComponent implements OnInit { type: 'VC', } }); - dialogRef.onClose.subscribe(async (result) => { }); + dialogRef.onClose.subscribe(async (result) => { + }); } openVPDocument(item: any) { @@ -403,7 +246,8 @@ export class ReportBlockComponent implements OnInit { type: 'VP', } }); - dialogRef.onClose.subscribe(async (result) => { }); + dialogRef.onClose.subscribe(async (result) => { + }); } openJsonDocument(item: ITokenReport) { @@ -419,28 +263,8 @@ export class ReportBlockComponent implements OnInit { type: 'JSON', } }); - dialogRef.onClose.subscribe(async (result) => { }); - } - - openRetireVCDocument( - item: any, - document?: any - ) { - const title = `Retire Document`; - const dialogRef = this.dialogService.open(VCViewerDialog, { - showHeader: false, - width: '1000px', - styleClass: 'guardian-dialog', - data: { - id: item.id, - row: item, - viewDocument: true, - document: item, - title: title, - type: 'VC', - } + dialogRef.onClose.subscribe(async (result) => { }); - dialogRef.onClose.subscribe(async (result) => { }); } mapData(data: any[]) { @@ -480,7 +304,7 @@ export class ReportBlockComponent implements OnInit { onBackClick() { this.loading = true; this.policyEngineService - .setBlockData(this.id, this.policyId, { filterValue: null }) + .setBlockData(this.id, this.policyId, {filterValue: null}) .subscribe( () => { this.loadData();