Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-base-APU
Manage
Activity
Members
Labels
Plan
Issues
0
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
Tor Martin Frøberg Wang
tdt4242-base-APU
Commits
153d882e
Commit
153d882e
authored
3 years ago
by
Tobias Ingebrigt Ørstad
Browse files
Options
Downloads
Plain Diff
Merge branch 'frontendsmells' into 'dev'
Frontendsmells See merge request
!28
parents
4e7e8cce
17959198
Branches
dev
Branches containing commit
No related tags found
2 merge requests
!31
Complete exercise 3
,
!28
Frontendsmells
Pipeline
#129265
passed with stage
Stage:
in 1 minute
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
frontend/www/exercise.html
+1
-1
1 addition, 1 deletion
frontend/www/exercise.html
frontend/www/scripts/exercise.js
+2
-1
2 additions, 1 deletion
frontend/www/scripts/exercise.js
frontend/www/scripts/workouts.js
+52
-46
52 additions, 46 deletions
frontend/www/scripts/workouts.js
with
55 additions
and
48 deletions
frontend/www/exercise.html
+
1
−
1
View file @
153d882e
...
...
@@ -51,7 +51,7 @@
</div>
</div>
<table
id=
"leaderboardstable"
class=
"table table-striped"
>
<tr><th
>
Rank
<th>
Username
<th
>
Score
<tr><th
scope=
"col"
>
Rank
<th
scope=
"col"
>
Username
<th
scope=
"col"
>
Score
</table>
</div>
<script
src=
"scripts/defaults.js"
></script>
...
...
This diff is collapsed.
Click to expand it.
frontend/www/scripts/exercise.js
+
2
−
1
View file @
153d882e
...
...
@@ -3,6 +3,8 @@ let okButton;
let
deleteButton
;
let
editButton
;
let
oldFormData
;
let
leaderboardTable
;
let
leaderboardTitle
;
function
handleCancelButtonDuringEdit
()
{
setReadOnly
(
true
,
"
#form-exercise
"
);
...
...
@@ -127,7 +129,6 @@ async function updateExercise(id) {
async
function
fetchLeaderBoards
(
id
)
{
// Fetches leaderboard data
let
response
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/leaderboards/
${
id
}
/`
);
let
data
=
await
response
.
json
();
...
...
This diff is collapsed.
Click to expand it.
frontend/www/scripts/workouts.js
+
52
−
46
View file @
153d882e
...
...
@@ -7,67 +7,76 @@ async function fetchWorkouts(ordering) {
let
data
=
await
response
.
json
();
let
workouts
=
data
.
results
;
let
container
=
document
.
getElementById
(
'
div-content
'
);
await
convertWorkoutDataToFrontend
(
workouts
);
for
(
const
workout
of
workouts
){
return
workouts
;
}
}
let
workoutLikes
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/workoutLiking/
${
workout
.
id
}
`
);
async
function
convertWorkoutDataToFrontend
(
workouts
){
let
container
=
document
.
getElementById
(
'
div-content
'
);
let
workoutLikesData
=
[
true
,
1
]
for
(
const
workout
of
workouts
){
if
(
workoutLikes
.
ok
){
workoutLikesData
=
await
workoutLikes
.
json
()
}
let
workoutLikes
=
await
sendRequest
(
"
GET
"
,
`
${
HOST
}
/api/workoutLiking/
${
workout
.
id
}
`
);
let
templateWorkout
=
document
.
querySelector
(
"
#template-workout
"
);
let
cloneWorkout
=
templateWorkout
.
content
.
cloneNode
(
true
);
let
workoutLikesData
=
[
true
,
1
]
let
aWorkout
=
cloneWorkout
.
querySelector
(
"
a
"
);
aWorkout
.
href
=
`workout.html?id=
${
workout
.
id
}
`
;
if
(
workoutLikes
.
ok
){
workoutLikesData
=
await
workoutLikes
.
json
()
}
let
h5
=
aWorkout
.
querySelector
(
"
h5
"
);
h5
.
textContent
=
workout
.
name
;
let
templateWorkout
=
document
.
querySelector
(
"
#template-workout
"
);
let
cloneWorkout
=
templateWorkout
.
content
.
cloneNode
(
true
)
;
let
localDate
=
new
Date
(
workout
.
date
);
let
aWorkout
=
cloneWorkout
.
querySelector
(
"
a
"
);
aWorkout
.
href
=
`workout.html?id=
${
workout
.
id
}
`
;
let
table
=
aWorkout
.
querySelector
(
"
table
"
);
let
rows
=
table
.
querySelectorAll
(
"
tr
"
);
rows
[
0
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
localDate
.
toLocaleDateString
();
// Date
rows
[
1
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
localDate
.
toLocaleTimeString
();
// Time
rows
[
2
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workout
.
owner_username
;
//Owner
rows
[
3
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workout
.
exercise_instances
.
length
;
// Exercises
let
h5
=
aWorkout
.
querySelector
(
"
h5
"
);
h5
.
textContent
=
workout
.
name
;
rows
[
4
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workoutLikesData
[
1
]
let
localDate
=
new
Date
(
workout
.
date
);
let
likeButton
=
rows
[
4
].
querySelectorAll
(
"
td
"
)[
2
].
querySelector
(
"
.like-button
"
)
let
table
=
aWorkout
.
querySelector
(
"
table
"
);
let
rows
=
table
.
querySelectorAll
(
"
tr
"
);
rows
[
0
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
localDate
.
toLocaleDateString
();
// Date
rows
[
1
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
localDate
.
toLocaleTimeString
();
// Time
rows
[
2
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workout
.
owner_username
;
//Owner
rows
[
3
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workout
.
exercise_instances
.
length
;
// Exercises
if
(
!
workoutLikesData
[
0
]){
likeButton
.
classList
.
add
(
"
active
"
)
}
rows
[
4
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
workoutLikesData
[
1
]
likeButton
.
addEventListener
(
"
click
"
,
async
function
(
e
)
{
e
.
preventDefault
();
let
likeButton
=
rows
[
4
].
querySelectorAll
(
"
td
"
)[
2
].
querySelector
(
"
.like-button
"
)
if
(
!
this
.
classList
.
contains
(
"
active
"
)){
this
.
classList
.
add
(
"
active
"
);
this
.
classList
.
add
(
"
animated
"
);
generateClones
(
this
);
if
(
!
workoutLikesData
[
0
]){
likeButton
.
classList
.
add
(
"
active
"
)
}
let
likeWorkoutResponse
=
await
sendRequest
(
"
POST
"
,
`
${
HOST
}
/api/workoutLiking/
${
workout
.
id
}
/`
,
{}
);
await
addEventListenersForLikeButtons
(
workout
,
likeButton
,
rows
);
if
(
likeWorkoutResponse
.
ok
){
let
likeWorkoutData
=
await
likeWorkoutResponse
.
json
()
rows
[
4
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
likeWorkoutData
[
1
]
likeButton
.
classList
.
add
(
"
active
"
)
}
}
})
container
.
appendChild
(
aWorkout
);
}
}
async
function
addEventListenersForLikeButtons
(
workout
,
likeButton
,
rows
){
likeButton
.
addEventListener
(
"
click
"
,
async
function
(
e
)
{
e
.
preventDefault
();
container
.
appendChild
(
aWorkout
);
};
return
workouts
;
}
if
(
!
this
.
classList
.
contains
(
"
active
"
)){
this
.
classList
.
add
(
"
active
"
);
this
.
classList
.
add
(
"
animated
"
);
generateClones
(
this
);
let
likeWorkoutResponse
=
await
sendRequest
(
"
POST
"
,
`
${
HOST
}
/api/workoutLiking/
${
workout
.
id
}
/`
,
{});
if
(
likeWorkoutResponse
.
ok
){
let
likeWorkoutData
=
await
likeWorkoutResponse
.
json
()
rows
[
4
].
querySelectorAll
(
"
td
"
)[
1
].
textContent
=
likeWorkoutData
[
1
]
likeButton
.
classList
.
add
(
"
active
"
)
}
}
})
}
function
createWorkout
()
{
...
...
@@ -171,9 +180,6 @@ function generateClones(button) {
clone
.
parentNode
.
removeChild
(
clone
);
clearTimeout
(
removeNodeTimeout
);
},
900
);
let
removeClassTimeout
=
setTimeout
(
function
()
{
button
.
classList
.
remove
(
"
animated
"
)
},
600
);
}
}
...
...
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