From 2bc6b2bdba84b5f004e2f04b541b9e98c3b84408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 19 Apr 2022 16:26:08 +0200 Subject: [PATCH] Web: start of notification bar Use Pinia store for notifications. WIP, only the last one is shown in the footer. --- web/app/src/App.vue | 11 +++++++++ web/app/src/components/JobActionsBar.vue | 7 ++++-- web/app/src/components/JobsTable.vue | 9 ++++--- web/app/src/stores/notifications.js | 31 ++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 web/app/src/stores/notifications.js diff --git a/web/app/src/App.vue b/web/app/src/App.vue index 2bfac418..935d3d7d 100644 --- a/web/app/src/App.vue +++ b/web/app/src/App.vue @@ -14,6 +14,7 @@
Footer + {{ notifs.last.msg }}
@@ -23,6 +24,7 @@ import * as urls from '@/urls' import * as API from '@/manager-api'; import { useJobs } from '@/stores/jobs'; +import { useNotifs } from '@/stores/notifications'; import ApiSpinner from '@/components/ApiSpinner.vue' import JobsTable from '@/components/JobsTable.vue' @@ -44,6 +46,7 @@ export default { messages: [], jobs: useJobs(), + notifs: useNotifs(), flamencoName: DEFAULT_FLAMENCO_NAME, flamencoVersion: DEFAULT_FLAMENCO_VERSION, @@ -145,6 +148,8 @@ export default { --header-height: 25px; --footer-height: 25px; --grid-gap: 4px; + + --action-bar-height: 3em; } html, @@ -221,6 +226,12 @@ footer { grid-area: footer; background-color: #333333; color: #EEE; + padding-top: 0.2rem; + padding-left: 0.2rem; +} + +section.action-bar { + height: var(--action-bar-height); } section.action-bar button.action { diff --git a/web/app/src/components/JobActionsBar.vue b/web/app/src/components/JobActionsBar.vue index 3440edf2..eadd51ad 100644 --- a/web/app/src/components/JobActionsBar.vue +++ b/web/app/src/components/JobActionsBar.vue @@ -6,12 +6,14 @@ - diff --git a/web/app/src/stores/notifications.js b/web/app/src/stores/notifications.js new file mode 100644 index 00000000..82301999 --- /dev/null +++ b/web/app/src/stores/notifications.js @@ -0,0 +1,31 @@ +import { defineStore } from 'pinia' + +/** + * Store notifications to users of the web frontend. + */ +export const useNotifs = defineStore('notifications', { + state: () => ({ + /** @type {{ msg: string, time: Date }[]} */ + history: [], + /** @type { msg: string, time: Date } */ + last: null, + }), + actions: { + /** + * Add a simple notification. + * @param {string} message + */ + add(message) { + const notif = {msg: message, time: new Date()}; + this.history.push(notif); + this.last = notif; + this._prune(); + }, + + /* Ensure there is only 1000 items in the history. */ + _prune() { + if (this.history.length <= 1000) return; + this.history.splice(0, 1000 - this.history.length); + }, + }, +})