Skip to content
Snippets Groups Projects
Commit 695372d7 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Implement auto-delete, manual delete, fixed notifications and better demo messages

parent 959f4583
No related branches found
No related tags found
No related merge requests found
module.exports = {
createUUID: () => {
let dt = new Date().getTime();
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (dt + Math.random()*16)%16 | 0;
dt = Math.floor(dt/16);
return (c==='x' ? r :(r&0x3|0x8)).toString(16);
});
return uuid;
}
};
...@@ -47,10 +47,11 @@ class NotificationDemo extends LitElement { ...@@ -47,10 +47,11 @@ class NotificationDemo extends LitElement {
} }
send() { send() {
const types = ["primary", "link", "info", "success", "danger", "warning"];
notification.send({ notification.send({
"summary": "Item deleted", "summary": "Item deleted",
"body": "Item foo was deleted!", "body": `Item ${Math.random().toString(36).substring(7)} foo was deleted!`,
"type": "info", "type": types[Math.floor(Math.random() * types.length)],
"timeout": 5, "timeout": 5,
}); });
} }
......
import {i18n} from './i18n.js'; import {i18n} from './i18n';
import utils from './utils'
import {html} from 'lit-element'; import {html} from 'lit-element';
import VPULitElement from 'vpu-common/vpu-lit-element' import VPULitElement from 'vpu-common/vpu-lit-element'
...@@ -30,28 +31,49 @@ class VPUNotification extends VPULitElement { ...@@ -30,28 +31,49 @@ class VPUNotification extends VPULitElement {
return; return;
} }
that.notificationBlock = that._("#notification");
const notificationId = `notification-${utils.createUUID()}`;
const type = typeof e.detail.type !== 'undefined' ? e.detail.type : "info"; const type = typeof e.detail.type !== 'undefined' ? e.detail.type : "info";
const body = typeof e.detail.body !== 'undefined' ? e.detail.body : ""; const body = typeof e.detail.body !== 'undefined' ? e.detail.body : "";
const summary = typeof e.detail.summary !== 'undefined' ? e.detail.summary : ""; const summary = typeof e.detail.summary !== 'undefined' ? e.detail.summary : "";
const timeout = typeof e.detail.timeout !== 'undefined' ? e.detail.timeout : 0; const timeout = typeof e.detail.timeout !== 'undefined' ? e.detail.timeout : 0;
const summaryHTML = summary !== "" ? `<strong>${summary}</strong><br/>` : "";
// TODO: take care about summary and timeout that.notificationBlock.innerHTML = `
that._("#notification").innerHTML += ` <div id="${notificationId}" class="notification is-${type}">
<div id="notification" class="notification is-${type}"> <button id="${notificationId}-button" onclick="parentNode.parentNode.removeChild(parentNode)" class="delete"></button>
<button class="delete"></button> ${summaryHTML}
${body} ${body}
</div> </div>
`; ` + that.notificationBlock.innerHTML;
const messageId = `#${notificationId}`;
if (timeout > 0) {
setTimeout(() => {
that.removeMessageId(messageId);
}, timeout * 1000);
}
}); });
this.updateComplete.then(()=>{ this.updateComplete.then(()=>{
}); });
} }
removeMessageId(messageElementId) {
const element = this._(messageElementId);
if (element) {
this.notificationBlock.removeChild(element);
}
}
render() { render() {
return html` return html`
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<style> <style>
#notification {position: fixed; top: 0; max-width: 500px; margin: 1% auto; left: 0; right: 0;}
</style> </style>
<div class="columns"> <div class="columns">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment