Skip to content

Commit

Permalink
Addded capability to delete tasks, that do not count towards progress…
Browse files Browse the repository at this point in the history
… metrics on dashboard
  • Loading branch information
hizaidii committed Feb 15, 2024
1 parent 2805dbc commit 2c0cb0a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
27 changes: 23 additions & 4 deletions controllers/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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 });
Expand All @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const taskSchema = new Schema({
},
position: {
type: Number,
default: 0, // Initialize to 0 or another appropriate value
default: 0,
},
});

Expand All @@ -40,7 +40,6 @@ const boardSchema = new Schema({
const userSchema = new Schema({
username: {
type: String,
// required: true,
},
name: String,
password: String,
Expand All @@ -54,10 +53,6 @@ const userSchema = new Schema({
type: Number,
default: 0,
},
// currentTasks: {
// type: Number,
// default: 0,
// },

FB_AccessToken: String,
FB_ID: String,
Expand Down
27 changes: 26 additions & 1 deletion public/js/celebrationFn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
});
});
});
1 change: 1 addition & 0 deletions routes/appRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion views/app/board.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<a class="editTaskBtn" data-id="{{task.id}}">Edit task</a>
<br />
<br />
<a class="celebrate-btn" data-task-id="{{task._id}}" data-swimlane-id="{{swimlane.id}}" data-board-id="{{../../board.id}}">Mark as complete</a>
<a class="delete-task-btn" data-task-id="{{task._id}}" data-swimlane-id="{{swimlane.id}}" data-board-id="{{../../board.id}}">Delete Task</a>
</div>
</div>
</div>
Expand Down

0 comments on commit 2c0cb0a

Please sign in to comment.