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(To do list)_Ajay_Kumar #42

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
80 changes: 46 additions & 34 deletions spa/index.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
<!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">
<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="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script defer src="todolist.js"></script>
<title>Document</title>
</head>
<style>

.striked {
text-decoration: line-through;
}
ul > li:hover {
cursor: pointer;
}
</style>

</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>
</div>

</div>


</div>
<div class="container mt-5">
<div class="row">
<div class="col-2 form-group" style="width: 30%;">
<label>Enter List Item:</label>
<input class="form-control" id="newTodo" type="text" placeholder="Add todo list">
<label>Enter date:</label>
<input class="form-control" id="dateInput" type="date">

</div>

<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" onclick="resetItems()">Reset</button>
<button class="btn btn-danger mt-1" onclick="removeTodos()">Bin</button>
<button type="button" class="btn btn-info" id="sortitems">Sort</button>
</div>
</div>
<br/><br/>
<div class="row mt-2">
<div class="col-10 offset-1">
<ul class="list-group" style="width: 50%;">

</ul>
</div>

</div>


</div>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="todolist.js" defer></script>

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

</body>
</html>
</html>
158 changes: 102 additions & 56 deletions spa/index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,113 @@
let todos = [
{
id: 1,
name: "Teach Class at Nagarro",
done: true
},
{
id: 2,
name: "Get Coffee",
done: false
{
id: 1,
name: "Teach Class at Nagarro",
done: true,
d:"2019-11-23"
},
{
id: 2,
name: "Get Coffee",
done: false,
d:"2020-11-28"
}
];

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"` : `class = "list-group-item"`
return `<li data-todo="${todo.id}" ${classString}> ${todo.name} ${todo.d}<button class="btn" data-todo="${todo.id}">Up</button> ${' '}<button class="btn" data-todo="${todo.id}">Down</button> </li>`;
})
.join("");
}

function paint() {
$("ul").html(render(todos));
const upBtn=`<button id="ubtn">⬆</button>`

}
function moveUp(id){
const tempArray = [].concat(todos);
tempArray.push(tempArray.shift())
todos = tempArray.map((el, index) => ({
...el,
id: index + 1,
}))
paint()
}
];

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"` : `class = "list-group-item"`
return `<li data-todo="${todo.id}" ${classString}> ${todo.name} </li>`;
})
.join("");
}

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

function addTodo() {
// document.getElementById('newTodo') != $('#newTodo')
const inputBox = $('#newTodo')
todos.push({
id: todos.length + 1,
name: inputBox.val(),
done: false
})

inputBox.val('')

paint()
}



function removeTodos() {
todos = todos.filter(todo => !todo.done)
function moveDown(id){
const tempArray = [].concat(todos);
tempArray.unshift(tempArray.pop())
todos = tempArray.map((el, index) => ({
...el,
id: index + 1,
}))

paint()
}

paint()
}

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

function addTodo() {
// document.getElementById('newTodo') != $('#newTodo')
const inputdate=$('#dateInput')
const inputBox = $('#newTodo')
todos.push({
id: todos.length + 1,
name: inputBox.val(),
done: false,
d:inputdate.val()
})

inputBox.val('')

paint()
}



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

paint()
}
function resetItems(){
const inputBox = $('#newTodo')
inputBox.val('')
}

paint()
$('#sortitems').click(()=>{
todos.sort((b,a)=> new Date(a.d) - new Date(b.d) );
paint()
})

$('#newTodo').on("keypress", function (e) {
if (e.which == 13) {
addTodo()
$('ul').on("click", function (e) {
if(e.target.localName === 'button'){
if(e.target.innerText === "Up"){
moveUp(+e.target.dataset.todo)
}else if (e.target.innerText === "Down"){
moveDown(+e.target.dataset.todo)
}
}else{
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();


paint();