From 86de4414a05252da6ebf5a6b038a6eca32f90639 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 20:51:57 +0530 Subject: [PATCH 01/18] Completing Tasks --- src/auth_required.js | 3 + src/init.js | 48 ++++++++++++- src/main.js | 146 ++++++++++++++++++++++++++++++++++++++++ src/no_auth_required.js | 5 +- 4 files changed, 200 insertions(+), 2 deletions(-) diff --git a/src/auth_required.js b/src/auth_required.js index 7f5e7bc..c0ee62e 100644 --- a/src/auth_required.js +++ b/src/auth_required.js @@ -1,3 +1,6 @@ /*** * @todo Redirect the user to login page if token is not present. */ + if (localStorage.token === undefined) { + window.location.href = 'login/'; +} diff --git a/src/init.js b/src/init.js index 3a88d74..77387e6 100644 --- a/src/init.js +++ b/src/init.js @@ -1,19 +1,65 @@ import axios from 'axios'; +import { updateTask, deleteTask, editTask } from './main'; const API_BASE_URL = 'https://todo-app-csoc.herokuapp.com/'; +window.deleteTask = deleteTask; +window.updateTask = updateTask; +window.editTask = editTask; +const taskList = document.getElementById("taskList"); function getTasks() { /*** * @todo Fetch the tasks created by the user and display them in the dom. */ + const headersForApiRequest = { + Authorization: 'Token ' + localStorage.getItem('token') } + +axios({ + headers: { + Authorization: 'Token ' + localStorage.getItem('token'), + }, + url: API_BASE_URL + 'todo/', + method: 'get', +}) +.then(function({data, status}) { + document.getElementById('tasksList').innerHTML = ""; + for(let i=0; i + +
+ +
+
+ ${data[i].title} +
+ + + + + + ` + document.getElementById('tasksList').innerHTML += content; + } + }) + .catch(function (err) { + displayErrorToast("Oops! Something's wrong!"); + }); +} axios({ headers: { Authorization: 'Token ' + localStorage.getItem('token'), }, url: API_BASE_URL + 'auth/profile/', method: 'get', -}).then(function({data, status}) { +}) +.then(function({data, status}) { document.getElementById('avatar-image').src = 'https://ui-avatars.com/api/?name=' + data.name + '&background=fff&size=33&color=007bff'; document.getElementById('profile-name').innerHTML = data.name; getTasks(); diff --git a/src/main.js b/src/main.js index 05849df..7e5f1de 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,34 @@ import axios from 'axios'; +import { getTasks } from './init'; +window.deleteTask = deleteTask; +window.updateTask = updateTask; +window.editTask = editTask; +const loginBtn = document.getElementById('login-btn'); +const logoutBtn = document.getElementById('logout-btn'); +const registerBtn = document.getElementById('register-btn'); +const addtaskBtn = document.getElementById('add-task'); +const searchBtn = document.getElementById('search-btn'); +const cancelBtn = document.getElementById('cancel-btn'); +window.onload = ()=>{ + + if(loginBtn) + loginBtn.onclick = login; + + if(logoutBtn) + logoutBtn.onclick = logout; + + if(registerBtn) + registerBtn.onclick = register; + + if(addtaskBtn) + addtaskBtn.onclick = addTask; + + if(searchBtn) + searchBtn.onclick = search; + + if(cancelBtn) + cancelBtn.onclick = cancel; + } function displaySuccessToast(message) { iziToast.success({ title: 'Success', @@ -75,6 +105,28 @@ function login() { * @todo 1. Write code for form validation. * @todo 2. Fetch the auth token from backend, login and direct user to home page. */ + const username = document.getElementById('inputUsername').value.trim(); + const password = document.getElementById('inputPassword').value; + + if (loginFieldsAreValid(username, password)) { + displayInfoToast("Please wait..."); + + const dataForApiRequest = { + username: username, + password: password + } + + axios({ + url: API_BASE_URL + 'auth/login/', + method: 'post', + data: dataForApiRequest, + }).then(function({data, status}) { + localStorage.setItem('token', data.token); + window.location.href = '/'; + }).catch(function(err) { + displayErrorToast('Invalid username or password'); + }) + } } function addTask() { @@ -83,6 +135,31 @@ function addTask() { * @todo 1. Send the request to add the task to the backend server. * @todo 2. Add the task in the dom. */ + const title = document.getElementById('new-task').value.trim(); + + if (title == '') { + displayErrorToast("Field cannot be empty."); + return; + } + + const dataForApiRequest = { + title: title + } + + axios({ + headers: { + Authorization: "Token " + localStorage.getItem("token"), + }, + url: API_BASE_URL + 'todo/create/', + method: 'post', + data: dataForApiRequest, + }).then(function ({ data, status }) { + displaySuccessToast("Task added."); + getTasks(); + document.getElementById('new-task').value =""; + }).catch(function (err) { + displayErrorToast("Something went wrong."); + }) } function editTask(id) { @@ -98,6 +175,22 @@ function deleteTask(id) { * @todo 1. Send the request to delete the task to the backend server. * @todo 2. Remove the task from the dom. */ + displayInfoToast("Loading..."); + + const headersForApiRequest = { + Authorization: 'Token ' + localStorage.getItem('token') + } + + axios({ + headers: headersForApiRequest, + url: API_BASE_URL + 'todo/' + id + '/', + method: 'DELETE', + }).then(function ({ data, status }) { + displaySuccessToast("Task deleted successfully..."); + getTasks(); + }).catch(function (err) { + displayErrorToast("Unable to delete task. Please try again..."); + }) } function updateTask(id) { @@ -106,4 +199,57 @@ function updateTask(id) { * @todo 1. Send the request to update the task to the backend server. * @todo 2. Update the task in the dom. */ + const taskname =document.getElementById("input-button-" + id).value.trim(); + + if (taskname == ""){ + displayErrorToast("Task name cannot be empty ."); + return; + } + + const dataForApiRequest = { + title: taskname + } + + axios({ + headers: { + Authorization: "Token " + localStorage.getItem("token"), + }, + url: API_BASE_URL + 'todo/' + id + '/', + method: 'put', + data: dataForApiRequest, + }).then(function ({ data, status }) { + displaySuccessToast("Task updated successfully ."); + getTasks(); + }).catch(function (err) { + displayErrorToast("Oops ! Something went wrong . "); + }) } +function searchTask(){ + const task = document.getElementById('searchTask').value.trim(); + + if (task == '') { + displayErrorToast("Field cannot be left empty!.."); + return; + } + + displayInfoToast("Loading..."); + + const headersForApiRequest = { + Authorization: 'Token ' + localStorage.getItem('token') + } + + axios({ + headers: headersForApiRequest, + url: API_BASE_URL + 'todo/', + method: 'GET', + }).then(function ({ data, status }) { + console.log(data); + for (var index = 0; index < data.length; index++) if (data[index].title == task){ + taskList.innerHTML = ""; + displaySuccessToast("Task Present"); + displayTask(data[index].id, data[index].title); + return; + } + displayErrorToast("Task Not Found.") + }) +} \ No newline at end of file diff --git a/src/no_auth_required.js b/src/no_auth_required.js index 82558d4..c40e9b0 100644 --- a/src/no_auth_required.js +++ b/src/no_auth_required.js @@ -1,3 +1,6 @@ /*** * @todo Redirect the user to main page if token is present. - */ \ No newline at end of file + */ + if (localStorage.token) { + window.location.href = '/'; +} From f2d79bf05b8fa097d385958ff267c87df618ced8 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 20:54:05 +0530 Subject: [PATCH 02/18] completed --- index.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.html b/index.html index ffda4cf..310a974 100644 --- a/index.html +++ b/index.html @@ -59,6 +59,12 @@ +
+ +
+ +
+
    Available Tasks From 41e577f703df87bd0fa5be3ed928adab694dd482 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 20:57:39 +0530 Subject: [PATCH 03/18] updated --- package-lock.json | 187 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 183 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a9cab7..8cc7763 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,187 @@ { "name": "csoc-task-2-web", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "csoc-task-2-web", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "axios": "^0.21.2", + "vite": "^2.3.7" + } + }, + "node_modules/axios": { + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz", + "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==", + "dependencies": { + "follow-redirects": "^1.14.0" + } + }, + "node_modules/colorette": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz", + "integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==" + }, + "node_modules/esbuild": { + "version": "0.12.8", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.8.tgz", + "integrity": "sha512-sx/LwlP/SWTGsd9G4RlOPrXnIihAJ2xwBUmzoqe2nWwbXORMQWtAGNJNYLBJJqa3e9PWvVzxdrtyFZJcr7D87g==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", + "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/is-core-module": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz", + "integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==", + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/nanoid": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "node_modules/postcss": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.4.tgz", + "integrity": "sha512-/tZY0PXExXXnNhKv3TOvZAOUYRyuqcCbBm2c17YMDK0PlVII3K7/LKdt3ScHL+hhouddjUWi+1sKDf9xXW+8YA==", + "dependencies": { + "colorette": "^1.2.2", + "nanoid": "^3.1.23", + "source-map-js": "^0.6.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + } + }, + "node_modules/resolve": { + "version": "1.20.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", + "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", + "dependencies": { + "is-core-module": "^2.2.0", + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/rollup": { + "version": "2.51.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.51.2.tgz", + "integrity": "sha512-ReV2eGEadA7hmXSzjxdDKs10neqH2QURf2RxJ6ayAlq93ugy6qIvXMmbc5cWMGCDh1h5T4thuWO1e2VNbMq8FA==", + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=10.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.1" + } + }, + "node_modules/source-map-js": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-0.6.2.tgz", + "integrity": "sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/vite": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/vite/-/vite-2.3.7.tgz", + "integrity": "sha512-Y0xRz11MPYu/EAvzN94+FsOZHbSvO6FUvHv127CyG7mV6oDoay2bw+g5y9wW3Blf8OY3chaz3nc/DcRe1IQ3Nw==", + "dependencies": { + "esbuild": "^0.12.5", + "postcss": "^8.3.0", + "resolve": "^1.19.0", + "rollup": "^2.38.5" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": ">=12.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.1" + } + } + }, "dependencies": { "axios": { "version": "0.21.2", @@ -55,9 +234,9 @@ } }, "nanoid": { - "version": "3.1.23", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz", - "integrity": "sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==" + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", + "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" }, "path-parse": { "version": "1.0.7", From 075e5950dfde37d4fef7d012c16c6dff252e545a Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:20:57 +0530 Subject: [PATCH 04/18] corrected --- src/main.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.js b/src/main.js index 7e5f1de..246ef63 100644 --- a/src/main.js +++ b/src/main.js @@ -145,6 +145,15 @@ function addTask() { const dataForApiRequest = { title: title } + export function editTask(id) { + document.getElementById('task-' + id).classList.add('hideme'); + document.getElementById('task-actions-' + id).classList.add('hideme'); + document.getElementById('input-button-' + id).classList.remove('hideme'); + document.getElementById('done-button-' + id).classList.remove('hideme'); + } + + export function deleteTask(id) { + displayInfoToast("Deleting Task"); axios({ headers: { From a5ff7b5d27f640ac8f5b6f7c863cefeb4cf92373 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:24:36 +0530 Subject: [PATCH 05/18] corrected --- src/main.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.js b/src/main.js index 246ef63..ea52ae5 100644 --- a/src/main.js +++ b/src/main.js @@ -36,6 +36,16 @@ function displaySuccessToast(message) { }); } +export function editTask(id) { + document.getElementById('task-' + id).classList.add('hideme'); + document.getElementById('task-actions-' + id).classList.add('hideme'); + document.getElementById('input-button-' + id).classList.remove('hideme'); + document.getElementById('done-button-' + id).classList.remove('hideme'); +} + +export function deleteTask(id) { + displayInfoToast("Deleting Task"); + function displayErrorToast(message) { iziToast.error({ title: 'Error', @@ -145,15 +155,7 @@ function addTask() { const dataForApiRequest = { title: title } - export function editTask(id) { - document.getElementById('task-' + id).classList.add('hideme'); - document.getElementById('task-actions-' + id).classList.add('hideme'); - document.getElementById('input-button-' + id).classList.remove('hideme'); - document.getElementById('done-button-' + id).classList.remove('hideme'); - } - - export function deleteTask(id) { - displayInfoToast("Deleting Task"); + axios({ headers: { @@ -178,6 +180,7 @@ function editTask(id) { document.getElementById('done-button-' + id).classList.remove('hideme'); } + function deleteTask(id) { /** * @todo Complete this function. From c757ae895fa1677a032f4862172001ec029de964 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:27:22 +0530 Subject: [PATCH 06/18] correct --- src/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.js b/src/main.js index ea52ae5..71d7f12 100644 --- a/src/main.js +++ b/src/main.js @@ -45,6 +45,7 @@ export function editTask(id) { export function deleteTask(id) { displayInfoToast("Deleting Task"); +} function displayErrorToast(message) { iziToast.error({ From af89d3798fd4a19c0c269f83695cbfc507b2dcb9 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:31:32 +0530 Subject: [PATCH 07/18] ammends --- src/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 71d7f12..a83deac 100644 --- a/src/main.js +++ b/src/main.js @@ -174,7 +174,7 @@ function addTask() { }) } -function editTask(id) { +export function editTask(id) { document.getElementById('task-' + id).classList.add('hideme'); document.getElementById('task-actions-' + id).classList.add('hideme'); document.getElementById('input-button-' + id).classList.remove('hideme'); @@ -182,7 +182,7 @@ function editTask(id) { } -function deleteTask(id) { +export function deleteTask(id) { /** * @todo Complete this function. * @todo 1. Send the request to delete the task to the backend server. @@ -206,7 +206,7 @@ function deleteTask(id) { }) } -function updateTask(id) { +export function updateTask(id) { /** * @todo Complete this function. * @todo 1. Send the request to update the task to the backend server. From 8156af04358777d1caabca0c36e407cf62069774 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:33:12 +0530 Subject: [PATCH 08/18] ok --- src/main.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main.js b/src/main.js index a83deac..0a16aa4 100644 --- a/src/main.js +++ b/src/main.js @@ -36,16 +36,6 @@ function displaySuccessToast(message) { }); } -export function editTask(id) { - document.getElementById('task-' + id).classList.add('hideme'); - document.getElementById('task-actions-' + id).classList.add('hideme'); - document.getElementById('input-button-' + id).classList.remove('hideme'); - document.getElementById('done-button-' + id).classList.remove('hideme'); -} - -export function deleteTask(id) { - displayInfoToast("Deleting Task"); -} function displayErrorToast(message) { iziToast.error({ From 09724e31e4c38c143ab0312c35168a1f9e5d8a52 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:34:49 +0530 Subject: [PATCH 09/18] added export --- src/init.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.js b/src/init.js index 77387e6..180ba44 100644 --- a/src/init.js +++ b/src/init.js @@ -6,7 +6,7 @@ window.updateTask = updateTask; window.editTask = editTask; const taskList = document.getElementById("taskList"); -function getTasks() { +export function getTasks() { /*** * @todo Fetch the tasks created by the user and display them in the dom. */ From c733a83502fa91680affea884c47cad820152079 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:42:15 +0530 Subject: [PATCH 10/18] login and register --- login/index.html | 2 +- register/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/login/index.html b/login/index.html index 305d461..9ff669e 100644 --- a/login/index.html +++ b/login/index.html @@ -50,7 +50,7 @@ - + diff --git a/register/index.html b/register/index.html index 3a1f03d..2fbc7e4 100644 --- a/register/index.html +++ b/register/index.html @@ -64,7 +64,7 @@ - + From 4057ade15b200925cc67216050ffa37c02881fa9 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:55:54 +0530 Subject: [PATCH 11/18] necessary changes --- index.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 310a974..d6f5092 100644 --- a/index.html +++ b/index.html @@ -45,7 +45,7 @@ data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Loading ...
@@ -54,9 +54,9 @@
- +
- +
@@ -66,7 +66,7 @@
    - + + Available Tasks +
    -
  • +
From d29280f64b30894eb5b8a8ce984d9c676752442b Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 21:59:53 +0530 Subject: [PATCH 12/18] search button --- style.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/style.css b/style.css index 2817a0d..176794f 100644 --- a/style.css +++ b/style.css @@ -35,3 +35,6 @@ .todo-task { max-width:260px; } +.todo-search-task { + max-width:400px; +} From 58a7cae9c4fef77df553b3d1a48e0d9ebd8a4ec8 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 22:29:42 +0530 Subject: [PATCH 13/18] changes --- index.html | 49 ++----------------------------------------------- src/main.js | 43 +++++++++++++++++++++++-------------------- 2 files changed, 25 insertions(+), 67 deletions(-) diff --git a/index.html b/index.html index d6f5092..846062c 100644 --- a/index.html +++ b/index.html @@ -66,57 +66,12 @@
    - + Available Tasks
    - +
diff --git a/src/main.js b/src/main.js index 0a16aa4..2e256d6 100644 --- a/src/main.js +++ b/src/main.js @@ -108,26 +108,29 @@ function login() { */ const username = document.getElementById('inputUsername').value.trim(); const password = document.getElementById('inputPassword').value; - - if (loginFieldsAreValid(username, password)) { - displayInfoToast("Please wait..."); - - const dataForApiRequest = { - username: username, - password: password - } - - axios({ - url: API_BASE_URL + 'auth/login/', - method: 'post', - data: dataForApiRequest, - }).then(function({data, status}) { - localStorage.setItem('token', data.token); - window.location.href = '/'; - }).catch(function(err) { - displayErrorToast('Invalid username or password'); - }) - } + + if (username == '' || password == '') { + displayErrorToast("Please fill all the required fields."); + return; + } + displayInfoToast("Loading"); + const dataForApiRequest = { + username: username, + password: password + } + axios({ + url: API_BASE_URL + 'auth/login/', + method: 'POST', + data: dataForApiRequest, + }).then(function ({ data, status }) { + displaySuccessToast("Logged in successfully"); + localStorage.setItem('token', data.token); + window.location.href = '/'; + }).catch(function (err) { + displayErrorToast("Invalid credentials"); + document.getElementById('inputUsername').value = ''; + document.getElementById('inputPassword').value = ''; + }) } function addTask() { From 1a6cb1f82e928723ba3267e43923b8ab3b2559c3 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 22:32:00 +0530 Subject: [PATCH 14/18] updated --- package-lock.json | 187 +--------------------------------------------- 1 file changed, 4 insertions(+), 183 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cc7763..3a9cab7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,187 +1,8 @@ { "name": "csoc-task-2-web", "version": "1.0.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "csoc-task-2-web", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "axios": "^0.21.2", - "vite": "^2.3.7" - } - }, - "node_modules/axios": { - "version": "0.21.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz", - "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==", - "dependencies": { - "follow-redirects": "^1.14.0" - } - }, - "node_modules/colorette": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz", - "integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==" - }, - "node_modules/esbuild": { - "version": "0.12.8", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.8.tgz", - "integrity": "sha512-sx/LwlP/SWTGsd9G4RlOPrXnIihAJ2xwBUmzoqe2nWwbXORMQWtAGNJNYLBJJqa3e9PWvVzxdrtyFZJcr7D87g==", - "hasInstallScript": true, - "bin": { - "esbuild": "bin/esbuild" - } - }, - "node_modules/follow-redirects": { - "version": "1.15.1", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz", - "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" - }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/is-core-module": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.4.0.tgz", - "integrity": "sha512-6A2fkfq1rfeQZjxrZJGerpLCTHRNEBiSgnu0+obeJpEPZRUooHgsizvzv0ZjJwOz3iWIHdJtVWJ/tmPr3D21/A==", - "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", - "bin": { - "nanoid": "bin/nanoid.cjs" - }, - "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" - } - }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" - }, - "node_modules/postcss": { - "version": "8.3.4", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.4.tgz", - "integrity": "sha512-/tZY0PXExXXnNhKv3TOvZAOUYRyuqcCbBm2c17YMDK0PlVII3K7/LKdt3ScHL+hhouddjUWi+1sKDf9xXW+8YA==", - "dependencies": { - "colorette": "^1.2.2", - "nanoid": "^3.1.23", - "source-map-js": "^0.6.2" - }, - "engines": { - "node": "^10 || ^12 || >=14" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/postcss/" - } - }, - "node_modules/resolve": { - "version": "1.20.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", - "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", - "dependencies": { - "is-core-module": "^2.2.0", - "path-parse": "^1.0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/rollup": { - "version": "2.51.2", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.51.2.tgz", - "integrity": "sha512-ReV2eGEadA7hmXSzjxdDKs10neqH2QURf2RxJ6ayAlq93ugy6qIvXMmbc5cWMGCDh1h5T4thuWO1e2VNbMq8FA==", - "bin": { - "rollup": "dist/bin/rollup" - }, - "engines": { - "node": ">=10.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.1" - } - }, - "node_modules/source-map-js": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-0.6.2.tgz", - "integrity": "sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/vite": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/vite/-/vite-2.3.7.tgz", - "integrity": "sha512-Y0xRz11MPYu/EAvzN94+FsOZHbSvO6FUvHv127CyG7mV6oDoay2bw+g5y9wW3Blf8OY3chaz3nc/DcRe1IQ3Nw==", - "dependencies": { - "esbuild": "^0.12.5", - "postcss": "^8.3.0", - "resolve": "^1.19.0", - "rollup": "^2.38.5" - }, - "bin": { - "vite": "bin/vite.js" - }, - "engines": { - "node": ">=12.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.1" - } - } - }, "dependencies": { "axios": { "version": "0.21.2", @@ -234,9 +55,9 @@ } }, "nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==" + "version": "3.1.23", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz", + "integrity": "sha512-FiB0kzdP0FFVGDKlRLEQ1BgDzU87dy5NnzjeW9YZNt+/c3+q82EQDUwniSAUxp/F0gFNI1ZhKU1FqYsMuqZVnw==" }, "path-parse": { "version": "1.0.7", From df06388154d3412ad016f76c6d22326e64497384 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 23:01:43 +0530 Subject: [PATCH 15/18] updated --- src/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 2e256d6..c0a1647 100644 --- a/src/main.js +++ b/src/main.js @@ -12,13 +12,13 @@ const cancelBtn = document.getElementById('cancel-btn'); window.onload = ()=>{ if(loginBtn) - loginBtn.onclick = login; + loginBtn.onclick = login if(logoutBtn) - logoutBtn.onclick = logout; + logoutBtn.onclick = logout if(registerBtn) - registerBtn.onclick = register; + registerBtn.onclick = register if(addtaskBtn) addtaskBtn.onclick = addTask; From 8c52964291f83a759f74d82a9812f9144024773b Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 23:20:11 +0530 Subject: [PATCH 16/18] needed --- src/main.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index c0a1647..f1b5790 100644 --- a/src/main.js +++ b/src/main.js @@ -3,12 +3,12 @@ import { getTasks } from './init'; window.deleteTask = deleteTask; window.updateTask = updateTask; window.editTask = editTask; -const loginBtn = document.getElementById('login-btn'); -const logoutBtn = document.getElementById('logout-btn'); -const registerBtn = document.getElementById('register-btn'); -const addtaskBtn = document.getElementById('add-task'); -const searchBtn = document.getElementById('search-btn'); -const cancelBtn = document.getElementById('cancel-btn'); +const loginBtn = document.getElementById('loginBtn'); +const logoutBtn = document.getElementById('logoutButton'); +const registerBtn = document.getElementById('register'); +const addtaskBtn = document.getElementById('addTaskButton'); +const searchBtn = document.getElementById('searchTaskBtn'); +// const cancelBtn = document.getElementById('cancel-btn'); window.onload = ()=>{ if(loginBtn) @@ -26,8 +26,8 @@ window.onload = ()=>{ if(searchBtn) searchBtn.onclick = search; - if(cancelBtn) - cancelBtn.onclick = cancel; + // if(cancelBtn) + // cancelBtn.onclick = cancel; } function displaySuccessToast(message) { iziToast.success({ From ab963bdd34ff85c59371720386b8773e61401f31 Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 23:31:58 +0530 Subject: [PATCH 17/18] required --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 846062c..ac3f8b4 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
From 64ca315e7b6f7b08ab10c317908d5c1ca32b5e5c Mon Sep 17 00:00:00 2001 From: AyushJ16 Date: Wed, 22 Jun 2022 23:51:41 +0530 Subject: [PATCH 18/18] just --- src/main.js | 59 +++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/main.js b/src/main.js index f1b5790..7692a10 100644 --- a/src/main.js +++ b/src/main.js @@ -198,6 +198,36 @@ export function deleteTask(id) { displayErrorToast("Unable to delete task. Please try again..."); }) } +function searchTask(){ + const taskforSearch = document.getElementById('searchTask').value.trim(); + + if (taskforSearch == '') { + displayErrorToast("Invalid Task Title : Empty"); + return; + } + + displayInfoToast("Searching"); + + const headersForApiRequest = { + Authorization: 'Token ' + localStorage.getItem('token') + } + + axios({ + headers: headersForApiRequest, + url: API_BASE_URL + 'todo/', + method: 'GET', + }).then(function ({ data, status }) { + console.log(data); + for (var j = 0; j < data.length; j++) if (data[j].title == taskforSearch){ + displaySuccessToast("Task found"); + + + + return; + } + displayErrorToast("Specified task does not exist") + }) +} export function updateTask(id) { /** @@ -230,32 +260,3 @@ export function updateTask(id) { displayErrorToast("Oops ! Something went wrong . "); }) } -function searchTask(){ - const task = document.getElementById('searchTask').value.trim(); - - if (task == '') { - displayErrorToast("Field cannot be left empty!.."); - return; - } - - displayInfoToast("Loading..."); - - const headersForApiRequest = { - Authorization: 'Token ' + localStorage.getItem('token') - } - - axios({ - headers: headersForApiRequest, - url: API_BASE_URL + 'todo/', - method: 'GET', - }).then(function ({ data, status }) { - console.log(data); - for (var index = 0; index < data.length; index++) if (data[index].title == task){ - taskList.innerHTML = ""; - displaySuccessToast("Task Present"); - displayTask(data[index].id, data[index].title); - return; - } - displayErrorToast("Task Not Found.") - }) -} \ No newline at end of file