Merge "Invalid ApplicationExceptionTest"
[portal.git] / portal-FE-common / src / app / pages / contact-us / contact-us.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 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  * 
37  */
38
39 import { Component, OnInit, ViewChild, Input } from '@angular/core';
40 import { MatTableDataSource } from '@angular/material';
41 import { MatSort, MatPaginator } from '@angular/material';
42 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
43 import { ContactUsService } from '../../shared/services/index';
44 import { ContactUsManageComponent } from './contact-us-manage/contact-us-manage.component';
45
46 @Component({
47   selector: 'app-contact-us',
48   templateUrl: './contact-us.component.html',
49   styleUrls: ['./contact-us.component.scss']
50 })
51 export class ContactUsComponent implements OnInit {
52
53   contactUsList: Array<Object> = [];
54   appTable: Array<Object> = [];
55   functionalTableData: Array<Object> = [];
56
57   ush_TicketInfoUrl: string;
58   portalInfo_Address: string;
59   feedback_Url: string;
60   showUp: boolean = true;
61   showDown: boolean = false;
62
63   result: any;
64   isEditMode: boolean = false;
65   displayedColumns: string[] = ['category', 'eCOMPFunctions','eCOMPApplications'];
66   dataSource = new MatTableDataSource(this.functionalTableData);
67   @ViewChild(MatSort) sort: MatSort;
68   @ViewChild(MatPaginator) paginator: MatPaginator;
69
70   constructor(public contactUsService: ContactUsService, public ngbModal: NgbModal) { }
71
72   ngOnInit() {
73     this.appTable=[];
74     this.functionalTableData=[];
75
76     this.getContactUSPortalDetails();
77     this.updateContactUsTable();
78     this.getAppCategoryFunctions()
79   }
80
81   getContactUSPortalDetails(){
82     console.log("getContactUSPortalDetails called...");
83     this.contactUsService.getContactUSPortalDetails()
84       .subscribe( _data => {
85         this.result = _data;
86         console.log("getContactUSPortalDetails Data :: ", _data);
87         if (this.result.response == null || this.result.response == 'undefined') {
88             console.log('ContactUsService::getContactUSPortalDetails Failed: Result or result.data is null');
89         }else{
90           var source = JSON.parse(this.result.response);
91           this.ush_TicketInfoUrl = source.ush_ticket_url; 
92           this.portalInfo_Address = source.feedback_email_address; 
93           this.feedback_Url = source.portal_info_url;
94         }
95       },error =>{
96         console.log(error);
97     });
98   }
99
100   updateContactUsTable(){
101     console.log("updateContactUsTable called...");
102     this.contactUsService.getAppsAndContacts()
103       .subscribe( _data => {
104         this.result = _data;
105         console.log("getAppsAndContacts Data :: ", _data);
106         if (this.result.response == null || this.result.response == 'undefined') {
107             console.log('ContactUsService::getAppsAndContacts Failed: Result or result.data is null');
108         }else{
109           var tableData=[];
110           var source = this.result.response;
111           for(var i=0; i<source.length; i++) {
112             var dataArr = source[i];
113             if ( !dataArr.appName  || dataArr.appId == 1) {
114               continue;
115             }
116
117             var dataTemp={
118               app_name: dataArr.appName,
119               contact_name: dataArr.contactName,
120               contact_email: dataArr.contactEmail,
121               desc: dataArr.description,
122               url_Info: dataArr.url,
123               app_Id: dataArr.appId,
124             }
125             
126             tableData.push(dataTemp);
127           }   
128
129           this.appTable=tableData;
130         }
131       },error =>{
132         console.log(error);
133     });
134   }
135
136   getAppCategoryFunctions(){
137     console.log("getAppCategoryFunctions called");
138     this.contactUsService.getAppCategoryFunctions()
139       .subscribe( _data => {
140         this.result = _data;
141         console.log("getAppCategoryFunctions Data :: ", _data);
142         if (this.result.response == null || this.result.response == 'undefined') {
143             console.log('ContactUsService::getAppCategoryFunctions Failed: Result or result.data is null');
144         }else{
145             var tablefunctionalData=[];
146             var source = this.result.response;
147             for(var i=0;i<source.length; i++) {
148               var datafunctionalArr = source[i];
149                 var datafuntionalTemp={
150                   category: datafunctionalArr.category,
151                   app_Name: datafunctionalArr.application,
152                   functions: datafunctionalArr.functions,
153                   app_Id: datafunctionalArr.appId,
154                 }
155                 tablefunctionalData.push(datafuntionalTemp);
156             }                   
157             this.functionalTableData = tablefunctionalData;
158             this.populateTableData(this.functionalTableData);
159         }
160       },error =>{
161         console.log(error);
162     });
163   }
164
165   populateTableData(functionalTableData: Array<Object>){
166     this.dataSource = new MatTableDataSource(functionalTableData);
167     this.dataSource.sort = this.sort;
168     this.dataSource.paginator = this.paginator;
169   }
170
171   editContactUsModal() {
172     const modalRef = this.ngbModal.open(ContactUsManageComponent, { size: 'lg' });
173   }
174
175   showApplicationInfo(appId: any){
176     console.log("AppId Contact US...",appId);
177     let appInfoDiv = document.getElementById('collapse'+appId);
178     let uparrowDiv = document.getElementById('arrowup'+appId);
179     let downarrowDiv = document.getElementById('arrowdown'+appId);
180
181     if(!appInfoDiv.getAttribute('hidden')){
182       appInfoDiv.setAttribute("hidden","true");
183       uparrowDiv.setAttribute("hidden", "true");
184       downarrowDiv.removeAttribute("hidden");
185     }else if(appInfoDiv.getAttribute('hidden')){
186       appInfoDiv.removeAttribute("hidden");
187       uparrowDiv.removeAttribute("hidden");
188       downarrowDiv.setAttribute("hidden","true");
189     }
190   }
191
192   goGetAccess(app_name: any){
193     console.log("Get Access :: goGetAccess method implemetation is pending... appName : ",app_name);
194   }
195
196 }