2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
39 * Created by robertlo on 09/26/2016.
44 class DashboardService {
45 constructor($q, $log, $http, conf, uuid) {
50 this.dashboardService = null;
54 getCommonWidgetData(widgetType) {
55 // this.$log.info('ecomp::dashboard-service::getting news data');
56 let deferred = this.$q.defer();
57 let url = this.conf.api.commonWidget + '?resourceType=' + widgetType;
64 'X-ECOMP-RequestID':this.uuid.generate()
68 // this.$log.info('ecomp::dashboard-service::getting news data',res);
69 // If response comes back as a redirected HTML page which IS NOT a success
70 if (Object.keys(res.data).length == 0 || Object.keys(res.data.response) ==null || Object.keys(res.data.response.items) ==null) {
71 deferred.reject("ecomp::dashboard-service::getNewsData Failed");
73 this.userProfile = res.data;
74 // this.$log.info('ecomp::dashboard-service::getNewsData Succeeded');
75 deferred.resolve(res.data);
79 deferred.reject(status);
81 return deferred.promise;
84 saveCommonWidgetData(newData){
85 let deferred = this.$q.defer();
86 //this.$log.info('ecomp::dashboard-service::saveCommonWidgetData');
87 //this.$log.debug('ecomp::dashboard-service::saveCommonWidgetData with:', newData);
91 url: this.conf.api.commonWidget,
95 'X-ECOMP-RequestID':this.uuid.generate()
98 // If response comes back as a redirected HTML page which IS NOT a success
99 // this.$log.info(res.data);
100 if (Object.keys(res.data).length == 0) {
101 deferred.reject("ecomp::dashboard-service::saveCommonWidgetData Failed");
103 // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
104 deferred.resolve(res.data);
108 deferred.reject(status);
110 return deferred.promise;
115 removeCommonWidgetData(widgetToRemove){
116 let deferred = this.$q.defer();
117 // this.$log.info('ecomp::dashboard-service::removeCommonWidgetData');
118 // this.$log.debug('ecomp::dashboard-service::removeCommonWidgetData with:', widgetToRemove);
121 url: this.conf.api.deleteCommonWidget,
122 data: widgetToRemove,
125 'X-ECOMP-RequestID':this.uuid.generate()
128 // If response comes back as a redirected HTML page which IS NOT a success
129 // this.$log.info(res.data);
130 if (Object.keys(res.data).length == 0) {
131 deferred.reject("ecomp::dashboard-service::saveCommonWidgetData Failed");
133 // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
134 deferred.resolve(res.data);
138 deferred.reject(status);
140 return deferred.promise;
143 getSearchAllByStringResults(searchStr) {
144 // this.$log.info('ecomp::getSearchAllByStringResults::getting search by string results');
145 let deferred = this.$q.defer();
146 let url = this.conf.api.getSearchAllByStringResults;
152 'searchString' : searchStr
156 'X-ECOMP-RequestID':this.uuid.generate()
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("ecomp::dashboard-service::getSearchAllByStringResults Failed");
163 //this.searchResults = res.data;
164 // this.$log.info('ecomp::dashboard-service::getSearchAllByStringResults Succeeded');
165 deferred.resolve(res.data.response);
167 }).catch( status => {
168 this.$log.error('ecomp::getSearchAllByStringResults error');
169 deferred.reject(status);
171 return deferred.promise;
175 getOnlineUserUpdateRate() {
176 let deferred = this.$q.defer();
177 let url = this.conf.api.onlineUserUpdateRate;
183 'X-ECOMP-RequestID':this.uuid.generate()
186 // If response comes back as a redirected HTML page which IS NOT a success
187 if (Object.keys(res.data).length == 0) {
188 deferred.reject("ecomp::dashboard-service::getOnlineUserUpdateRate Failed");
190 // this.$log.info('ecomp::dashboard-service::getOnlineUserUpdateRate Succeeded',res);
191 deferred.resolve(res.data);
193 }).catch( status => {
194 deferred.reject(status);
196 return deferred.promise;
201 DashboardService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
202 angular.module('ecompApp').service('dashboardService', DashboardService)