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 class userNotificationsCtrl {
25 constructor($scope, $log, notificationService, confirmBoxService, $modal, ngDialog, $state) {
27 var priorityItems={"1":"Normal","2":"Important"};
28 $scope.priorityItems=priorityItems;
29 $scope.searchString='';
30 $scope.externalNotification="External System";
31 $scope.itemExpired={"background-color":"silver "};
32 $scope.showInput = true;
33 $scope.totalPages1 = 0;
34 $scope.viewPerPage1 = 15;
35 $scope.currentPage1 = 1;
36 $scope.showLoader = false;
37 $scope.firstPlay = true;
38 // Start with empty list to silence error in console
39 $scope.tableData = [];
40 $scope.tableAdminNotifItems = [];
41 let getAdminNotifications = () => {
42 $scope.isLoadingTable = true;
43 notificationService.getAdminNotification().then(res => {
44 $scope.adminNotifications = res.data;
45 $scope.isLoadingTable = false;
46 $scope.tableData = res.data;
47 var totalItems = $scope.tableData.length;
48 $scope.totalPages1 = Math.ceil(totalItems / $scope.viewPerPage1);
49 $scope.showLoader = false;
50 $scope.currentPage1=1;
51 var endIndex = 1 * $scope.viewPerPage1;
52 var startIndex = endIndex - $scope.viewPerPage1;
53 $scope.tableAdminNotifItems = $scope.tableData.slice(startIndex, endIndex);
55 $log.error('userNotificationsCtrl:getAdminNotifications:: error ', err);
56 $scope.isLoadingTable = false;
60 getAdminNotifications();
62 $scope.customPageHandler = function(num) {
63 $scope.currentPage1=num;
64 var endIndex = num * $scope.viewPerPage1;
65 var startIndex = endIndex - $scope.viewPerPage1;
66 $scope.tableAdminNotifItems = $scope.tableData.slice(startIndex, endIndex);
73 $scope.removeUserNotification = function (selectedAdminNotification) {
74 selectedAdminNotification.activeYn = 'N';
75 confirmBoxService.deleteItem(selectedAdminNotification.msgHeader)
76 .then(isConfirmed => {
78 notificationService.updateAdminNotification(selectedAdminNotification)
80 getAdminNotifications();
83 case '409': // Conflict
84 // handleConflictErrors(err);
86 case '500': // Internal Server
88 confirmBoxService.showInformation('There was a problem updating the notification. ' +
89 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
91 case '403': // Forbidden...
95 confirmBoxService.showInformation('There was a problem updating the notification. ' +
96 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
99 confirmBoxService.showInformation('There was a problem updating the notification. ' +
100 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
102 $log.error('UserNotifCtlr::updateAdminNOtif failed: ' + JSON.stringify(err));
104 var objOffsetVersion = objAgent.indexOf("MSIE");
105 if (objOffsetVersion != -1) {
106 $window.location.reload();
111 $log.error('UserNotifCtlr::deleteItem error: ' + err);
117 $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
118 notificationService.getMessageRecipients(selectedAdminNotification.notificationId).then(res =>{
119 $scope.messageRecipients = res;
120 var messageObject=JSON.parse(selectedAdminNotification.msgDescription);
122 html+='<p>'+'Message Source'+' : '+selectedAdminNotification.msgSource+'</p>';
123 html+='<p>'+'Message Title'+' : '+selectedAdminNotification.msgHeader+'</p>';
124 html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
126 for(var field in messageObject){
127 if(field=='eventDate'||field=='lastModifiedDate'){
128 html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
131 html+='<p>'+field+' : '+messageObject[field]+'</p>';
136 var modalInstance = ngDialog.open({
137 templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
138 controller: 'userNotificationCtrl',
140 message: function () {
153 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
154 $scope.isLoadingTable = false;
160 $scope.editUserNotificationModal = function (selectedAdminNotification) {
162 // retrieve roleIds here
163 selectedAdminNotification.roleIds = null;
164 notificationService.getNotificationRoles(selectedAdminNotification.notificationId)
166 selectedAdminNotification.roleIds = res.data;
168 $scope.openUserNotificationModal(selectedAdminNotification);
170 $log.error('UserNotifCtlr:getNotificationRoles:: error ', err);
175 $scope.openUserNotificationModal = function (selectedAdminNotification) {
177 if (selectedAdminNotification) {
179 notif: selectedAdminNotification
183 templateUrl: 'app/views/user-notifications-admin/user.notifications.modal.page.html',
184 controller: 'userNotificationsModalCtrl',
185 controllerAs: 'userNotifModal',
187 }).closePromise.then(function (needUpdate) {
188 getAdminNotifications();
194 userNotificationsCtrl.$inject = ['$scope', '$log', 'notificationService', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
195 angular.module('ecompApp').controller('userNotificationsCtrl', userNotificationsCtrl);