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