Advertisement
eqeqwan21

Untitled

Jun 17th, 2024 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(async function() {
  2.   $('#notificationBell').hide();
  3.   $('#loader').show();
  4.   let town;
  5.   if (environment.login_name.indexOf("_") !== -1) {
  6.     town = '&town='+capitalizeFirstLetter(environment.login_name.split('_')[0])
  7.   }
  8.   else{
  9.     town = ''
  10.   }
  11.   let previousTotal = localStorage.getItem('previousTotal') ? parseInt(localStorage.getItem('previousTotal') - 1) : 0;
  12.   let soundEnabled = false;
  13.  
  14.   function updateEventData() {
  15.     $.ajax({
  16.       url: environment.base_url+"/"+'?do=api&fn=last_statistic'+town,
  17.       type: 'GET',
  18.       dataType: "json",
  19.       success: function(data) {
  20.         let eventData = data.rows[0]
  21.         var eventList = $('#eventList');
  22.         const now = new Date();
  23.         const formattedDateTime = now.toLocaleString();
  24.         const total = eventData.PowerFailureCount + eventData.EquipmentFailureCount + eventData.SipFailureCount + eventData.IpFailureCount + eventData.TimeAlertFailureCount + eventData.ControllerFailureCount + eventData.DoorOpenCount + eventData.SyncFailureCount;
  25.         if (total !== previousTotal) {
  26.           eventList.empty();
  27.           eventList.append('<li class="datetime">Current Time: ' + formattedDateTime + '</li>');
  28.           eventList.append('<li>' + i18next.t("Power Failure") + ': ' + eventData.PowerFailureCount + '</li>');
  29.           eventList.append('<li>' + i18next.t("Object Failure") + ': ' + eventData.EquipmentFailureCount + '</li>');
  30.           eventList.append('<li>' + i18next.t("SIP failure") + ':  ' + eventData.SipFailureCount + '</li>');
  31.           eventList.append('<li>' + i18next.t("IP failure") + ': ' + eventData.IpFailureCount + '</li>');
  32.           eventList.append('<li>' + i18next.t("Clock error") + ': ' + eventData.TimeAlertFailureCount + '</li>');
  33.           eventList.append('<li>' + i18next.t("Controller error") + ': ' + eventData.ControllerFailureCount + '</li>');
  34.           eventList.append('<li>' + i18next.t("Door open") + ': ' + eventData.DoorOpenCount + '</li>');
  35.           eventList.append('<li>' + i18next.t("Out of sync") + ': ' + eventData.SyncFailureCount + '</li>');
  36.           $('#eventCount').text(total)
  37.         } else {
  38.           eventList.find('li.datetime').text('Current Time: ' + formattedDateTime + '')
  39.         }
  40.         $('#loader').hide();
  41.         $('#notificationBell').show();
  42.         if(total > 100){
  43.           $('.notification-container').addClass('large')
  44.         }
  45.         if (total > previousTotal && soundEnabled) {
  46.           $('#notificationSound')[0].play();
  47.         }
  48.  
  49.         previousTotal = total;
  50.         localStorage.setItem('previousTotal', previousTotal);
  51.       }
  52.     });
  53.   }
  54.  
  55.   setInterval(updateEventData, 1000);
  56.  
  57.   $('#eventCount').click(function() {
  58.     $('#eventDropdown').toggle();
  59.   });
  60.  
  61.   $('#notificationBell').click(function() {
  62.     soundEnabled = true;
  63.     $('#notificationBell').removeClass('disabled').addClass('active');
  64.   });
  65.  
  66.   $(document).click(function(event) {
  67.     if (!$(event.target).closest('#eventCount, #eventDropdown').length) {
  68.       if ($('#eventDropdown').is(":visible")) {
  69.         $('#eventDropdown').hide();
  70.       }
  71.     }
  72.   });
  73. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement