static: fix messages update only working once

This commit is contained in:
Jens Langhammer 2020-10-16 16:30:38 +02:00
parent c49b57ad1d
commit 6c0c12c90a
5 changed files with 20 additions and 13 deletions

View file

@ -53,7 +53,7 @@ class TaskViewSet(ViewSet):
task_module = import_module(task.task_call_module) task_module = import_module(task.task_call_module)
task_func = getattr(task_module, task.task_call_func) task_func = getattr(task_module, task.task_call_func)
task_func.delay(*task.task_call_args, **task.task_call_kwargs) task_func.delay(*task.task_call_args, **task.task_call_kwargs)
messages.success(self.request, _("Successfully re-scheduled Task!")) messages.success(self.request, _("Successfully re-scheduled Task %(name)s!" % {'name': task.task_name}))
return Response( return Response(
{ {
"successful": True, "successful": True,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -32,8 +32,9 @@ class ActionButton extends HTMLButtonElement {
this.classList.remove(...PROGRESS_CLASSES); this.classList.remove(...PROGRESS_CLASSES);
this.innerText = this.oldBody; this.innerText = this.oldBody;
this.classList.replace(PRIMARY_CLASS, statusClass); this.classList.replace(PRIMARY_CLASS, statusClass);
// Trigger messages to update
document.querySelector("pb-messages").setAttribute("touch", Date.now());
setTimeout(() => { setTimeout(() => {
console.log('test');
this.classList.replace(statusClass, PRIMARY_CLASS); this.classList.replace(statusClass, PRIMARY_CLASS);
}, 1000); }, 1000);
} }

View file

@ -7,8 +7,8 @@ const LEVEL_ICON_MAP = {
"info": "fas fa-info", "info": "fas fa-info",
}; };
let ID = function () { let ID = function (prefix) {
return '_' + Math.random().toString(36).substr(2, 9); return prefix + Math.random().toString(36).substr(2, 9);
}; };
class Messages extends LitElement { class Messages extends LitElement {
@ -17,23 +17,29 @@ class Messages extends LitElement {
return { return {
url: { type: String }, url: { type: String },
messages: { type: Array }, messages: { type: Array },
touch: { type: Object },
}; };
} }
set touch(value) {
this.firstUpdated();
}
createRenderRoot() { createRenderRoot() {
return this; return this;
} }
firstUpdated() { firstUpdated() {
fetch(this.url).then(r => r.json()).then(r => this.messages = r); return fetch(this.url).then(r => r.json()).then(r => this.messages = r);
} }
renderMessage(message) { renderMessage(message) {
const id = `pb-message-${ID()}`; const id = ID("pb-message");
const item = html`<li id=${id} class="pf-c-alert-group__item"> const el = document.createElement("template");
el.innerHTML = `<li id=${id} class="pf-c-alert-group__item">
<div class="pf-c-alert pf-m-${message.level_tag} ${message.level_tag === 'error' ? 'pf-m-danger': ''}"> <div class="pf-c-alert pf-m-${message.level_tag} ${message.level_tag === 'error' ? 'pf-m-danger': ''}">
<div class="pf-c-alert__icon"> <div class="pf-c-alert__icon">
<i class="${LEVEL_ICON_MAP[message.level_tag]}"> <i class="${LEVEL_ICON_MAP[message.level_tag]}"></i>
</div> </div>
<p class="pf-c-alert__title"> <p class="pf-c-alert__title">
${message.message} ${message.message}
@ -43,7 +49,7 @@ class Messages extends LitElement {
setTimeout(() => { setTimeout(() => {
this.querySelector(`#${id}`).remove(); this.querySelector(`#${id}`).remove();
}, 1500); }, 1500);
return item; return el.content.firstChild;
} }
render() { render() {