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
Ruginosu, M.I. (Ioana, Student B-BIT)
mod4-wp-2023-2024-pokemon
Commits
1c2dfc0e
Commit
1c2dfc0e
authored
10 months ago
by
Ruginosu, M.I. (Ioana, Student B-BIT)
Browse files
Options
Downloads
Patches
Plain Diff
issue 2 the (final) correct version
parent
9ced3aff
Branches
issue#1
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
+38
-32
38 additions, 32 deletions
src/main/webapp/js/trainers.js
src/main/webapp/trainers.html
+2
-2
2 additions, 2 deletions
src/main/webapp/trainers.html
with
40 additions
and
34 deletions
src/main/webapp/js/trainers.js
+
38
−
32
View file @
1c2dfc0e
let
pokemonType
s
=
{};
let
trainer
s
=
{};
let
tableParentId
=
'
table
'
;
let
detailsParentId
=
'
details
'
;
...
...
@@ -7,39 +7,52 @@ function getRowId(resource) {
return
`
${
resource
.
id
}
_row`
}
function
updateDetails
(
pokemonTypeId
)
{
const
pt
=
pokemonTypes
?.
data
?.
find
(
item
=>
item
.
id
===
pokemonTypeId
);
const
parent
=
document
.
getElementById
(
detailsParentId
);
function
updateTrainerTable
()
{
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
trainers
=
data
;
})
.
catch
(
err
=>
{
console
.
error
(
`Unable to fetch trainers
${
err
.
status
}
`
);
console
.
error
(
err
);
});
}
function
updateDetails
()
{
const
trainerId
=
document
.
getElementById
(
'
idTrainer
'
);
const
pt
=
trainers
?.
data
?.
find
(
item
=>
item
.
id
===
trainerId
);
const
parent
=
document
.
getElementById
(
detailsParentId
);
let
time
=
new
Date
();
parent
.
innerHTML
=
`
<div class="card" id="
${
pt
.
id
}
_card">
<img src="
${
pt
.
imgUrl
}
" class="card-img-top" alt="
${
pt
.
classification
}
">
<div class="card-body">
<h5 class="card-title">
${
pt
.
name
}
#
${
pt
.
pokedexNumber
}
</h5>
<p class="card-text">
Japanese n
ame:
${
pt
.
japaneseN
ame
}
</br>
C
lassification:
${
pt
.
classification
}
</br>
Abilities:
${
pt
.
abilities
?.
join
(
"
,
"
)
||
"
none
"
}
</br>
Type:
${
pt
.
pr
imaryType
}${
pt
.
secondaryType
?
"
,
"
+
pt
.
secondaryType
:
""
}
N
ame:
${
pt
.
n
ame
}
</br>
C
reate:
${
pt
.
created
}
</br>
Last updated:
${
pt
.
lastUpDate
?.
join
(
"
,
"
)
||
"
none
"
}
</br>
Type:
${
pt
.
pr
ofileUrl
}
</p>
</div>
</div>
`
}
function
pokemonTypeToRow
(
pokemonType
)
{
function
trainersToRow
(
trainers
)
{
return
`
<tr id="
${
getRowId
(
pokemonType
)}
" onclick="updateDetails('
${
pokemonType
?.
id
?.
trim
()}
')">
<th scope="row">
${
pokemonType
.
id
}
</th>
<td>
${
pokemonType
.
name
}
</td>
<td>#
${
pokemonType
.
pokedexNumber
}
</td>
<td>
${
pokemonType
.
primaryTyp
e
}
</td>
<td>
${
pokemonType
.
secondaryType
||
'
-
'
}
</td>
<tr id="
${
getRowId
(
trainers
)}
" onclick="updateDetails('
${
trainers
?.
id
?.
trim
()}
')">
<th scope="row">
${
trainers
.
id
}
</th>
<td>
${
trainers
.
name
}
</td>
<td>#
${
trainers
.
created
}
</td>
<td>
${
trainers
.
lastUpDat
e
}
</td>
<td>
${
trainers
.
profileUrl
||
'
-
'
}
</td>
</tr>
`
}
function
create
PokemonType
sTable
()
{
function
create
Trainer
sTable
()
{
const
tableParent
=
document
.
getElementById
(
tableParentId
);
tableParent
.
innerHTML
=
`
<table class="table table-striped table-hover">
...
...
@@ -47,14 +60,14 @@ function createPokemonTypesTable() {
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">
Pokedex Number
</th>
<th scope="col">
Primary Type
</th>
<th scope="col">
Secondary Type
</th>
<th scope="col">
Created
</th>
<th scope="col">
Last updated
</th>
<th scope="col">
Profile url
</th>
</tr>
</thead>
<tbody>
${
pokemonType
s
.
data
.
map
(
resource
=>
`
${
pokemonType
ToRow
(
resource
)}
`
).
join
(
"
\n
"
)
trainer
s
.
data
.
map
(
resource
=>
`
${
trainers
ToRow
(
resource
)}
`
).
join
(
"
\n
"
)
||
"
no data
"
}
</tbody>
...
...
@@ -63,9 +76,12 @@ function createPokemonTypesTable() {
}
function
createTrainer
()
{
let
time
=
new
Date
();
const
name
=
document
.
getElementById
(
'
trainerName
'
).
value
;
const
profileurl
=
document
.
getElementById
(
'
profileUrl
'
).
value
;
const
data
=
{
created
:
time
,
lastUpDate
:
time
,
profileUrl
:
profileurl
,
name
:
name
}
...
...
@@ -78,15 +94,5 @@ function createTrainer() {
}).
then
(
response
=>
updateTrainerTable
())
}
function
updateTrainerTable
()
{
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
pokemonTypes
=
data
;
createTrainerTable
();
})
.
catch
(
err
=>
{
console
.
error
(
`Unable to fetch Pokemon Types:
${
err
.
status
}
`
);
console
.
error
(
err
);
});
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/webapp/trainers.html
+
2
−
2
View file @
1c2dfc0e
...
...
@@ -22,8 +22,8 @@
fetch
(
'
/pokemon/api/trainers
'
)
.
then
(
res
=>
res
.
json
())
.
then
(
data
=>
{
pokemonType
s
=
data
;
create
PokemonType
sTable
();
trainer
s
=
data
;
create
Trainer
sTable
();
})
.
catch
(
err
=>
{
console
.
error
(
`Unable to fetch Pokemon Types:
${
err
.
status
}
`
);
...
...
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