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 @@ - - - Messages - + + Messages + + + mdi-check-all + - - - - - {{ item.message }} - - - - - - - - {{ show[index] ? "mdi-chevron-up" : "mdi-information" }} - - - - - mdi-check - - + + + + + + + {{ item.raw.message }} + + + + + + + + {{ isExpanded(item) ? "mdi-chevron-up" : "mdi-information" }} + + + + + mdi-check + + - - {{ getTimeDelta(item.time) }} - + + {{ getTimeDelta(item.raw.time) }} + + + + + + + + + {{ item.raw.detail }} + + + + - - - - - - - {{ item.detail }} - - - - - + + + @@ -153,8 +160,13 @@ function markReaded(id: string) { }); } +function markAllReaded(){ + messageService.markAllRead().then((value) => { + messages.value = value; + }) +} + onBeforeUnmount(() => { clearInterval(interval); }); - -@/store/message \ No newline at end of file + \ No newline at end of file diff --git a/nextcloud_backup/frontend/src/services/messageService.ts b/nextcloud_backup/frontend/src/services/messageService.ts index 08a9821..98a0366 100644 --- a/nextcloud_backup/frontend/src/services/messageService.ts +++ b/nextcloud_backup/frontend/src/services/messageService.ts @@ -8,3 +8,7 @@ export function getMessages() { export function markRead(id: string) { return kyClient.patch(`messages/${encodeURI(id)}/readed`).json(); } + +export function markAllRead(){ + return kyClient.post(`messages/allReaded`).json(); +} \ No newline at end of file