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 * ================================================================================
24 constructor($q, $log, $http, conf, uuid, utilsService) {
30 this.utilsService = utilsService;
33 GetFunctionalMenuForUser() {
34 let deferred = this.$q.defer();
35 // this.$log.info('MenusService::GetFunctionalMenuForUser via REST API');
38 url: this.conf.api.functionalMenuForAuthUser,
41 'X-ECOMP-RequestID':this.uuid.generate()
44 // If response comes back as a redirected HTML page which IS NOT a success
45 if (this.utilsService.isValidJSON(res)== false) {
46 deferred.reject('MenusService::GetFunctionalMenuForUser Failed');
48 // this.$log.info('MenusService::GetFunctionalMenuForUser success:');
49 deferred.resolve(res.data);
53 this.$log.error('MenusService::rejection:' + status);
54 deferred.reject(status);
57 return deferred.promise;
60 getEcompPortalTitle () {
61 let deferred = this.$q.defer();
64 url: this.conf.api.ecompTitle,
67 'X-ECOMP-RequestID':this.uuid.generate()
70 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
71 deferred.reject('MenusService::getEcompPortalTitle rest call failed');
73 if(res.data.status!='OK' && res.data.message!=null)
74 deferred.reject('MenusService::getEcompPortalTitle rest call failed ' + res.data.message);
76 deferred.resolve(res.data);
80 this.$log.error('MenusService::getEcompPortalTitle rejection:' + status);
81 deferred.reject(status);
84 return deferred.promise;
88 let deferred = this.$q.defer();
89 // this.$log.info('MenusService::getFavoriteItems via REST API');
92 url: this.conf.api.getFavoriteItems +'?date='+new Date().getTime(),
95 'X-ECOMP-RequestID':this.uuid.generate()
98 // If response comes back as a redirected HTML page which IS NOT a success
99 if (this.utilsService.isValidJSON(res)== false) {
100 deferred.reject('MenusService::getFavoriteItems has no favorites');
102 // this.$log.info('MenusService::getFavoriteItems success:');
103 deferred.resolve(res.data);
107 this.$log.error('MenusService::getFavoriteItems rejection:' + status);
108 deferred.reject(status);
111 return deferred.promise;
114 setFavoriteItem(menuId) {
115 let deferred = this.$q.defer();
116 // this.$log.info('menus-service.service::setFavoriteItem via REST API' + menuId);
117 let url = this.conf.api.setFavoriteItem;
123 'X-ECOMP-RequestID':this.uuid.generate(),
124 'Content-Type': 'application/json'
128 // If response comes back as a redirected HTML page which IS NOT a success
129 if (this.utilsService.isValidJSON(res)== false) {
130 deferred.reject('MenusService::setFavoriteItem Failed');
132 // this.$log.info('MenusService::setFavoriteItem success:');
133 deferred.resolve(res.data);
137 this.$log.error('MenusService::setFavoriteItem rejection:' + JSON.stringify(errRes));
138 deferred.reject(errRes);
140 return deferred.promise;
143 removeFavoriteItem(menuId) {
144 let deferred = this.$q.defer();
145 // this.$log.info('menus-service.service::removeFavoriteItem via REST API');
146 let url = this.conf.api.removeFavoriteItem.replace(':menuId', menuId);
152 'X-ECOMP-RequestID':this.uuid.generate()
155 // If response comes back as a redirected HTML page which IS NOT a success
156 if (this.utilsService.isValidJSON(res)== false) {
157 deferred.reject('MenusService::removeFavoriteItem Failed');
159 // this.$log.info('MenusService::removeFavoriteItem success:');
160 deferred.resolve(res.data);
164 this.$log.error('MenusService::removeFavoriteItem rejection:' + status);
165 deferred.reject(errRes);
167 return deferred.promise;
172 MenusService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService'];
173 angular.module('ecompApp').service('menusService', MenusService)