Commit 0864a99b authored by Matthieu Fesselier's avatar Matthieu Fesselier

Merge branch 'feature/auto-refresh' into 'master'

feature: auto refresh

See merge request !15
parents 44dfb9b0 0f0b76b4
Pipeline #4256 passed with stage
in 27 seconds
...@@ -49,6 +49,13 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -49,6 +49,13 @@ class SIBNotifications extends SIBTemplateElement {
if (notificationsMenu) notificationsMenu.removeAttribute("open") 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() { static get propsDefinition() {
...@@ -75,6 +82,11 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -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 */ /* Events listeners */
_onReadResource(resourceId) { _onReadResource(resourceId) {
const edits = this._getNotificationsList() const edits = this._getNotificationsList()
...@@ -128,9 +140,12 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -128,9 +140,12 @@ class SIBNotifications extends SIBTemplateElement {
return this.props.dateFormat ? this.props.dateFormat : 'DD/MM/YYYY - kk:mm'; 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) { if (dataSrc) {
let sourceUrl = dataSrc + (idSuffix ? idSuffix + '/' : '')
return ` return `
<div class="sib-notifications"> <div class="sib-notifications">
<sib-widget name="custom-date"> <sib-widget name="custom-date">
...@@ -142,7 +157,7 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -142,7 +157,7 @@ class SIBNotifications extends SIBTemplateElement {
<div class="sib-notifications__counter"> <div class="sib-notifications__counter">
<sib-display <sib-display
id="unread-filter" id="unread-filter"
data-src="${sourceUrl}" data-src="${this.resourceId}"
data-fields="none" data-fields="none"
search-fields="unread" search-fields="unread"
search-value-unread="true" search-value-unread="true"
...@@ -155,7 +170,7 @@ class SIBNotifications extends SIBTemplateElement { ...@@ -155,7 +170,7 @@ class SIBNotifications extends SIBTemplateElement {
<sib-display <sib-display
id="notifications-list" id="notifications-list"
class="sib-notifications__items" class="sib-notifications__items"
data-src="${sourceUrl}" data-src="${this.resourceId}"
widget-unread="read-badge" widget-unread="read-badge"
set-source="type, object.name" set-source="type, object.name"
widget-object.name="sib-display-labelled-div" 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