2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
22 class MicroserviceAddDetailsCtrl {
23 constructor($scope, $log, $interval, widgetsCatalogService, applicationsService, adminsService, microserviceService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies) {
26 let getAvailableApps = () => {
27 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
28 this.availableApps=[];
33 for(var i = 0; i < apps.length; i++) {
34 this.availableApps.push({
38 if(this.isEditMode == true && this.service.appId == apps[i].id){
39 this.service.application = this.availableApps[i];
47 let getAvailableWidgets = () => {
48 microserviceService.getWidgetListByService(this.service.id).then(widgets =>{
49 this.availableWidgets = [];
50 for(var i = 0; i < widgets.length; i++){
51 this.availableWidgets.push({
61 let getAvailableSecurityTypes = () => {
62 this.availableSecurityTypes = [];
63 this.availableSecurityTypes.push({
65 name: 'No Authentication'
67 this.availableSecurityTypes.push({
69 name: 'Basic Authentication'
71 this.availableSecurityTypes.push({
73 name: 'Cookie based Authentication'
78 $log.info('MicroserviceAddDetailsCtrl::init');
80 this.availableApps=[];
81 this.service.parameterList = [];
82 this.service.active = true;
83 this.emptyServiceName = false;
84 this.emptyServiceDesc = false;
85 this.emptyServiceURL = false;
86 this.emptyServiceApp = false;
87 this.dupliateName = false;
88 this.serviceList = $scope.ngDialogData.list;
90 if ($scope.ngDialogData && $scope.ngDialogData.service) {
92 this.isEditMode = true;
93 this.service = _.clone($scope.ngDialogData.service);
95 this.originalName = this.service.name;
96 if(this.service.active == 'Y')
97 this.service.active = true;
99 this.service.active = false;
101 this.isEditMode = false;
104 getAvailableSecurityTypes();
105 //getAvailableWidgets();
108 * 0: Basic Authentication
110 * TODO: change the structure
112 if(this.service.securityType == "No Authentication"){
113 this.service.security = this.availableSecurityTypes[0];
114 }else if(this.service.securityType == "Basic Authentication"){
115 this.service.security = this.availableSecurityTypes[1];
116 }else if(this.service.securityType == "Cookie based Authentication"){
117 this.service.security = this.availableSecurityTypes[2];
121 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
122 this.conflictMessages = {};
125 let resetConflict = fieldName => {
126 delete this.conflictMessages[fieldName];
127 if($scope.widgetForm[fieldName]){
128 $scope.widgetForm[fieldName].$setValidity('conflict', true);
132 this.addParameter = () => {
133 document.getElementById('microservice-scroll-end').scrollIntoView();
134 this.service.parameterList.push({});
137 this.closeThisDialog = () => {
138 $scope.closeThisDialog(true);
141 this.removeParamItem = (parameter) => {
142 microserviceService.getUserParameterById(parameter.id).then((res) => {
144 var message = res.length + " users have their own widget parameters. Are you sure you want to delete?";
145 confirmBoxService.editItem(message).then(isConfirmed => {
147 microserviceService.deleteUserParameterById(parameter.id).then((res) => {
148 for(var i = 0; i < this.service.parameterList.length; i++){
149 if(this.service.parameterList[i].para_key == parameter.para_key
150 && this.service.parameterList[i].para_value == parameter.para_value){
151 this.service.parameterList.splice(i, 1);
160 for(var i = 0; i < this.service.parameterList.length; i++){
161 if(this.service.parameterList[i].para_key == parameter.para_key
162 && this.service.parameterList[i].para_value == parameter.para_value){
163 this.service.parameterList.splice(i, 1);
173 this.updateServiceName = () => {
174 this.dupliateName = false;
175 for(var i = 0; i < this.serviceList.length; i++){
176 if(this.serviceList[i].name == this.service.name){
177 if(this.isEditMode && this.service.name == this.originalName)
179 this.dupliateName = true;
185 this.updateDesc = () => {
186 this.emptyServiceDesc = false;
189 this.updateURL = () => {
190 this.emptyServiceURL = false;
193 this.updateApp = () => {
194 this.emptyServiceApp = false;
197 //This is a fix for dropdown selection, due to b2b dropdown only update value field
198 $scope.$watch('microserviceAddDetails.service.application.name', (newVal, oldVal) => {
199 for(var i=0;i<$scope.microserviceAddDetails.availableApps.length;i++){
200 if($scope.microserviceAddDetails.availableApps[i].name==newVal){
201 $scope.microserviceAddDetails.service.application=angular.copy($scope.microserviceAddDetails.availableApps[i]);
205 $scope.$watch('microserviceAddDetails.service.security.name', (newVal, oldVal) => {
206 for(var i=0;i<$scope.microserviceAddDetails.availableSecurityTypes.length;i++){
207 if($scope.microserviceAddDetails.availableSecurityTypes[i].name==newVal){
208 $scope.microserviceAddDetails.service.security=angular.copy($scope.microserviceAddDetails.availableSecurityTypes[i]);
213 let emptyCookies = () => {
214 userProfileService.getUserProfile()
216 $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
217 $scope.attuid = profile.attuid;
218 $log.info('user has the following attuid: ' + profile.attuid);
219 if ($cookies.getObject($scope.attuid + '_widget') != undefined && $cookies.getObject($scope.attuid + '_widget') != null) {
220 $cookies.remove($scope.attuid + '_widget');
225 this.testServiceURL = () =>{
226 widgetsCatalogService.getServiceJSON(this.service.id).then(res => {
227 document.getElementById("microservice-details-input-json").innerHTML = (JSON.stringify(res));
231 this.saveChanges = () => {
232 /* TODO: add form validation */
235 this.updateServiceName();
237 if(this.service.name == ''
238 || this.service.name == undefined){
239 this.emptyServiceName = true;
243 if(this.dupliateName == true){
248 if(this.service.desc == ''
249 || this.service.desc == undefined){
250 this.emptyServiceDesc = true;
254 if(this.service.url == ''
255 || this.service.url == undefined){
256 this.emptyServiceURL = true;
260 if(this.service.application == undefined
261 || this.service.application == null){
262 this.emptyServiceApp = true;
270 * Check the parameter list, delete those parameters that don't
273 for(var i = 0; i < this.service.parameterList.length; i++){
274 if(this.service.parameterList[i].para_key == undefined
275 || this.service.parameterList[i].para_key == null
276 || this.service.parameterList[i].para_key == ""){
277 this.service.parameterList.splice(i, 1);
285 if(this.service.security == undefined ||
286 this.service.security == null)
287 securityType = "No Authentication";
289 securityType = this.service.security.name;
290 username = this.service.username;
291 password = this.service.password;
295 if(this.service.active == true)
299 name: this.service.name,
300 desc: this.service.desc,
301 appId: this.service.application.id,
302 url: this.service.url,
303 securityType: securityType,
307 parameterList: this.service.parameterList
311 // console.log(this.service.parameterList);
312 var message = "Are you sure you want to change '" + this.service.name + "'?"
313 confirmBoxService.editItem(message).then(isConfirmed => {
315 microserviceService.updateService(this.service.id, newService).then(() => {
316 // TODO: result validation check
317 this.closeThisDialog();
322 microserviceService.createService(newService).then(() => {
323 // TODO: result validation check
324 $scope.closeThisDialog(true);
330 $scope.$on('$stateChangeStart', e => {
335 MicroserviceAddDetailsCtrl.$inject = ['$scope', '$log', '$interval', 'widgetsCatalogService', 'applicationsService', 'adminsService', 'microserviceService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies'];
336 angular.module('ecompApp').controller('MicroserviceAddDetailsCtrl', MicroserviceAddDetailsCtrl);