[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / views / notification-history / notificationhistory.controller.js
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23
24     class notificationHistoryCtrl {
25         constructor( $scope, $log,notificationService, confirmBoxService, $modal, ngDialog, $state) {
26                 
27                 var priorityItems={"1":"Normal","2":"Important"};
28                 $scope.priorityItems=priorityItems;
29             $scope.externalNotification="External System";
30                 $scope.isLoadingTable = false;
31             $scope.searchString = '';
32             $scope.notificationHistory = [];
33             let getNotificationHistory = () => {
34                 $scope.isLoadingTable = true;
35                 notificationService.getNotificationHistory().then(res => {
36                     $scope.notificationHistory = res.data;
37                     $scope.isLoadingTable = false;
38                 }).catch(err => {
39                     $log.error('notificationHistoryCtlr:notifSvc.getNotifHist failed: ', err);
40                     $scope.isLoadingTable = false;
41                 });
42             }
43
44             getNotificationHistory();           
45                 
46             $scope.showDetailedJsonMessage=function (selectedAdminNotification) {
47                  notificationService.getMessageRecipients(selectedAdminNotification.notificationId).then(res =>{
48                     $scope.messageRecipients = res;
49                                  var messageObject=JSON.parse(selectedAdminNotification.msgDescription);
50                                  var html="";
51                                  html+='<p>'+'Message Source'+' : '+selectedAdminNotification.msgSource+'</p>';
52                                  html+='<p>'+'Message Title'+' : '+selectedAdminNotification.msgHeader+'</p>';
53                                  html+='<p>'+'Message Recipient'+' : '+$scope.messageRecipients+'</p>';
54
55                                  for(var field in  messageObject){
56                                          if(field=='eventDate'||field=='lastModifiedDate'){
57                                                  html+='<p>'+field+' : '+new Date(+messageObject[field])+'</p>';
58                                                   
59                                          }else{
60                                          html+='<p>'+field+' : '+messageObject[field]+'</p>';
61                                          
62                                          }
63                                  }
64
65                      var modalInstance = ngDialog.open({
66                                     templateUrl: 'app/views/user-notifications-admin/user.notifications.Json.details.modal.page.html',
67                                     controller: 'userNotificationCtrl',
68                                     resolve: {
69                                         message: function () {
70                                                 var message = {
71                                                            title:    '',
72                                                 text:    html
73                                                 
74                                                 };
75                                           return message;
76                                         },
77                                      
78                                       }
79                                   }); 
80                      
81          }).catch(err => {
82                 $log.error('userNotificationsCtrl:getMessageRecipients:: error ', err);
83                 $scope.isLoadingTable = false;
84             });
85
86                          };
87          }
88     }
89     notificationHistoryCtrl.$inject = ['$scope', '$log', 'notificationService', 'confirmBoxService', '$modal', 'ngDialog', '$state'];
90     angular.module('ecompApp').controller('notificationHistoryCtrl', notificationHistoryCtrl);
91 })();