Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mod4-wp-2023-2024-pokemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Morais Fonseca, Claudenir (UT-EEMCS)
mod4-wp-2023-2024-pokemon
Commits
390d3c02
Commit
390d3c02
authored
10 months ago
by
Joost080
Browse files
Options
Downloads
Patches
Plain Diff
solution
parent
7d77e368
No related branches found
No related tags found
3 merge requests
!124
Assignment3
,
!120
Assigment 2
,
!108
solution answer 1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/webapp/TrainerData.html
+44
-0
44 additions, 0 deletions
src/main/webapp/TrainerData.html
src/main/webapp/js/requests.js
+74
-7
74 additions, 7 deletions
src/main/webapp/js/requests.js
with
118 additions
and
7 deletions
src/main/webapp/TrainerData.html
0 → 100644
+
44
−
0
View file @
390d3c02
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<!-- Required meta tags -->
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, shrink-to-fit=no"
>
<!-- Bootstrap CSS -->
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
integrity=
"sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin=
"anonymous"
>
<title>
Title
</title>
<link
rel=
"icon"
type=
"image/x-icon"
href=
"/pokemon/favicon.ico"
>
</head>
<body>
<script
src=
"js/requests.js"
></script>
<script>
tableParentId
=
"
tableDiv
"
;
detailsParentId
=
"
detailsDiv
"
;
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
trainers
=
data
;
createTrainerTable
();
})
.
catch
(
err
=>
{
console
.
error
(
`unable to fetch trainers:
${
err
.
status
}
`
);
console
.
error
(
err
);
});
</script>
<h1>
Trainers
</h1>
<div
class=
"container"
>
<div
class=
"row"
>
<div
id=
"tableDiv"
class=
"col-8"
>
No data
</div>
<div
id=
"detailsDiv"
class=
"col-4"
>
No data
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/webapp/js/requests.js
+
74
−
7
View file @
390d3c02
let
pokemonTypes
=
{};
let
trainers
=
{};
let
tableParentId
=
'
table
'
;
let
detailsParentId
=
'
details
'
;
function
getRowId
(
resource
)
{
return
`
${
resource
.
id
}
_row`
}
function
updateDetails
(
pokemonTypeId
)
{
function
updateDetails
Pokemon
(
pokemonTypeId
)
{
const
pt
=
pokemonTypes
?.
data
?.
find
(
item
=>
item
.
id
===
pokemonTypeId
);
const
parent
=
document
.
getElementById
(
detailsParentId
);
...
...
@@ -26,10 +28,28 @@ function updateDetails(pokemonTypeId) {
</div>
`
}
function
updateDetailsTrainer
(
TrainerID
)
{
const
tr
=
trainers
?.
data
?.
find
(
item
=>
item
.
id
===
TrainerID
);
const
parent
=
document
.
getElementById
(
detailsParentId
);
parent
.
innerHTML
=
`
<div class="card" id="
${
tr
.
id
}
_card">
<img src="
${
tr
.
profileUrl
}
" class="card-img-top" alt="
${
tr
.
created
}
">
<div class="card-body">
<h5 class="card-title">
${
tr
.
name
}
#
${
tr
.
id
}
</h5>
<p class="card-text">
createdDate:
${
tr
.
created
}
</br>
LastUpDate:
${
tr
.
lastUpDate
}
</br>
profileURL:
${
tr
.
profileUrl
}
</br>
</p>
</div>
</div>
`
}
function
pokemonTypeToRow
(
pokemonType
)
{
return
`
<tr id="
${
getRowId
(
pokemonType
)}
" onclick="updateDetails('
${
pokemonType
?.
id
?.
trim
()}
')">
<tr id="
${
getRowId
(
pokemonType
)}
" onclick="updateDetails
Pokemon
('
${
pokemonType
?.
id
?.
trim
()}
')">
<th scope="row">
${
pokemonType
.
id
}
</th>
<td>
${
pokemonType
.
name
}
</td>
<td>#
${
pokemonType
.
pokedexNumber
}
</td>
...
...
@@ -38,7 +58,16 @@ function pokemonTypeToRow(pokemonType) {
</tr>
`
}
function
TrainerToRow
(
trainer
)
{
return
`
<tr id="
${
getRowId
(
trainer
)}
" onclick="updateDetailsTrainer('
${
trainer
?.
id
?.
trim
()}
')">
<th scope="row">
${
trainer
.
id
}
</th>
<td>
${
trainer
.
name
}
</td>
<td>
${
trainer
.
created
}
</td>
<td>
${
trainer
.
lastUpDate
}
</td>
</tr>
`
}
function
createPokemonTypesTable
()
{
const
tableParent
=
document
.
getElementById
(
tableParentId
);
tableParent
.
innerHTML
=
`
...
...
@@ -54,10 +83,48 @@ function createPokemonTypesTable() {
</thead>
<tbody>
${
pokemonTypes
.
data
.
map
(
resource
=>
`
${
pokemonTypeToRow
(
resource
)}
`
).
join
(
"
\n
"
)
||
"
no data
"
}
pokemonTypes
.
data
.
map
(
resource
=>
`
${
pokemonTypeToRow
(
resource
)}
`
).
join
(
"
\n
"
)
||
"
no data
"
}
</tbody>
</table>
`
}
\ No newline at end of file
}
function
createTrainerTable
()
{
const
tableParent
=
document
.
getElementById
(
tableParentId
);
tableParent
.
innerHTML
=
`
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">created</th>
<th scope="col">lastUpDate</th>
<th scope="col">profileURL</th>
</tr>
</thead>
<tbody>
${
trainers
.
data
.
map
(
resource
=>
`
${
TrainerToRow
(
resource
)}
`
).
join
(
"
\n
"
)
||
"
no data
"
}
</tbody>
</table>
`
}
// function addTrainer() {
// // Retrieve trainer details from the form
// var trainerName = document.getElementById("trainerName").value;
// var trainerID = document.getElementById("trainerID").value;
//
// // Create a new row in the table with the trainer details
// var newRow = "<tr><td>" + trainerName + "</td><td>" + trainerID + "</td></tr>";
// document.getElementById("tableDiv").innerHTML += newRow;
//
// // Clear the form fields
// document.getElementById("trainerName").value = "";
// document.getElementById("trainerID").value = "";
//
// // Close the modal
// $('#addTrainerModal').modal('hide');
// }
\ 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