From 2dae0089872c89d8a569e94ee976cdf689870740 Mon Sep 17 00:00:00 2001 From: IshikaMaheshwari <56021457+IshikaMaheshwari@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:05:47 +0530 Subject: [PATCH 1/2] Update index.html --- spa/index.html | 62 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/spa/index.html b/spa/index.html index 36f06aa..4d080d9 100644 --- a/spa/index.html +++ b/spa/index.html @@ -1,50 +1,74 @@ + + + + Document - + + + + + +
-
- - Add a new todo +
+
+
+ +
+
+ +
+
-
-
- - - +
+
+ + + +
- +
-
    - -
+
    + +
- +
- -
+
- + - \ No newline at end of file + + From ec3679f937eb03f6f45679dd065171d8c2ea9f36 Mon Sep 17 00:00:00 2001 From: IshikaMaheshwari <56021457+IshikaMaheshwari@users.noreply.github.com> Date: Tue, 1 Oct 2019 16:06:19 +0530 Subject: [PATCH 2/2] Update index.js --- spa/index.js | 152 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 63 deletions(-) diff --git a/spa/index.js b/spa/index.js index 062d888..bcc835a 100644 --- a/spa/index.js +++ b/spa/index.js @@ -1,67 +1,93 @@ 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, + deadline: new Date(2019, 11, 24) + }, + { + id: 2, + name: "Get Coffee", + 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 `
  • ${todo.name} ${todo.deadline.getDate()}/${todo.deadline.getMonth()}/${todo.deadline.getFullYear()}
  • `; + }) + .join(""); } -]; - -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 `
  • ${todo.name}
  • `; + + 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() + } + + 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() } -}) - -paint(); + + $("#sortable").sortable({ + update: function (event, ui) { + let temp = []; + var idsInOrder = $("#sortable").sortable().toArray(); + + children = idsInOrder[0].children; + for (var i = 0; i < children.length; i++) { + temp[i] = todos.find(todo => todo.id == children[i].attributes['0'].value) + } + todos = temp; + paint(); + } + }); + + function reset() { + todos=[] + 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, #newTododate').on("keypress", function (e) { + if (e.which == 13) { + addTodo() + } + }) + + paint();