import {Injectable} from '@angular/core'; import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model'; import * as _ from 'lodash'; import {Observable} from 'rxjs/Observable'; import {NgRedux} from "@angular-redux/store"; import {AppState} from "../shared/store/reducers"; import {AaiService} from "../shared/services/aaiService/aai.service"; import {ServiceModel} from "../shared/models/serviceModel"; import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service"; import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes"; import {updateDrawingBoardStatus} from "../shared/storeUtil/utils/global/global.actions"; import {Router, UrlTree} from "@angular/router"; import {of} from "rxjs"; import {MsoService} from "../shared/services/msoService/mso.service"; import {ServiceAction} from "../shared/models/serviceInstanceActions"; import {InstantiationBase} from "../shared/models/InstantiationBase"; export let PENDING : string = "pending"; export let INPROGRESS : string = "in_progress"; export let PAUSE : string = "pause"; export let X_O : string = "x-circle-o"; export let SUCCESS_CIRCLE : string = "success-circle-o"; export let STOPPED : string = "stop"; export let COMPLETED_WITH_ERRORS : string = "success_with_warning"; export let PAUSE_UPON_COMPLETION : string = "stopped-upon-success"; export let FAILED_AND_PAUSED : string = "success_with_warning"; export let UNKNOWN : string = "question-mark-circle-o"; @Injectable() export class InstantiationStatusComponentService { constructor( private _aaiService: AaiService, private _msoService: MsoService, private _router : Router, private _store: NgRedux, private _featureFlagsService:FeatureFlagsService) { } generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{ let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {}; for(let item of arr){ if(_.isNil(serviceInfoData[item.templateId])){ serviceInfoData[item.templateId] = [item]; }else { serviceInfoData[item.templateId].push(item); } } return serviceInfoData; } convertObjectToArray(arr: ServiceInfoModel[]) : Observable{ const obj = this.generateServiceInfoDataMapping(arr); let index:number = 0; let result = []; for(let item in obj) { obj[item].map(item => { item['serviceStatus'] = this.getStatus(item.jobStatus); item['serviceIndex'] = index; }); index++; result = result.concat(obj[item]); } console.log(result); return of(result); } isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean { if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI) && serviceModel.vidNotions.viewEditUI !== 'legacy'){ return true; } return false; } open(item: ServiceInfoModel): void { if (this._featureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING)) { this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{ const serviceModel = new ServiceModel(result); if (this.isDrawingBoardViewEdit(serviceModel)) { this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT); return; } this.navigateToNewViewOnlyOrOldEditView(item); }); } /*this else is here only to save time in case we don't need to retrieve service model it can be removed once it service model is always needed, and it doesn't save time*/ else { this.navigateToNewViewOnlyOrOldEditView(item); } } navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) { if (this._featureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT)) { this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW); } else { this.navigateToOldViewEdit(item); } } navigateToOldViewEdit(item: ServiceInfoModel) { let query = `subscriberId=${item.subscriberId}&` + `subscriberName=${item.subscriberName}&` + `serviceType=${item.serviceType}&` + `serviceInstanceId=${item.serviceInstanceId}`; this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT)); window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query); } navigateToNewViewEdit(item: InstantiationBase, mode: DrawingBoardModes): void { console.log("Mode : ", mode); this._store.dispatch(updateDrawingBoardStatus(mode)); const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode); this._router.navigateByUrl(viewEditUrlTree); window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree)); } getNewViewEditUrlTree(item: InstantiationBase, mode: DrawingBoardModes): UrlTree { return this._router.createUrlTree( ['/servicePlanning/' + mode], { queryParams: mode==DrawingBoardModes.RECREATE ? this.getRecreateQueryParams(item) : this.getDefaultViewEditQueryParams( item) }); } private getDefaultViewEditQueryParams(item: ServiceInfoModel) { return { serviceModelId: item.serviceModelId, serviceInstanceId: item.serviceInstanceId, serviceType: item.serviceType, subscriberId: item.subscriberId, jobId: item.jobId }; } private getRecreateQueryParams(item: InstantiationBase) { return { serviceModelId: item.serviceModelId, jobId: item.jobId }; } getViewEditUrl(viewEditUrlTree:UrlTree): string { return '../../serviceModels.htm#' + viewEditUrlTree.toString(); } getStatus(status : string) : ServiceStatus { switch(`${status}`.toUpperCase()) { case 'PENDING' : return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.'); case 'IN_PROGRESS' : return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.'); case 'PAUSED' : return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.'); case 'FAILED' : return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.'); case 'COMPLETED' : return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.'); case 'STOPPED' : return new ServiceStatus(STOPPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.'); case 'COMPLETED_WITH_ERRORS' : return new ServiceStatus(COMPLETED_WITH_ERRORS, 'success', 'Completed with errors: some of the planned actions where successfully committed while other have not.\n Open the service to check it out.'); case 'COMPLETED_AND_PAUSED' : return new ServiceStatus(PAUSE_UPON_COMPLETION, 'default','Pause upon completion. you may resume the instantiation.\n Open the service to check it out.' ); case 'FAILED_AND_PAUSED' : return new ServiceStatus(FAILED_AND_PAUSED, 'success','Failed and Paused: you may re-deploy the instantiation.' ); default: return new ServiceStatus(UNKNOWN, 'primary', `Unexpected status: "${status}"`); } } retry(item: ServiceInfoModel): void { this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT); } resume(item: ServiceInfoModel): void { this.navigateToNewViewEdit(item, DrawingBoardModes.RESUME); } recreate(item: ServiceInfoModel): void { this.navigateToNewViewEdit(item, DrawingBoardModes.RECREATE); } isRecreateEnabled(item: ServiceInfoModel): boolean { return item.action === ServiceAction.INSTANTIATE; } isRecreateVisible(): boolean { return this._featureFlagsService.getFlagState(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE); } isNewViewEditVisible(): boolean { return this._featureFlagsService.getFlagState(Features.FLAG_2006_NEW_VIEW_EDIT_BUTTON_IN_INSTANTIATION_STATUS); } forwardToNewViewEdit(item: ServiceInfoModel): void { this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT); } } export class ServiceStatus { iconClassName : string; color : string; tooltip : string; constructor(_iconClassName : string, _color : string, _tooltip : string){ this.iconClassName = _iconClassName; this.color = _color; this.tooltip = _tooltip; } }