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, filterFilter,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;
37 $scope.showLoader = false;
38 $scope.firstPlay = true;
39 // Start with empty list to silence error in console
40 $scope.tableData = [];
41 $scope.tableAdminNotifItems = [];
42 let getAdminNotifications = () => {
43 $scope.isLoadingTable = true;
44 notificationService.getAdminNotification().then(res => {
45 $scope.adminNotifications = res.data;
46 $scope.isLoadingTable = false;
47 $scope.tableData = res.data;
48 var totalItems = $scope.tableData.length;
49 $scope.totalPages1 = Math.ceil(totalItems / $scope.viewPerPage1);
50 $scope.showLoader = false;
51 $scope.currentPage1=1;
52 $scope.tableAdminNotifItems = $scope.tableData;
54 $log.error('userNotificationsCtrl:getAdminNotifications:: error ', err);
55 $scope.isLoadingTable = false;
60 getAdminNotifications();
63 $scope.$watch('searchString', function (searchKey) {
64 var search = searchKey;
65 this.totalPage1 = filterFilter($scope.tableData, search);
66 var resultLen = this.totalPage1.length;
67 $scope.totalPage1 = Math.ceil(resultLen/$scope.viewPerPage1);
68 $scope.currentPage1 = 1;
71 $scope.updateTable = (num) => {
72 this.startIndex=this.viewPerPage1*(num-1);
73 this.currentPage1 = num;
76 this.removeUserNotification = (selectedAdminNotification) => {
77 selectedAdminNotification.activeYn = 'N';
78 confirmBoxService.deleteItem(selectedAdminNotification.msgHeader)
79 .then(isConfirmed => {
81 notificationService.updateAdminNotification(selectedAdminNotification)
83 getAdminNotifications();
86 case '409': // Conflict
87 // handleConflictErrors(err);
89 case '500': // Internal Server
91 confirmBoxService.showInformation('There was a problem updating the notification. ' +
92 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
94 case '403': // Forbidden...
98 confirmBoxService.showInformation('There was a problem updating the notification. ' +
99 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
102 confirmBoxService.showInformation('There was a problem updating the notification. ' +
103 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
105 $log.error('UserNotifCtlr::updateAdminNOtif failed: ' + JSON.stringify(err));
107 var objOffsetVersion = objAgent.indexOf("MSIE");
108 if (objOffsetVersion != -1) {
109 $window.location.reload();
114 $log.error('UserNotifCtlr::deleteItem error: ' + err);
120 this.showDetailedJsonMessage = (selectedAdminNotification) => {
121 notificationService.getMessageRecipients(selectedAdminNotification.notificationId).then(res =>{
122 $scope.messageRecipients = res;
123 var messageObject=JSON.parse(selectedAdminNotification.msgDescription);
124 var modalInstance = $modal.open({
125 templateUrl: 'app/views/user-notifications-admin/user.notifications.json.details.modal.page.html',
126 controller: 'userNotificationCtrl',
127 sizeClass: 'modal-large',
132 selectedAdminNotification:selectedAdminNotification,messageObject:messageObject,messageRecipients:$scope.messageRecipients
142 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
143 $scope.isLoadingTable = false;
149 this.editUserNotificationModal = (selectedAdminNotification) => {
151 // retrieve roleIds here
152 selectedAdminNotification.roleIds = null;
153 notificationService.getNotificationRoles(selectedAdminNotification.notificationId)
155 selectedAdminNotification.roleIds = res.data;
157 this.openUserNotificationModal(selectedAdminNotification);
159 $log.error('UserNotifCtlr:getNotificationRoles:: error ', err);
164 this.openUserNotificationModal = (selectedAdminNotification) => {
166 if (selectedAdminNotification) {
168 notif: selectedAdminNotification
173 var modalInstance = $modal.open({
174 templateUrl: 'app/views/user-notifications-admin/user.notifications.modal.page.html',
175 controller: 'userNotificationsModalCtrl as userNotifModal',
176 sizeClass: 'modal-large',
184 modalInstance.result.finally(function () {
185 getAdminNotifications();
188 $scope.customPageHandler = function(num) {
189 $scope.currentPage1=num;
190 this.startIndex=$scope.viewPerPage1*(num-1);
195 userNotificationsCtrl.$inject = ['$scope', '$log', 'notificationService','filterFilter', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
196 angular.module('ecompApp').controller('userNotificationsCtrl', userNotificationsCtrl);