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

Assignment1[Mohammad Asif] #41

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
50 changes: 32 additions & 18 deletions spa/index.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,64 @@
<!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">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</head>
<style>
.striked {
text-decoration: line-through;
}
ul > li:hover {
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 class="col-sm-8 col-12 form-group">
<div class="row">
<div class="col-sm-8 col-6">
<input class="form-control" id="newTodo" type="text" placeholder="Add What's On Your Mind...!!">
</div>
<div class="col-sm-4 col-6">
<input class="form-control" id="newTododate" type="date">
</div>
</div>
<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>
<div class="col-sm-3 col-12">
<div class="flex-row justify-content-center align-items-center">
<button class="btn btn-primary mt-1" onclick="addTodo()">ADD +</button>
<button class="btn btn-secondary mt-1" onclick="reset()">Reset</button>
<button class="btn btn-danger mt-1" onclick="removeTodos()">Bin</button>
<button class="btn btn-warning mt-1" onclick="sortTodos()">Sort</button>
</div>
</div>
</div>

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

</ul>
<ul id = "sortable" class="list-group">
</ul>
</div>

</div>


</div>

</div>

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

<script src="index.js" defer></script>
</body>
</html>

</html>
154 changes: 91 additions & 63 deletions spa/index.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,95 @@
let todos = [
{
id: 1,
name: "Teach Class at Nagarro",
done: true
},
{
id: 2,
name: "Get Coffee",
done: false
}
];
{
id: 1,
name: "Complete The Budget App",
done: false,
deadline: new Date(2019, 11, 24)
},
{
id: 2,
name: "Fork Github Repository",
done: false,
deadline: new Date(2019, 10, 11)
},

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>`;
{
id: 3,
name: "Implement Data Structures in java",
done: false,
deadline: new Date(2019, 10, 11)
}
];

function render(state) {
return state
.map(todo => {
const classString = todo.done ? `list-group-item striked` : `list-group-item`
return `<li data-todo="${todo.id}" class="draggable ${classString}" draggable="true"> ${todo.name} <span style="float: right">${todo.deadline}</span></li>`;
})
.join("");
}


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

function addTodo() {
// document.getElementById('newTodo') != $('#newTodo')
const inputBox = $('#newTodo')
const deadlinedate = $('#newTododate')
todos.push({
id: todos.length + 1,
name: inputBox.val(),
done: false,
deadline: new Date(deadlinedate.val())
})
.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)

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()

inputBox.val('')
deadlinedate.val('')

paint()
}
})

paint();



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

paint()
}

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

paint()
}


$("#sortable").sortable(function(){

});

function reset() {
$("#newTodo").val('');
$("#newTododate").val('');
}

$('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, #newTododate').on("keypress", function (e) {
if (e.which == 13) {
addTodo()
}
})


paint();