{"version":3,"sources":["space1.notifications.js"],"names":["Space1","Notifications","$list","$dropdown","$btn","$viewAllBtn","$unreadCount","$innerCount","isOpen","notifications","notificationModel","type","text","id","status","progress","state","linktype","eNotificationTypes","generic","alert","pendingApproval","eNotificationExecutionStatus","queue","inProgress","completed","error","eNotificationStatus","read","notRead","eLinkType","Download","Url","setUnreadCount","count","this","Strings","getKey","replace","css","setNotifications","empty","forEach","notification","addNotification","$","toSafeID","length","$notification","class","Object","keys","$notificationProgressBar","hide","append","getNotificationIcon","click","doNotificationAction","attachProgress","push","show","undefined","LoadAnimation","setProgress","updateNotification","find","Description","k","removeClass","addClass","off","unreadcount","parseInt","connection","invoke","modalContentUrl","modal","ajax","url","Env","getBaseUrl","success","redirect","window","location","href","UI","Modal","remote","backdrop","size","defaultActions","autodestruction","autodestructionWait","footer","dom","$modal","on","open","onOpen","onViewAll","initSignalr","self","signalR","HubConnectionBuilder","withUrl","build","result","resultObj","JSON","parse","console","log","UnreadNotificationsCount","Type","NotificationId","ProgressPercentage","ExecutionState","LinkType","n","start","then","catch","err","toString","init"],"mappings":"AAAAA,OAAOC,cAAgB,CACnBC,MAAO,KACPC,UAAW,KACXC,KAAM,KACNC,YAAa,KACbC,aAAc,KACdC,YAAa,KACbC,QAAQ,EACRC,cAAe,GACfC,kBAAmB,CACfC,KAAM,KACNC,KAAM,KACNC,GAAI,KACJC,OAAQ,KACRC,SAAU,KACVC,MAAO,KACPC,SAAU,MAEdC,mBAAoB,CAChBC,QAAS,EACTC,MAAO,EACPL,SAAU,EACVM,gBAAiB,GAErBC,6BAA8B,CAC1BC,MAAO,EACPC,WAAY,EACZC,UAAW,EACXC,MAAO,GAEXC,oBAAqB,CACjBC,KAAM,EACNC,QAAS,GAEbC,UACA,CACIC,SAAU,EACVC,IAAK,GAETC,cAAAA,CAAeC,GACXC,KAAK7B,aAAaM,KAAKsB,GACvBC,KAAK5B,YAAYK,KAAKZ,OAAOoC,QAAQC,OAAO,0BAA0BC,QAAQ,KAAM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AAKoD,OAAM,KACZrB,KAAK3B,QAAU2B,KAAK3B,OAEhB2B,KAAK3B,QACL2B,KAAKgE,QACT,IAGJhE,KAAK9B,YAAYmD,OAAM,KACnBrB,KAAKiE,WAAW,IAGpBjE,KAAKsC,WAAatC,KAAKkE,aAE3B","file":"space1.notifications.min.js","sourcesContent":["Space1.Notifications = {\n $list: null,\n $dropdown: null,\n $btn: null,\n $viewAllBtn: null,\n $unreadCount: null,\n $innerCount: null,\n isOpen: false,\n notifications: [],\n notificationModel: {\n type: null,\n text: null,\n id: null,\n status: null,\n progress: null,\n state: null,\n linktype: null\n },\n eNotificationTypes: {\n generic: 0,\n alert: 1,\n progress: 2,\n pendingApproval: 3\n },\n eNotificationExecutionStatus: {\n queue: 0,\n inProgress: 1,\n completed: 2,\n error: 3\n },\n eNotificationStatus: {\n read: 0,\n notRead: 1\n },\n eLinkType:\n {\n Download: 0,\n Url: 1\n },\n setUnreadCount(count) {\n this.$unreadCount.text(count);\n this.$innerCount.text(Space1.Strings.getKey('YouHave{}Notifications').replace('{}', count));\n if (count == 0) {\n this.$unreadCount.css('opacity', 0);\n } else {\n this.$unreadCount.css('opacity', 100);\n }\n },\n setNotifications(notifications) { // array of notificationModel\n this.$list.empty();\n\n notifications.forEach(notification => {\n this.addNotification(notification);\n });\n },\n addNotification(notification) {\n if (notification) {\n if ($(\"#\" + notification.id.toSafeID()).length == 0) {\n const $notification = $('
  • ', {\n id: notification.id.toSafeID(),\n class: `notification notification--${Object.keys(this.eNotificationStatus)[notification.status]} notification--${Object.keys(this.eNotificationTypes)[notification.type]} notification--${Object.keys(this.eNotificationExecutionStatus)[notification.state]}`\n });\n const $notificationProgressBar = $('
    ').hide();\n\n $notification.append(``)\n\n $notification.append(`${notification.text}`);\n $notification.append($notificationProgressBar);\n\n $notification.click(() => {\n this.doNotificationAction(notification);\n });\n\n this.$list.append($notification);\n\n if (notification.type == this.eNotificationTypes.progress && (notification.state == this.eNotificationExecutionStatus.inProgress || notification.state == this.eNotificationExecutionStatus.queue && notification.state != this.eNotificationExecutionStatus.error)) {\n this.attachProgress(notification);\n }\n\n this.notifications.push(notification);\n this.setUnreadCount(this.notifications.length);\n }\n }\n },\n attachProgress(notification) {\n const $notificationProgressBar = $(`#${notification.id.toSafeID()} .notification__progressbar`);\n if (notification.state.error) {\n $notificationProgressBar.hide();\n } else {\n $notificationProgressBar.show();\n const loadAnimation = $notificationProgressBar[0][\"loadAnimation\"] !== undefined ? $notificationProgressBar[0][\"loadAnimation\"] : new LoadAnimation(`#${notification.id.toSafeID()} .notification__progressbar`, \"progressbar\");\n loadAnimation.setProgress(notification.progress, `${notification.progress}%`);\n }\n\n if (notification.progress == 100) {\n $notificationProgressBar.hide();\n }\n },\n updateNotification(notification) {\n if (notification) {\n const $notification = this.$list.find(\"#\" + notification.id.toSafeID());\n $notification.find(\".notification__text\").text(notification.Description);\n\n Object.keys(this.eNotificationExecutionStatus).forEach(k => {\n $notification.removeClass(`notification--${k}`);\n });\n $notification.addClass(`notification--${Object.keys(this.eNotificationExecutionStatus)[notification.state]}`);\n\n $notification.off('click');\n $notification.click(() => {\n this.doNotificationAction(notification);\n });\n\n if (notification.type == this.eNotificationTypes.queue || notification.type == this.eNotificationTypes.progress) {\n this.attachProgress(notification);\n }\n }\n },\n getNotificationIcon(notification) {\n switch (notification.type) {\n case this.eNotificationTypes.alert:\n return 'fas fa-exclamation-triangle';\n case this.eNotificationTypes.pendingApproval:\n return 'fas fa-business-time';\n case this.eNotificationTypes.progress:\n if (notification.state == this.eLinkType.error) {\n return \"fas fa-times\";\n }\n if (notification.linktype != null) {\n if (notification.linktype == this.eLinkType.Download) {\n return 'fas fa-download';\n } else if (notification.linktype == this.eLinkType.Url) {\n return 'glyphicon glyphicon-arrow-right';\n }\n }\n default:\n return 'far fa-circle';\n }\n },\n doNotificationAction(notification) {\n if (notification.type != this.eNotificationTypes.progress || notification.state == this.eNotificationExecutionStatus.completed) {\n var unreadcount = parseInt(this.$unreadCount.text());\n if (unreadcount >= 1) {\n this.setUnreadCount(unreadcount - 1);\n } else {\n this.setUnreadCount(0);\n }\n $(\"#\" + notification.id.toSafeID()).hide();\n\n this.connection.invoke(\"ReadNotification\", notification.id);\n let modalContentUrl = '';\n\n let modal = null;\n switch (notification.type) {\n case this.eNotificationTypes.progress:\n if (notification.state == this.eNotificationExecutionStatus.completed || notification.state == this.eNotificationExecutionStatus.error) {\n $.ajax({\n url: `${Space1.Env.getBaseUrl()}/Notification/ShowNotification?notificationId=${notification.id}`,\n success: function (redirect) {\n $(\"body\").append(redirect);\n }\n });\n }\n break;\n case this.eNotificationTypes.pendingApproval:\n window.location.href = `${Space1.Env.getBaseUrl()}/WorkflowPendingApproval`;\n break;\n default:\n modalContentUrl = `${Space1.Env.getBaseUrl()}/Notification/ShowNotification?notificationId=${notification.id}`;\n modal = new Space1.UI.Modal({\n remote: modalContentUrl,\n backdrop: 'static',\n size: 'large',\n defaultActions: false,\n autodestruction: true,\n autodestructionWait: 0,\n footer: true,\n });\n\n modal.dom.$modal.on('loaded.bs.modal', () => {\n\n });\n\n modal.open();\n break;\n }\n }\n },\n onOpen() {\n\n },\n onViewAll() {\n\n },\n initSignalr() {\n let self = this;\n var connection = new signalR.HubConnectionBuilder()\n .withUrl(\"/notificationsHub\")\n .build();\n\n const newNotificaiton = function (notification) {\n const resultObj = JSON.parse(notification);\n console.log(resultObj);\n let n = {\n type: resultObj.Type,\n text: resultObj.Description,\n id: '' + resultObj.NotificationId,\n status: self.eNotificationStatus.notRead,\n progress: resultObj.ProgressPercentage,\n state: resultObj.ExecutionState,\n linktype: resultObj.LinkType\n };\n self.addNotification(n);\n }\n\n const updateNotificaitonManagement = function (notification) {\n const resultObj = JSON.parse(notification);\n console.log(resultObj);\n let n = {\n type: resultObj.Type,\n text: resultObj.Description,\n id: '' + resultObj.NotificationId,\n status: self.eNotificationStatus.notRead,\n progress: resultObj.ProgressPercentage,\n state: resultObj.ExecutionState,\n linktype: resultObj.LinkType\n };\n self.updateNotification(n);\n }\n\n const unreadNotifications = function (result) {\n const resultObj = JSON.parse(result);\n console.log(resultObj);\n self.setUnreadCount(resultObj.UnreadNotificationsCount);\n resultObj.Notifications.forEach(notification => {\n self.addNotification({\n type: notification.Type,\n text: notification.Description,\n id: '' + notification.NotificationId,\n status: self.eNotificationStatus.notRead,\n progress: notification.ProgressPercentage,\n state: notification.ExecutionState,\n linktype: notification.LinkType\n });\n });\n }\n\n connection.on(\"UnreadNotificationsResult\", unreadNotifications);\n connection.on(\"NewNotification\", newNotificaiton);\n connection.on(\"UpdateNotification\", updateNotificaitonManagement);\n\n connection.start().then(function () {\n console.log(\"Started hub\")\n connection.invoke(\"UnreadNotifications\");\n }).catch(function (err) {\n return console.error(err.toString());\n });\n return connection;\n },\n init() {\n this.$dropdown = $('#notifications-dropdown');\n this.$list = $('#notifications-list');\n this.$btn = $('#notifications-button');\n this.$viewAllBtn = $('#notification-view-all');\n this.$unreadCount = $('#notifications-unread-count');\n this.$innerCount = $('#notifications-inner-count');\n\n this.$btn.click(() => {\n this.isOpen = !this.isOpen;\n\n if (this.isOpen) {\n this.onOpen();\n }\n });\n\n this.$viewAllBtn.click(() => {\n this.onViewAll();\n });\n\n this.connection = this.initSignalr();\n // here we should get the unread notifications count\n },\n};\n"]}