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

Assignment Todolist [Farman khan] #43

Open
wants to merge 2 commits into
base: master
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
54 changes: 54 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<style>
.striked {
text-decoration: line-through;
}
ul > li:hover {
cursor: pointer;
}
</style>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-8 form-group">
<input class="form-control" id="newTodo" type="text" placeholder="Add new todo">
<small class="form-text text-muted">Today I must ...</small>
<input class="form-control" id="TodoDate" type="date" >
<small class="form-text text-muted">Complete it till..</small>
</div>
<div class="col-4">
<div class="flex-row justify-content-center align-items-center ">
<button class="btn btn-primary mt-1 mt-md-0" onclick="addTodo()">ADD +</button>
<button class="btn btn-secondary mt-1 mt-md-0" >Reset</button>
<button class="btn btn-danger mt-1 mt-md-0" onclick="removeTodos()">Bin</button>
<button class="btn btn-danger mt-1 mt-md-0" onclick="sortTodo()">Sort</button>

</div>
</div>
</div>

<div class="row mt-2">
<div class="col-10 offset-1 ">
<ul>

</ul>
</div>

</div>


</div>


<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="index.js" defer></script>
</body>
</html>
116 changes: 116 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
let todos = [
{
id: 1,
name: "Teach Class at Nagarro",
done: true,
deadline:'09-30-2019'
},
{
id: 2,
name: "Get Coffee",
done: false,
deadline:'10-30-2019'
}
];

function render(state) {
return state
.map(todo => {
// const li = document.createElement('li')
// li.classList.add("striked")
// document.body.append(li)
const classString = todo.done ? `class = "list-group-item striked list-group-item-primary"` : `class = "list-group-item list-group-item-info"`
return `<li data-todo="${todo.id}" ${classString} >
<button class="btn btn-success btn-sm" data-button="btnup">UP</button>
<button class="btn btn-info btn-sm" data-button="btndn">DOWN</button>
${todo.name} <small><span style="float: right;">${todo.deadline}</span></small>
</li>`;
})
.join("");
}



function paint() {
$("ul").html(render(todos));
}

function addTodo() {
// document.getElementById('newTodo') != $('#newTodo')
const inputBox = $('#newTodo')
const dateBox = $('#TodoDate')
if(inputBox.val() == '' || dateBox.val() == '' )
return;

todos.push({
id: todos.length + 1,
name: inputBox.val(),
done: false,
deadline:dateBox.val()
})

inputBox.val('')
dateBox.val('')

paint()
}
$('ul').on("click", function (e) {
if(!(e.target.dataset.button==="btnup" || e.target.dataset.button === "btndn"))
{
let idToFind = e.target.dataset.todo
let todo = todos.find(todo => todo.id == idToFind)
todo.done = !todo.done
paint();
}
else{
if(e.target.dataset.button==="btnup")
{
e.target.parentElement.parentElement.insertBefore(
e.target.parentElement,
e.target.parentElement.previousElementSibling
)
}
else
{
e.target.parentElement.parentElement.insertBefore(
e.target.parentElement.nextElementSibling,
e.target.parentElement
)
}
}
})

function resetTodo()
{
$('#newTodo').val('')
$('#TodoDate').val('')

}
function sortTodo()
{
todos.sort(function(a, b) { return new Date(a.deadline) - new Date(b.deadline) })
paint();
}

function removeTodos() {
todos = todos.filter(todo => !todo.done)

paint()
}


// $('ul').on("click", function (e) {
// const idToFind = e.target.dataset.todo
// const todo = todos.find(todo => todo.id == idToFind)
// todo.done = !todo.done

// paint()
// })

$('#newTodo').on("keypress", function (e) {
if (e.which == 13) {
addTodo()
}
})

paint();
82 changes: 37 additions & 45 deletions spa/index.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<style>
.striked {
text-decoration: line-through;
}
ul > li:hover {
cursor: pointer;
}
</style>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-8 form-group">
<input class="form-control" id="newTodo" type="text" placeholder="Today i must...">
<small class="form-text text-muted">Add a new todo</small>
</div>
<div class="col-4">
<div class="flex-row justify-content-center align-items-center">
<button class="btn btn-primary mt-1 mt-md-0" onclick="addTodo()">ADD +</button>
<button class="btn btn-secondary mt-1 mt-md-0" >Reset</button>
<button class="btn btn-danger mt-1" onclick="removeTodos()">Bin</button>
</div>
</div>
</div>

<div class="row mt-2">
<div class="col-10 offset-1">
<ul class="list-group">

</ul>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-responsive.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<title>Document</title>
</head>
<style>
.striked {
text-decoration: line-through;
}
</style>
<body>
<div class="input-group mb-3">
<input id="newTodo" class=class="custom-file-input" type="text" placeholder="Add new todo" style="margin-left:40%;margin-top:50px">
<div class="input-group-append">
<button id="btn1" class="btn btn-primary btn-sm" onclick="addTodo()" style="margin-top:50px"> ADD +</button>
</div>

</div>

<table style="margin-left:40%;margin-top:50px">
</table>

<button class="btn btn-dark btn-sm" onclick="removeStrike()" style="margin-left:44%;margin-top:4%">BIN </button>
<script>
$("#newTodo").keyup(function(event) {
if (event.keyCode === 13) {
$("#btn1").click("addTodo()");
}
});

</div>


</div>


<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="index.js" defer></script>
</body>
</script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="index.js" defer></script>
</body>
</html>
Loading