Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Priorities, and edit options for tasks #154

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PORT = 2121
DB_STRING = mongodb+srv://demo:demo@cluster0.hcds1.mongodb.net/todos?retryWrites=true&w=majority
DB_STRING = mongodb+srv://Devknight:Testing@cluster0.k84utii.mongodb.net/?retryWrites=true&w=majority
20 changes: 18 additions & 2 deletions controllers/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
},
createTodo: async (req, res)=>{
try{
await Todo.create({todo: req.body.todoItem, completed: false, userId: req.user.id})
await Todo.create({todo: req.body.todoItem, completed: false, priority: req.body.todoPriority, userId: req.user.id})
console.log('Todo has been added!')
res.redirect('/todos')
}catch(err){
Expand Down Expand Up @@ -51,5 +51,21 @@ module.exports = {
}catch(err){
console.log(err)
}
}
},

updateTodo: async (req, res)=>{
console.log(req.body.taskID)

try{
await Todo.findOneAndUpdate({_id:req.body.taskID},{
todo: req.body.todoTaskEdit,
priority: req.body.todoPriorityEdit,
})
console.log("updated to information")
res.redirect('/todos')
}catch(err){
console.log(err)
}
},

}
5 changes: 5 additions & 0 deletions models/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const TodoSchema = new mongoose.Schema({
userId: {
type: String,
required: true
},
priority: {
type: Number,
required: true
}
})


module.exports = mongoose.model('Todo', TodoSchema)
36 changes: 35 additions & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,38 @@ h1{
}
.not{
text-decoration: underline;
}
}

.delete:hover{
background-color: red;
font-weight: bold;
cursor: pointer;
border: 3px solid black;
}

.urgent{
background-color: red;
font-weight: bold;
}
.urgent:hover{
background-color: pink;
font-weight: bold;
}

.high{
background-color: yellow;
font-weight: bold;
}
.normal{
background-color: yellowgreen;
font-weight: bold;
}
.low{
background-color: lightblue;
font-weight: bold;
}
.backlog{
background-color: grey;
font-weight: bold;

}
28 changes: 27 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const deleteBtn = document.querySelectorAll('.del')
const todoItem = document.querySelectorAll('span.not')
const todoComplete = document.querySelectorAll('span.completed')
// const submitbtns = document.querySelectorAll('#submit')

Array.from(deleteBtn).forEach((el)=>{
el.addEventListener('click', deleteTodo)
el.classList.add('delete')
})

Array.from(todoItem).forEach((el)=>{
Expand All @@ -14,6 +16,12 @@ Array.from(todoComplete).forEach((el)=>{
el.addEventListener('click', markIncomplete)
})

// Array.from(submitbtns).forEach((el)=>{
// el.addEventListener('click', update)
// })



async function deleteTodo(){
const todoId = this.parentNode.dataset.id
try{
Expand Down Expand Up @@ -66,4 +74,22 @@ async function markIncomplete(){
}catch(err){
console.log(err)
}
}
}

// async function update(){
// const todoId = this.parentNode.dataset.id
// try{
// const response = await fetch('todos/update', {
// method: 'put',
// headers: {'Content-type': 'application/json'},
// body: JSON.stringify({
// 'todoOBJ': todoId
// })
// })
// const data = await response.json()
// console.log(data)
// location.reload()
// }catch(err){
// console.log(err)
// }
// }
2 changes: 2 additions & 0 deletions routes/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ router.put('/markIncomplete', todosController.markIncomplete)

router.delete('/deleteTodo', todosController.deleteTodo)

router.post('/updateTodo', todosController.updateTodo)

module.exports = router
118 changes: 112 additions & 6 deletions views/todos.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,133 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h1>Todos</h1>
<ul>
<% todos.forEach( el => { %>
<li class='todoItem' data-id='<%=el._id%>'>
<ul class="list-group">
<% todos.forEach( (el) => { %>
<li class='todoItem list-group-item' data-id='<%=el._id%>'>
<span class='<%= el.completed === true ? 'completed' : 'not'%>'><%= el.todo %></span>
<span class='del'> Delete </span>

<% switch(el.priority) {
case 1 : %>
<span class="urgent">Urgent</span>
<% break;
case 2 : %>
<span class="high">High</span>
<% break;
case 3 : %>
<span class="normal">Normal</span>
<% break;
case 4 : %>
<span class="low">Low</span>
<% break;
case 5 : %>
<span class="backlog">Backlogged</span>
<% break;
} %>

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary edit" data-bs-toggle="modal" data-bs-target="#<%='modal'+ el.id%>">Edit</button>


<!-- modal variables to programmatically created modal -->
<!-- modal -->
<div class="modal fade" id="<%='modal'+ el.id%>" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">Update To Do Item</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="/todos/updateTodo" method='POST'>
<input name="taskID" style="display:none" value="<%=el.id%>">
<input type="text" value="<%=el.todo%>" name="todoTaskEdit">
<label for="todoPriorityEdit">Priority:</label>
<select id="todoPriorityEdit" name="todoPriorityEdit">

<% switch(el.priority) {
case 1 : %>
<option value=1 selected>Urgent</option>
<option value=2>High</option>
<option value=3>Normal</option>
<option value=4>Low</option>
<option value=5>Backlog</option>
<% break;
case 2 : %>
<option value=1>Urgent</option>
<option value=2 selected>High</option>
<option value=3>Normal</option>
<option value=4>Low</option>
<option value=5>Backlog</option>
<% break;
case 3 : %>
<option value=1>Urgent</option>
<option value=2>High</option>
<option value=3 selected>Normal</option>
<option value=4>Low</option>
<option value=5>Backlog</option>
<% break;
case 4 : %>
<option value=1>Urgent</option>
<option value=2>High</option>
<option value=3>Normal</option>
<option value=4 selected>Low</option>
<option value=5>Backlog</option>
<% break;
case 5 : %>
<option value=1>Urgent</option>
<option value=2>High</option>
<option value=3>Normal</option>
<option value=4>Low</option>
<option value=5 selected>Backlog</option>

<% break;
} %>
</select>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" id="submit" class="btn btn-primary">Understood</button>
</div>
</form> <!--end form -->
</div>
</div>
</div>
<!-- end modal -->


<span class='del'> Delete </span>
</li>
<% }) %>
<% }) %> <!-- end foreach loop -->
</ul>

<h2><%= user.userName %> has <%= left %> things left to do.</h2>

<form action="/todos/createTodo" method='POST'>
<input type="text" placeholder="Enter Todo Item" name='todoItem'>

<label for="todoPriority">Priority:</label>
<select id="todoPriority" name="todoPriority">
<option value=1>Urgent</option>
<option value=2>High</option>
<option value=3 selected>Normal</option>
<option value=4>Low</option>
<option value=5>Backlog</option>
</select>

<input type="submit">
</form>

<a href="/logout">Logout</a>



<script src="js/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
</body>
</html>
</html>