1 import {Component, ViewChild} from '@angular/core';
2 import {DialogComponent, DialogService} from 'ng2-bootstrap-modal';
3 import {ServiceModel} from '../../shared/models/serviceModel';
4 import {Constants} from '../../shared/utils/constants';
5 import {ServiceInstanceDetailsComponent} from './service-instance-details/service-instance-details.component';
6 import {ActivatedRoute} from "@angular/router";
7 import {AaiService} from "../../services/aaiService/aai.service";
8 import {Utils} from "../../utils/utils";
9 import {ServicePlanningService} from "../../services/service-planning.service";
10 import * as _ from 'lodash';
11 import {ModelInformationItem} from '../../shared/components/model-information/model-information.component';
12 import {deleteServiceInstance} from '../../service.actions';
14 import {InstancePopup} from "../instance-popup/instance-popup.components";
15 import {NgRedux} from "@angular-redux/store";
16 import {AppState} from "../../store/reducers";
17 import {ServicePopupService} from './service-popup.service';
18 import {IframeService} from "../../shared/utils/iframe.service";
20 export interface ServicePopupModel {
21 serviceModel: ServiceModel
25 selector: 'service-popup',
26 templateUrl: 'service-popup.html',
27 styleUrls: ['service-popup.scss'],
28 providers: [AaiService, ServicePopupService]
31 export class ServicePopupComponent extends DialogComponent<ServicePopupModel, boolean>
32 implements ServicePopupModel, InstancePopup{
33 @ViewChild(ServiceInstanceDetailsComponent) serviceInstanceDetails: ServiceInstanceDetailsComponent;
35 serviceModel: ServiceModel;
36 serviceModelId: string;
37 serviceInstance: any = {
38 'rollbackOnFailure' : 'false'
40 title: string = Constants.ServicePopup.TITLE;
41 dynamicInputs: any[] = null;
43 maxServiceQty:number = 50;
44 minServiceQty:number = 1;
45 servicesQty = 1; //default
46 quantityOptions = this.getQuantityOptions();
48 modelInformationItems: Array<ModelInformationItem> = [];
49 hasGeneralApiError : boolean = false;
50 parentElementClassName = 'content';
52 constructor(dialogService: DialogService, private route: ActivatedRoute, private _aaiService: AaiService,
53 private _iframeService : IframeService,
54 private _servicePlanningService: ServicePlanningService, private store: NgRedux<AppState>, private _servicePopupService : ServicePopupService) {
56 this.title = Constants.ServicePopup.TITLE;
59 updateGeneralErrorSection() : void {
60 this.hasGeneralApiError = this._servicePopupService.onControlError(this.serviceInstanceDetails, this.serviceInstanceDetails.serviceInstanceDetailsFormGroup);
67 .subscribe(params => {
68 this.serviceModelId = params['serviceModelId'];
69 if(params['isCreate']=="true") {
70 this.store.dispatch(deleteServiceInstance(this.serviceModelId));
72 this.updateServiceModelById(this.serviceModelId);
73 this.updateInstanceFromStore();
77 updateInstanceFromStore() {
79 if (_.has(this.store.getState().service.serviceInstance, this.serviceModelId)) {
80 serviceInstance = Object.assign({}, this.store.getState().service.serviceInstance[this.serviceModelId]);
83 this.serviceInstance = serviceInstance ? serviceInstance : this.serviceInstance;
84 this.servicesQty = serviceInstance ? serviceInstance.bulkSize : 1;
85 if (serviceInstance && serviceInstance.instanceParams && serviceInstance.instanceParams[0]) {
86 this.dynamicInputs = this.dynamicInputs.map(function (x) {
87 x.value = (serviceInstance.instanceParams[0][x.id]) ? serviceInstance.instanceParams[0][x.id] : x.value;
93 updateServiceModelById(serviceModelId) {
94 this._aaiService.getServiceModelById(serviceModelId).subscribe(
96 const convertedModel = Utils.convertModel(value);
97 this.serviceModel = new ServiceModel(convertedModel);
98 let displayInputs = Object.assign({},convertedModel.service.inputs);
99 this.dynamicInputs = _.isEmpty(displayInputs)? [] : this._servicePlanningService.getArbitraryInputs(displayInputs);
100 this.modelInformationItems = this.createModelInformationItems();
102 error => {console.log('error is ', error)},
103 () => {console.log('completed')}
107 createModelInformationItems() : Array<ModelInformationItem> {
109 new ModelInformationItem("Model version", "modelVersion", [this.serviceModel.version], "", true),
110 new ModelInformationItem("Description", "description", [this.serviceModel.description]),
111 new ModelInformationItem("Category", "category", [this.serviceModel.category]),
112 new ModelInformationItem("UUID", "uuid", [this.serviceModel.uuid], Constants.ServicePopup.TOOLTIP_UUID, true),
113 new ModelInformationItem("Invariant UUID", "invariantUuid", [this.serviceModel.invariantUuid], Constants.ServicePopup.TOOLTIP_INVARIANT_UUID, true),
114 new ModelInformationItem("Service type", "serviceType", [this.serviceModel.serviceType]),
115 new ModelInformationItem("Service role", "serviceRole", [this.serviceModel.serviceRole])
120 this._iframeService.removeClassCloseModal(this.parentElementClassName);
121 this.dialogService.removeDialog(this);
122 this.serviceInstance = this.serviceInstanceDetails.oldServiceInstance;
124 this._servicePopupService.resetDynamicInputs(this.serviceInstanceDetails, this.dynamicInputs);
125 // Delaying the iframe close in few milliseconds.
126 // This should workaround a problem in Selenium tests' that
127 // blocks after click because the iframe goes out before
128 // the driver understands it was clicked. Similar bug is
130 // - https://github.com/mozilla/geckodriver/issues/611
131 // - https://bugzilla.mozilla.org/show_bug.cgi?id=1223277
133 window.parent.postMessage("closeIframe", "*");
137 getModelName(): string {
138 return (this.serviceModel && this.serviceModel.name) || "";
141 getQuantityOptions(){
142 return _.range(this.minServiceQty, this.maxServiceQty + 1);