Replace ecomp references
[portal.git] / ecomp-portal-FE-common / client / app / services / contact-us / contact-us.service.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  * 
37  */
38 /**
39  * Created by robertlo on 10/10/2016.
40  */
41 'use strict';
42
43 (function () {
44     class ContactUsService {
45         constructor($q, $log, $http, conf, uuid) {
46             this.$q = $q;
47             this.$log = $log;
48             this.$http = $http;
49             this.conf = conf;
50             this.uuid = uuid;
51         }
52         getListOfApp() {
53             // this.$log.info('ContactUsService::getListOfavailableApps: get all app list');
54             let deferred = this.$q.defer();
55             // this.$log.info('ContactUsService::getListOfavailableApps: ', this.conf.api.listOfApp);
56             this.$http({
57                 method: "GET",
58                 url: this.conf.api.availableApps,           
59                 cache: false
60             }).then( res => {
61                 // If response comes back as a redirected HTML page which IS NOT a success
62                 // this.$log.info('ContactUsService::getListOfavailableApps availableApps response: ', res);
63                 if (Object.keys(res).length == 0) {
64                     deferred.reject("ContactUsService::getListOfavailableApps: Failed"); 
65                 } else {
66                     // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);
67                     deferred.resolve(res);
68                 }
69             }).catch( status => {
70                 this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);
71                 deferred.reject(status);
72             });
73             return deferred.promise;           
74         }
75         
76         getContactUs() {
77             let deferred = this.$q.defer();
78             // this.$log.info('ContactUsService::get all Contact Us list');
79             this.$http({
80                     url: this.conf.api.getContactUS,
81                     method: 'GET',
82                     cache: false,
83                     headers: {
84                         'X-ECOMP-RequestID':this.uuid.generate()
85                     }
86                 }).then(res => {
87                     // If response comes back as a redirected HTML page which IS NOT a success
88                     if (Object.keys(res.data).length == 0) {
89                         deferred.reject("ContactUsService::getContactUs Failed");
90                     } else {
91                         deferred.resolve(res.data);
92                     }
93                 })
94                 .catch(status => {
95                     deferred.reject(status);
96                 });
97             return deferred.promise;
98         }
99         
100         getAppsAndContacts() {
101             let deferred = this.$q.defer();
102             // this.$log.info('ContactUsService::getAppsAndContacts');
103             this.$http({
104                     url: this.conf.api.getAppsAndContacts,
105                     method: 'GET',
106                     cache: false,
107                     headers: {
108                         'X-ECOMP-RequestID':this.uuid.generate()
109                     }
110                 }).then(res => {
111                     // If response comes back as a redirected HTML page which IS NOT a success
112                     if (Object.keys(res.data).length == 0) {
113                         deferred.reject("ContactUsService::getAppsAndContacts Failed");
114                     } else {
115                         deferred.resolve(res.data);
116                     }
117                 })
118                 .catch(status => {
119                     deferred.reject(status);
120                 });
121             return deferred.promise;
122         }
123
124         getContactUSPortalDetails(){
125                 let deferred = this.$q.defer();
126             // this.$log.info('ContactUsService::get all Contact Us Portal Details');
127             this.$http({
128                     url: this.conf.api.getContactUSPortalDetails,
129                     method: 'GET',
130                     cache: false,
131                     headers: {
132                         'X-ECOMP-RequestID':this.uuid.generate()
133                     }
134                 }).then(res => {
135                     // If response comes back as a redirected HTML page which IS NOT a success
136                     if (Object.keys(res.data).length == 0) {
137                         deferred.reject("ContactUsService::getContactUSPortalDetails Failed");
138                     } else {
139                         deferred.resolve(res.data);
140                     }
141                 })
142                 .catch(status => {
143                     deferred.reject(status);
144                 });
145             return deferred.promise;
146         }
147
148         getAppCategoryFunctions(){
149                 let deferred = this.$q.defer();
150             // this.$log.info('ContactUsService::get all App Category Functions');
151             this.$http({
152                     url: this.conf.api.getAppCategoryFunctions,
153                     method: 'GET',
154                     cache: false,
155                     headers: {
156                         'X-ECOMP-RequestID':this.uuid.generate()
157                     }
158                 }).then(res => {
159                     // If response comes back as a redirected HTML page which IS NOT a success
160                     if (Object.keys(res.data).length == 0) {
161                         deferred.reject("ContactUsService::getAppCategoryFunctions Failed");
162                     } else {
163                         deferred.resolve(res.data);
164                     }
165                 })
166                 .catch(status => {
167                     deferred.reject(status);
168                 });
169             return deferred.promise;
170         }
171         
172         addContactUs(newContactUs) {
173                 // this.$log.info('ContactUsService::add a new Contact Us');
174                 // this.$log.info(newContactUs)
175                 let deferred = this.$q.defer();
176             // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
177             
178             var contactUsObj={
179                         appId:newContactUs.app.value,
180                         appName:newContactUs.app.title,
181                         description:newContactUs.desc,
182                         contactName:newContactUs.name,
183                         contactEmail:newContactUs.email,
184                         url:newContactUs.url,                           
185             };
186             this.$http({
187                 url: this.conf.api.saveContactUS,
188                 method: 'POST',
189                 cache: false,
190                 headers: {
191                     'X-ECOMP-RequestID':this.uuid.generate()
192                 },
193                 data: contactUsObj
194             }).then(res => {
195                 // this.$log.info('ContactUsService:: add Contact Us res' ,res);
196                 // If response comes back as a redirected HTML page which IS NOT a success
197                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
198                     deferred.reject("Add Contact Us failed");
199                     this.$log.error('ContactUsService:: add Contact Us failed');
200                 } else {
201                     deferred.resolve(res.data);
202                 }
203             }).catch(errRes => {
204                    deferred.reject(errRes);
205              });
206             return deferred.promise;
207         }
208         
209         modifyContactUs(contactUsObj) {
210                 // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);            
211                 let deferred = this.$q.defer();
212             this.$http({
213                 url: this.conf.api.saveContactUS,
214                 method: 'POST',
215                 cache: false,
216                 headers: {
217                     'X-ECOMP-RequestID':this.uuid.generate()
218                 },
219                 data: contactUsObj
220             }).then(res => {
221                 // this.$log.info('ContactUsService:: edit Contact Us res' ,res);
222                 // If response comes back as a redirected HTML page which IS NOT a success
223                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
224                     deferred.reject("Edit Contact Us failed");
225                     this.$log.error('ContactUsService:: edit Contact Us failed');
226                 } else {
227                     deferred.resolve(res.data);
228                 }
229             }).catch(errRes => {
230                    deferred.reject(errRes);
231              });
232             return deferred.promise;
233         }
234
235         removeContactUs(id) {
236             let deferred = this.$q.defer();
237             let url = this.conf.api.deleteContactUS + '/' + id;
238             // this.$log.info('ContactUsService:: remove Contact Us');
239             this.$http({
240                 url: url,
241                 method: 'POST',
242                 cache: false,
243                 data: '',
244                 headers: {
245                     'X-ECOMP-RequestID':this.uuid.generate()
246                 }
247             }).then(res => {
248                 // If response comes back as a redirected HTML page which IS NOT a success
249                 // this.$log.info("ContactUsService::removeContactUs res",res);
250                 deferred.resolve(res.data);
251                 if (Object.keys(res.data).length == 0) {
252                     deferred.reject("ContactUsService::removeContactUs Failed");
253                 } else {
254                     deferred.resolve(res.data);
255                 }
256             }).catch(errRes => {
257                 deferred.reject(errRes);
258             });
259
260             return deferred.promise;
261         }
262     }
263     ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
264     angular.module('ecompApp').service('contactUsService', ContactUsService)
265 })();