From 2c0cb0aa09bf2a501152e8a32704ec5290db8835 Mon Sep 17 00:00:00 2001 From: hizaidii <90659514+hizaidii@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:29:59 +0530 Subject: [PATCH] Addded capability to delete tasks, that do not count towards progress metrics on dashboard --- controllers/appController.js | 27 +++++++++++++++++++++++---- models/users.js | 7 +------ public/js/celebrationFn.js | 27 ++++++++++++++++++++++++++- routes/appRoutes.js | 1 + views/app/board.hbs | 2 +- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/controllers/appController.js b/controllers/appController.js index 424c091..a7883ff 100644 --- a/controllers/appController.js +++ b/controllers/appController.js @@ -224,8 +224,8 @@ module.exports.getDeleteBoard = async (req, res, next) => { } }); //updating the deleted tasks count - user.deletedTasks = Number(user.deletedTasks) || 0; - user.deletedTasks += noOfTasks; + user.totalTasks = Number(user.totalTasks) || 0; + user.totalTasks -= noOfTasks; // deleting the board user.boards.pull({ _id: boardId }); @@ -246,8 +246,8 @@ module.exports.getDeleteColumn = async (req, res, next) => { //marking all tasks in this swimlane as deleted let noOfTasks = board.swimlanes.id(swimlaneId).tasks.length; - user.deletedTasks = Number(user.deletedTasks) || 0; - user.deletedTasks += noOfTasks; + user.totalTasks = Number(user.totalTasks) || 0; + user.totalTasks -= noOfTasks; // deleting the swimlane board.swimlanes.pull({ _id: swimlaneId }); @@ -261,6 +261,25 @@ module.exports.getDeleteColumn = async (req, res, next) => { // deleting a task module.exports.getDeleteTask = async (req, res, next) => { + const { taskId, swimlaneId, boardId } = req.query; + try { + let user = await User.findById(req.user._id); + let board = user.boards.id(boardId); + let swimlane = board.swimlanes.id(swimlaneId); + swimlane.tasks.pull({ _id: taskId }); + + user.totalTasks = Number(user.totalTasks) || 0; + user.totalTasks -= 1; + + await user.save(); + res.redirect("/app/board?boardId=" + boardId); + } catch (err) { + res.render("error", { err }); + } +}; + +// completing a task +module.exports.getCompleteTask = async (req, res, next) => { const { taskId, swimlaneId, boardId } = req.query; try { let user = await User.findById(req.user._id); diff --git a/models/users.js b/models/users.js index 8d14787..67d955e 100644 --- a/models/users.js +++ b/models/users.js @@ -13,7 +13,7 @@ const taskSchema = new Schema({ }, position: { type: Number, - default: 0, // Initialize to 0 or another appropriate value + default: 0, }, }); @@ -40,7 +40,6 @@ const boardSchema = new Schema({ const userSchema = new Schema({ username: { type: String, - // required: true, }, name: String, password: String, @@ -54,10 +53,6 @@ const userSchema = new Schema({ type: Number, default: 0, }, - // currentTasks: { - // type: Number, - // default: 0, - // }, FB_AccessToken: String, FB_ID: String, diff --git a/public/js/celebrationFn.js b/public/js/celebrationFn.js index 5f255e8..5a584a9 100644 --- a/public/js/celebrationFn.js +++ b/public/js/celebrationFn.js @@ -7,7 +7,7 @@ celebrateButtons.forEach(function (button) { const swimlaneId = this.getAttribute("data-swimlane-id"); const boardId = this.getAttribute("data-board-id"); - const url = `/app/board/deleteTask?taskId=${taskId}&swimlaneId=${swimlaneId}&boardId=${boardId}`; + const url = `/app/board/completeTask?taskId=${taskId}&swimlaneId=${swimlaneId}&boardId=${boardId}`; axios .get(url) @@ -49,3 +49,28 @@ celebrateButtons.forEach(function (button) { }, 2000); }); }); + +// Delete function without celebration +const deleteBtn = document.querySelectorAll(".delete-task-btn"); + +deleteBtn.forEach(function (button) { + button.addEventListener("click", function () { + console.log("Delete button clicked"); + const taskId = this.getAttribute("data-task-id"); + const swimlaneId = this.getAttribute("data-swimlane-id"); + const boardId = this.getAttribute("data-board-id"); + const url = `/app/board/deleteTask?taskId=${taskId}&swimlaneId=${swimlaneId}&boardId=${boardId}`; + + axios + .get(url) + .then((response) => { + const taskCard = button.closest(".taskCard"); + if (taskCard) { + taskCard.remove(); + } + }) + .catch((error) => { + console.log(error); + }); + }); +}); diff --git a/routes/appRoutes.js b/routes/appRoutes.js index 6cf7c9f..caa13c0 100644 --- a/routes/appRoutes.js +++ b/routes/appRoutes.js @@ -14,6 +14,7 @@ router.get("/moveTask", appController.getMoveTask); router.get("/board/deleteBoard", appController.getDeleteBoard); router.get("/board/deleteColumn", appController.getDeleteColumn); router.get("/board/deleteTask", appController.getDeleteTask); +router.get("/board/completeTask", appController.getCompleteTask); router.post("/board/editBoard", appController.postEditBoard); router.post("/board/editSwimlane", appController.postEditSwimlane); router.post("/board/editTask", appController.postEditTask); diff --git a/views/app/board.hbs b/views/app/board.hbs index 920afa8..37d4557 100644 --- a/views/app/board.hbs +++ b/views/app/board.hbs @@ -134,7 +134,7 @@ Edit task

- Mark as complete + Delete Task