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
8ec3eb88
Commit
8ec3eb88
authored
Apr 07, 2020
by
Milan Iliev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TaskController+saving
parent
2bc86048
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
main.js
web/main.js
+38
-15
No files found.
web/main.js
View file @
8ec3eb88
...
...
@@ -27,7 +27,39 @@ class Task extends EventTarget {
}
}
let
tasks
=
[]
class
TaskController
{
constructor
(){
this
.
tasks
=
[]
}
addTask
(
task
){
let
view
=
new
TaskView
(
task
)
view
.
element
.
addEventListener
(
"click"
,
()
=>
detail_view
.
task
=
task
)
list
.
appendChild
(
view
.
element
)
task_views
.
push
(
view
)
task
.
addEventListener
(
"change"
,
()
=>
this
.
save
(
task
))
}
async
refresh
(){
let
tasks_response
=
await
fetch
(
"/tasks"
,
{
method
:
"GET"
})
let
tasks_data
=
await
tasks_response
.
json
()
for
(
let
task_data
of
tasks_data
){
this
.
tasks
.
push
(
new
Task
(
task_data
))
}
for
(
let
task
of
this
.
tasks
){
this
.
addTask
(
task
)
}
}
async
save
(
task
){
let
tasks_response
=
await
fetch
(
`/tasks/
${
task
.
id
}
`
,
{
method
:
"PUT"
,
body
:
JSON
.
stringify
(
task
.
data
),
headers
:
{
'Content-Type'
:
'application/json'
}
})
}
}
let
task_views
=
[]
...
...
@@ -110,25 +142,16 @@ class DetailTaskView {
let
detail_view
=
new
DetailTaskView
(
document
.
querySelector
(
"task-detail"
))
let
addTask
=
function
(
task
){
let
view
=
new
TaskView
(
task
)
view
.
element
.
addEventListener
(
"click"
,
()
=>
detail_view
.
task
=
task
)
list
.
appendChild
(
view
.
element
)
task_views
.
push
(
view
)
}
let
addButton
=
document
.
querySelector
(
'#add_button'
)
addButton
.
addEventListener
(
"click"
,
()
=>
{
addTask
(
new
Task
({
done
:
false
,
description
:
"New Task"
}))
})
let
main
=
async
()
=>
{
let
tasks_response
=
await
fetch
(
"/tasks"
,
{
method
:
"GET"
})
let
tasks_data
=
await
tasks_response
.
json
()
for
(
let
task_data
of
tasks_data
){
tasks
.
push
(
new
Task
(
task_data
))
}
let
task_controller
=
new
TaskController
()
for
(
let
task
of
tasks
){
addTask
(
task
)
}
let
main
=
async
()
=>
{
task_controller
.
refresh
()
}
main
()
\ No newline at end of file
main
()
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