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
2f35db15
Commit
2f35db15
authored
2 years ago
by
hollum
Browse files
Options
Downloads
Patches
Plain Diff
Shotgun surgery
parent
f11ab032
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/www/scripts/exercise.js
+45
-38
45 additions, 38 deletions
frontend/www/scripts/exercise.js
with
45 additions
and
38 deletions
frontend/www/scripts/exercise.js
+
45
−
38
View file @
2f35db15
...
...
@@ -4,7 +4,14 @@ let deleteButton;
let
editButton
;
let
oldFormData
;
class
MuscleGroup
{
const
name
=
"
name
"
;
const
description
=
"
description
"
;
const
duration
=
"
duration
"
;
const
calories
=
"
calories
"
;
const
muscleGroup
=
"
muscleGroup
"
;
const
unit
=
"
unit
"
;
class
MuscleGroup
{
constructor
(
type
)
{
this
.
isValidType
=
false
;
this
.
validTypes
=
[
"
Legs
"
,
"
Chest
"
,
"
Back
"
,
"
Arms
"
,
"
Abdomen
"
,
"
Shoulders
"
]
...
...
@@ -14,7 +21,7 @@ class MuscleGroup {
setMuscleGroupType
=
(
newType
)
=>
{
this
.
isValidType
=
false
;
if
(
this
.
validTypes
.
includes
(
newType
)){
this
.
isValidType
=
true
;
this
.
type
=
newType
;
...
...
@@ -24,7 +31,7 @@ class MuscleGroup {
}
}
getMuscleGroupType
=
()
=>
{
console
.
log
(
this
.
type
,
"
SWIOEFIWEUFH
"
)
return
this
.
type
;
...
...
@@ -42,19 +49,19 @@ function handleCancelButtonDuringEdit() {
cancelButton
.
removeEventListener
(
"
click
"
,
handleCancelButtonDuringEdit
);
const
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
"
);
if
(
oldFormData
.
has
(
"
calories
"
))
form
.
calories
.
value
=
oldFormData
.
get
(
"
calories
"
);
if
(
oldFormData
.
has
(
"
muscleGroup
"
))
form
.
muscleGroup
.
value
=
oldFormData
.
get
(
"
muscleGroup
"
);
if
(
oldFormData
.
has
(
"
unit
"
))
form
.
unit
.
value
=
oldFormData
.
get
(
"
unit
"
);
oldFormData
.
delete
(
"
name
"
);
oldFormData
.
delete
(
"
description
"
);
oldFormData
.
delete
(
"
duration
"
);
oldFormData
.
delete
(
"
calories
"
);
oldFormData
.
delete
(
"
muscleGroup
"
);
oldFormData
.
delete
(
"
unit
"
);
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
);
if
(
oldFormData
.
has
(
calories
))
form
.
calories
.
value
=
oldFormData
.
get
(
calories
);
if
(
oldFormData
.
has
(
muscleGroup
))
form
.
muscleGroup
.
value
=
oldFormData
.
get
(
muscleGroup
);
if
(
oldFormData
.
has
(
unit
))
form
.
unit
.
value
=
oldFormData
.
get
(
unit
);
oldFormData
.
delete
(
name
);
oldFormData
.
delete
(
description
);
oldFormData
.
delete
(
duration
);
oldFormData
.
delete
(
calories
);
oldFormData
.
delete
(
muscleGroup
);
oldFormData
.
delete
(
unit
);
}
...
...
@@ -66,12 +73,12 @@ async function createExercise() {
document
.
querySelector
(
"
select
"
).
removeAttribute
(
"
disabled
"
)
const
form
=
document
.
querySelector
(
"
#form-exercise
"
);
const
formData
=
new
FormData
(
form
);
const
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
"
)};
const
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
)};
const
response
=
await
sendRequest
(
"
POST
"
,
`
${
HOST
}
/api/exercises/`
,
body
);
...
...
@@ -145,12 +152,12 @@ async function updateExercise(id) {
const
selectedMuscleGroup
=
new
MuscleGroup
(
formData
.
get
(
"
muscleGroup
"
));
const
body
=
{
"
name
"
:
formData
.
get
(
"
name
"
),
"
description
"
:
formData
.
get
(
"
description
"
),
"
duration
"
:
formData
.
get
(
"
duration
"
),
"
calories
"
:
formData
.
get
(
"
calories
"
),
"
muscleGroup
"
:
selectedMuscleGroup
.
getMuscleGroupType
(),
"
unit
"
:
formData
.
get
(
"
unit
"
)};
const
body
=
{
name
:
formData
.
get
(
name
),
description
:
formData
.
get
(
description
),
duration
:
formData
.
get
(
duration
),
calories
:
formData
.
get
(
calories
),
muscleGroup
:
selectedMuscleGroup
.
getMuscleGroupType
(),
unit
:
formData
.
get
(
"
unit
"
)};
const
response
=
await
sendRequest
(
"
PUT
"
,
`
${
HOST
}
/api/exercises/
${
id
}
/`
,
body
);
if
(
!
response
.
ok
)
{
...
...
@@ -167,15 +174,15 @@ async function updateExercise(id) {
deleteButton
.
className
+=
"
hide
"
;
cancelButton
.
className
+=
"
hide
"
;
editButton
.
className
=
editButton
.
className
.
replace
(
"
hide
"
,
""
);
cancelButton
.
removeEventListener
(
"
click
"
,
handleCancelButtonDuringEdit
);
oldFormData
.
delete
(
"
name
"
);
oldFormData
.
delete
(
"
description
"
);
oldFormData
.
delete
(
"
duration
"
);
oldFormData
.
delete
(
"
calories
"
);
oldFormData
.
delete
(
"
muscleGroup
"
);
oldFormData
.
delete
(
"
unit
"
);
oldFormData
.
delete
(
name
);
oldFormData
.
delete
(
description
);
oldFormData
.
delete
(
duration
);
oldFormData
.
delete
(
calories
);
oldFormData
.
delete
(
muscleGroup
);
oldFormData
.
delete
(
unit
);
}
window
.
addEventListener
(
"
DOMContentLoaded
"
,
async
()
=>
{
...
...
@@ -196,7 +203,7 @@ window.addEventListener("DOMContentLoaded", async () => {
deleteButton
.
addEventListener
(
"
click
"
,
(
async
(
id
)
=>
deleteExercise
(
id
)).
bind
(
undefined
,
exerciseId
));
okButton
.
addEventListener
(
"
click
"
,
(
async
(
id
)
=>
updateExercise
(
id
)).
bind
(
undefined
,
exerciseId
));
return
;
}
}
//create
setReadOnly
(
false
,
"
#form-exercise
"
);
...
...
@@ -206,4 +213,4 @@ window.addEventListener("DOMContentLoaded", async () => {
okButton
.
addEventListener
(
"
click
"
,
async
()
=>
createExercise
());
cancelButton
.
addEventListener
(
"
click
"
,
handleCancelButtonDuringCreate
);
});
\ No newline at end of file
});
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