Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Component, ViewChild} from '@angular/core'; |
| 2 | import {Subject} from 'rxjs/Subject'; |
| 3 | import {ModalDirective} from 'ngx-bootstrap' |
| 4 | import {Constants} from '../../shared/utils/constants'; |
| 5 | import {ModelInformationItem} from '../../shared/components/model-information/model-information.component'; |
| 6 | import {ServiceModel} from '../../shared/models/serviceModel'; |
| 7 | import {ServiceInfoService} from '../../shared/server/serviceInfo/serviceInfo.service'; |
| 8 | import {ServiceInfoModel} from '../../shared/server/serviceInfo/serviceInfo.model'; |
| 9 | import {AuditStatus} from '../../shared/server/serviceInfo/AuditStatus.model'; |
| 10 | import {IframeService} from "../../shared/utils/iframe.service"; |
| 11 | |
| 12 | @Component({ |
| 13 | selector: 'audit-info-modal', |
| 14 | templateUrl: './auditInfoModal.component.html', |
| 15 | styleUrls: ['./auditInfoModal.component.scss'] |
| 16 | }) |
| 17 | export class AuditInfoModalComponent { |
| 18 | static openModal: Subject<ServiceInfoModel> = new Subject<ServiceInfoModel>(); |
| 19 | @ViewChild('auditInfoModal') public auditInfoModal: ModalDirective; |
| 20 | title: string = Constants.AuditInfoModal.TITLE; |
| 21 | modelInfoItems: Array<ModelInformationItem> = []; |
| 22 | serviceModel: ServiceModel; |
| 23 | serviceModelName: string; |
| 24 | vidInfoData: Array<AuditStatus> = []; |
| 25 | msoInfoData: Array<AuditStatus> = []; |
| 26 | parentElementClassName = 'content'; |
| 27 | isLoading = true; |
| 28 | |
| 29 | constructor(private _serviceInfoService: ServiceInfoService, private _iframeService : IframeService) { |
| 30 | AuditInfoModalComponent.openModal.subscribe((jobData: ServiceInfoModel) => { |
| 31 | this.initializeProperties(); |
| 32 | if (jobData) { |
| 33 | this.openAuditInfoModal(jobData); |
| 34 | _iframeService.addClassOpenModal(this.parentElementClassName); |
| 35 | this.serviceModelName = jobData.serviceModelName ? jobData.serviceModelName : ''; |
| 36 | this.auditInfoModal.show(); |
| 37 | } else { |
| 38 | _iframeService.removeClassCloseModal(this.parentElementClassName); |
| 39 | this.auditInfoModal.hide(); |
| 40 | } |
| 41 | }) |
| 42 | } |
| 43 | |
| 44 | initializeProperties() : void { |
| 45 | this.modelInfoItems = null; |
| 46 | this.vidInfoData = []; |
| 47 | this.msoInfoData = []; |
| 48 | this.isLoading = true; |
| 49 | } |
| 50 | |
| 51 | openAuditInfoModal(jobData: ServiceInfoModel): void { |
| 52 | this.modelInfoItems = this.createModelInformationItems(jobData); |
| 53 | this.initAuditInfoData(jobData['jobId']); |
| 54 | this.auditInfoModal.show(); |
| 55 | } |
| 56 | |
| 57 | initAuditInfoData(jobId: string) { |
| 58 | this._serviceInfoService.getJobAuditStatus(jobId) |
| 59 | .subscribe((res: Array<Array<AuditStatus>>) => { |
| 60 | this.vidInfoData = res[0]; |
| 61 | this.msoInfoData = res[1]; |
| 62 | this.isLoading = false; |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | createModelInformationItems(serviceModel: ServiceInfoModel): Array<ModelInformationItem> { |
| 67 | return [ |
| 68 | new ModelInformationItem('Subscriber name', 'subscriberName', [serviceModel.subscriberName]), |
| 69 | new ModelInformationItem('Service type', 'serviceType', [serviceModel.serviceType]), |
| 70 | new ModelInformationItem('Service model version', 'serviceModelVersion', [serviceModel.serviceModelVersion]), |
| 71 | new ModelInformationItem('Service instance name', 'serviceInstanceName', [serviceModel.serviceInstanceName], '', true), |
| 72 | new ModelInformationItem('Service instance ID', 'serviceInstanceId', [serviceModel.serviceInstanceId]), |
| 73 | new ModelInformationItem('Requestor User ID', 'userId', [serviceModel.userId]), |
| 74 | ]; |
| 75 | } |
| 76 | |
| 77 | onCancelClick() { |
| 78 | this._iframeService.removeClassCloseModal(this.parentElementClassName); |
| 79 | this.initializeProperties(); |
| 80 | this.auditInfoModal.hide(); |
| 81 | } |
| 82 | } |
| 83 | |