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
Malnačs, E. (Ernests, Student B-TCS)
mod4-wp-2023-2024-pokemon
Commits
1bea63fb
Commit
1bea63fb
authored
10 months ago
by
Ernests Malnacs
Browse files
Options
Downloads
Patches
Plain Diff
Added creating trainers, through a form.
parent
6d97fb98
Branches
create-trainer
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/webapp/js/trainers.js
+42
-1
42 additions, 1 deletion
src/main/webapp/js/trainers.js
src/main/webapp/trainers.html
+20
-18
20 additions, 18 deletions
src/main/webapp/trainers.html
with
62 additions
and
19 deletions
src/main/webapp/js/trainers.js
+
42
−
1
View file @
1bea63fb
...
...
@@ -13,7 +13,7 @@ function updateDetails(trainerId) {
parent
.
innerHTML
=
`
<div class="card" id="
${
tr
.
id
}
_card">
<img src="
${
tr
.
profileUrl
}
" class="card-img-top" alt="
${
tr
.
name
}
">
${
tr
.
profileUrl
?
`
<img src="
${
tr
.
profileUrl
}
" class="card-img-top" alt="
${
tr
.
name
}
">
`
:
''
}
<div class="card-body">
<h5 class="card-title">
${
tr
.
name
}
</h5>
<p class="card-text">
...
...
@@ -52,4 +52,45 @@ function createTrainersTable() {
</tbody>
</table>
`
}
function
refreshTable
()
{
tableParentId
=
"
tableDiv
"
;
detailsParentId
=
"
detailsDiv
"
;
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
trainers
=
data
;
createTrainersTable
()
})
.
catch
(
err
=>
{
console
.
error
(
`Unable to fetch trainers:
${
err
.
status
}
`
);
console
.
error
(
err
);
});
}
function
handleTrainerCreate
(
event
)
{
event
.
preventDefault
();
const
trainerName
=
document
.
getElementById
(
"
trainerName
"
).
value
;
const
postData
=
JSON
.
stringify
({
name
:
trainerName
})
fetch
(
'
api/trainers
'
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
postData
})
.
then
(
response
=>
response
.
json
())
.
then
(
data
=>
{
refreshTable
();
})
.
catch
(
err
=>
{
console
.
error
(
'
Error
'
,
err
);
})
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/webapp/trainers.html
+
20
−
18
View file @
1bea63fb
...
...
@@ -15,30 +15,32 @@
<body>
<script
src=
"js/trainers.js"
></script>
<script>
tableParentId
=
"
tableDiv
"
;
detailsParentId
=
"
detailsDiv
"
;
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
trainers
=
data
;
createTrainersTable
()
})
.
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
style=
"padding:20px"
>
<form
id=
"createTrainerForm"
>
<div
class=
"form-group"
>
<label
for=
"trainerName"
>
Trainer Name
</label>
<input
type=
"text"
class=
"form-control"
id=
"trainerName"
placeholder=
"Enter Trainer Name"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
Create Trainer
</button>
</form>
</div>
<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>
</div>
<script>
const
createTrainerForm
=
document
.
getElementById
(
"
createTrainerForm
"
);
createTrainerForm
.
addEventListener
(
"
submit
"
,
handleTrainerCreate
);
refreshTable
();
</script>
</body>
</html>
\ 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