Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CloudComputing_Act1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jesus Galaz Reyes
CloudComputing_Act1
Commits
caa0834c
Commit
caa0834c
authored
9 months ago
by
Jesus Galaz
Browse files
Options
Downloads
Patches
Plain Diff
Adding show completed tasks button an hide completed task by default
parent
a20e3d3f
No related branches found
Branches containing commit
No related tags found
1 merge request
!6
Adding toDo app functionability
Pipeline
#15714
passed
9 months ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
public/css/index.css
+16
-3
16 additions, 3 deletions
public/css/index.css
public/index.html
+1
-0
1 addition, 0 deletions
public/index.html
public/js/index.js
+36
-10
36 additions, 10 deletions
public/js/index.js
with
53 additions
and
13 deletions
public/css/index.css
+
16
−
3
View file @
caa0834c
...
...
@@ -26,16 +26,29 @@ h1 {
margin
:
0
;
}
#logout-btn
{
background-color
:
transparent
;
background-color
:
rgb
(
170
,
17
,
17
)
;
border
:
1px
solid
#333
;
color
:
#333
;
color
:
white
;
padding
:
0.5rem
1rem
;
border-radius
:
4px
;
cursor
:
pointer
;
transition
:
all
0.3s
ease
;
}
#logout-btn
:hover
{
background-color
:
#333
;
background-color
:
#852828
;
color
:
#fff
;
}
#toggle-completed-btn
{
background-color
:
rgb
(
42
,
50
,
170
);
border
:
1px
solid
#333
;
color
:
white
;
padding
:
0.5rem
1rem
;
border-radius
:
4px
;
cursor
:
pointer
;
transition
:
all
0.3s
ease
;
}
#toggle-completed-btn
:hover
{
background-color
:
#1c277e
;
color
:
#fff
;
}
#new-task-form
{
...
...
This diff is collapsed.
Click to expand it.
public/index.html
+
1
−
0
View file @
caa0834c
...
...
@@ -12,6 +12,7 @@
<header>
<h1>
ToDo List
</h1>
<button
id=
"logout-btn"
>
Logout
</button>
<button
id=
"toggle-completed-btn"
>
Show Completed Tasks
</button>
</header>
<main>
...
...
This diff is collapsed.
Click to expand it.
public/js/index.js
+
36
−
10
View file @
caa0834c
...
...
@@ -3,6 +3,9 @@ document.addEventListener('DOMContentLoaded', async () => {
const
input
=
form
.
querySelector
(
'
input[name="task"]
'
);
const
taskList
=
document
.
getElementById
(
"
task-list
"
);
const
logoutBtn
=
document
.
getElementById
(
'
logout-btn
'
);
const
toggleCompletedBtn
=
document
.
getElementById
(
'
toggle-completed-btn
'
);
let
showCompletedTasks
=
false
;
// Load the tasks when page is initiated
async
function
loadTasks
()
{
...
...
@@ -10,11 +13,11 @@ document.addEventListener('DOMContentLoaded', async () => {
const
res
=
await
fetch
(
"
/api/todos
"
);
const
todos
=
await
res
.
json
();
// Verif
icar
if the response has tasks
// Verif
y
if the response has tasks
if
(
todos
.
length
>
0
)
{
renderTasks
(
todos
);
}
else
{
console
.
log
(
'
No
hay tareas para mostrar
.
'
);
console
.
log
(
'
No
tasks to show
.
'
);
}
}
catch
(
err
)
{
console
.
error
(
"
Error loading tasks:
"
,
err
);
...
...
@@ -28,6 +31,8 @@ document.addEventListener('DOMContentLoaded', async () => {
const
taskItem
=
createTaskElement
(
todo
);
taskList
.
appendChild
(
taskItem
);
});
toggleCompletedVisibility
();
}
// Function to create an element in DOM
...
...
@@ -36,6 +41,7 @@ document.addEventListener('DOMContentLoaded', async () => {
li
.
dataset
.
id
=
todo
.
_id
;
if
(
todo
.
isDone
)
{
li
.
classList
.
add
(
'
completed
'
);
li
.
style
.
display
=
'
none
'
;
}
li
.
innerHTML
=
`
...
...
@@ -54,6 +60,7 @@ document.addEventListener('DOMContentLoaded', async () => {
completeBtn
.
addEventListener
(
"
click
"
,
async
()
=>
{
await
toggleComplete
(
todo
.
_id
,
!
todo
.
isDone
);
li
.
classList
.
toggle
(
"
completed
"
);
toggleCompletedVisibility
();
});
const
deleteBtn
=
li
.
querySelector
(
"
.delete-btn
"
);
...
...
@@ -90,6 +97,25 @@ document.addEventListener('DOMContentLoaded', async () => {
return
li
;
}
// Function to toggle completed task visibility
function
toggleCompletedVisibility
()
{
const
completedTasks
=
document
.
querySelectorAll
(
'
.completed
'
);
completedTasks
.
forEach
(
task
=>
{
if
(
showCompletedTasks
)
{
task
.
style
.
display
=
'
block
'
;
}
else
{
task
.
style
.
display
=
'
none
'
;
}
});
}
// Toggle button event listener
toggleCompletedBtn
.
addEventListener
(
'
click
'
,
()
=>
{
showCompletedTasks
=
!
showCompletedTasks
;
toggleCompletedVisibility
();
toggleCompletedBtn
.
textContent
=
showCompletedTasks
?
'
Hide Completed Tasks
'
:
'
Show Completed Tasks
'
;
});
// Function to alternate to the completed state
async
function
toggleComplete
(
taskId
,
isDone
)
{
try
{
...
...
@@ -99,10 +125,10 @@ document.addEventListener('DOMContentLoaded', async () => {
body
:
JSON
.
stringify
({
isDone
})
});
if
(
!
res
.
ok
)
{
console
.
error
(
'
Error mar
cando la tarea como
complet
ada
.
'
);
console
.
error
(
'
Error mar
king task as
complet
e
.
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error
actualizando la tarea
:
'
,
err
);
console
.
error
(
'
Error
updating task
:
'
,
err
);
}
}
...
...
@@ -113,10 +139,10 @@ document.addEventListener('DOMContentLoaded', async () => {
method
:
'
DELETE
'
});
if
(
!
res
.
ok
)
{
console
.
error
(
'
Error el
iminando la tarea
.
'
);
console
.
error
(
'
Error
d
el
eting task
.
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error el
iminando la tarea
:
'
,
err
);
console
.
error
(
'
Error
d
el
eting task
:
'
,
err
);
}
}
...
...
@@ -129,10 +155,10 @@ document.addEventListener('DOMContentLoaded', async () => {
body
:
JSON
.
stringify
({
description
:
newDescription
})
});
if
(
!
res
.
ok
)
{
console
.
error
(
'
Error
actualizando la tarea
.
'
);
console
.
error
(
'
Error
updating task
.
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error
actualizando la tarea
:
'
,
err
);
console
.
error
(
'
Error
updating task
:
'
,
err
);
}
}
...
...
@@ -161,10 +187,10 @@ document.addEventListener('DOMContentLoaded', async () => {
const
newTodo
=
await
res
.
json
();
taskList
.
appendChild
(
createTaskElement
(
newTodo
));
}
else
{
console
.
error
(
'
Error a
ñadiendo tarea
.
'
);
console
.
error
(
'
Error a
dding task
.
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
Error a
ñadiendo tarea
:
'
,
err
);
console
.
error
(
'
Error a
dding task
:
'
,
err
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment