2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
21 * Created by robertlo on 09/26/2016.
26 class DashboardService {
27 constructor($q, $log, $http, conf, uuid) {
32 this.dashboardService = null;
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;
46 'X-ECOMP-RequestID':this.uuid.generate()
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");
55 this.userProfile = res.data;
56 // this.$log.info('ecomp::dashboard-service::getNewsData Succeeded');
57 deferred.resolve(res.data);
61 deferred.reject(status);
63 return deferred.promise;
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);
73 url: this.conf.api.commonWidget,
77 'X-ECOMP-RequestID':this.uuid.generate()
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");
85 // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
86 deferred.resolve(res.data);
90 deferred.reject(status);
92 return deferred.promise;
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);
103 url: this.conf.api.deleteCommonWidget,
104 data: widgetToRemove,
107 'X-ECOMP-RequestID':this.uuid.generate()
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");
115 // this.$log.info('ecomp::dashboard-service::saveCommonWidgetData Succeeded');
116 deferred.resolve(res.data);
120 deferred.reject(status);
122 return deferred.promise;
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;
134 'searchString' : searchStr
138 'X-ECOMP-RequestID':this.uuid.generate()
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");
145 //this.searchResults = res.data;
146 // this.$log.info('ecomp::dashboard-service::getSearchAllByStringResults Succeeded');
147 deferred.resolve(res.data.response);
149 }).catch( status => {
150 this.$log.error('ecomp::getSearchAllByStringResults error');
151 deferred.reject(status);
153 return deferred.promise;
157 getOnlineUserUpdateRate() {
158 let deferred = this.$q.defer();
159 let url = this.conf.api.onlineUserUpdateRate;
165 'X-ECOMP-RequestID':this.uuid.generate()
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");
172 // this.$log.info('ecomp::dashboard-service::getOnlineUserUpdateRate Succeeded',res);
173 deferred.resolve(res.data);
175 }).catch( status => {
176 deferred.reject(status);
178 return deferred.promise;
183 DashboardService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
184 angular.module('ecompApp').service('dashboardService', DashboardService)