nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / dashboard / dashboard.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 /**
21  * Created by robertlo on 09/26/2016.
22  */
23 'use strict';
24
25 (function () {
26     class DashboardService {
27         constructor($q, $log, $http, conf, uuid) {
28             this.$q = $q;
29             this.$log = $log;
30             this.$http = $http;
31             this.conf = conf;
32             this.dashboardService = null;
33             this.uuid = uuid;
34         }
35
36         getCommonWidgetData(widgetType) {
37             // this.$log.info('ecomp::dashboard-service::getting news data');
38             let deferred = this.$q.defer();
39             let url = this.conf.api.commonWidget + '?resourceType=' + widgetType;
40                  
41             this.$http({
42                     method: "GET",
43                     url: url,
44                     cache: false,
45                     headers: {
46                         'X-ECOMP-RequestID':this.uuid.generate()
47                     }
48                 })
49                 .then( res => {
50                          // this.$log.info('ecomp::dashboard-service::getting news data',res);
51                     // If response comes back as a redirected HTML page which IS NOT a success
52                     if (Object.keys(res.data).length == 0 || Object.keys(res.data.response) ==null || Object.keys(res.data.response.items) ==null) {
53                         deferred.reject("ecomp::dashboard-service::getNewsData Failed");
54                     } else {
55                         this.userProfile = res.data;
56                         // this.$log.info('ecomp::dashboard-service::getNewsData Succeeded');
57                         deferred.resolve(res.data);
58                     }
59                 })
60                 .catch( status => {
61                     deferred.reject(status);
62                 });
63             return deferred.promise;
64         }
65         
66         saveCommonWidgetData(newData){
67             let deferred = this.$q.defer();
68             //this.$log.info('ecomp::dashboard-service::saveCommonWidgetData');
69             //this.$log.debug('ecomp::dashboard-service::saveCommonWidgetData with:', newData);
70
71             this.$http({
72                 method: "POST",
73                 url: this.conf.api.commonWidget,
74                 data: newData,
75                 cache: false,
76                 headers: {
77                     'X-ECOMP-RequestID':this.uuid.generate()
78                 }
79             }).then( res => {
80                     // If response comes back as a redirected HTML page which IS NOT a success
81                         // this.$log.info(res.data);
82                     if (Object.keys(res.data).length == 0) {
83                         deferred.reject("ecomp::dashboard-service::saveCommonWidgetData Failed");
84                     } else {
85                         // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
86                         deferred.resolve(res.data);
87                     }
88                 })
89                 .catch( status => {
90                     deferred.reject(status);
91                 });
92             return deferred.promise;
93         }
94         
95         
96         
97         removeCommonWidgetData(widgetToRemove){
98             let deferred = this.$q.defer();
99             // this.$log.info('ecomp::dashboard-service::removeCommonWidgetData');
100             // this.$log.debug('ecomp::dashboard-service::removeCommonWidgetData with:', widgetToRemove);
101             this.$http({
102                 method: "POST",
103                 url: this.conf.api.deleteCommonWidget,
104                 data: widgetToRemove,
105                 cache: false,
106                 headers: {
107                     'X-ECOMP-RequestID':this.uuid.generate()
108                 }
109             }).then( res => {
110                     // If response comes back as a redirected HTML page which IS NOT a success
111                         // this.$log.info(res.data);
112                     if (Object.keys(res.data).length == 0) {
113                         deferred.reject("ecomp::dashboard-service::saveCommonWidgetData Failed");
114                     } else {
115                         // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
116                         deferred.resolve(res.data);
117                     }
118                 })
119                 .catch( status => {
120                     deferred.reject(status);
121                 });
122             return deferred.promise;
123         }
124
125         getSearchAllByStringResults(searchStr) {
126                 // this.$log.info('ecomp::getSearchAllByStringResults::getting search by string results');
127             let deferred = this.$q.defer();
128             let url = this.conf.api.getSearchAllByStringResults;
129             
130             this.$http({
131                     method: "GET",
132                     url : url,
133                     params : {
134                         'searchString' : searchStr
135                     },
136                     cache: false,
137                     headers: {
138                         'X-ECOMP-RequestID':this.uuid.generate()
139                     }
140                 }).then( res => {
141                     // If response comes back as a redirected HTML page which IS NOT a success
142                     if (Object.keys(res.data).length == 0) {
143                         deferred.reject("ecomp::dashboard-service::getSearchAllByStringResults Failed");
144                     } else {
145                         //this.searchResults = res.data;
146                         // this.$log.info('ecomp::dashboard-service::getSearchAllByStringResults Succeeded');
147                         deferred.resolve(res.data.response);
148                     }
149                 }).catch( status => {
150                     this.$log.error('ecomp::getSearchAllByStringResults error');
151                     deferred.reject(status);
152                 });
153             return deferred.promise;
154                 
155         }
156         
157         getOnlineUserUpdateRate() {
158             let deferred = this.$q.defer();
159             let url = this.conf.api.onlineUserUpdateRate;
160             this.$http({
161                     method: "GET",
162                     url: url,
163                     cache: false,
164                     headers: {
165                         'X-ECOMP-RequestID':this.uuid.generate()
166                     }
167                 }).then( res => {
168                     // If response comes back as a redirected HTML page which IS NOT a success
169                         if (Object.keys(res.data).length == 0) {
170                         deferred.reject("ecomp::dashboard-service::getOnlineUserUpdateRate Failed");
171                     } else {
172                         this.$log.info('ecomp::dashboard-service::getOnlineUserUpdateRate Succeeded',res);
173                         deferred.resolve(res.data);
174                     }
175                 }).catch( status => {
176                     deferred.reject(status);
177                 });
178             return deferred.promise;
179         }
180     
181     }
182     
183     DashboardService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
184     angular.module('ecompApp').service('dashboardService', DashboardService)
185 })();