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============================================
42 constructor($q, $log, $http, conf, uuid, utilsService) {
48 this.utilsService = utilsService;
51 GetFunctionalMenuForUser() {
52 let deferred = this.$q.defer();
53 // this.$log.info('MenusService::GetFunctionalMenuForUser via REST API');
56 url: this.conf.api.functionalMenuForAuthUser,
59 'X-ECOMP-RequestID':this.uuid.generate()
62 // If response comes back as a redirected HTML page which IS NOT a success
63 if (this.utilsService.isValidJSON(res)== false) {
64 deferred.reject('MenusService::GetFunctionalMenuForUser Failed');
66 // this.$log.info('MenusService::GetFunctionalMenuForUser success:');
67 deferred.resolve(res.data);
71 this.$log.error('MenusService::rejection:' + status);
72 deferred.reject(status);
75 return deferred.promise;
78 getEcompPortalTitle () {
79 let deferred = this.$q.defer();
82 url: this.conf.api.ecompTitle,
85 'X-ECOMP-RequestID':this.uuid.generate()
88 if (res.data==null || !this.utilsService.isValidJSON(res.data)) {
89 deferred.reject('MenusService::getEcompPortalTitle rest call failed');
91 if(res.data.status!='OK' && res.data.message!=null)
92 deferred.reject('MenusService::getEcompPortalTitle rest call failed ' + res.data.message);
94 deferred.resolve(res.data);
98 this.$log.error('MenusService::getEcompPortalTitle rejection:' + status);
99 deferred.reject(status);
102 return deferred.promise;
106 let deferred = this.$q.defer();
107 // this.$log.info('MenusService::getFavoriteItems via REST API');
110 url: this.conf.api.getFavoriteItems +'?date='+new Date().getTime(),
113 'X-ECOMP-RequestID':this.uuid.generate()
116 // If response comes back as a redirected HTML page which IS NOT a success
117 if (this.utilsService.isValidJSON(res)== false) {
118 deferred.reject('MenusService::getFavoriteItems has no favorites');
120 // this.$log.info('MenusService::getFavoriteItems success:');
121 deferred.resolve(res.data);
125 this.$log.error('MenusService::getFavoriteItems rejection:' + status);
126 deferred.reject(status);
129 return deferred.promise;
132 setFavoriteItem(menuId) {
133 let deferred = this.$q.defer();
134 // this.$log.info('menus-service.service::setFavoriteItem via REST API' + menuId);
135 let url = this.conf.api.setFavoriteItem;
141 'X-ECOMP-RequestID':this.uuid.generate(),
142 'Content-Type': 'application/json'
146 // If response comes back as a redirected HTML page which IS NOT a success
147 if (this.utilsService.isValidJSON(res)== false) {
148 deferred.reject('MenusService::setFavoriteItem Failed');
150 // this.$log.info('MenusService::setFavoriteItem success:');
151 deferred.resolve(res.data);
155 this.$log.error('MenusService::setFavoriteItem rejection:' + JSON.stringify(errRes));
156 deferred.reject(errRes);
158 return deferred.promise;
161 removeFavoriteItem(menuId) {
162 let deferred = this.$q.defer();
163 // this.$log.info('menus-service.service::removeFavoriteItem via REST API');
164 let url = this.conf.api.removeFavoriteItem.replace(':menuId', menuId);
170 'X-ECOMP-RequestID':this.uuid.generate()
173 // If response comes back as a redirected HTML page which IS NOT a success
174 if (this.utilsService.isValidJSON(res)== false) {
175 deferred.reject('MenusService::removeFavoriteItem Failed');
177 // this.$log.info('MenusService::removeFavoriteItem success:');
178 deferred.resolve(res.data);
182 this.$log.error('MenusService::removeFavoriteItem rejection:' + status);
183 deferred.reject(errRes);
185 return deferred.promise;
190 MenusService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService'];
191 angular.module('ecompApp').service('menusService', MenusService)