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=========================================================
22 import {DataTypesService} from "app/services/data-types-service";
23 import {PropertyModel, InputPropertyBase, Component, DataTypesMap} from "app/models";
24 import {IPropertyFormBaseViewScope, PropertyFormBaseView} from "../base-property-form/property-form-base-model";
25 import {PROPERTY_TYPES} from "app/utils/constants";
27 interface ISelectDataTypeViewModelScope extends IPropertyFormBaseViewScope {
28 selectedPropertiesName:string;
29 dataTypesService:DataTypesService;
31 isTypeDataType:boolean;
34 modelNameFilter:string;
37 export class SelectDataTypeViewModel extends PropertyFormBaseView {
47 'Sdc.Services.DataTypesService',
52 constructor(protected $scope:ISelectDataTypeViewModelScope,
53 protected $templateCache:ng.ITemplateCacheService,
54 protected $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
55 protected $injector:ng.auto.IInjectorService,
56 protected originalProperty:PropertyModel,
57 protected component:Component,
58 protected filteredProperties:Array<PropertyModel>,
59 protected DataTypesService:DataTypesService,
60 private propertiesMap:Array<InputPropertyBase>,
61 private $q:ng.IQService) {
62 super($scope, $uibModalInstance, $injector, originalProperty, component, filteredProperties, DataTypesService);
64 this.$templateCache.put("select-datatype-modal-view.html", require('app/view-models/forms/property-forms/select-datatype-modal/select-datatype-modal-view.html'));
65 this.$scope.innerViewSrcUrl = "select-datatype-modal-view.html";
66 this.$scope.modelNameFilter = this.component.model;
67 this.initChildScope();
71 save(isNeedToCloseModal):ng.IPromise<boolean> {
72 let deferred = this.$q.defer<boolean>();
73 this.$scope.property.propertiesName = this.DataTypesService.selectedPropertiesName;
74 this.$scope.property.input = this.DataTypesService.selectedInput;
75 this.$scope.property.isAlreadySelected = true;
76 this.$uibModalInstance.close(this.$scope.property);
77 deferred.resolve(true);
78 return deferred.promise;
81 private initForNotSimpleType = ():void => {
82 let property = this.$scope.property;
83 this.$scope.isTypeDataType = this.DataTypesService.isDataTypeForPropertyType(this.$scope.property);
84 if (property.type && this.$scope.simpleTypes.indexOf(property.type) == -1) {
85 if (!(property.value || property.defaultValue)) {
86 switch (property.type) {
87 case PROPERTY_TYPES.MAP:
88 this.$scope.myValue = {'': null};
90 case PROPERTY_TYPES.LIST:
91 this.$scope.myValue = [];
94 this.$scope.myValue = {};
97 this.$scope.myValue = JSON.parse(property.value || property.defaultValue);
102 //remove selection property on the modal
103 private removeSelected = ():void => {
104 this.DataTypesService.selectedPropertiesName = null;
105 this.DataTypesService.selectedInput = null;
108 private initChildScope = ():void => {
110 this.$scope.forms = {};
111 this.$scope.path = this.$scope.property.name;
112 this.$scope.isArrowsDisabled = true;
113 this.DataTypesService.alreadySelectedProperties = this.propertiesMap;
114 this.$scope.dataTypesService = this.DataTypesService;
115 this.$scope.isReadOnly = true;
116 this.initForNotSimpleType();
117 this.removeSelected();
120 public getAllDataTypesFromModel = (modelName: string): DataTypesMap => {
121 return this.DataTypesService.getAllDataTypesFromModel(modelName);