Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

All tasks done #15

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
6 changes: 3 additions & 3 deletions auth_required.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/***
* @todo Redirect the user to login page if token is not present.
*/
if (localStorage.getItem('token') == null) {
window.location.href = '/login';
}
51 changes: 2 additions & 49 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,63 +55,16 @@
</nav>
<center>
<div class="input-group mb-3 todo-add-task">
<input type="text" class="form-control" placeholder="Enter Task">
<input type="text" id="task-input" class="form-control" placeholder="Enter Task">
<div class="input-group-append">
<button type="button" class="btn btn-outline-success" onclick="addTask()">Add Task</button>
</div>
</div>
<ul class="list-group todo-available-tasks">
<ul id="task-list" class="list-group todo-available-tasks">
<span class="badge badge-primary badge-pill todo-available-tasks-text">
Available Tasks
</span>


<li class="list-group-item d-flex justify-content-between align-items-center">
<input id="input-button-1" type="text" class="form-control todo-edit-task-input hideme" placeholder="Edit The Task">
<div id="done-button-1" class="input-group-append hideme">
<button class="btn btn-outline-secondary todo-update-task" type="button" onclick="updateTask(1)">Done</button>
</div>
<div id="task-1" class="todo-task">
Sample Task 1
</div>

<span id="task-actions-1">
<button style="margin-right:5px;" type="button" onclick="editTask(1)"
class="btn btn-outline-warning">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486663/CSOC/edit.png"
width="18px" height="20px">
</button>
<button type="button" class="btn btn-outline-danger" onclick="deleteTask(1)">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg"
width="18px" height="22px">
</button>
</span>
</li>


<li class="list-group-item d-flex justify-content-between align-items-center">
<input id="input-button-2" type="text" class="form-control todo-edit-task-input hideme" placeholder="Edit The Task">
<div id="done-button-2" class="input-group-append hideme">
<button class="btn btn-outline-secondary todo-update-task" type="button" onclick="updateTask(2)">Done</button>
</div>

<div id="task-2" class="todo-task">
Sample Task 2
</div>
<span id="task-actions-2">
<button style="margin-right:5px;" type="button" onclick="editTask(2)"
class="btn btn-outline-warning">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486663/CSOC/edit.png"
width="18px" height="20px">
</button>
<button type="button" class="btn btn-outline-danger" onclick="deleteTask(2)">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg"
width="18px" height="22px">
</button>
</span>
</li>


</ul>
</center>
<script src="init.js"></script>
Expand Down
78 changes: 74 additions & 4 deletions init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
function taskToListItem(task_id, task_input) {
return `
<li
class="list-group-item d-flex justify-content-between align-items-center"
>
<input
id="input-button-${task_id}"
type="text"
class="form-control todo-edit-task-input hideme"
placeholder="Edit The Task"
/>
<div id="done-button-${task_id}" class="input-group-append hideme">
<button
class="btn btn-outline-secondary todo-update-task"
type="button"
onclick="updateTask(${task_id})"
>
Done
</button>
</div>
<div id="task-${task_id}" class="todo-task">
${task_input}
</div>

<span id="task-actions-${task_id}">
<button
style="margin-right: 5px;"
type="button"
onclick="editTask(${task_id})"
class="btn btn-outline-warning"
>
<img
src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486663/CSOC/edit.png"
width="18px"
height="20px"
/>
</button>
<button
type="button"
class="btn btn-outline-danger"
onclick="deleteTask(${task_id})"
>
<img
src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg"
width="18px"
height="22px"
/>
</button>
</span>
</li>
`
};

function getTasks() {
/***
* @todo Fetch the tasks created by the user and display them in the dom.
*/
$.ajax({
headers: {
Authorization: 'Token ' + localStorage.getItem('token'),
},
url: API_BASE_URL + 'todo/',
method: 'GET',
success: function (data, status, xhr) {
$('#task-list').empty();
for (let i = 0; i < data.length; i++) {
$('#task-list').append(taskToListItem(data[i].id, data[i].title)).hide().show('fast');
}
},
error: (xhr, status, err) => {
if (xhr.status == 0) {
displayErrorToast("Connection failure. Please check your internet connection...");
} else {
displayErrorToast("Unknown error occured");
}
}
})
}

$.ajax({
Expand All @@ -10,7 +80,7 @@ $.ajax({
},
url: API_BASE_URL + 'auth/profile/',
method: 'GET',
success: function(data, status, xhr) {
success: function (data, status, xhr) {
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();
Expand Down
135 changes: 80 additions & 55 deletions login/index.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,83 @@
<html lang="en">
<head>
<title>Login - Todo</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/css/iziToast.min.css"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"
type="text/css"
rel="stylesheet"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/js/iziToast.min.js"></script>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script src="../no_auth_required.js"></script>
<script src="../main.js"></script>
</head>

<head>
<title>Login - Todo</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/css/iziToast.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" type="text/css"
rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/izitoast/1.4.0/js/iziToast.min.js"></script>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<script src="../no_auth_required.js"></script>
<script src="../main.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="#">Todo</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarTogglerDemo03"
aria-controls="navbarTogglerDemo03"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="#">Todo</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo03"
aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>


<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="/register">Register<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item active">
<a class="nav-link" href="/login">Login</a>
</li>
</ul>
</div>
</nav>
<div style="padding-left:6%; max-width:70%; padding-top:6%;">
<div style="padding-bottom:10px">
<span style="color:grey;font-size:20px;">
Login
</span>
</div>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" id="inputUsername">
</div>
<div class="form-group">
<label>Password</label>
<input type="Password" class="form-control" id="inputPassword">
</div>
<button class="btn btn-outline-success my-2 my-sm-0" onclick="login()" type="submit">Log In</button>
</div>
</body>

</html>
<div class="collapse navbar-collapse" id="navbarTogglerDemo03">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="/register"
>Register<span class="sr-only">(current)</span></a
>
</li>
<li class="nav-item active">
<a class="nav-link" href="/login">Login</a>
</li>
</ul>
</div>
</nav>
<div style="padding-left: 6%; max-width: 70%; padding-top: 6%;">
<div style="padding-bottom: 10px;">
<span style="color: grey; font-size: 20px;">
Login
</span>
</div>
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" id="inputUsername" />
</div>
<div class="form-group">
<label>Password</label>
<input
type="Password"
class="form-control"
id="inputPassword"
/>
</div>
<button
class="btn btn-outline-success my-2 my-sm-0"
onclick="login()"
type="submit"
>
Log In
</button>
</div>
</body>
</html>
Loading