Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
| 2 | import {ServiceInfoModel, ServiceInfoUiModel} from '../shared/server/serviceInfo/serviceInfo.model'; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 3 | import * as _ from 'lodash'; |
| 4 | import {Observable} from 'rxjs/Observable'; |
| 5 | import {NgRedux} from "@angular-redux/store"; |
| 6 | import {AppState} from "../shared/store/reducers"; |
| 7 | import {AaiService} from "../shared/services/aaiService/aai.service"; |
| 8 | import {ServiceModel} from "../shared/models/serviceModel"; |
| 9 | import {FeatureFlagsService, Features} from "../shared/services/featureFlag/feature-flags.service"; |
| 10 | import {DrawingBoardModes} from "../drawingBoard/service-planning/drawing-board.modes"; |
| 11 | import {updateDrawingBoardStatus} from "../shared/storeUtil/utils/global/global.actions"; |
| 12 | import {Router, UrlTree} from "@angular/router"; |
| 13 | import {of} from "rxjs"; |
| 14 | import {MsoService} from "../shared/services/msoService/mso.service"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 15 | export let PENDING : string = "pending"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 16 | export let INPROGRESS : string = "in_progress"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 17 | export let PAUSE : string = "pause"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 18 | export let X_O : string = "x-circle-o"; |
| 19 | export let SUCCESS_CIRCLE : string = "success-circle-o"; |
| 20 | export let STOPED : string = "stop"; |
| 21 | export let COMPLETED_WITH_ERRORS : string = "success_with_warning"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 22 | |
| 23 | |
| 24 | @Injectable() |
| 25 | export class InstantiationStatusComponentService { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 26 | constructor( private _aaiService: AaiService, |
| 27 | private _msoService: MsoService, |
| 28 | private _router : Router, |
| 29 | private _store: NgRedux<AppState>) { |
| 30 | } |
| 31 | |
| 32 | generateServiceInfoDataMapping(arr: ServiceInfoModel[]) : { [serviceInstanceId: string]: ServiceInfoModel[]}{ |
| 33 | let serviceInfoData: { [serviceInstanceId: string]: ServiceInfoModel[]; } = {}; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 34 | for(let item of arr){ |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 35 | if(_.isNil(serviceInfoData[item.templateId])){ |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 36 | serviceInfoData[item.templateId] = [item]; |
| 37 | }else { |
| 38 | serviceInfoData[item.templateId].push(item); |
| 39 | } |
| 40 | } |
| 41 | return serviceInfoData; |
| 42 | } |
| 43 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 44 | convertObjectToArray(arr: ServiceInfoModel[]) : Observable<ServiceInfoUiModel[]>{ |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 45 | const obj = this.generateServiceInfoDataMapping(arr); |
| 46 | let index:number = 0; |
| 47 | let result = []; |
| 48 | for(let item in obj) { |
| 49 | obj[item].map(item => { |
| 50 | item['serviceStatus'] = this.getStatus(item.jobStatus); |
| 51 | item['serviceIndex'] = index; |
| 52 | }); |
| 53 | index++; |
| 54 | result = result.concat(obj[item]); |
| 55 | } |
| 56 | |
| 57 | console.log(result); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 58 | return of(result); |
| 59 | } |
| 60 | |
| 61 | isDrawingBoardViewEdit(serviceModel: ServiceModel): boolean { |
| 62 | if (!_.isNil(serviceModel.vidNotions) && !_.isNil(serviceModel.vidNotions.viewEditUI) |
| 63 | && serviceModel.vidNotions.viewEditUI !== 'legacy'){ |
| 64 | return true; |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | open(item: ServiceInfoModel): void { |
| 70 | if (FeatureFlagsService.getFlagState(Features.FLAG_1902_VNF_GROUPING, this._store)) { |
| 71 | this._aaiService.getServiceModelById(item['serviceModelId']).subscribe((result)=>{ |
| 72 | const serviceModel = new ServiceModel(result); |
| 73 | |
| 74 | if (this.isDrawingBoardViewEdit(serviceModel)) { |
| 75 | this.navigateToNewViewEdit(item, DrawingBoardModes.EDIT); |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | this.navigateToNewViewOnlyOrOldEditView(item); |
| 80 | |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | /*this else is here only to save time in case we don't need to retrieve service model |
| 85 | it can be removed once it service model is always needed, and it doesn't save time*/ |
| 86 | else { |
| 87 | this.navigateToNewViewOnlyOrOldEditView(item); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | navigateToNewViewOnlyOrOldEditView(item: ServiceInfoModel) { |
| 92 | if (FeatureFlagsService.getFlagState(Features.FLAG_1902_NEW_VIEW_EDIT, this._store)) { |
| 93 | this.navigateToNewViewEdit(item, DrawingBoardModes.VIEW); |
| 94 | } |
| 95 | else { |
| 96 | this.navigateToOldViewEdit(item); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | navigateToOldViewEdit(item: ServiceInfoModel) { |
| 101 | let query = |
| 102 | `subscriberId=${item.subscriberId}&` + |
| 103 | `subscriberName=${item.subscriberName}&` + |
| 104 | `serviceType=${item.serviceType}&` + |
| 105 | `serviceInstanceId=${item.serviceInstanceId}`; |
| 106 | |
| 107 | this._store.dispatch(updateDrawingBoardStatus(DrawingBoardModes.OLD_VIEW_EDIT)); |
| 108 | window.parent.location.assign('../../serviceModels.htm#/instantiate?' + query); |
| 109 | } |
| 110 | |
| 111 | navigateToNewViewEdit(item: ServiceInfoModel, mode: DrawingBoardModes): void{ |
| 112 | this._store.dispatch(updateDrawingBoardStatus(mode)); |
| 113 | const viewEditUrlTree:UrlTree = this.getNewViewEditUrlTree(item, mode); |
| 114 | this._router.navigateByUrl(viewEditUrlTree); |
| 115 | window.parent.location.assign(this.getViewEditUrl(viewEditUrlTree)); |
| 116 | } |
| 117 | |
| 118 | getNewViewEditUrlTree(item: ServiceInfoModel, mode: DrawingBoardModes): UrlTree { |
| 119 | return this._router.createUrlTree( |
| 120 | ['/servicePlanning/' + mode], |
| 121 | { |
| 122 | queryParams: |
| 123 | { |
| 124 | serviceModelId: item.serviceModelId, |
| 125 | serviceInstanceId: item.serviceInstanceId, |
| 126 | serviceType : item.serviceType, |
| 127 | subscriberId : item.subscriberId, |
| 128 | jobId: item.jobId |
| 129 | } |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | getViewEditUrl(viewEditUrlTree:UrlTree): string { |
| 134 | return '../../serviceModels.htm#' + viewEditUrlTree.toString(); |
| 135 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | getStatus(status : string) : ServiceStatus { |
| 139 | switch(status.toUpperCase()) { |
| 140 | case 'PENDING' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 141 | return new ServiceStatus(PENDING, 'primary', 'Pending: The action required will be sent as soon as possible.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 142 | case 'IN_PROGRESS' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 143 | return new ServiceStatus(INPROGRESS, 'primary', 'In-progress: the service is in process of the action required.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 144 | case 'PAUSED' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 145 | return new ServiceStatus(PAUSE, 'primary', 'Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 146 | case 'FAILED' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 147 | return new ServiceStatus(X_O, 'error', 'Failed: All planned actions have failed.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 148 | case 'COMPLETED' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 149 | return new ServiceStatus(SUCCESS_CIRCLE, 'success', 'Completed successfully: Service is successfully instantiated, updated or deleted.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 150 | case 'STOPPED' : |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 151 | return new ServiceStatus(STOPED, 'error', 'Stopped: Due to previous failure, will not be instantiated.'); |
| 152 | case 'COMPLETED_WITH_ERRORS' : |
| 153 | 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.'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 154 | } |
| 155 | } |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 156 | |
| 157 | retry(item: ServiceInfoModel): void { |
| 158 | this.navigateToNewViewEdit(item, DrawingBoardModes.RETRY_EDIT); |
| 159 | } |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | export class ServiceStatus { |
| 164 | iconClassName : string; |
| 165 | color : string; |
| 166 | tooltip : string; |
| 167 | |
| 168 | constructor(_iconClassName : string, _color : string, _tooltip : string){ |
| 169 | this.iconClassName = _iconClassName; |
| 170 | this.color = _color; |
| 171 | this.tooltip = _tooltip; |
| 172 | } |
| 173 | } |