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

completed week2 #48

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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5503
}
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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='logoutBtn' >Logout</a>
</div>
</li>
</ul>
Expand All @@ -54,12 +54,12 @@
</nav>
<center>
<div class="input-group mb-3 todo-add-task">
<input type="text" class="form-control" placeholder="Enter Task">
<input id="inpTask" 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="addTaskBtn" >Add Task</button>
</div>
</div>
<ul class="list-group todo-available-tasks">
<ul class="list-group todo-available-tasks" id="listOfTodos">
<span class="badge badge-primary badge-pill todo-available-tasks-text">
Available Tasks
</span>
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 id='loginbtn' class="btn btn-outline-success my-2 my-sm-0" type="submit">Log In</button>
</div>
</body>

Expand Down
181 changes: 180 additions & 1 deletion 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="registerBtn" class="btn btn-outline-success my-2 my-sm-0" type="submit">Register</button>
</div>
</body>

Expand Down
3 changes: 3 additions & 0 deletions src/auth_required.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/***
* @todo Redirect the user to login page if token is not present.
*/
if(localStorage.token == null || localStorage.token == undefined){
window.location.href = 'login/'
}
44 changes: 44 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@ function getTasks() {
/***
* @todo Fetch the tasks created by the user and display them in the dom.
*/
fetch(API_BASE_URL+'todo/', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization' : `Token ${localStorage.token}`,
},
mode: 'cors',
method: 'GET'
})
.then(response => response.json())
.then(function(data){

let listOfTodos = document.getElementById('listOfTodos');
listOfTodos.innerHTML = `<span class="badge badge-primary badge-pill todo-available-tasks-text">Available Tasks</span>`

for(let entry of data){
listOfTodos.innerHTML += `<li class="list-group-item d-flex justify-content-between align-items-center">
<input id="input-button-${entry.id}" type="text" class="form-control todo-edit-task-input hideme" placeholder="Edit The Task">
<div id="done-button-${entry.id}" class="input-group-append hideme">
<button class="btn btn-outline-secondary todo-update-task" type="button" onclick="updateTask(${entry.id})">Done</button>
</div>
<div id="task-${entry.id}" class="todo-task">
${entry.title}
</div>

<span id="task-actions-${entry.id}">
<button style="margin-right:5px;" type="button" onclick="editTask(${entry.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(${entry.id})">
<img src="https://res.cloudinary.com/nishantwrp/image/upload/v1587486661/CSOC/delete.svg"
width="18px" height="22px">
</button>
</span>
</li>`;
}
})
.catch(err => console.log(err));


}

axios({
Expand All @@ -18,3 +60,5 @@ axios({
document.getElementById('profile-name').innerHTML = data.name;
getTasks();
})

window.getTasks = getTasks;
Loading