From 17a6f1cbec05d24cf0af0b198a13f1340b36f573 Mon Sep 17 00:00:00 2001 From: SebClem Date: Mon, 19 Feb 2024 10:52:37 +0100 Subject: [PATCH] :hammer: Add mark all read to message --- .../backend/src/routes/messages.ts | 15 +- .../backend/src/tools/messageManager.ts | 31 +++-- .../frontend/src/components/MessageBar.vue | 130 ++++++++++-------- .../frontend/src/services/messageService.ts | 4 + 4 files changed, 105 insertions(+), 75 deletions(-) diff --git a/nextcloud_backup/backend/src/routes/messages.ts b/nextcloud_backup/backend/src/routes/messages.ts index dd920ea..1b9cd8a 100644 --- a/nextcloud_backup/backend/src/routes/messages.ts +++ b/nextcloud_backup/backend/src/routes/messages.ts @@ -3,16 +3,21 @@ import messageManager from "../tools/messageManager.js"; const messageRouter = express.Router(); -messageRouter.get('/', (req, res, next)=>{ - res.json(messageManager.get()) +messageRouter.get("/", (req, res) => { + res.json(messageManager.get()); }); -messageRouter.patch('/:messageId/readed', (req, res, next)=>{ - if(messageManager.markReaded(req.params.messageId)){ +messageRouter.patch("/:messageId/readed", (req, res) => { + if (messageManager.markReaded(req.params.messageId)) { res.json(messageManager.get()); - }else{ + } else { res.status(404).send(); } }); +messageRouter.post("/allReaded", (req, res) => { + messageManager.markAllReaded(); + res.json(messageManager.get()); +}); + export default messageRouter; diff --git a/nextcloud_backup/backend/src/tools/messageManager.ts b/nextcloud_backup/backend/src/tools/messageManager.ts index ad80cc8..6514cd8 100644 --- a/nextcloud_backup/backend/src/tools/messageManager.ts +++ b/nextcloud_backup/backend/src/tools/messageManager.ts @@ -7,14 +7,19 @@ const maxMessageLength = 255; class MessageManager { private messages: Message[] = []; - public addMessage(type: MessageType, message: string, detail?: string, isImportant = false) { - this.messages.push({ + public addMessage( + type: MessageType, + message: string, + detail?: string, + isImportant = false + ) { + this.messages.unshift({ id: randomUUID(), message: message, type: type, time: DateTime.now(), viewed: !isImportant, - detail: detail + detail: detail, }); if (this.messages.length > maxMessageLength) { this.messages.shift(); @@ -37,24 +42,28 @@ class MessageManager { this.addMessage(MessageType.SUCCESS, message, detail); } - public get(){ + public get() { return this.messages; } - public getById(id: string){ - return this.messages.find(value=>value.id == id); - } + public getById(id: string) { + return this.messages.find((value) => value.id == id); + } - public markReaded(id: string){ - const index = this.messages.findIndex(value=>value.id == id); - if(index == -1){ + public markReaded(id: string) { + const index = this.messages.findIndex((value) => value.id == id); + if (index == -1) { return false; } this.messages[index].viewed = true; return true; } + public markAllReaded() { + this.messages.forEach((value: Message) => { + value.viewed = true; + }); + } } - const messageManager = new MessageManager(); export default messageManager; diff --git a/nextcloud_backup/frontend/src/components/MessageBar.vue b/nextcloud_backup/frontend/src/components/MessageBar.vue index f6c2d45..addf406 100644 --- a/nextcloud_backup/frontend/src/components/MessageBar.vue +++ b/nextcloud_backup/frontend/src/components/MessageBar.vue @@ -1,69 +1,76 @@