Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame^] | 1 | import {Component, ViewChild} from '@angular/core'; |
| 2 | import {Subject} from 'rxjs/Subject'; |
| 3 | import {ModalDirective} from 'ngx-bootstrap' |
| 4 | import {ModelInformationItem} from '../model-information/model-information.component'; |
| 5 | import {ServiceModel} from '../../models/serviceModel'; |
| 6 | import {ServiceInfoService} from '../../server/serviceInfo/serviceInfo.service'; |
| 7 | import {ServiceInfoModel} from '../../server/serviceInfo/serviceInfo.model'; |
| 8 | import {AuditStatus} from '../../server/serviceInfo/AuditStatus.model'; |
| 9 | import {IframeService} from "../../utils/iframe.service"; |
| 10 | import {NgRedux} from "@angular-redux/store"; |
| 11 | import {AppState} from "../../store/reducers"; |
| 12 | import {AuditInfoModalComponentService} from "./auditInfoModal.component.service"; |
| 13 | |
| 14 | @Component({ |
| 15 | selector: 'audit-info-modal', |
| 16 | templateUrl: './auditInfoModal.component.html', |
| 17 | styleUrls: ['./auditInfoModal.component.scss'] |
| 18 | }) |
| 19 | export class AuditInfoModalComponent { |
| 20 | static openModal: Subject<ServiceInfoModel> = new Subject<ServiceInfoModel>(); |
| 21 | static openInstanceAuditInfoModal: Subject<{instanceId , type, model, instance, isInstanceFailed?, trackById?}> = new Subject<{instanceId , type, model, instance, isInstanceFailed, trackById}>(); |
| 22 | @ViewChild('auditInfoModal') public auditInfoModal: ModalDirective; |
| 23 | title: string = 'Service Instantiation Information'; |
| 24 | modelInfoItems: ModelInformationItem[] = []; |
| 25 | serviceModel: ServiceModel; |
| 26 | serviceModelName: string; |
| 27 | vidInfoData: AuditStatus[] = []; |
| 28 | msoInfoData: AuditStatus[] = []; |
| 29 | isAlaCarte: boolean; |
| 30 | parentElementClassName = 'content'; |
| 31 | isLoading = true; |
| 32 | model: any; |
| 33 | instanceId: string; |
| 34 | isALaCarteFlagOn: boolean; |
| 35 | type : string = "Service"; |
| 36 | showVidStatus : boolean = true; |
| 37 | auditInfoModalComponentService : AuditInfoModalComponentService; |
| 38 | constructor(private _serviceInfoService: ServiceInfoService, private _iframeService : IframeService, |
| 39 | private _auditInfoModalComponentService : AuditInfoModalComponentService, |
| 40 | private store: NgRedux<AppState>) { |
| 41 | this.auditInfoModalComponentService = this._auditInfoModalComponentService; |
| 42 | AuditInfoModalComponent.openModal.subscribe((jobData: ServiceInfoModel) => { |
| 43 | this.isALaCarteFlagOn = this.store.getState().global.flags['FLAG_A_LA_CARTE_AUDIT_INFO']; |
| 44 | this.initializeProperties(); |
| 45 | this.showVidStatus = true; |
| 46 | if (jobData) { |
| 47 | this.isAlaCarte = jobData.aLaCarte; |
| 48 | this.openAuditInfoModal(jobData); |
| 49 | _iframeService.addClassOpenModal(this.parentElementClassName); |
| 50 | this.serviceModelName = jobData.serviceModelName ? jobData.serviceModelName : ''; |
| 51 | this.auditInfoModal.show(); |
| 52 | } else { |
| 53 | _iframeService.removeClassCloseModal(this.parentElementClassName); |
| 54 | this.auditInfoModal.hide(); |
| 55 | } |
| 56 | }); |
| 57 | |
| 58 | AuditInfoModalComponent.openInstanceAuditInfoModal.subscribe(({instanceId , type , model, instance, isInstanceFailed, trackById}) => { |
| 59 | this.showVidStatus = false; |
| 60 | this.initializeProperties(); |
| 61 | this.setModalTitles(type); |
| 62 | this.serviceModelName = AuditInfoModalComponentService.getInstanceModelName(model); |
| 63 | |
| 64 | if (isInstanceFailed) { |
| 65 | this._serviceInfoService.getAuditStatusForRetry(trackById).subscribe((res: AuditStatus) => { |
| 66 | this.msoInfoData = [res]; |
| 67 | }); |
| 68 | }else{ |
| 69 | this._serviceInfoService.getInstanceAuditStatus(instanceId, type).subscribe((res : AuditStatus[]) =>{ |
| 70 | this.msoInfoData = res; |
| 71 | }); |
| 72 | } |
| 73 | this.modelInfoItems = this.auditInfoModalComponentService.getModelInfo(model, instance, instanceId); |
| 74 | _iframeService.addClassOpenModal(this.parentElementClassName); |
| 75 | this.auditInfoModal.show(); |
| 76 | }); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | setModalTitles(type : string) : void{ |
| 81 | this.type = AuditInfoModalComponentService.setModalTitlesType(type) ; |
| 82 | this.title = AuditInfoModalComponentService.setModalTitle(type); |
| 83 | } |
| 84 | |
| 85 | initializeProperties() : void { |
| 86 | this.modelInfoItems = null; |
| 87 | this.vidInfoData = []; |
| 88 | this.msoInfoData = []; |
| 89 | this.isLoading = true; |
| 90 | } |
| 91 | |
| 92 | openAuditInfoModal(jobData: ServiceInfoModel): void { |
| 93 | this.modelInfoItems = AuditInfoModalComponentService.createModelInformationItemsJob(jobData); |
| 94 | this.initAuditInfoData(jobData); |
| 95 | this.auditInfoModal.onHide.subscribe(()=>{ |
| 96 | this._iframeService.removeClassCloseModal(this.parentElementClassName); |
| 97 | this.initializeProperties(); |
| 98 | }); |
| 99 | this.auditInfoModal.show(); |
| 100 | } |
| 101 | |
| 102 | initAuditInfoData(jobData: ServiceInfoModel) { |
| 103 | this._serviceInfoService.getJobAuditStatus(jobData) |
| 104 | .subscribe((res: AuditStatus[][]) => { |
| 105 | this.vidInfoData = res[0]; |
| 106 | this.msoInfoData = res[1]; |
| 107 | this.isLoading = false; |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | onCancelClick() { |
| 112 | this._iframeService.removeClassCloseModal(this.parentElementClassName); |
| 113 | this.initializeProperties(); |
| 114 | this.auditInfoModal.hide(); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | onNavigate(){ |
| 119 | window.open("https://wiki.onap.org/display/DW/SO+Building+blocks", "_blank"); |
| 120 | } |
| 121 | } |
| 122 | |