Merge "InvalidRoleException-junits"
[portal.git] / portal-FE-common / src / app / pages / contact-us / contact-us-manage / contact-us-manage.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, Input} from '@angular/core';
40 import { ContactUsService } from '../../../shared/services/index';
41 import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
42
43 @Component({
44   selector: 'app-contact-us-manage',
45   templateUrl: './contact-us-manage.component.html',
46   styleUrls: ['./contact-us-manage.component.scss']
47 })
48 export class ContactUsManageComponent implements OnInit {
49
50   contactUsList = [];
51   contactUsAllAppList = [];
52   result: any;
53   selectedApp: any;
54   showEdit: boolean = false;
55   newContactUs ={
56     appId:'',
57     appName:'',
58     description:'',
59     contactName:'',
60     contactEmail:'',
61     url:'' ,
62     activeYN:''                         
63  };
64   
65
66   constructor(public activeModal: NgbActiveModal, public ngbModal: NgbModal, public contactUsService: ContactUsService) { }
67
68   ngOnInit() {
69
70     this.getContactUsList();
71     this.getListOfApp();
72   }
73
74   getContactUsList(){
75     console.log("getContactUsList called...");
76     this.contactUsService.getContactUs()
77       .subscribe( _data => {
78         this.result = _data;
79         console.log("getContactUsList Data :: ", _data);
80         if (this.result.response == null || this.result.response == 'undefined') {
81             console.log('ContactUsService::getContactUsList Failed: Result or result.data is null');
82         }else{
83           for(var i=0; i<this.result.response.length;i++){
84             if(this.result.response[i].appId!=1)
85               this.contactUsList.push(this.result.response[i]);
86           }
87         }
88       },error =>{
89         console.log(error);
90     });
91   }
92
93   getListOfApp(){
94     console.log("getListOfApp called...");
95     this.contactUsService.getListOfApp()
96       .subscribe( _data => {
97         this.result = _data;
98         console.log("getListOfApp Data :: ", _data);
99         if (this.result == null || this.result == 'undefined') {
100             console.log('ContactUsService::getListOfApp Failed: Result or result.data is null');
101         }else{
102           let res1 = this.result;
103           let realAppIndex = 0;
104           this.contactUsAllAppList.length=0;
105           console.log("this.contactUsList ",this.contactUsList)
106           for (var i = 1; i <= res1.length; i++) {
107               if (!res1[i - 1].restrictedApp) {
108                 var okToAdd = true;
109                 for(var j =0; j<this.contactUsList.length;j++){
110                   if(res1[i - 1].title == this.contactUsList[j].appName){
111                     okToAdd=false;
112                     console.log("okToAdd=false res1[i - 1].title ",res1[i - 1].title);
113                   }
114                 }
115                 // not allowed to add(duplicate) another entry if the app is already available in the table
116                 if(okToAdd){
117                   if(res1[i - 1].title){
118                     this.contactUsAllAppList.push({
119                         index: realAppIndex,
120                         title: res1[i - 1].title,
121                         value: res1[i - 1].index
122                     });
123                   }       
124                   realAppIndex = realAppIndex + 1;
125                 }         
126               }
127           }
128         }
129       },error =>{
130         console.log(error);
131     });
132   }
133
134   addNewContactUs(){
135     console.log("Calling addNewContactUs");
136     let selectedApplication = this.selectedApp;
137     this.newContactUs.appId = selectedApplication.value;
138     this.newContactUs.appName = selectedApplication.title;
139     console.log("newContactUsObj ",this.newContactUs);
140     this.contactUsService.addContactUs(this.newContactUs)
141       .subscribe( _data => {
142         this.result = _data;
143         console.log("addContactUs response :: ", _data);
144         this.contactUsList.push(this.newContactUs);
145       },error =>{
146         console.log(error);
147     });
148   }
149
150   editContactUs(contactObj: any){
151
152     var contactUsObj={
153       appId:contactObj.appId,
154       appName:contactObj.appName,
155       description:contactObj.description,
156       contactName:contactObj.contactName,
157       contactEmail:contactObj.contactEmail,
158       url:contactObj.url,                       
159     };
160
161     this.contactUsService.modifyContactUs(contactUsObj)
162       .subscribe( _data => {
163         this.result = _data;
164         console.log("editContactUsFun response :: ", _data);
165         this.showEdit=false;
166       },error =>{
167         console.log(error);
168     });
169   }
170
171   delContactUs(appObj: any){
172       this.contactUsService.removeContactUs(appObj.appId)
173       .subscribe( _data => {
174         this.result = _data;
175         console.log("delContactUsFun response :: ", _data);
176         this.contactUsList.splice(appObj, 1);
177       },error =>{
178         console.log(error);
179       });
180   }
181
182 }