3v4l.org

run code in 300+ PHP versions simultaneously
<?php import { Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild, ViewChildren, } from "@angular/core"; import { DatePipe } from "@angular/common"; import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop"; import { Clipboard } from "@angular/cdk/clipboard"; import { DomSanitizer, SafeHtml } from "@angular/platform-browser"; import { ToastrService } from "ngx-toastr"; import { InterimReviewCASections, TemplateEnum, WatchlistSections, } from "@sw/credit-review/enums/template-enum"; import { ParameterDataModel } from "@sw/credit-review/models/master-template-model"; import { ApiConfig } from "@sw/shared/utils/api.config"; import { ApiConstant, InterimReviewConstants, } from "@sw/shared/utils/api.constant"; import { CASectionService } from "./ca-section.service"; import { SectionsService } from "../../sections.service"; import { ProgressTimelineService } from "@sw/shared/progress-timeline/progress-timeline.service"; import { UserService } from "@sw/shared/services/user.service"; import { CustomizedEditorComponent } from "@sw/shared/customised-editor/customized-editor.component"; import { MultiUserEditConfig } from "@sw/shared/ca-action-box/ca-action-box.component"; import { ActivatedRoute } from "@angular/router"; import { TrackChangesComponent } from "@sw/shared/track-changes/track-changes.component"; import { ModalComponent } from "@sw/shared/modal/modal.component"; import { ReviewStatus } from "@sw/credit-review/enums/review-status-enum"; import { editorDataInput } from "@sw/credit-review/models/editor-data-input-model"; import { Subscription, catchError, forkJoin, of, take } from "rxjs"; import { HttpErrorResponse } from "@angular/common/http"; import { SanctioningService } from "@sw/credit-review/sanctioning/sanctioning.service"; import { Subject } from "@microsoft/signalr"; import { userInfo } from "@sw/credit-review/models/userInfo"; @Component({ selector: "ca-section", templateUrl: "ca-section.component.html", styleUrls: ["ca-section.component.scss"], }) export class CASectionComponent implements OnInit, OnChanges, OnDestroy { @Input() sectionData; @Input() reviewSectionId; @Input() isReadOnlyModeRequired; @Input() isSimultaneousEditing: boolean; @Input() templateId: number; @Input() status: string; @Input() validationTriggered: boolean = false; reviewUId: number; @Output() SaveActionCallback = new EventEmitter<{ sectionObject: any; editorContent: any; }>(); @Output() EditActionCallback = new EventEmitter<{ sectionObject: any; editorContent: any; }>(); @Output() EditorContentChange = new EventEmitter<ParameterDataModel>(); @Output() creditAnalysisDnD = new EventEmitter(); @Output() creditProfileSelectionUpdated = new EventEmitter<boolean | null>( null ); @ViewChildren("editorComponent") editorComponent: Array<CustomizedEditorComponent>; public onPasteVisibitliy: boolean; @ViewChildren("caSection") caSection!: ElementRef; public assetURL = ApiConfig.CREDIT_REVIEW_MFE_URL + ApiConfig.UIASSET; public mandatoryCASections; public editorData = ""; public lastEditedSection: any = null; public currentUserName: any; public currentTimestamp: any; public simultaneous: MultiUserEditConfig; public autosaveNotification: string = null; public autoSimultaneousNotification: any; @ViewChild("trackChangesComp") trackChangesComp: TrackChangesComponent; @ViewChild("trackChanges") trackChanges: ModalComponent; public templateEnum = TemplateEnum; public materialChangeSelectedValue: boolean; public isCreditProfileSectionVisible: boolean = false; public interimReviewConstants = InterimReviewConstants; public interimReviewCASections = InterimReviewCASections; public reviewStatus = ReviewStatus; public isInterimReviewMaterialChangeInitialising: boolean = true; public sectionDataChanges!: Subscription; public sectionDataUpdate: any; public isNewSectionAdded: boolean = false; public groupId!: number; private _destroy$ = new Subject<void>(); finalBookSelection: string = ""; levLendindResponse: any; isMandatory: boolean; private userInfo = new userInfo(); constructor( private clipboard: Clipboard, private _crSanctioningService: SanctioningService, private route: ActivatedRoute, public cASectionService: CASectionService, private toastrService: ToastrService, private _sectionsService: SectionsService, private timelineStatusService: ProgressTimelineService, public datePipe: DatePipe, private userService: UserService, private sanitizer: DomSanitizer ) { this.reviewUId = +this.route.snapshot.data.status.reviewUId; this.simultaneous = new MultiUserEditConfig(); } ngOnInit(): void { this.cASectionService.setTemplateId(this.templateId); this.route.params.pipe(take(1)).subscribe(params => { this.groupId = +params["id"]; if (this.groupId && this.templateId == TemplateEnum.Standard) { this.getLevLendingDetails(); } }); this.currentTimestamp = Date.now(); this.cASectionService.sequenceCreditAnalysisData = undefined; document.documentElement.style.setProperty( "--dndurl", `url(${this.assetURL}drag-nd-drop.png)` ); this.userService.getCurrentUser().subscribe(obj => { if (obj) { this.currentUserName = obj.firstname + " " + obj.surname; this.userInfo.FirstName = obj.firstname; this.userInfo.LastName = obj.surname; this.userInfo.UserName = obj.username; } }); if (this.sectionData.length) { const materialChangeValue = this.sectionData.find( item => item.parameterId === this.interimReviewCASections.MATERIAL_CHANGE )?.data?.materialChange; this.materialChangeCheckboxUpdate(materialChangeValue, true); } this.sectionDataChanges = this.cASectionService.sectionData$.subscribe( (data: any) => { if (data != null && data != undefined) { this.isNewSectionAdded = true; this.sectionDataUpdate = data; if ( !this.sectionData.some( section => section.parameterId === data.parameterId ) ) { this.sectionData = [...this.sectionData, data]; } this.triggerSectionUpdate(); } } ); } triggerSectionUpdate() { const sectionsData = this.cASectionService.generateCAObject( this.sectionData ); if (sectionsData) { this.sectionData = sectionsData.sort( (a, b) => a.data?.sequence - b.data?.sequence ); } this.mandatoryCASections = sectionsData; if (this.isNewSectionAdded && this.sectionDataUpdate) { this.addNewSection(); } } getLevLendingDetails(): void { this._crSanctioningService .getLevLendingDetails(this.groupId) .pipe( catchError(err => { console.error("Api error", err); return of({ error: true, messsage: "Lev lending api failed" }); }), take(1) ) .subscribe(response => { this.levLendindResponse = response; this.updateLevLendingMandatoryStatus(); }); } updateLevLendingMandatoryStatus(): void { const { isLevLendingFlag, finalBookSelection } = this .levLendindResponse ?? { isLevLendingFlag: false, finalBookSelection: null, }; this.cASectionService.sequenceCreditAnalysisData.forEach(section => { if ( section.parameterDisplayName?.trim() === "Lev Lending Considerations" ) { const condition = isLevLendingFlag === true && finalBookSelection === "BQLL"; section.isMandatory = condition; if (condition) { this.isMandatory = true; section.data = null; } else { this.isMandatory = false; section.isMandatory = false; if (!section.data) { section.data = {}; } } } }); } addNewSection() { const newEditorData: editorDataInput[] = []; if (this.mandatoryCASections && this.sectionDataUpdate) { this.sectionDataUpdate.forEach(element => { const currentEditorData = new editorDataInput(); const addedSection = this.mandatoryCASections.find( x => x.parameterId === element.parameterId ); if (addedSection) { currentEditorData.editorData = ""; currentEditorData.parameterDisplayName = addedSection.parameterDisplayName; currentEditorData.parameterId = element.parameterId; currentEditorData.reviewSectionId = this.reviewSectionId; currentEditorData.reviewUId = this.reviewUId; currentEditorData.sequence = addedSection.data && addedSection.data.sequence ? addedSection.data.sequence : addedSection.sequence; currentEditorData.updatedBy = this.userInfo.UserName; newEditorData.push(currentEditorData); } else { if (this.shouldIncludeSection(element)) { this.mandatoryCASections = [ ...this.mandatoryCASections, { ...element, data: null, isActionbox: false, isOpen: false, isRTE: false, }, ]; currentEditorData.editorData = ""; currentEditorData.parameterDisplayName = element.parameterDisplayName; currentEditorData.parameterId = element.parameterId; currentEditorData.reviewSectionId = this.reviewSectionId; currentEditorData.reviewUId = this.reviewUId; currentEditorData.sequence = element.sequence || this.mandatoryCASections.length; currentEditorData.updatedBy = this.userInfo.UserName; newEditorData.push(currentEditorData); } } }); } if (newEditorData && newEditorData.length > 0) { this.isNewSectionAdded = false; this.bulkEditorBulkSequenceUpdate( newEditorData, ApiConstant.MSG_EDITOR_DATA_SECTION_ADD_SUCCESS ); } } private shouldIncludeSection(section: any): boolean { if ( this.templateId === TemplateEnum.Rbar || this.templateId === TemplateEnum.Standard ) { return ( section.isMandatory === true || section.checked === true || section.isSaved === true || section.isDefaultView === true ); } else { return ( section.isMandatory === true || section.checked === true || section.isSaved === true ); } } ngOnChanges(changes: SimpleChanges) { if (changes.sectionData) { let sectionsData = this.cASectionService.generateCAObject( this.sectionData ); if (sectionsData) { sectionsData = sectionsData.sort( (a, b) => a.data?.sequence - b.data?.sequence ); } this.mandatoryCASections = sectionsData; this.updateDefaultViewSections(); if (this.isNewSectionAdded) { this.addNewSection(); } } } updateDefaultViewSections() { this.updateDefaultViewSections = this.sectionData?.filter(section => section.isDefaultView === true) || []; } ngOnDestroy() { this.sectionDataChanges?.unsubscribe(); } getSafeHtmlSectionDescription(section): SafeHtml { return this.sanitizer.bypassSecurityTrustHtml(section); } showActionboxPanel(data) { if ( this.lastEditedSection && this.lastEditedSection.parameterId !== data.parameterId ) { const previousContent = this.lastEditedSection.data?.editorData || ""; this.lastEditedSection.sectionDescription = previousContent; this.lastEditedSection.isRTE = false; if (previousContent.trim() !== "") { this.timelineStatusService.updateStatus( this.lastEditedSection.parameterName, true ); } } this.cASectionService.collapseAll(); this.mandatoryCASections = this.cASectionService.enableActionBox(data); this.lastEditedSection = data; } compareSequence(dbList: any, localList: any): boolean { let result: boolean = true; if (dbList.length > 0) { const sortedLocalList = localList.sort(x => x.sequence); dbList.forEach(element => { const currentUIRecord = sortedLocalList.find( x => x.parameterId == element.parameterId ); if (currentUIRecord) { if ( (currentUIRecord.data && element.sequence !== currentUIRecord.data.sequence) || (!currentUIRecord.data && element.sequence !== currentUIRecord.sequence) ) { result = false; } } else { result = false; } }); } return result; } getEditorDataAll(reviewUId: number, reviewSectionId: number) { this._sectionsService .getEditorDataAll(this.reviewUId, reviewSectionId) .subscribe({ next: res => { if (res) { } }, error: err => { this.toastrService.error(ApiConstant.MSG_EDITOR_DATA_SAVE_FAIL); }, }); } public drop(event: CdkDragDrop<any>) { if ( this.templateId === TemplateEnum.Rbar || this.templateId === TemplateEnum.Standard ) { if (!event || event.previousIndex === event.currentIndex) { return; } try { const textdataResponse = this._sectionsService.getEditorDataAll( this.reviewUId, this.reviewSectionId ); if (textdataResponse) { if ( this.compareSequence(textdataResponse, this.mandatoryCASections) ) { this.continueDrop(event.previousIndex, event.currentIndex); } else { this.toastrService.error( ApiConstant.MSG_EDITOR_DATA_SEQUENCE_CHANGED ); return; } } } catch (error) { console.error("Error in drop method:", error); this.toastrService.warning( ApiConstant.MSG_EDITOR_DATA_CREDITANALYSIS_FETCH_FAILED ); } } else { const texteditorDataAll = this._sectionsService.getEditorDataAll( this.reviewUId, this.reviewSectionId ); const serviceData = [texteditorDataAll]; forkJoin(serviceData).subscribe({ next: ([textdataResponse]) => { if (textdataResponse) { if ( this.compareSequence(textdataResponse, this.mandatoryCASections) ) { this.continueDrop(event.previousIndex, event.currentIndex); } else { this.toastrService.error( ApiConstant.MSG_EDITOR_DATA_SEQUENCE_CHANGED ); return; } } }, error: (error: HttpErrorResponse) => { this.toastrService.warning( ApiConstant.MSG_EDITOR_DATA_CREDITANALYSIS_FETCH_FAILED ); return; }, }); } } continueDrop(previousIndex: number, currentIndex: number): void { if ( this.templateId === TemplateEnum.Rbar || this.templateId === TemplateEnum.Standard ) { if ( previousIndex === currentIndex || !this.mandatoryCASections || previousIndex < 0 || currentIndex < 0 || previousIndex >= this.mandatoryCASections.length || currentIndex >= this.mandatoryCASections.length ) { return; } try { moveItemInArray(this.mandatoryCASections, previousIndex, currentIndex); const editorData: any[] = []; this.mandatoryCASections.forEach((item, index) => { if (!item) return; if (!item.data) { item.data = this._sectionsService.getDefaultEditorData( item, this.reviewSectionId, this.reviewUId, index ); } if (item.data && !item.data.updatedBy) { item.data.updatedBy = this.userInfo && this.userInfo.UserName ? this.userInfo.UserName : this.currentUserName; } if (item.data) { item.data.sequence = index + 1; editorData.push(item.data); } }); if (editorData.length > 0) { this.bulkEditorBulkSequenceUpdate( editorData, ApiConstant.MSG_EDITOR_DATA_SEQUENCE_SUCCESS ); } this.cASectionService.sequenceCreditAnalysisData = [ ...this.mandatoryCASections, ]; this.creditAnalysisDnD.emit( this.cASectionService.sequenceCreditAnalysisData ); } catch (error) { console.error("Error in continueDrop:", error); } } else { moveItemInArray(this.mandatoryCASections, previousIndex, currentIndex); const editorData = []; this.mandatoryCASections.forEach((item, index) => { if (item && !item.data) { item.data = this._sectionsService.getDefaultEditorData( item, this.reviewSectionId, this.reviewUId, index ); } if (item.data && !item.data.updatedBy) { item.data["updatedBy"] = this.userInfo && this.userInfo.UserName ? this.userInfo.UserName : this.currentUserName; } item.data.sequence = index + 1; editorData.push(item.data); }); this.bulkEditorBulkSequenceUpdate( editorData, ApiConstant.MSG_EDITOR_DATA_SEQUENCE_SUCCESS ); this.cASectionService.sequenceCreditAnalysisData = structuredClone( this.mandatoryCASections ); this.creditAnalysisDnD.emit( this.cASectionService.sequenceCreditAnalysisData ); } } onEditorAutoSave(section, content) { const savedContent = content?.trim() || ""; if (this.simultaneous?.isSaveAction) { section.sectionDescription = savedContent; if (section.data) { section.data.editorData = savedContent; } this.lastEditedSection = section; return; } if (section.data) { section.data.editorData = savedContent; if (section && section.data) { if (!section.data.parameterDisplayName) { section.data["parameterDisplayName"] = section.parameterDisplayName; } if (!section.data.parameterId) { section.data["parameterId"] = section.parameterId; } if (!section.data.reviewSectionId) { section.data["reviewSectionId"] = this.reviewSectionId; } if (!section.data.reviewUId) { section.data["reviewUId"] = this.reviewUId; } if (!section.data.sequence) { section.data["sequence"] = section.sequence; } } } else { section.data = this._sectionsService.getDefaultEditorData( section, this.reviewSectionId, this.reviewUId, section.sequence ); section.data.editorData = savedContent; } const existingContent = section.sectionDescription?.trim() || ""; const isChanged = savedContent !== existingContent; section.sectionDescription = savedContent; if (!savedContent && existingContent) { this.onSaveAction(section); this.timelineStatusService.updateStatus(section.parameterName, false); this.bulkSaveEditorData([section.data], { isAutoSave: true, displayName: section.parameterDisplayName, }); this.lastEditedSection = section; return; } if (isChanged) { this.onSaveAction(section); this.updateTimelineStatusForSection(section); this.bulkSaveEditorData([section.data], { isAutoSave: true, displayName: section.parameterDisplayName, }); } else { section.sectionDescription = savedContent; this.onSaveAction(section); } this.lastEditedSection = section; } updateTimelineStatusForSection(section: any) { const hasContent = section.data?.editorData && section.data.editorData !== ""; const hasMaterialChangeValue = section.data?.materialChange !== undefined && section.data?.materialChange !== null; if (this.shouldUpdateTimelineForSection(section)) { if (section.parameterId === InterimReviewCASections.MATERIAL_CHANGE) { this.timelineStatusService.updateStatus( section.parameterName, hasMaterialChangeValue ); } else { this.timelineStatusService.updateStatus( section.parameterName, hasContent ); } } } shouldUpdateTimelineForSection(section: any): boolean { if (!section) return false; if (section.isMandatory === true) return true; if ( (this.templateId === TemplateEnum.Rbar || this.templateId === TemplateEnum.Standard) && section.isDefaultView === true ) { return true; } if (section.checked === true || section.isSaved === true) { return true; } return false; }
Output for 8.4.1 - 8.4.15, 8.5.0
Parse error: syntax error, unexpected token "{" in /in/LsJTf on line 3
Process exited with code 255.
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28
Parse error: syntax error, unexpected token "," in /in/LsJTf on line 4
Process exited with code 255.

preferences:
155.99 ms | 1004 KiB | 7 Q