nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / menus / menus.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20
21 'use strict';
22
23 (function () {
24   class MenusService {
25     constructor($q, $log, $http, conf, uuid) {
26       this.$q = $q;
27       this.$log = $log;
28       this.$http = $http;
29       this.conf = conf;
30       this.uuid = uuid;
31     }
32
33     GetFunctionalMenuForUser() {
34       let deferred = this.$q.defer();
35       // this.$log.info('MenusService::GetFunctionalMenuForUser via REST API');
36       this.$http({
37         method: "GET",
38         url: this.conf.api.functionalMenuForAuthUser,
39         cache: false,
40         headers: {
41           'X-ECOMP-RequestID':this.uuid.generate()
42         }
43       }).then( res => {
44           if (Object.keys(res.data).length == 0) {
45               deferred.reject("MenusService::GetFunctionalMenuForUser Failed");
46           } else {
47               this.$log.info('MenusService::GetFunctionalMenuForUser success:');
48               deferred.resolve(res.data);
49           }
50       })
51       .catch( status => {
52         this.$log.info('MenusService::rejection:' + status);
53         deferred.reject(status);
54       });
55              
56
57       return deferred.promise;
58     }
59       
60     getFavoriteItems() {
61       let deferred = this.$q.defer();
62       // this.$log.info('MenusService::getFavoriteItems via REST API');
63         this.$http({
64             method: "GET",
65             url: this.conf.api.getFavoriteItems +"?date="+new Date().getTime(),
66             cache: false,
67             headers: {
68                 'X-ECOMP-RequestID':this.uuid.generate()
69             }
70         }).then( res => {
71             if (Object.keys(res.data).length == 0) {
72                 deferred.reject("MenusService::getFavoriteItems Failed");
73             } else {
74                 this.$log.info('MenusService::getFavoriteItems success:');
75                 deferred.resolve(res.data);
76             }
77         })
78         .catch( status => {
79             this.$log.error('MenusService::getFavoriteItems rejection:' + status);
80             deferred.reject(status);
81         });
82                
83
84         return deferred.promise;
85     }
86     
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;
91       this.$http({
92           method: "POST",
93           url: url,
94           cache: false,
95           headers: {
96               'X-ECOMP-RequestID':this.uuid.generate(),
97               'Content-Type': 'application/json'
98           },
99           data: menuId
100       }).then(res => {
101           if (Object.keys(res.data).length == 0) {
102               deferred.reject("MenusService::setFavoriteItem Failed");
103           } else {
104               this.$log.info('MenusService::setFavoriteItem success:');
105               deferred.resolve(res.data);
106           }
107       })
108       .catch(errRes => {
109           this.$log.error('MenusService::setFavoriteItem rejection:' + JSON.stringify(errRes));
110           deferred.reject(errRes);
111       });
112               
113       return deferred.promise;
114     }
115     
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);
120           this.$http({
121               method: "DELETE",
122               url: url,
123               cache: false,
124               headers: {
125                   'X-ECOMP-RequestID':this.uuid.generate()
126               }
127           }).then(res => {
128               if (Object.keys(res.data).length == 0) {
129                   deferred.reject("MenusService::removeFavoriteItem Failed");
130               } else {
131                   // this.$log.info('MenusService::removeFavoriteItem success:');
132                   deferred.resolve(res.data);
133               }
134           })
135           .catch(errRes => {
136               this.$log.error('MenusService::removeFavoriteItem rejection:' + status);
137               deferred.reject(errRes);
138           });
139           return deferred.promise;
140       }
141     
142   }
143   MenusService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
144   angular.module('ecompApp').service('menusService', MenusService)
145 })();