2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
40 class MicroserviceAddDetailsCtrl {
41 constructor($scope, $log, $interval, widgetsCatalogService, applicationsService, adminsService, microserviceService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies,items) {
43 $scope.ngDialogData=items;
44 let getAvailableApps = () => {
45 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
46 this.availableApps=[];
51 for(var i = 0; i < apps.length; i++) {
52 this.availableApps.push({
56 if(this.isEditMode == true && this.service.appId == apps[i].id){
57 this.service.application = this.availableApps[i];
65 let getAvailableWidgets = () => {
66 microserviceService.getWidgetListByService(this.service.id).then(widgets =>{
67 this.availableWidgets = [];
68 for(var i = 0; i < widgets.length; i++){
69 this.availableWidgets.push({
79 let getAvailableSecurityTypes = () => {
80 this.availableSecurityTypes = [];
81 this.availableSecurityTypes.push({
83 name: 'No Authentication'
85 this.availableSecurityTypes.push({
87 name: 'Basic Authentication'
89 this.availableSecurityTypes.push({
91 name: 'Cookie based Authentication'
96 $log.info('MicroserviceAddDetailsCtrl::init');
98 this.availableApps=[];
99 this.service.parameterList = [];
100 this.service.active = true;
101 this.emptyServiceName = false;
102 this.emptyServiceDesc = false;
103 this.emptyServiceURL = false;
104 this.emptyServiceApp = false;
105 this.dupliateName = false;
106 this.serviceList = $scope.ngDialogData.list;
108 if ($scope.ngDialogData && $scope.ngDialogData.service) {
110 this.isEditMode = true;
111 this.service = _.clone($scope.ngDialogData.service);
113 this.originalName = this.service.name;
114 if(this.service.active == 'Y')
115 this.service.active = true;
117 this.service.active = false;
119 this.isEditMode = false;
122 getAvailableSecurityTypes();
123 //getAvailableWidgets();
126 * 0: Basic Authentication
128 * TODO: change the structure
130 if(this.service.securityType == "No Authentication"){
131 this.service.security = this.availableSecurityTypes[0];
132 }else if(this.service.securityType == "Basic Authentication"){
133 this.service.security = this.availableSecurityTypes[1];
134 }else if(this.service.securityType == "Cookie based Authentication"){
135 this.service.security = this.availableSecurityTypes[2];
139 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
140 this.conflictMessages = {};
143 let resetConflict = fieldName => {
144 delete this.conflictMessages[fieldName];
145 if($scope.widgetForm[fieldName]){
146 $scope.widgetForm[fieldName].$setValidity('conflict', true);
150 this.addParameter = () => {
151 this.service.parameterList.push({});
154 this.closeThisDialog = () => {
155 $scope.closeThisDialog(true);
158 this.removeParamItem = (parameter) => {
159 microserviceService.getUserParameterById(parameter.id).then((res) => {
161 var message = res.length + " users have their own widget parameters. Are you sure you want to delete?";
162 confirmBoxService.editItem(message).then(isConfirmed => {
164 microserviceService.deleteUserParameterById(parameter.id).then((res) => {
165 for(var i = 0; i < this.service.parameterList.length; i++){
166 if(this.service.parameterList[i].para_key == parameter.para_key
167 && this.service.parameterList[i].para_value == parameter.para_value){
168 this.service.parameterList.splice(i, 1);
177 for(var i = 0; i < this.service.parameterList.length; i++){
178 if(this.service.parameterList[i].para_key == parameter.para_key
179 && this.service.parameterList[i].para_value == parameter.para_value){
180 this.service.parameterList.splice(i, 1);
190 this.updateServiceName = () => {
191 this.dupliateName = false;
192 for(var i = 0; i < this.serviceList.length; i++){
193 if(this.serviceList[i].name == this.service.name){
194 if(this.isEditMode && this.service.name == this.originalName)
196 this.dupliateName = true;
202 this.updateDesc = () => {
203 this.emptyServiceDesc = false;
206 this.updateURL = () => {
207 this.emptyServiceURL = false;
210 this.updateApp = () => {
211 this.emptyServiceApp = false;
214 //This is a fix for dropdown selection, due to b2b dropdown only update value field
215 $scope.$watch('microserviceAddDetails.service.application.name', (newVal, oldVal) => {
216 for(var i=0;i<$scope.microserviceAddDetails.availableApps.length;i++){
217 if($scope.microserviceAddDetails.availableApps[i].name==newVal){
218 $scope.microserviceAddDetails.service.application=angular.copy($scope.microserviceAddDetails.availableApps[i]);
222 $scope.$watch('microserviceAddDetails.service.security.name', (newVal, oldVal) => {
223 for(var i=0;i<$scope.microserviceAddDetails.availableSecurityTypes.length;i++){
224 if($scope.microserviceAddDetails.availableSecurityTypes[i].name==newVal){
225 $scope.microserviceAddDetails.service.security=angular.copy($scope.microserviceAddDetails.availableSecurityTypes[i]);
230 let emptyCookies = () => {
231 userProfileService.getUserProfile()
233 $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
234 $scope.orgUserId = profile.orgUserId;
235 $log.info('user has the following orgUserId: ' + profile.orgUserId);
236 if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {
237 $cookies.remove($scope.orgUserId + '_widget');
242 this.testServiceURL = () =>{
243 widgetsCatalogService.getServiceJSON(this.service.id).then(res => {
244 document.getElementById("microservice-details-input-json").innerHTML = (JSON.stringify(res));
248 this.saveChanges = () => {
249 /* TODO: add form validation */
252 this.updateServiceName();
254 if(this.service.name == ''
255 || this.service.name == undefined){
256 this.emptyServiceName = true;
260 if(this.dupliateName == true){
265 if(this.service.desc == ''
266 || this.service.desc == undefined){
267 this.emptyServiceDesc = true;
271 if(this.service.url == ''
272 || this.service.url == undefined){
273 this.emptyServiceURL = true;
277 if(this.service.application == undefined
278 || this.service.application == null){
279 this.emptyServiceApp = true;
287 * Check the parameter list, delete those parameters that don't
290 for(var i = 0; i < this.service.parameterList.length; i++){
291 if(this.service.parameterList[i].para_key == undefined
292 || this.service.parameterList[i].para_key == null
293 || this.service.parameterList[i].para_key == ""){
294 this.service.parameterList.splice(i, 1);
302 if(this.service.security == undefined ||
303 this.service.security == null)
304 securityType = "No Authentication";
306 securityType = this.service.security.name;
307 username = this.service.username;
308 password = this.service.password;
312 if(this.service.active == true)
316 name: this.service.name,
317 desc: this.service.desc,
318 appId: this.service.application.id,
319 url: this.service.url,
320 securityType: securityType,
324 parameterList: this.service.parameterList
328 // console.log(this.service.parameterList);
329 var message = "Are you sure you want to change '" + this.service.name + "'?"
330 confirmBoxService.editItem(message).then(isConfirmed => {
332 microserviceService.updateService(this.service.id, newService).then(() => {
333 // TODO: result validation check
334 //this.closeThisDialog();
335 $scope.$dismiss('cancel');
340 microserviceService.createService(newService).then(() => {
341 // TODO: result validation check
342 //$scope.closeThisDialog(true);
343 $scope.$dismiss('cancel');
349 $scope.$on('$stateChangeStart', e => {
354 MicroserviceAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'widgetsCatalogService', 'applicationsService', 'adminsService', 'microserviceService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies','items'];
355 angular.module('ecompApp').controller('MicroserviceAddDetailsCtrl', MicroserviceAddDetailsCtrl);