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;
61 let deferred = this.$q.defer();
62 // this.$log.info('MenusService::getFavoriteItems via REST API');
65 url: this.conf.api.getFavoriteItems +'?date='+new Date().getTime(),
68 'X-ECOMP-RequestID':this.uuid.generate()
71 // If response comes back as a redirected HTML page which IS NOT a success
72 if (this.utilsService.isValidJSON(res)== false) {
73 deferred.reject('MenusService::getFavoriteItems has no favorites');
75 // this.$log.info('MenusService::getFavoriteItems success:');
76 deferred.resolve(res.data);
80 this.$log.error('MenusService::getFavoriteItems rejection:' + status);
81 deferred.reject(status);
84 return deferred.promise;
87 setFavoriteItem(menuId) {
88 let deferred = this.$q.defer();
89 // this.$log.info('menus-service.service::setFavoriteItem via REST API' + menuId);
90 let url = this.conf.api.setFavoriteItem;
96 'X-ECOMP-RequestID':this.uuid.generate(),
97 'Content-Type': 'application/json'
101 // If response comes back as a redirected HTML page which IS NOT a success
102 if (this.utilsService.isValidJSON(res)== false) {
103 deferred.reject('MenusService::setFavoriteItem Failed');
105 // this.$log.info('MenusService::setFavoriteItem success:');
106 deferred.resolve(res.data);
110 this.$log.error('MenusService::setFavoriteItem rejection:' + JSON.stringify(errRes));
111 deferred.reject(errRes);
113 return deferred.promise;
116 removeFavoriteItem(menuId) {
117 let deferred = this.$q.defer();
118 // this.$log.info('menus-service.service::removeFavoriteItem via REST API');
119 let url = this.conf.api.removeFavoriteItem.replace(':menuId', menuId);
125 'X-ECOMP-RequestID':this.uuid.generate()
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::removeFavoriteItem Failed');
132 // this.$log.info('MenusService::removeFavoriteItem success:');
133 deferred.resolve(res.data);
137 this.$log.error('MenusService::removeFavoriteItem rejection:' + status);
138 deferred.reject(errRes);
140 return deferred.promise;
145 MenusService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService'];
146 angular.module('ecompApp').service('menusService', MenusService)