2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
24 class userNotificationsCtrl {
\r
25 constructor($scope, $log, notificationService, confirmBoxService, $modal, ngDialog, $state) {
\r
27 var priorityItems={"1":"Normal","2":"Important"};
\r
28 $scope.priorityItems=priorityItems;
\r
29 $scope.searchString='';
\r
30 $scope.externalNotification="External System";
\r
31 $scope.itemExpired={"background-color":"silver "};
\r
32 $scope.showInput = true;
\r
33 $scope.totalPages1 = 0;
\r
34 $scope.viewPerPage1 = 15;
\r
35 $scope.currentPage1 = 1;
\r
36 $scope.showLoader = false;
\r
37 $scope.firstPlay = true;
\r
38 // Start with empty list to silence error in console
\r
39 $scope.tableData = [];
\r
40 $scope.tableAdminNotifItems = [];
\r
41 let getAdminNotifications = () => {
\r
42 $scope.isLoadingTable = true;
\r
43 notificationService.getAdminNotification().then(res => {
\r
44 $scope.adminNotifications = res.data;
\r
45 $scope.isLoadingTable = false;
\r
46 $scope.tableData = res.data;
\r
47 var totalItems = $scope.tableData.length;
\r
48 $scope.totalPages1 = Math.ceil(totalItems / $scope.viewPerPage1);
\r
49 $scope.showLoader = false;
\r
50 $scope.currentPage1=1;
\r
51 var endIndex = 1 * $scope.viewPerPage1;
\r
52 var startIndex = endIndex - $scope.viewPerPage1;
\r
53 $scope.tableAdminNotifItems = $scope.tableData.slice(startIndex, endIndex);
\r
55 $log.error('userNotificationsCtrl:getAdminNotifications:: error ', err);
\r
56 $scope.isLoadingTable = false;
\r
60 getAdminNotifications();
\r
62 $scope.customPageHandler = function(num) {
\r
63 $scope.currentPage1=num;
\r
64 var endIndex = num * $scope.viewPerPage1;
\r
65 var startIndex = endIndex - $scope.viewPerPage1;
\r
66 $scope.tableAdminNotifItems = $scope.tableData.slice(startIndex, endIndex);
\r
73 $scope.removeUserNotification = function (selectedAdminNotification) {
\r
74 selectedAdminNotification.activeYn = 'N';
\r
75 confirmBoxService.deleteItem(selectedAdminNotification.msgHeader)
\r
76 .then(isConfirmed => {
\r
78 notificationService.updateAdminNotification(selectedAdminNotification)
\r
80 getAdminNotifications();
\r
82 switch (err.status) {
\r
83 case '409': // Conflict
\r
84 // handleConflictErrors(err);
\r
86 case '500': // Internal Server
\r
88 confirmBoxService.showInformation('There was a problem updating the notification. ' +
\r
89 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
\r
91 case '403': // Forbidden...
\r
93 // webjunction error
\r
95 confirmBoxService.showInformation('There was a problem updating the notification. ' +
\r
96 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
\r
99 confirmBoxService.showInformation('There was a problem updating the notification. ' +
\r
100 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
\r
102 $log.error('UserNotifCtlr::updateAdminNOtif failed: ' + JSON.stringify(err));
\r
104 var objOffsetVersion = objAgent.indexOf("MSIE");
\r
105 if (objOffsetVersion != -1) {
\r
106 $window.location.reload();
\r
111 $log.error('UserNotifCtlr::deleteItem error: ' + err);
\r
117 $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
\r
118 notificationService.getMessageRecipients(selectedAdminNotification.notificationId).then(res =>{
\r
119 $scope.messageRecipients = res;
\r
120 var messageObject=JSON.parse(selectedAdminNotification.msgDescription);
\r
122 html+='<p>'+'Message Source'+' : '+selectedAdminNotification.msgSource+'</p>';
\r
123 html+='<p>'+'Message Title'+' : '+selectedAdminNotification.msgHeader+'</p>';
\r
124 html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
\r
126 for(var field in messageObject){
\r
127 if(field=='eventDate'||field=='lastModifiedDate'){
\r
128 html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
\r
131 html+='<p>'+field+' : '+messageObject[field]+'</p>';
\r
136 var modalInstance = ngDialog.open({
\r
137 templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
\r
138 controller: 'userNotificationCtrl',
\r
140 message: function () {
\r
153 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
\r
154 $scope.isLoadingTable = false;
\r
160 $scope.editUserNotificationModal = function (selectedAdminNotification) {
\r
162 // retrieve roleIds here
\r
163 selectedAdminNotification.roleIds = null;
\r
164 notificationService.getNotificationRoles(selectedAdminNotification.notificationId)
\r
166 selectedAdminNotification.roleIds = res.data;
\r
168 $scope.openUserNotificationModal(selectedAdminNotification);
\r
170 $log.error('UserNotifCtlr:getNotificationRoles:: error ', err);
\r
175 $scope.openUserNotificationModal = function (selectedAdminNotification) {
\r
177 if (selectedAdminNotification) {
\r
179 notif: selectedAdminNotification
\r
183 templateUrl: 'app/views/user-notifications-admin/user.notifications.modal.page.html',
\r
184 controller: 'userNotificationsModalCtrl',
\r
185 controllerAs: 'userNotifModal',
\r
187 }).closePromise.then(function (needUpdate) {
\r
188 getAdminNotifications();
\r
194 userNotificationsCtrl.$inject = ['$scope', '$log', 'notificationService', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
\r
195 angular.module('ecompApp').controller('userNotificationsCtrl', userNotificationsCtrl);
\r