Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-ex2
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
Jørgen Hollum
tdt4242-ex2
Commits
969de810
Commit
969de810
authored
2 years ago
by
Sigurd
Browse files
Options
Downloads
Patches
Plain Diff
Exercise.js - let->const
P42 changes
parent
ce668400
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#168406
passed with stage
in 34 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/www/scripts/exercise.js
+28
-28
28 additions, 28 deletions
frontend/www/scripts/exercise.js
with
28 additions
and
28 deletions
frontend/www/scripts/exercise.js
+
28
−
28
View file @
969de810
...
...
@@ -41,7 +41,7 @@ function handleCancelButtonDuringEdit() {
cancelButton
.
removeEventListener
(
"
click
"
,
handleCancelButtonDuringEdit
);
le
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
cons
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
if
(
oldFormData
.
has
(
"
name
"
))
form
.
name
.
value
=
oldFormData
.
get
(
"
name
"
);
if
(
oldFormData
.
has
(
"
description
"
))
form
.
description
.
value
=
oldFormData
.
get
(
"
description
"
);
if
(
oldFormData
.
has
(
"
duration
"
))
form
.
duration
.
value
=
oldFormData
.
get
(
"
duration
"
);
...
...
@@ -64,23 +64,23 @@ function handleCancelButtonDuringCreate() {
async
function
createExercise
()
{
document
.
querySelector
(
"
select
"
).
removeAttribute
(
"
disabled
"
)
le
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
le
t
formData
=
new
FormData
(
form
);
le
t
body
=
{
"
name
"
:
formData
.
get
(
"
name
"
),
cons
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
cons
t
formData
=
new
FormData
(
form
);
cons
t
body
=
{
"
name
"
:
formData
.
get
(
"
name
"
),
"
description
"
:
formData
.
get
(
"
description
"
),
"
duration
"
:
formData
.
get
(
"
duration
"
),
"
calories
"
:
formData
.
get
(
"
calories
"
),
"
muscleGroup
"
:
formData
.
get
(
"
muscleGroup
"
),
"
unit
"
:
formData
.
get
(
"
unit
"
)};
le
t
response
=
await
sendRequest
(
"
POST
"
,
`
${
HOST
}
/api/exercises/`
,
body
);
cons
t
response
=
await
sendRequest
(
"
POST
"
,
`
${
HOST
}
/api/exercises/`
,
body
);
if
(
response
.
ok
)
{
window
.
location
.
replace
(
"
exercises.html
"
);
return
;
}
le
t
data
=
await
response
.
json
();
le
t
alert
=
createAlert
(
"
Could not create new exercise!
"
,
data
);
cons
t
data
=
await
response
.
json
();
cons
t
alert
=
createAlert
(
"
Could not create new exercise!
"
,
data
);
document
.
body
.
prepend
(
alert
);
}
...
...
@@ -96,15 +96,15 @@ function handleEditExerciseButtonClick() {
cancelButton
.
addEventListener
(
"
click
"
,
handleCancelButtonDuringEdit
);
le
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
cons
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
oldFormData
=
new
FormData
(
form
);
}
async
function
deleteExercise
(
id
)
{
le
t
response
=
await
sendRequest
(
"
DELETE
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
);
cons
t
response
=
await
sendRequest
(
"
DELETE
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
);
if
(
!
response
.
ok
)
{
le
t
data
=
await
response
.
json
();
le
t
alert
=
createAlert
(
`Could not delete exercise
${
id
}
`
,
data
);
cons
t
data
=
await
response
.
json
();
cons
t
alert
=
createAlert
(
`Could not delete exercise
${
id
}
`
,
data
);
document
.
body
.
prepend
(
alert
);
}
else
{
window
.
location
.
replace
(
"
exercises.html
"
);
...
...
@@ -112,50 +112,50 @@ async function deleteExercise(id) {
}
async
function
retrieveExercise
(
id
)
{
le
t
response
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
);
cons
t
response
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
);
console
.
log
(
response
.
ok
)
if
(
!
response
.
ok
)
{
le
t
data
=
await
response
.
json
();
le
t
alert
=
createAlert
(
"
Could not retrieve exercise data!
"
,
data
);
cons
t
data
=
await
response
.
json
();
cons
t
alert
=
createAlert
(
"
Could not retrieve exercise data!
"
,
data
);
document
.
body
.
prepend
(
alert
);
return
;
}
document
.
querySelector
(
"
select
"
).
removeAttribute
(
"
disabled
"
)
le
t
exerciseData
=
await
response
.
json
();
le
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
le
t
formData
=
new
FormData
(
form
);
cons
t
exerciseData
=
await
response
.
json
();
cons
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
cons
t
formData
=
new
FormData
(
form
);
for
(
le
t
key
of
formData
.
keys
())
{
for
(
cons
t
key
of
formData
.
keys
())
{
const
selector
=
key
!==
"
muscleGroup
"
?
`input[name="
${
key
}
"], textarea[name="
${
key
}
"]`
:
`select[name=
${
key
}
]`
le
t
input
=
form
.
querySelector
(
selector
);
le
t
newVal
=
exerciseData
[
key
];
cons
t
input
=
form
.
querySelector
(
selector
);
cons
t
newVal
=
exerciseData
[
key
];
input
.
value
=
newVal
;
}
document
.
querySelector
(
"
select
"
).
setAttribute
(
"
disabled
"
,
""
)
}
async
function
updateExercise
(
id
)
{
le
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
le
t
formData
=
new
FormData
(
form
);
cons
t
form
=
document
.
querySelector
(
"
#form-exercise
"
);
cons
t
formData
=
new
FormData
(
form
);
le
t
muscleGroupSelector
=
document
.
querySelector
(
"
select
"
)
cons
t
muscleGroupSelector
=
document
.
querySelector
(
"
select
"
)
muscleGroupSelector
.
removeAttribute
(
"
disabled
"
)
le
t
selectedMuscleGroup
=
new
MuscleGroup
(
formData
.
get
(
"
muscleGroup
"
));
cons
t
selectedMuscleGroup
=
new
MuscleGroup
(
formData
.
get
(
"
muscleGroup
"
));
le
t
body
=
{
"
name
"
:
formData
.
get
(
"
name
"
),
cons
t
body
=
{
"
name
"
:
formData
.
get
(
"
name
"
),
"
description
"
:
formData
.
get
(
"
description
"
),
"
duration
"
:
formData
.
get
(
"
duration
"
),
"
calories
"
:
formData
.
get
(
"
calories
"
),
"
muscleGroup
"
:
selectedMuscleGroup
.
getMuscleGroupType
(),
"
unit
"
:
formData
.
get
(
"
unit
"
)};
le
t
response
=
await
sendRequest
(
"
PUT
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
,
body
);
cons
t
response
=
await
sendRequest
(
"
PUT
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
,
body
);
if
(
!
response
.
ok
)
{
le
t
data
=
await
response
.
json
();
le
t
alert
=
createAlert
(
`Could not update exercise
${
id
}
`
,
data
);
cons
t
data
=
await
response
.
json
();
cons
t
alert
=
createAlert
(
`Could not update exercise
${
id
}
`
,
data
);
document
.
body
.
prepend
(
alert
);
return
;
}
...
...
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