2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 /// <reference path="../../../../../references"/>
21 module Sdc.ViewModels {
23 import Dictionary = Sdc.Utils.Dictionary;
24 import InputModel = Sdc.Models.InputModel;
26 export interface IInputsViewModelScope extends IWorkspaceViewModelScope {
27 InstanceInputsProperties:Models.InstanceInputsPropertiesMapData; //this is tha map object that hold the selected inputs and the inputs we already used
28 vfInstancesList: Array<Models.ComponentsInstances.ComponentInstance>;
29 component:Models.Components.Resource;
31 onArrowPressed():void;
32 getInputPropertiesForInstance(instanceId:string, instance:Models.ComponentsInstances.ComponentInstance): ng.IPromise<boolean> ;
33 loadInputPropertiesForInstance(instanceId:string, input:Models.InputModel): ng.IPromise<boolean> ;
34 loadInputInputs(input:Models.InputModel): ng.IPromise<boolean>;
37 export class ResourceInputsViewModel {
44 constructor(private $scope:IInputsViewModelScope, private $q: ng.IQService) {
48 private initScope = (): void => {
50 this.$scope.InstanceInputsProperties = new Models.InstanceInputsPropertiesMapData();
51 this.$scope.vfInstancesList = this.$scope.component.componentInstances;
53 // Need to cast all inputs to InputModel for the search to work
54 let tmpInputs:Array<Models.InputModel> = new Array<Models.InputModel>();
55 _.each(this.$scope.component.inputs, (input):void => {
56 tmpInputs.push(new Models.InputModel(input));
58 this.$scope.component.inputs = tmpInputs;
59 // This function is not supported for resource
60 //this.$scope.component.getComponentInputs();
63 * When clicking on instance input in the left or right table, this function will load all properties of the selected input
65 this.$scope.getInputPropertiesForInstance = (instanceId:string, instance:Models.ComponentsInstances.ComponentInstance): ng.IPromise<boolean> => {
66 let deferred = this.$q.defer();
67 instance.properties = this.$scope.component.componentInstancesProperties[instanceId];
68 deferred.resolve(true);
69 return deferred.promise;
73 * When clicking on input in the right table, this function will load all inputs of the selected input
75 this.$scope.loadInputInputs = (input:Models.InputModel): ng.IPromise<boolean> => {
76 let deferred = this.$q.defer();
78 let onSuccess = () => { deferred.resolve(true); };
79 let onError = () => { deferred.resolve(false); };
82 this.$scope.component.getResourceInputInputs(input.uniqueId).then(onSuccess, onError);
84 deferred.resolve(true);
86 return deferred.promise;
90 * When clicking on instance input in the left or right table, this function will load all properties of the selected input
92 this.$scope.loadInputPropertiesForInstance = (instanceId:string, input:Models.InputModel): ng.IPromise<boolean> => {
93 let deferred = this.$q.defer();
95 let onSuccess = (properties:Array<Models.PropertyModel>) => {
96 input.properties = properties;
97 deferred.resolve(true);
100 let onError = () => {
101 deferred.resolve(false)
104 if(!input.properties) {
105 this.$scope.component.getComponentInstanceInputProperties(instanceId, input.uniqueId).then(onSuccess, onError);
107 deferred.resolve(true);
109 return deferred.promise;
113 * When pressing the arrow, we create service inputs from the inputs selected
115 this.$scope.onArrowPressed = ():void => {
116 let onSuccess = (inputsCreated: Array<Models.InputModel>) => {
118 //disabled all the inputs in the left table
119 _.forEach(this.$scope.InstanceInputsProperties, (properties:Array<Models.PropertyModel>) => {
120 _.forEach(properties, (property:Models.PropertyModel) => {
121 property.isAlreadySelected = true;
125 // Adding color to the new inputs (right table)
126 _.forEach(inputsCreated, (input) => {
130 // Removing color to the new inputs (right table)
132 _.forEach(inputsCreated, (input) => {
135 this.$scope.$apply();
139 this.$scope.component.createInputsFormInstances(this.$scope.InstanceInputsProperties).then(onSuccess);