From 113f69f55a07cc1be12a74f9ddc8be4638280393 Mon Sep 17 00:00:00 2001 From: FarmanKhan97 Date: Mon, 30 Sep 2019 10:29:35 +0530 Subject: [PATCH 1/2] assignment farman --- spa/index.html | 82 +++++++++--------- spa/index.js | 219 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 213 insertions(+), 88 deletions(-) diff --git a/spa/index.html b/spa/index.html index 36f06aa..00b2b91 100644 --- a/spa/index.html +++ b/spa/index.html @@ -1,50 +1,42 @@ - - - - - Document - - - - -
-
-
- - Add a new todo -
-
-
- - - -
-
-
- -
-
-
    - -
+ + + + + + + + + Document + + + +
+ +
+
+ +
+ + +
+ + + - - + + + + \ No newline at end of file diff --git a/spa/index.js b/spa/index.js index 062d888..15000e4 100644 --- a/spa/index.js +++ b/spa/index.js @@ -1,67 +1,200 @@ +var len; +var temp; +var pos; +var StrikeToggleLocation; + 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 + + }, + + { + + id: 2, + + name: "Get Coffee", + + done: false + + } + ]; + +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 `
  • ${todo.name}
  • `; + + return state + + .map(todo => { + + const classString = todo.done ? `class = "striked"` : '' + + return ` + + + ${todo.name} + `; + }) + .join(""); + +} + + + +function moveup(pos) { + debugger + if (pos != 1) { + const todo1 = todos.find(todo => todo.id == pos); + const todo2 = todos.find(todo => todo.id == (pos - 1)); + + var temp = todo1.id; + todo1.id = todo2.id; + todo2.id = temp; + + const idToFind = pos - 1; + var ElementToReplaceId = idToFind - 1 + + todos[idToFind] = todo2; + todos[ElementToReplaceId] = todo1; + + + paint() + } else { + + len = todos.length; + const todo1 = todos.find(todo => todo.id == len); + const todo2 = todos.find(todo => todo.id == pos); + + temp = todo1.id; + todo1.id = todo2.id; + todo2.id = temp; + + + todos[len - 1] = todo2; + todos[pos - 1] = todo1; + + paint() + } +} + + + +function movedown(pos) { + debugger + if (pos != todos.length) { + const todo1 = todos.find(todo => todo.id == pos); + const todo2 = todos.find(todo => todo.id == (pos + 1)); + + var temp = todo1.id; + todo1.id = todo2.id; + todo2.id = temp; + + const idToFind = pos - 1; + var ElementToReplaceId = idToFind + 1 + + todos[idToFind] = todo2; + todos[ElementToReplaceId] = todo1; + + + paint() + } else { + + len = todos.length; + pos=1; + const todo1 = todos.find(todo => todo.id == len); + const todo2 = todos.find(todo => todo.id == pos); + + temp = todo1.id; + todo1.id = todo2.id; + todo2.id = temp; + + + todos[len - 1] = todo1; + todos[pos - 1] = todo2; + + paint() + } } + + + + + + + function paint() { - $("ul").html(render(todos)); + $("table").html(render(todos)); } + +$('#newTodo').keypress(function(event){ + var keycode = (event.keyCode ? event.keyCode : event.which); + if(keycode == '13'){ + addTodo() + } +}); + + function addTodo() { - // document.getElementById('newTodo') != $('#newTodo') - const inputBox = $('#newTodo') - todos.push({ - id: todos.length + 1, - name: inputBox.val(), - done: false - }) - inputBox.val('') + // document.getElementById('newTodo') != $('#newTodo') + $('button').on('click', function() { - paint() -} + }) + debugger + var inputBox = $('#newTodo') + if (inputBox.val() != "") { + todos.push({ -function removeTodos() { - todos = todos.filter(todo => !todo.done) + id: todos.length + 1, - paint() + name: inputBox.val(), + + done: false, + + }) + + inputBox.val('') + paint() + } else { + alert('Todo Name is Required'); + } } -$('ul').on("click", function (e) { - const idToFind = e.target.dataset.todo - const todo = todos.find(todo => todo.id == idToFind) - todo.done = !todo.done - paint() -}) +function ToggleStrike(StrikeToggleLocation) { + debugger + const todo = todos.find(todo => todo.id == StrikeToggleLocation) + todo.done = !todo.done + + paint(); +} -$('#newTodo').on("keypress", function (e) { - if (e.which == 13) { - addTodo() - } -}) -paint(); + +function removeStrike() { + debugger + todos = todos.filter(todo => !todo.done) + len = todos.length; + for (var i = 1; i <= len; i++) { + todo1 = todos[i - 1]; + todo1.id = i; + } + + paint() +} \ No newline at end of file From b2f5ea941ef71c250aa42bd22c841be06e70a363 Mon Sep 17 00:00:00 2001 From: FarmanKhan97 <55954657+FarmanKhan97@users.noreply.github.com> Date: Tue, 1 Oct 2019 14:51:32 +0530 Subject: [PATCH 2/2] Add files via upload --- index.html | 54 +++++++++++++++++++++++++ index.js | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 index.html create mode 100644 index.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..0d74251 --- /dev/null +++ b/index.html @@ -0,0 +1,54 @@ + + + + + + + Document + + + + +
    +
    +
    + + Today I must ... + + Complete it till.. +
    +
    +
    + + + + + +
    +
    +
    + +
    +
    +
      + +
    +
    + +
    + + +
    + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..3c2442d --- /dev/null +++ b/index.js @@ -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 `
  • + + + ${todo.name} ${todo.deadline} +
  • `; + }) + .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(); \ No newline at end of file