blob: 51f90534bd3a1abcafcfa477dcd7dc38f5e2018b [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {Component, ViewChild} from '@angular/core';
2import {ContextMenuComponent, ContextMenuService} from 'ngx-contextmenu';
3import {DialogService} from 'ng2-bootstrap-modal';
4import {MsoService} from '../../../shared/services/msoService/mso.service'
5import * as _ from 'lodash';
6import {ActivatedRoute} from '@angular/router';
7import {ServiceInstance} from "../../../shared/models/serviceInstance";
8import {OwningEntity} from "../../../shared/models/owningEntity";
9import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data";
10import {NgRedux} from "@angular-redux/store";
11import {AppState} from "../../../shared/store/reducers";
12import {IframeService} from "../../../shared/utils/iframe.service";
13import {
14 GenericFormPopupComponent,
15 PopupType
16} from "../../../shared/components/genericFormPopup/generic-form-popup.component";
17import {ServicePopupService} from "../../../shared/components/genericFormPopup/genericFormServices/service/service.popup.service";
18import {SdcUiCommon} from "onap-ui-angular";
19import {DrawingBoardModes} from "../drawing-board.modes";
20import {DrawingBoardHeaderService} from "./drawing-board-header.service";
21import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
22import {DrawingBoardPermissions} from "../../guards/servicePlanningGuard/drawingBoardGuard";
23import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service";
24
25@Component({
26 selector: 'drawing-board-header',
27 providers: [MsoService],
28 templateUrl: './drawing-board-header.component.html',
29 styleUrls: ['./drawing-board-header.component.scss']
30})
31
32export class DrawingBoardHeader {
33 serviceName: string;
34 numServicesToDeploy: number;
35 status: string = 'Designing a new service';
36 serviceModelId: string;
37 jobId: string;
38 parentElementClassName = 'content';
39 mode : DrawingBoardModes = DrawingBoardModes.CREATE;
40 serviceOrchStatus: string;
41 isDeleted: boolean = false;
Ittay Sternf7926712019-07-07 19:23:03 +030042 isResume: boolean = false;
Ittay Stern6f900cc2018-08-29 17:01:32 +030043 store : NgRedux<AppState>;
44 drawingBoardPermissions : DrawingBoardPermissions;
45 drawingBoardHeaderService : DrawingBoardHeaderService;
46 isServiceFailed: boolean;
47 serviceStatusMessage: string;
48 constructor(private _contextMenuService: ContextMenuService, private dialogService: DialogService,
49 private _iframeService : IframeService,
50 private route: ActivatedRoute, private msoService: MsoService,
51 private _servicePopupService : ServicePopupService,
52 private _drawingBoardHeaderService : DrawingBoardHeaderService,
53 private _store: NgRedux<AppState>,
54 private _drawingBoardPermissions : DrawingBoardPermissions) {
55 this.store = _store;
56 this.drawingBoardPermissions = _drawingBoardPermissions;
57 this.drawingBoardHeaderService = _drawingBoardHeaderService;
58 this.mode = (!_.isNil(this.route.routeConfig.path) && this.route.routeConfig.path !== "") ? this.route.routeConfig.path as DrawingBoardModes : DrawingBoardModes.CREATE;
59 this.route
60 .queryParams
61 .subscribe((params) => {
62 this.serviceModelId = params['serviceModelId'];
63 this.jobId = params['jobId'];
64 if (_.has(this.store.getState().service.serviceHierarchy, this.serviceModelId)) {
65 this.setValuesFromStore();
66 this.store.subscribe(() => {
67 this.setValuesFromStore();
68 });
69 }
70 });
71 }
72
73
74 @ViewChild(ContextMenuComponent) public contextMenu: ContextMenuComponent;
75
76 editViewEdit(): void {
77 window.parent.location.assign(this._drawingBoardHeaderService.generateOldViewEditPath());
78 }
79
80 isPermitted() : boolean {
81 return this.drawingBoardPermissions.isEditPermitted;
82}
83
84 getModeName():string {
85 switch (this.mode) {
86 case DrawingBoardModes.CREATE:
87 return 'IN DESIGN';
88 case DrawingBoardModes.VIEW:
89 case DrawingBoardModes.RETRY:
90 return 'VIEW ONLY';
91 case DrawingBoardModes.EDIT:
92 case DrawingBoardModes.RETRY_EDIT:
93 return 'IN EDITING';
94 default:
95 return 'IN DESIGN';
96 }
97
98 }
99 public onContextMenu($event: MouseEvent, item: any): void {
100 this._contextMenuService.show.next({
101 contextMenu: this.contextMenu,
102 event: $event,
103 item: item,
104 });
105 $event.preventDefault();
106 $event.stopPropagation();
107 }
108
109 private setValuesFromStore() {
110 if(!_.isNil(this.store.getState().service.serviceInstance) && !_.isNil(this.store.getState().service.serviceInstance[this.serviceModelId])){
111 const serviceInstance = this.store.getState().service.serviceInstance[this.serviceModelId];
112 this.numServicesToDeploy = serviceInstance.bulkSize;
113 this.serviceName = serviceInstance.instanceName || '<Automatically Assigned>';
114 this.serviceOrchStatus = serviceInstance.orchStatus || "";
115 this.isServiceFailed = serviceInstance.isFailed;
116 this.serviceStatusMessage = serviceInstance.statusMessage;
117 }
118 }
119
120 public editService(): void {
121 this._iframeService.addClassOpenModal(this.parentElementClassName);
122 this.dialogService.addDialog(GenericFormPopupComponent, {
123 type: PopupType.SERVICE,
124 uuidData: <any>{
125 type : PopupType.SERVICE,
Ittay Sternf7926712019-07-07 19:23:03 +0300126 isMacro : this.store.getState().service.serviceHierarchy[this.serviceModelId].service.vidNotions.instantiationType === 'Macro',
Ittay Stern6f900cc2018-08-29 17:01:32 +0300127 serviceId: this.serviceModelId,
128 popupService: this._servicePopupService
129 },
130 isUpdateMode: true
131 });
132 }
133
Ittay Sternf7926712019-07-07 19:23:03 +0300134 onDeleteUndoDeleteClick(){
135 this.cancelResume(this.serviceModelId);
136 this.isDeleted = !this.isDeleted;
137 this._drawingBoardHeaderService.deleteService(this.serviceModelId, this.isDeleted)
138 }
139
140 onResumeUndoResumeClick(){
141 this.cancelDelete(this.serviceModelId);
142 this.isResume = !this.isResume;
143 this._drawingBoardHeaderService.toggleResumeService(this.serviceModelId, this.isResume);
144 }
145
146 cancelDelete(serviceModelId: string) {
147 if (this.isDeleted) {
148 this.isDeleted = false;
149 this._drawingBoardHeaderService.deleteService(serviceModelId,this.isDeleted);
150 }
151 }
152
153 cancelResume(serviceModelId: string) {
154 if (this.isResume) {
155 this.isResume = false;
156 this._drawingBoardHeaderService.toggleResumeService(serviceModelId,this.isResume);
157 }
158 }
159
Ittay Stern6f900cc2018-08-29 17:01:32 +0300160 extractOwningEntityNameAccordingtoId(id:String): string {
161 let owningEntityName;
162 _.forEach(this.store.getState().service.categoryParameters.owningEntityList,(owningEntity: OwningEntity) => {
163 if (owningEntity.id === id) {
164 owningEntityName = owningEntity.name;
165
166 }});
167 return owningEntityName;
168 }
169
170 extractServiceFields(): any {
171 let instanceFields : ServiceInstance;
172 instanceFields = this.store.getState().service.serviceInstance[this.serviceModelId];
173 if (instanceFields.action === ServiceInstanceActions.Create) {
174 instanceFields.subscriberName = this.store.getState().service.subscribers.find(sub => sub.id === instanceFields.globalSubscriberId).name;
175 instanceFields.owningEntityName = this.extractOwningEntityNameAccordingtoId(instanceFields.owningEntityId);
176 }
177 return _.omit(instanceFields,'optionalGroupMembersMap');
178 }
179
180
181 public deployService(): void {
182 let instanceFields = this.extractServiceFields();
183 if (this.mode !== DrawingBoardModes.RETRY_EDIT) {
184 instanceFields.rollbackOnFailure = instanceFields.rollbackOnFailure === 'true';
185 this.msoService.submitMsoTask(instanceFields).subscribe((result) => {
186 window.parent.postMessage("navigateToInstantiationStatus", '*');
187 });
188 } else {
189 this.msoService.retryBulkMsoTask(this.jobId, instanceFields).subscribe((result) => {
190 window.parent.postMessage("navigateToInstantiationStatus", '*');
191 });
192 }
193 }
194
195 closePage() {
196 let messageBoxData : MessageBoxData = new MessageBoxData(
197 "Delete Instantiation", // modal title
198 "You are about to stop the instantiation process of this service. \nAll data will be lost. Are you sure you want to stop?",
199 SdcUiCommon.ModalType.warning,
200 SdcUiCommon.ModalSize.medium,
201 [
202 {text:"Stop Instantiation", size:"large", callback: this.navigate.bind(this), closeModal:true},
203 {text:"Cancel", size:"medium", closeModal:true}
204 ]);
205
206 MessageBoxService.openModal.next(messageBoxData);
207 }
208
209
210
211 navigate(){
212 window.parent.postMessage("navigateTo", "*");
213 }
214}