|
|
@ -15,7 +15,7 @@ export default class extends Controller { |
|
|
|
const commonOptions = { gravity: 'top', position: 'center', duration: 4000, offset: { y: '1em' }, close: true, escapeMarkup: false } |
|
|
|
this.toastifyNotice = Toastify({ className: 'toastify-notice', ...commonOptions }) |
|
|
|
this.toastifyAlert = Toastify({ className: 'toastify-alert', ...commonOptions }) |
|
|
|
this.lastId = 0 |
|
|
|
this.idQueue = Array(5) |
|
|
|
} |
|
|
|
|
|
|
|
initialize() { |
|
|
@ -23,14 +23,16 @@ export default class extends Controller { |
|
|
|
} |
|
|
|
|
|
|
|
connect() { |
|
|
|
const id = this.element.dataset.id |
|
|
|
if (id != this.constructor.lastId) { // test whether duplicates
|
|
|
|
this.constructor.lastId = id |
|
|
|
|
|
|
|
const id = Number(this.element.dataset.id) |
|
|
|
const queue = this.constructor.idQueue |
|
|
|
if (!this.constructor.idQueue.includes(id)) { // test whether duplicates from the 5 latest items
|
|
|
|
queue.splice(0, 0, id) |
|
|
|
queue.splice(5) |
|
|
|
this.clearChildrenElement() |
|
|
|
this.showMessage(this.constructor.toastifyNotice, this.element.dataset.notice) |
|
|
|
this.showMessage(this.constructor.toastifyAlert, this.element.dataset.alert) |
|
|
|
} |
|
|
|
// else console.warn(`reminiscient id <${id}> from queue <${queue}`)
|
|
|
|
} |
|
|
|
|
|
|
|
showMessage(toastify, message) { |
|
|
@ -40,7 +42,7 @@ export default class extends Controller { |
|
|
|
toastify.showToast() |
|
|
|
|
|
|
|
const lastClassNameWord = toastify.options.className.split('-').pop() |
|
|
|
console.info(`TOAST ${lastClassNameWord}: ${message}`) |
|
|
|
console.info(`TOAST#${this.constructor.idQueue[0]} ${lastClassNameWord}: ${message}`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|