2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
18 import {ICompositionViewModelScope} from "../../composition-view-model";
19 import {Service, PropertiesGroup, InputsGroup, ServiceInstanceObject, InterfaceModel, InputBEModel} from 'app/models';
20 import {ComponentGenericResponse} from "app/ng2/services/responses/component-generic-response";
21 import {ServiceServiceNg2} from "app/ng2/services/component-services/service.service";
23 interface IServiceConsumptionViewModelScope extends ICompositionViewModelScope {
25 instancesMappedList: Array<ServiceInstanceObject>;
26 componentInstancesProperties: PropertiesGroup;
27 componentInstancesInputs: InputsGroup;
28 componentInstancesInterfaces: Map<string, Array<InterfaceModel>>;
29 componentInputs: Array<InputBEModel>;
33 export class ServiceConsumptionViewModel {
40 constructor(private $scope:IServiceConsumptionViewModelScope, private ServiceServiceNg2:ServiceServiceNg2) {
41 this.$scope.service = <Service>this.$scope.currentComponent;
46 private initInstances = ():void => {
47 this.ServiceServiceNg2.getServiceConsumptionData(this.$scope.service).subscribe((genericResponse:ComponentGenericResponse) => {
48 this.$scope.componentInstancesProperties = genericResponse.componentInstancesProperties;
49 this.$scope.componentInstancesInputs = genericResponse.componentInstancesInputs;
50 this.$scope.componentInstancesInterfaces = genericResponse.componentInstancesInterfaces;
51 this.$scope.componentInputs = genericResponse.inputs;
52 this.updateInstanceAttributes();
56 private updateInstanceAttributes = ():void => {
57 if (this.$scope.isComponentInstanceSelected() && this.$scope.componentInstancesProperties) {
58 this.$scope.instancesMappedList = this.$scope.service.componentInstances.map(coInstance => new ServiceInstanceObject({
59 id: coInstance.uniqueId,
60 name: coInstance.name,
61 properties: this.$scope.componentInstancesProperties[coInstance.uniqueId] || [],
62 inputs: this.$scope.componentInstancesInputs[coInstance.uniqueId] || [],
63 interfaces: this.$scope.componentInstancesInterfaces[coInstance.uniqueId] || []
68 private initScope = ():void => {
69 this.$scope.$watch('currentComponent.selectedInstance', ():void => {
70 this.updateInstanceAttributes();
73 this.$scope.registerCreateInstanceEvent(() => {
77 this.$scope.$on('$destroy', this.$scope.unregisterCreateInstanceEvent);