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
Merge requests
!82
The source project of this merge request has been removed.
ex 1
Closed
ex 1
(removed):trainerPage
into
main
Overview
0
Commits
2
Pipelines
0
Changes
2
Closed
Pūslys, A. (Adomas, Student B-TCS)
requested to merge
(removed):trainerPage
into
main
10 months ago
Overview
0
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
main
version 1
d48deedd
10 months ago
main (base)
and
latest version
latest version
d48deedd
2 commits,
10 months ago
version 1
d48deedd
2 commits,
10 months ago
2 files
+
146
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/main/webapp/js/requests.js
+
90
−
1
Options
@@ -60,4 +60,93 @@ function createPokemonTypesTable() {
</tbody>
</table>
`
}
\ No newline at end of file
}
// ----------------------------- Trainers ---------------------------------------------
function
updateTrainerDetails
(
trainerId
)
{
const
tt
=
trainerTypes
?.
data
?.
find
(
item
=>
item
.
id
===
trainerId
);
const
parent
=
document
.
getElementById
(
detailsParentId
);
parent
.
innerHTML
=
`
<div class="card" id="
${
tt
.
id
}
_card">
<img src="
${
tt
.
profileUrl
}
" class="card-img-top" alt="
${
tt
.
name
}
">
<div class="card-body">
<h5 class="card-title">
${
tt
.
name
}
</h5>
<p class="card-text">
Created:
${
tt
.
created
}
</br>
Last Update:
${
tt
.
lastUpdate
}
</br>
</p>
</div>
</div>
`
}
function
trainerToRow
(
trainer
)
{
return
`
<tr id="
${
getRowId
(
trainer
)}
" onclick="updateTrainerDetails('
${
trainer
?.
id
?.
trim
()}
')">
<th scope="row">
${
trainer
.
id
}
</th>
<td>
${
trainer
.
name
}
</td>
<td>
${
trainer
.
created
}
</td>
<td>
${
trainer
.
lastUpdate
}
</td>
</tr>
`
}
function
createTrainersTable
()
{
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">Last Updated</th>
</tr>
</thead>
<tbody>
${
trainerTypes
.
data
.
map
(
trainer
=>
`
${
trainerToRow
(
trainer
)}
`
).
join
(
"
\n
"
)
||
"
no data
"
}
</tbody>
</table>
`
}
document
.
addEventListener
(
'
DOMContentLoaded
'
,
()
=>
{
const
form
=
document
.
getElementById
(
'
addTrainerForm
'
);
form
.
addEventListener
(
'
submit
'
,
function
(
event
)
{
// prevent submitting through HTML form action
event
.
preventDefault
();
const
trainerName
=
document
.
getElementById
(
'
trainerName
'
).
value
;
const
trainerData
=
{
name
:
trainerName
};
// Fetch API to send data to server
fetch
(
'
/pokemon/api/trainers/
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
(
trainerData
)
})
.
then
(
response
=>
{
if
(
!
response
.
ok
)
{
throw
new
Error
(
'
Network response not ok
'
+
response
.
statusText
);
}
return
response
.
json
();
})
.
then
(
data
=>
{
console
.
log
(
'
Success:
'
,
data
);
alert
(
'
Trainer added successfully!
'
)
})
.
catch
(
error
=>
{
console
.
error
(
'
Error:
'
,
error
);
alert
(
'
Failed to add trainer:
'
+
error
.
message
);
});
});
})
Loading