[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / contact-us / contact-us.service.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 /**\r
21  * Created by robertlo on 10/10/2016.\r
22  */\r
23 'use strict';\r
24 \r
25 (function () {\r
26     class ContactUsService {\r
27         constructor($q, $log, $http, conf, uuid) {\r
28             this.$q = $q;\r
29             this.$log = $log;\r
30             this.$http = $http;\r
31             this.conf = conf;\r
32             this.uuid = uuid;\r
33         }\r
34         getListOfApp() {\r
35             // this.$log.info('ContactUsService::getListOfavailableApps: get all app list');\r
36             let deferred = this.$q.defer();\r
37             // this.$log.info('ContactUsService::getListOfavailableApps: ', this.conf.api.listOfApp);\r
38             this.$http({\r
39                 method: "GET",\r
40                 url: this.conf.api.availableApps,           \r
41                 cache: false\r
42             }).then( res => {\r
43                 // If response comes back as a redirected HTML page which IS NOT a success\r
44                 // this.$log.info('ContactUsService::getListOfavailableApps availableApps response: ', res);\r
45                 if (Object.keys(res).length == 0) {\r
46                     deferred.reject("ContactUsService::getListOfavailableApps: Failed"); \r
47                 } else {\r
48                     // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);\r
49                     deferred.resolve(res);\r
50                 }\r
51             }).catch( status => {\r
52                 this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);\r
53                 deferred.reject(status);\r
54             });\r
55             return deferred.promise;           \r
56         }\r
57         \r
58         getContactUs() {\r
59             let deferred = this.$q.defer();\r
60             // this.$log.info('ContactUsService::get all Contact Us list');\r
61             this.$http({\r
62                     url: this.conf.api.getContactUS,\r
63                     method: 'GET',\r
64                     cache: false,\r
65                     headers: {\r
66                         'X-ECOMP-RequestID':this.uuid.generate()\r
67                     }\r
68                 }).then(res => {\r
69                     // If response comes back as a redirected HTML page which IS NOT a success\r
70                     if (Object.keys(res.data).length == 0) {\r
71                         deferred.reject("ContactUsService::getContactUs Failed");\r
72                     } else {\r
73                         deferred.resolve(res.data);\r
74                     }\r
75                 })\r
76                 .catch(status => {\r
77                     deferred.reject(status);\r
78                 });\r
79             return deferred.promise;\r
80         }\r
81         \r
82         getAppsAndContacts() {\r
83             let deferred = this.$q.defer();\r
84             // this.$log.info('ContactUsService::getAppsAndContacts');\r
85             this.$http({\r
86                     url: this.conf.api.getAppsAndContacts,\r
87                     method: 'GET',\r
88                     cache: false,\r
89                     headers: {\r
90                         'X-ECOMP-RequestID':this.uuid.generate()\r
91                     }\r
92                 }).then(res => {\r
93                     // If response comes back as a redirected HTML page which IS NOT a success\r
94                     if (Object.keys(res.data).length == 0) {\r
95                         deferred.reject("ContactUsService::getAppsAndContacts Failed");\r
96                     } else {\r
97                         deferred.resolve(res.data);\r
98                     }\r
99                 })\r
100                 .catch(status => {\r
101                     deferred.reject(status);\r
102                 });\r
103             return deferred.promise;\r
104         }\r
105 \r
106         getContactUSPortalDetails(){\r
107                 let deferred = this.$q.defer();\r
108             // this.$log.info('ContactUsService::get all Contact Us Portal Details');\r
109             this.$http({\r
110                     url: this.conf.api.getContactUSPortalDetails,\r
111                     method: 'GET',\r
112                     cache: false,\r
113                     headers: {\r
114                         'X-ECOMP-RequestID':this.uuid.generate()\r
115                     }\r
116                 }).then(res => {\r
117                     // If response comes back as a redirected HTML page which IS NOT a success\r
118                     if (Object.keys(res.data).length == 0) {\r
119                         deferred.reject("ContactUsService::getContactUSPortalDetails Failed");\r
120                     } else {\r
121                         deferred.resolve(res.data);\r
122                     }\r
123                 })\r
124                 .catch(status => {\r
125                     deferred.reject(status);\r
126                 });\r
127             return deferred.promise;\r
128         }\r
129 \r
130         getAppCategoryFunctions(){\r
131                 let deferred = this.$q.defer();\r
132             // this.$log.info('ContactUsService::get all App Category Functions');\r
133             this.$http({\r
134                     url: this.conf.api.getAppCategoryFunctions,\r
135                     method: 'GET',\r
136                     cache: false,\r
137                     headers: {\r
138                         'X-ECOMP-RequestID':this.uuid.generate()\r
139                     }\r
140                 }).then(res => {\r
141                     // If response comes back as a redirected HTML page which IS NOT a success\r
142                     if (Object.keys(res.data).length == 0) {\r
143                         deferred.reject("ContactUsService::getAppCategoryFunctions Failed");\r
144                     } else {\r
145                         deferred.resolve(res.data);\r
146                     }\r
147                 })\r
148                 .catch(status => {\r
149                     deferred.reject(status);\r
150                 });\r
151             return deferred.promise;\r
152         }\r
153         \r
154         addContactUs(newContactUs) {\r
155                 // this.$log.info('ContactUsService::add a new Contact Us');\r
156                 // this.$log.info(newContactUs)\r
157                 let deferred = this.$q.defer();\r
158             // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));\r
159             \r
160             var contactUsObj={\r
161                         appId:newContactUs.app.value,\r
162                         appName:newContactUs.app.title,\r
163                         description:newContactUs.desc,\r
164                         contactName:newContactUs.name,\r
165                         contactEmail:newContactUs.email,\r
166                         url:newContactUs.url,                           \r
167             };\r
168             this.$http({\r
169                 url: this.conf.api.saveContactUS,\r
170                 method: 'POST',\r
171                 cache: false,\r
172                 headers: {\r
173                     'X-ECOMP-RequestID':this.uuid.generate()\r
174                 },\r
175                 data: contactUsObj\r
176             }).then(res => {\r
177                 // this.$log.info('ContactUsService:: add Contact Us res' ,res);\r
178                 // If response comes back as a redirected HTML page which IS NOT a success\r
179                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {\r
180                     deferred.reject("Add Contact Us failed");\r
181                     this.$log.error('ContactUsService:: add Contact Us failed');\r
182                 } else {\r
183                     deferred.resolve(res.data);\r
184                 }\r
185             }).catch(errRes => {\r
186                    deferred.reject(errRes);\r
187              });\r
188             return deferred.promise;\r
189         }\r
190         \r
191         modifyContactUs(contactUsObj) {\r
192                 // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);            \r
193                 let deferred = this.$q.defer();\r
194             this.$http({\r
195                 url: this.conf.api.saveContactUS,\r
196                 method: 'POST',\r
197                 cache: false,\r
198                 headers: {\r
199                     'X-ECOMP-RequestID':this.uuid.generate()\r
200                 },\r
201                 data: contactUsObj\r
202             }).then(res => {\r
203                 // this.$log.info('ContactUsService:: edit Contact Us res' ,res);\r
204                 // If response comes back as a redirected HTML page which IS NOT a success\r
205                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {\r
206                     deferred.reject("Edit Contact Us failed");\r
207                     this.$log.error('ContactUsService:: edit Contact Us failed');\r
208                 } else {\r
209                     deferred.resolve(res.data);\r
210                 }\r
211             }).catch(errRes => {\r
212                    deferred.reject(errRes);\r
213              });\r
214             return deferred.promise;\r
215         }\r
216 \r
217         removeContactUs(id) {\r
218             let deferred = this.$q.defer();\r
219             let url = this.conf.api.deleteContactUS + '/' + id;\r
220             // this.$log.info('ContactUsService:: remove Contact Us');\r
221             this.$http({\r
222                 url: url,\r
223                 method: 'POST',\r
224                 cache: false,\r
225                 data: '',\r
226                 headers: {\r
227                     'X-ECOMP-RequestID':this.uuid.generate()\r
228                 }\r
229             }).then(res => {\r
230                 // If response comes back as a redirected HTML page which IS NOT a success\r
231                 // this.$log.info("ContactUsService::removeContactUs res",res);\r
232                 deferred.resolve(res.data);\r
233                 if (Object.keys(res.data).length == 0) {\r
234                     deferred.reject("ContactUsService::removeContactUs Failed");\r
235                 } else {\r
236                     deferred.resolve(res.data);\r
237                 }\r
238             }).catch(errRes => {\r
239                 deferred.reject(errRes);\r
240             });\r
241 \r
242             return deferred.promise;\r
243         }\r
244     }\r
245     ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];\r
246     angular.module('ecompApp').service('contactUsService', ContactUsService)\r
247 })();\r