2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
22 class MicroserviceAddDetailsCtrl {
\r
23 constructor($scope, $log, $interval, widgetsCatalogService, applicationsService, adminsService, microserviceService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies) {
\r
26 let getAvailableApps = () => {
\r
27 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
\r
28 this.availableApps=[];
\r
31 name: "ECOMP Portal"
\r
33 for(var i = 0; i < apps.length; i++) {
\r
34 this.availableApps.push({
\r
38 if(this.isEditMode == true && this.service.appId == apps[i].id){
\r
39 this.service.application = this.availableApps[i];
\r
47 let getAvailableWidgets = () => {
\r
48 microserviceService.getWidgetListByService(this.service.id).then(widgets =>{
\r
49 this.availableWidgets = [];
\r
50 for(var i = 0; i < widgets.length; i++){
\r
51 this.availableWidgets.push({
\r
61 let getAvailableSecurityTypes = () => {
\r
62 this.availableSecurityTypes = [];
\r
63 this.availableSecurityTypes.push({
\r
65 name: 'No Authentication'
\r
67 this.availableSecurityTypes.push({
\r
69 name: 'Basic Authentication'
\r
71 this.availableSecurityTypes.push({
\r
73 name: 'Cookie based Authentication'
\r
78 $log.info('MicroserviceAddDetailsCtrl::init');
\r
80 this.service.parameterList = [];
\r
81 this.service.active = true;
\r
82 this.emptyServiceName = false;
\r
83 this.emptyServiceDesc = false;
\r
84 this.emptyServiceURL = false;
\r
85 this.emptyServiceApp = false;
\r
86 this.dupliateName = false;
\r
87 this.serviceList = $scope.ngDialogData.list;
\r
89 if ($scope.ngDialogData && $scope.ngDialogData.service) {
\r
91 this.isEditMode = true;
\r
92 this.service = _.clone($scope.ngDialogData.service);
\r
94 console.log(this.service);
\r
95 if(this.service.active == 'Y')
\r
96 this.service.active = true;
\r
98 this.service.active = false;
\r
100 this.isEditMode = false;
\r
102 getAvailableApps();
\r
103 getAvailableSecurityTypes();
\r
104 //getAvailableWidgets();
\r
107 * 0: Basic Authentication
\r
109 * TODO: change the structure
\r
111 if(this.service.securityType == "No Authentication"){
\r
112 this.service.security = this.availableSecurityTypes[0];
\r
113 }else if(this.service.securityType == "Basic Authentication"){
\r
114 this.service.security = this.availableSecurityTypes[1];
\r
115 }else if(this.service.securityType == "Cookie based Authentication"){
\r
116 this.service.security = this.availableSecurityTypes[2];
\r
120 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
\r
121 this.conflictMessages = {};
\r
122 this.scrollApi = {};
\r
124 let resetConflict = fieldName => {
\r
125 delete this.conflictMessages[fieldName];
\r
126 if($scope.widgetForm[fieldName]){
\r
127 $scope.widgetForm[fieldName].$setValidity('conflict', true);
\r
131 this.addParameter = () => {
\r
132 document.getElementById('microservice-scroll-end').scrollIntoView();
\r
133 this.service.parameterList.push({});
\r
136 this.closeThisDialog = () => {
\r
137 $scope.closeThisDialog(true);
\r
140 this.removeParamItem = (parameter) => {
\r
141 microserviceService.getUserParameterById(parameter.id).then((res) => {
\r
142 if(res.length > 0){
\r
143 var message = res.length + " users have their own widget parameters. Are you sure you want to delete?";
\r
144 confirmBoxService.editItem(message).then(isConfirmed => {
\r
146 microserviceService.deleteUserParameterById(parameter.id).then((res) => {
\r
147 for(var i = 0; i < this.service.parameterList.length; i++){
\r
148 if(this.service.parameterList[i].para_key == parameter.para_key
\r
149 && this.service.parameterList[i].para_value == parameter.para_value){
\r
150 this.service.parameterList.splice(i, 1);
\r
159 for(var i = 0; i < this.service.parameterList.length; i++){
\r
160 if(this.service.parameterList[i].para_key == parameter.para_key
\r
161 && this.service.parameterList[i].para_value == parameter.para_value){
\r
162 this.service.parameterList.splice(i, 1);
\r
172 this.updateServiceName = () => {
\r
173 this.dupliateName = false;
\r
174 for(var i = 0; i < this.serviceList.length; i++){
\r
175 if(this.serviceList[i].name == this.service.name){
\r
176 this.dupliateName = true;
\r
182 this.updateDesc = () => {
\r
183 this.emptyServiceDesc = false;
\r
186 this.updateURL = () => {
\r
187 this.emptyServiceURL = false;
\r
190 this.updateApp = () => {
\r
191 this.emptyServiceApp = false;
\r
194 //This is a fix for dropdown selection, due to b2b dropdown only update value field
\r
195 $scope.$watch('microserviceAddDetails.service.application.name', (newVal, oldVal) => {
\r
196 for(var i=0;i<$scope.microserviceAddDetails.availableApps.length;i++){
\r
197 if($scope.microserviceAddDetails.availableApps[i].name==newVal){
\r
198 $scope.microserviceAddDetails.service.application=angular.copy($scope.microserviceAddDetails.availableApps[i]);
\r
202 $scope.$watch('microserviceAddDetails.service.security.name', (newVal, oldVal) => {
\r
203 for(var i=0;i<$scope.microserviceAddDetails.availableSecurityTypes.length;i++){
\r
204 if($scope.microserviceAddDetails.availableSecurityTypes[i].name==newVal){
\r
205 $scope.microserviceAddDetails.service.security=angular.copy($scope.microserviceAddDetails.availableSecurityTypes[i]);
\r
210 let emptyCookies = () => {
\r
211 userProfileService.getUserProfile()
\r
213 $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
\r
214 $scope.attuid = profile.attuid;
\r
215 $log.info('user has the following attuid: ' + profile.attuid);
\r
216 if ($cookies.getObject($scope.attuid + '_widget') != undefined && $cookies.getObject($scope.attuid + '_widget') != null) {
\r
217 $cookies.remove($scope.attuid + '_widget');
\r
222 this.testServiceURL = () =>{
\r
223 //console.log(this.service.id);
\r
224 widgetsCatalogService.getServiceJSON(this.service.id).then(res => {
\r
225 document.getElementById("microservice-details-input-json").innerHTML = (JSON.stringify(res));
\r
229 this.saveChanges = () => {
\r
230 /* TODO: add form validation */
\r
232 var isValid = true;
\r
233 this.updateServiceName();
\r
235 if(this.service.name == ''
\r
236 || this.service.name == undefined){
\r
237 this.emptyServiceName = true;
\r
241 if(this.dupliateName == true
\r
242 && this.isEditMode == false){
\r
247 if(this.service.desc == ''
\r
248 || this.service.desc == undefined){
\r
249 this.emptyServiceDesc = true;
\r
253 if(this.service.url == ''
\r
254 || this.service.url == undefined){
\r
255 this.emptyServiceURL = true;
\r
259 if(this.service.application == undefined
\r
260 || this.service.application == null){
\r
261 this.emptyServiceApp = true;
\r
269 * Check the parameter list, delete those parameters that don't
\r
272 for(var i = 0; i < this.service.parameterList.length; i++){
\r
273 if(this.service.parameterList[i].para_key == undefined
\r
274 || this.service.parameterList[i].para_key == null
\r
275 || this.service.parameterList[i].para_key == ""){
\r
276 this.service.parameterList.splice(i, 1);
\r
284 if(this.service.security == undefined ||
\r
285 this.service.security == null)
\r
286 securityType = "No Authentication";
\r
288 securityType = this.service.security.name;
\r
289 username = this.service.username;
\r
290 password = this.service.password;
\r
294 if(this.service.active == true)
\r
298 name: this.service.name,
\r
299 desc: this.service.desc,
\r
300 appId: this.service.application.id,
\r
301 url: this.service.url,
\r
302 securityType: securityType,
\r
303 username: username,
\r
304 password: password,
\r
306 parameterList: this.service.parameterList
\r
309 if(this.isEditMode){
\r
310 // console.log(this.service.parameterList);
\r
311 var message = "Are you sure you want to change '" + this.service.name + "'?"
\r
312 confirmBoxService.editItem(message).then(isConfirmed => {
\r
314 microserviceService.updateService(this.service.id, newService).then(() => {
\r
315 // TODO: result validation check
\r
316 this.closeThisDialog();
\r
321 microserviceService.createService(newService).then(() => {
\r
322 // TODO: result validation check
\r
323 $scope.closeThisDialog(true);
\r
329 $scope.$on('$stateChangeStart', e => {
\r
330 e.preventDefault();
\r
334 MicroserviceAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'widgetsCatalogService', 'applicationsService', 'adminsService', 'microserviceService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies'];
\r
335 angular.module('ecompApp').controller('MicroserviceAddDetailsCtrl', MicroserviceAddDetailsCtrl);
\r