diff --git a/spa/index.html b/spa/index.html index 36f06aa..dcf0932 100644 --- a/spa/index.html +++ b/spa/index.html @@ -1,50 +1,64 @@ + Document - + + + + + +
-
- - Add a new todo +
+
+
+ +
+
+ +
+
+ Add a new todo
-
-
- - +
+
+ + +
- +
-
    - -
+
    + +
- +
- -
+
- + - \ No newline at end of file + + diff --git a/spa/index.js b/spa/index.js index 062d888..18c0b0e 100644 --- a/spa/index.js +++ b/spa/index.js @@ -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 `
  • ${todo.name}
  • `; + { + 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 `
  • ${todo.name} ${todo.deadline}
  • `; + }) + .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();