c65a8ccb760dfdd81d0d09deb0ae9c5892186b8a
[portal.git] / ecomp-portal-FE-common / client / app / views / support / contact-us / contact-us.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39
40 (function () {  
41                 
42     class ContactUsCtrl {
43         constructor($log, contactUsService, applicationsService, $modal, ngDialog, $state,$anchorScroll,$location) {  
44                 
45                 contactUsService.getContactUSPortalDetails().then(res => {
46                         // $log.info('ContactUsCtrl:: contactUsService getContactUSPortalDetails res',res);
47                 // $log.info('getting res',res);
48                 var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;
49                 //      $log.info('result',result);
50                 //      $log.info('done');
51                 var source = JSON.parse(result);
52                 //      $log.info(source); 
53                 this.ush_TicketInfoUrl = source.ush_ticket_url; 
54                 this.portalInfo_Address = source.feedback_email_address; 
55                 this.feedback_Url = source.portal_info_url;                     
56                 }).catch(err=> {
57                         $log.error('ContactUsCtrl:error:: ', err);
58             }).finally(() => {
59            });
60                 
61                 let init = () => {
62                 // $log.info('ecomp app::contact-us-controller::initializing...');
63                 this.appTable=[];
64                 this.functionalTableData=[];
65             };
66             init();     
67             
68             let updateContactUsTable = () => {
69                 contactUsService.getAppsAndContacts().then(res=> {
70                                 // $log.info('ContactUsCtrl:: contactUsService getAppsAndContacts res',res);
71                         var tableData=[];
72                         // $log.info('getting res',res);
73                         var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;
74                         // $log.info('result',result);
75                         // $log.info('done');
76                         var source = result;
77                         // $log.info(source);
78                         // Drop Portal app, empty name entries
79                         for(var i=0;i<source.length; i++) {
80                                 var dataArr = source[i];
81                                 if ( !dataArr.appName  || dataArr.appId == 1) {
82                                         continue;
83                                 }
84                         var dataTemp={
85                                 app_name: dataArr.appName,
86                                 contact_name: dataArr.contactName,
87                                 contact_email: dataArr.contactEmail,
88                                 desc: dataArr.description,
89                                 url_Info: dataArr.url,
90                                 app_Id: dataArr.appId,
91                         }
92                         tableData.push(dataTemp);
93                         }               
94                         this.appTable=tableData;
95                  }).catch(err=> {
96                                  $log.error('ContactUsCtrl.updateContactUsTable:error:: ', err);
97                          })
98             };
99             
100             contactUsService.getAppCategoryFunctions().then(res=> {
101                         // $log.info('ContactUsCtrl:: contactUsService getAppCategoryFunctionsthen res',res);
102                 var tablefunctionalData=[];
103                 // $log.info('getting res',res);
104                 var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;
105                 // $log.info('result',result);
106                 // $log.info('done');
107                 var source = result;
108                 // $log.info(source);                   
109                 for(var i=0;i<source.length; i++) {
110                         var datafunctionalArr = source[i];
111                         var datafuntionalTemp={
112                                 category: datafunctionalArr.category,
113                                 app_Name: datafunctionalArr.application,
114                                 functions: datafunctionalArr.functions,
115                                 app_Id: datafunctionalArr.appId,
116                         }
117                         tablefunctionalData.push(datafuntionalTemp);
118                 }               
119                 this.functionalTableData=tablefunctionalData;
120              }).catch(err=> {
121                          $log.error('ContactUsCtrl:error:: ', err);
122                  })
123             
124             updateContactUsTable();
125             this.editContactUsModalPopup = () => {
126                 var modalInstance = $modal.open({
127                     templateUrl: 'app/views/support/contact-us/contact-us-manage/contact-us-manage.html',
128                     controller: 'ContactUsManageController',
129                     windowClass: 'modal-docked',
130                     resolve: {
131                         message: function message() {
132                             var message = {
133                                 type: 'Contact',
134                             };
135                             return message;
136                         }
137                     }
138                 });
139                 
140                 modalInstance.result.finally(function (needUpdate) {
141                         updateContactUsTable();            
142                 });
143                     
144              };
145              
146              this.goToSection = (id) => {
147                 
148                  var targetDiv = document.getElementById(id);  
149                  
150                  var offSetHeight = 0;
151                  for(var i=0;i<this.appTable.length;i++){  
152                          if(this.appTable[i].app_Id==id)
153                                  break;
154                          if(this.appTable[i].showFlag==true){
155                                  offSetHeight+=document.getElementById('collapse'+i).clientHeight;                              
156                          }
157                  }
158                  console.log(offSetHeight);
159                  this.appTable.forEach(d => d.showFlag = false);
160                 // let index = this.appTable.findIndex(a => a.app_Id == id);
161                  var index =-1;
162                  for(var i=0; i<this.appTable.length;i++){
163                          if(this.appTable[i].app_Id==id){
164                                  index = i;
165                                  break;
166                          }
167                  }
168                  console.log(index);
169                  if (index > -1) {
170                          // setting the showFlag to true based on index comparing with the app_Id 
171                          this.appTable[index].showFlag = true;
172                          $location.hash('appId'+index);
173                       $anchorScroll();
174                 /*       $('#contentId').animate({
175                             scrollTop: targetDiv.offsetTop-offSetHeight
176                         }, 'fast');*/
177                  }                               
178                  
179              };
180              
181              // Take the user to the application on the get access page.
182              this.goGetAccess = (appName) => {
183                  // $log.debug('ContactUsCtrl::goGetAccess received name ' + appName);
184                  applicationsService.goGetAccessAppName = appName;
185                  $state.go('root.getAccess');
186              };
187              
188         }
189     }
190     ContactUsCtrl.$inject = ['$log','contactUsService', 'applicationsService', '$modal', 'ngDialog', '$state','$anchorScroll','$location'];
191     angular.module('ecompApp').controller('ContactUsCtrl', ContactUsCtrl);
192 })();