Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 2 submission #38

Open
wants to merge 1 commit into
base: main
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
25 changes: 15 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</head>

<body>
<!-- Navigation Bar -->
<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="#navbarSupportedContent"
Expand All @@ -45,50 +46,54 @@
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src="#" class="rounded-circle" id="avatar-image"><span class="todo-profile-name" id="profile-name">Loading ...</span></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#" onclick="logout()">Logout</a>
<a class="dropdown-item" href="#" id="logout-button">Logout</a>
</div>
</li>
</ul>
</form>
</div>
</nav>
<center>


<div class="input-group mb-3 todo-add-task">
<input type="text" class="form-control" placeholder="Enter Task">
<input id="task-input" type="text" class="form-control" placeholder="Enter Task">
<div class="input-group-append">
<button type="button" class="btn btn-outline-success" onclick="addTask()">Add Task</button>
<button type="button" class="btn btn-outline-success" id="add-task">Add Task</button>
</div>
</div>
<ul class="list-group todo-available-tasks">
<span class="badge badge-primary badge-pill todo-available-tasks-text">
Available Tasks
</span>


<div id="tasks"></div>
<!--

<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>
<button class="btn btn-outline-secondary todo-update-task" type="button" id="update-task-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)"
<button style="margin-right:5px;" type="button" id="edit-task-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)">
<button type="button" class="btn btn-outline-danger" id = "delete-task-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">
<!-- <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>
Expand All @@ -108,7 +113,7 @@
width="18px" height="22px">
</button>
</span>
</li>
</li> -->


</ul>
Expand Down
2 changes: 1 addition & 1 deletion login/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<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>
<button class="btn btn-outline-success my-2 my-sm-0" id= 'login' type="submit">Log In</button>
</div>
</body>

Expand Down
43 changes: 22 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion register/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<label for="inputAddress2">Password</label>
<input type="Password" class="form-control" id="inputPassword">
</div>
<button class="btn btn-outline-success my-2 my-sm-0" onclick="register()" type="submit">Register</button>
<button id="register" class="btn btn-outline-success my-2 my-sm-0" type="submit">Register</button>
</div>
</body>

Expand Down
6 changes: 3 additions & 3 deletions src/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.token === undefined) {
window.location.href = 'login/';
};
67 changes: 62 additions & 5 deletions src/init.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,68 @@
import axios from 'axios';
const API_BASE_URL = 'https://todo-app-csoc.herokuapp.com/';

function getTasks() {
/***
* @todo Fetch the tasks created by the user and display them in the dom.
*/
}
const tasks = document.getElementById("tasks");

export function getTasks() {
const headersForApiRequest = {
Authorization: 'Token ' + localStorage.getItem('token')
}

axios({
url:API_BASE_URL + "todo/",
method:"get",
headers:{
Authorization:"Token "+localStorage.getItem("token")
}

})
.then(function({data})
{
tasks.innerHTML = "";
data.forEach((task) => newTask(task));
})

};

const newTask = (task) => {
const newElement = document.createElement('li');
newElement.innerHTML = `<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" id="update-task-${task.id}">Done</button>
</div>
<div id="task-${task.id}" class="todo-task">
${task.title}
</div>

<span id="task-actions-${task.id}">
<button style="margin-right:5px;" type="button" id="edit-task-${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" id = "delete-task-${task.id}">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg"
width="18px" height="22px">
</button>
</span>
</li>`;
newElement.id = `todo-${task.id}`;
newElement.classList.add('list-group-item', 'd-flex', 'justify-content-between', 'align-items-center');
tasks.appendChild(newElement);

document.querySelector(`#edit-task-${task.id}`)
.addEventListener("click", () => editTask(task.id));
document.querySelector(`#update-task-${task.id}`)
.addEventListener("click", () => updateTask(task.id));
document.querySelector(`#delete-task-${task.id}`)
.addEventListener("click", () => deleteTask(task.id));
document.getElementById("input-button-" +task.id).value = task.title;

};

export {newTask};


axios({
headers: {
Expand Down
Loading