Security/ Package Name changes
[portal.git] / ecomp-portal-FE-common / client / app / views / user-notifications-admin / user.notifications.controller.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39
40 (function () {
41
42     class userNotificationsCtrl {
43         constructor($scope, $log, notificationService, filterFilter,confirmBoxService, $modal, ngDialog, $state) {
44
45                 var priorityItems={"1":"Normal","2":"Important"};
46                 $scope.priorityItems=priorityItems;
47                 $scope.searchString='';
48             $scope.externalNotification="External System";
49                 $scope.itemExpired={"background-color":"silver "};
50                 $scope.showInput = true;
51                 $scope.totalPages1 = 0;
52                 $scope.viewPerPage1 = 15;
53                 $scope.currentPage1 = 1;
54             $scope.startIndex=0;
55             $scope.showLoader = false;
56                 $scope.firstPlay = true;
57                 // Start with empty list to silence error in console
58                 $scope.tableData = [];
59                 $scope.tableAdminNotifItems = [];
60                  let getAdminNotifications = () => {
61                $scope.isLoadingTable = true;
62                 notificationService.getAdminNotification().then(res => {
63                 $scope.adminNotifications = res.data;
64                 $scope.isLoadingTable = false;
65                 $scope.tableData = res.data;
66                 var totalItems = $scope.tableData.length;
67                         $scope.totalPages1  = Math.ceil(totalItems / $scope.viewPerPage1);
68                         $scope.showLoader = false;
69                         $scope.currentPage1=1;
70                         $scope.tableAdminNotifItems = $scope.tableData; 
71                 }).catch(err => {
72                 $log.error('userNotificationsCtrl:getAdminNotifications:: error ', err);
73                 $scope.isLoadingTable = false;
74             });
75              }
76                  
77                 
78            getAdminNotifications();           
79            
80                 
81                   $scope.$watch('searchString', function (searchKey) {
82                   var search = searchKey;               
83                   this.totalPage1 = filterFilter($scope.tableData, search);
84                   var resultLen = this.totalPage1.length;
85                   $scope.totalPage1 = Math.ceil(resultLen/$scope.viewPerPage1);
86                   $scope.currentPage1 = 1;
87               });
88           
89                   $scope.updateTable = (num) => {
90                   this.startIndex=this.viewPerPage1*(num-1);
91                   this.currentPage1 = num;
92               };
93                 
94            this.removeUserNotification = (selectedAdminNotification) => {
95                 selectedAdminNotification.activeYn = 'N';
96                 confirmBoxService.deleteItem(selectedAdminNotification.msgHeader)
97                     .then(isConfirmed => {
98                         if (isConfirmed) {
99                             notificationService.updateAdminNotification(selectedAdminNotification)
100                                 .then(() => {
101                                     getAdminNotifications();
102                                 }).catch(err => {
103                                     switch (err.status) {
104                                         case '409':         // Conflict
105                                             // handleConflictErrors(err);
106                                             break;
107                                         case '500':         // Internal Server
108                                                                                                                         // Error
109                                             confirmBoxService.showInformation('There was a problem updating the notification. ' +
110                                                 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
111                                             break;
112                                         case '403':         // Forbidden...
113                                                                                                                         // possible
114                                                                                                                         // webjunction error
115                                                                                                                         // to try again
116                                             confirmBoxService.showInformation('There was a problem updating the notification. ' +
117                                                 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
118                                             break;
119                                         default:
120                                             confirmBoxService.showInformation('There was a problem updating the notification. ' +
121                                                 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
122                                     }
123                                     $log.error('UserNotifCtlr::updateAdminNOtif failed: ' + JSON.stringify(err));
124                                 }).finally(() => {
125                                     var objOffsetVersion = objAgent.indexOf("MSIE");
126                                     if (objOffsetVersion != -1) {
127                                         $window.location.reload();       
128                                     }
129                                 });
130                         }
131                     }).catch(err => {
132                         $log.error('UserNotifCtlr::deleteItem error: ' + err);
133                     });
134             }
135            
136
137           
138            this.showDetailedJsonMessage = (selectedAdminNotification) => {
139                          notificationService.getMessageRecipients(selectedAdminNotification.notificationId).then(res =>{
140                      $scope.messageRecipients = res;
141                                  var messageObject=JSON.parse(selectedAdminNotification.msgDescription);
142                                   var modalInstance = $modal.open({
143                             templateUrl: 'app/views/user-notifications-admin/user.notifications.json.details.modal.page.html',
144                             controller: 'userNotificationCtrl',
145                             sizeClass: 'modal-large', 
146                             resolve: {
147                                                 items: function () {
148                                                         var items = {
149                                                                    title:    '',
150                                                     selectedAdminNotification:selectedAdminNotification,messageObject:messageObject,messageRecipients:$scope.messageRecipients
151                                                         
152                                                         };
153                                                   return items;
154                                                 }
155                                 }
156                         })
157                      
158          
159                  }).catch(err => {
160                  $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
161                  $scope.isLoadingTable = false;
162              });
163
164                          };
165     
166                          
167             this.editUserNotificationModal = (selectedAdminNotification) => {
168
169                 // retrieve roleIds here
170                 selectedAdminNotification.roleIds = null;
171                 notificationService.getNotificationRoles(selectedAdminNotification.notificationId)
172                     .then(res => {
173                         selectedAdminNotification.roleIds = res.data;
174
175                         this.openUserNotificationModal(selectedAdminNotification);
176                     }).catch(err => {
177                         $log.error('UserNotifCtlr:getNotificationRoles:: error ', err);
178
179                     });
180             }
181
182             this.openUserNotificationModal = (selectedAdminNotification) => {
183                 let data = null;
184                 if (selectedAdminNotification) {
185                     data = {
186                         notif: selectedAdminNotification
187                     }
188                 }
189              
190                 
191                 var modalInstance = $modal.open({
192                     templateUrl: 'app/views/user-notifications-admin/user.notifications.modal.page.html',
193                     controller: 'userNotificationsModalCtrl as userNotifModal',
194                     sizeClass: 'modal-large', 
195                     resolve: {
196                                         items: function () {
197                                   return data;
198                                         }
199                         }
200                 })
201                 
202                 modalInstance.result.finally(function () {
203                                 getAdminNotifications();
204                 });
205             }
206             $scope.customPageHandler = function(num) {
207                         $scope.currentPage1=num;
208                         this.startIndex=$scope.viewPerPage1*(num-1);
209                 };
210                   
211         }
212     }
213     userNotificationsCtrl.$inject = ['$scope', '$log', 'notificationService','filterFilter', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
214     angular.module('ecompApp').controller('userNotificationsCtrl', userNotificationsCtrl);
215 })();