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
507f898e
Commit
507f898e
authored
Apr 16, 2020
by
Geovanny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added response check for api calls
parent
86b306ae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
7 deletions
+35
-7
controller.js
web/tasks/controller.js
+35
-7
No files found.
web/tasks/controller.js
View file @
507f898e
...
...
@@ -17,7 +17,7 @@ class TaskController {
async
createTask
(){
let
new_task
=
{
done
:
false
,
description
:
"New Task"
}
try
{
await
this
.
create
(
new_task
)
new_task
.
id
=
await
this
.
create
(
new_task
)
this
.
addTask
(
new
Task
(
new_task
))
}
catch
(
error
)
{
console
.
log
(
error
)
...
...
@@ -27,17 +27,26 @@ class TaskController {
addTask
(
task
){
this
.
view
.
addTaskView
(
task
)
task
.
addEventListener
(
"change"
,
()
=>
this
.
update
(
task
))
task
.
addEventListener
(
"change"
,
async
()
=>
this
.
updateTask
(
task
))
}
remoteTask
(
task
){
this
.
tasks
.
remove
(
task
)
this
.
view
.
removeTaskView
(
task
)
this
.
requestDelete
(
task
)
async
remoteTask
(
task
){
try
{
await
this
.
requestDelete
(
task
)
this
.
tasks
.
remove
(
task
)
this
.
view
.
removeTaskView
(
task
)
}
catch
(
error
)
{
console
.
log
(
error
)
alert
(
'Failed to delete task.'
)
}
}
async
refresh
(){
let
tasks_response
=
await
fetch
(
"/tasks"
,
{
method
:
"GET"
})
if
(
!
tasks_response
.
ok
){
throw
new
Error
(
`Got
${
tasks_response
.
status
}
from server.`
)
}
let
tasks_data
=
await
tasks_response
.
json
()
for
(
let
task_data
of
tasks_data
){
this
.
tasks
.
push
(
new
Task
(
task_data
))
}
...
...
@@ -58,8 +67,19 @@ class TaskController {
}
let
task_data
=
await
tasks_response
.
json
()
if
(
!
task_data
.
id
){
throw
new
Error
(
'No task id created'
)
}
return
task_data
.
id
}
return
task_data
async
updateTask
(
task
){
try
{
await
this
.
update
(
task
)
}
catch
(
error
)
{
console
.
log
(
error
)
alert
(
'Changes applied locally only'
)
}
}
async
update
(
task
){
...
...
@@ -70,12 +90,20 @@ class TaskController {
'Content-Type'
:
'application/json'
}
})
if
(
!
tasks_response
.
ok
){
throw
new
Error
(
`Got
${
tasks_response
.
status
}
from server.`
)
}
}
async
requestDelete
(
task
){
let
tasks_response
=
await
fetch
(
`/tasks/
${
task
.
id
}
`
,
{
method
:
"DELETE"
})
if
(
!
tasks_response
.
ok
){
throw
new
Error
(
`Got
${
tasks_response
.
status
}
from server.`
)
}
}
}
...
...
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