Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
A
app-todo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Geovanny E. Vera Pazmino
app-todo
Commits
36e83d84
Commit
36e83d84
authored
Apr 10, 2020
by
Milan Iliev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deleting tasks
parent
eec35420
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
12 deletions
+31
-12
main_view.js
web/main_view.js
+13
-2
controller.js
web/tasks/controller.js
+15
-2
detail_view.js
web/tasks/detail_view.js
+3
-8
No files found.
web/main_view.js
View file @
36e83d84
...
@@ -2,16 +2,21 @@ import Task from "./tasks/task.js"
...
@@ -2,16 +2,21 @@ import Task from "./tasks/task.js"
import
TaskView
from
"./tasks/view.js"
import
TaskView
from
"./tasks/view.js"
import
DetailTaskView
from
"./tasks/detail_view.js"
import
DetailTaskView
from
"./tasks/detail_view.js"
class
MainView
{
class
MainView
extends
EventTarget
{
constructor
(){
constructor
(){
super
()
this
.
task_views
=
[]
this
.
task_views
=
[]
this
.
list_element
=
document
.
querySelector
(
"task-list"
)
this
.
list_element
=
document
.
querySelector
(
"task-list"
)
this
.
detail_view
=
new
DetailTaskView
(
document
.
querySelector
(
"task-detail"
))
this
.
detail_view
=
new
DetailTaskView
(
document
.
querySelector
(
"task-detail"
))
this
.
detail_view
.
addEventListener
(
"delete_task"
,
(
event
)
=>
{
this
.
dispatchEvent
(
new
CustomEvent
(
"delete_task"
,
{
detail
:
{
task
:
event
.
detail
.
task
}}))
})
this
.
addButton
=
document
.
querySelector
(
'#add_button'
)
this
.
addButton
=
document
.
querySelector
(
'#add_button'
)
this
.
addButton
.
addEventListener
(
"click"
,
()
=>
{
this
.
addButton
.
addEventListener
(
"click"
,
()
=>
{
this
.
addTask
(
new
Task
({
done
:
false
,
description
:
"New Task"
}
))
this
.
dispatchEvent
(
new
CustomEvent
(
"add_task"
))
})
})
}
}
...
@@ -21,6 +26,12 @@ class MainView {
...
@@ -21,6 +26,12 @@ class MainView {
this
.
list_element
.
appendChild
(
view
.
element
)
this
.
list_element
.
appendChild
(
view
.
element
)
this
.
task_views
.
push
(
view
)
this
.
task_views
.
push
(
view
)
}
}
removeTaskView
(
task
){
let
summary_view_for_deleted_task
=
this
.
task_views
.
find
((
summary_view
)
=>
summary_view
.
task
===
task
)
this
.
task_views
.
remove
(
summary_view_for_deleted_task
)
this
.
list_element
.
removeChild
(
summary_view_for_deleted_task
.
element
)
}
}
}
export
default
MainView
export
default
MainView
\ No newline at end of file
web/tasks/controller.js
View file @
36e83d84
...
@@ -4,6 +4,14 @@ class TaskController {
...
@@ -4,6 +4,14 @@ class TaskController {
constructor
(
main_view
){
constructor
(
main_view
){
this
.
tasks
=
[]
this
.
tasks
=
[]
this
.
view
=
main_view
this
.
view
=
main_view
this
.
view
.
addEventListener
(
"add_task"
,
()
=>
{
this
.
addTask
(
new
Task
({
done
:
false
,
description
:
"New Task"
}))
})
this
.
view
.
addEventListener
(
"delete_task"
,
event
=>
{
this
.
remoteTask
(
event
.
detail
.
task
)
})
}
}
addTask
(
task
){
addTask
(
task
){
...
@@ -11,6 +19,11 @@ class TaskController {
...
@@ -11,6 +19,11 @@ class TaskController {
task
.
addEventListener
(
"change"
,
()
=>
this
.
save
(
task
))
task
.
addEventListener
(
"change"
,
()
=>
this
.
save
(
task
))
}
}
remoteTask
(
task
){
this
.
tasks
.
remove
(
task
)
this
.
view
.
removeTaskView
(
task
)
}
async
refresh
(){
async
refresh
(){
let
tasks_response
=
await
fetch
(
"/tasks"
,
{
method
:
"GET"
})
let
tasks_response
=
await
fetch
(
"/tasks"
,
{
method
:
"GET"
})
let
tasks_data
=
await
tasks_response
.
json
()
let
tasks_data
=
await
tasks_response
.
json
()
...
...
web/tasks/detail_view.js
View file @
36e83d84
class
DetailTaskView
{
class
DetailTaskView
extends
EventTarget
{
constructor
(
element
){
constructor
(
element
){
super
()
this
.
element
=
element
this
.
element
=
element
this
.
fields
=
{
this
.
fields
=
{
done
:
this
.
element
.
querySelector
(
"[name=done]"
),
done
:
this
.
element
.
querySelector
(
"[name=done]"
),
...
@@ -17,13 +18,7 @@ class DetailTaskView {
...
@@ -17,13 +18,7 @@ class DetailTaskView {
this
.
deleteButton
=
this
.
element
.
querySelector
(
"#delete_button"
)
this
.
deleteButton
=
this
.
element
.
querySelector
(
"#delete_button"
)
this
.
deleteButton
.
addEventListener
(
"click"
,
()
=>
{
this
.
deleteButton
.
addEventListener
(
"click"
,
()
=>
{
let
summary_view_for_deleted_task
=
task_views
.
find
((
summary_view
)
=>
summary_view
.
task
===
this
.
task
)
this
.
dispatchEvent
(
new
CustomEvent
(
"delete_task"
,
{
detail
:
{
task
:
this
.
task
}}))
task_views
.
remove
(
summary_view_for_deleted_task
)
tasks
.
remove
(
this
.
task
)
list
.
removeChild
(
summary_view_for_deleted_task
.
element
)
})
})
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment