Commit 0f0b76b4 authored by Matthieu Fesselier's avatar Matthieu Fesselier

feature: auto refresh

parent 44dfb9b0
Pipeline #4250 passed with stage
in 27 seconds
......@@ -49,6 +49,13 @@ class SIBNotifications extends SIBTemplateElement {
if (notificationsMenu) notificationsMenu.removeAttribute("open")
}
});
// Refresh every 30 seconds
window.setInterval(() => {
if (!this.querySelector('details').hasAttribute("open")) { // prevent menu from closing on refresh
this.refresh()
}
}, 30000);
}
static get propsDefinition() {
......@@ -75,6 +82,11 @@ class SIBNotifications extends SIBTemplateElement {
}
}
refresh() {
const context = document.querySelector('#notifications-list').context;
store.get(this.resourceId, context, true).then(() => this.render())
}
/* Events listeners */
_onReadResource(resourceId) {
const edits = this._getNotificationsList()
......@@ -128,9 +140,12 @@ class SIBNotifications extends SIBTemplateElement {
return this.props.dateFormat ? this.props.dateFormat : 'DD/MM/YYYY - kk:mm';
}
template({ dataSrc, idSuffix }) {
get resourceId() {
return this.props.dataSrc + (this.props.idSuffix ? this.props.idSuffix + '/' : '')
}
template({ dataSrc }) {
if (dataSrc) {
let sourceUrl = dataSrc + (idSuffix ? idSuffix + '/' : '')
return `
<div class="sib-notifications">
<sib-widget name="custom-date">
......@@ -142,7 +157,7 @@ class SIBNotifications extends SIBTemplateElement {
<div class="sib-notifications__counter">
<sib-display
id="unread-filter"
data-src="${sourceUrl}"
data-src="${this.resourceId}"
data-fields="none"
search-fields="unread"
search-value-unread="true"
......@@ -155,7 +170,7 @@ class SIBNotifications extends SIBTemplateElement {
<sib-display
id="notifications-list"
class="sib-notifications__items"
data-src="${sourceUrl}"
data-src="${this.resourceId}"
widget-unread="read-badge"
set-source="type, object.name"
widget-object.name="sib-display-labelled-div"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment