2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
42 class userNotificationsCtrl {
43 constructor($scope, $log, notificationService, filterFilter,confirmBoxService, $modal, ngDialog, $state) {
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;
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;
72 $log.error('userNotificationsCtrl:getAdminNotifications:: error ', err);
73 $scope.isLoadingTable = false;
78 getAdminNotifications();
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;
89 $scope.updateTable = (num) => {
90 this.startIndex=this.viewPerPage1*(num-1);
91 this.currentPage1 = num;
94 this.removeUserNotification = (selectedAdminNotification) => {
95 selectedAdminNotification.activeYn = 'N';
96 confirmBoxService.deleteItem(selectedAdminNotification.msgHeader)
97 .then(isConfirmed => {
99 notificationService.updateAdminNotification(selectedAdminNotification)
101 getAdminNotifications();
103 switch (err.status) {
104 case '409': // Conflict
105 // handleConflictErrors(err);
107 case '500': // Internal Server
109 confirmBoxService.showInformation('There was a problem updating the notification. ' +
110 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
112 case '403': // Forbidden...
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 => { });
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 => { });
123 $log.error('UserNotifCtlr::updateAdminNOtif failed: ' + JSON.stringify(err));
125 var objOffsetVersion = objAgent.indexOf("MSIE");
126 if (objOffsetVersion != -1) {
127 $window.location.reload();
132 $log.error('UserNotifCtlr::deleteItem error: ' + err);
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',
150 selectedAdminNotification:selectedAdminNotification,messageObject:messageObject,messageRecipients:$scope.messageRecipients
160 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
161 $scope.isLoadingTable = false;
167 this.editUserNotificationModal = (selectedAdminNotification) => {
169 // retrieve roleIds here
170 selectedAdminNotification.roleIds = null;
171 notificationService.getNotificationRoles(selectedAdminNotification.notificationId)
173 selectedAdminNotification.roleIds = res.data;
175 this.openUserNotificationModal(selectedAdminNotification);
177 $log.error('UserNotifCtlr:getNotificationRoles:: error ', err);
182 this.openUserNotificationModal = (selectedAdminNotification) => {
184 if (selectedAdminNotification) {
186 notif: selectedAdminNotification
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',
202 modalInstance.result.finally(function () {
203 getAdminNotifications();
206 $scope.customPageHandler = function(num) {
207 $scope.currentPage1=num;
208 this.startIndex=$scope.viewPerPage1*(num-1);
213 userNotificationsCtrl.$inject = ['$scope', '$log', 'notificationService','filterFilter', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
214 angular.module('ecompApp').controller('userNotificationsCtrl', userNotificationsCtrl);