Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TP4 - AJAX
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noe Decobecq
TP4 - AJAX
Commits
e8d54df1
Commit
e8d54df1
authored
2 years ago
by
Noe Decobecq
Browse files
Options
Downloads
Patches
Plain Diff
c'est bon je rigolais ca marche
parent
d12c80c7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/AboutView.js
+7
-21
7 additions, 21 deletions
src/AboutView.js
src/GameListView.js
+18
-24
18 additions, 24 deletions
src/GameListView.js
src/main.js
+2
-1
2 additions, 1 deletion
src/main.js
with
27 additions
and
46 deletions
src/AboutView.js
+
7
−
21
View file @
e8d54df1
import
View
from
'
./View.js
'
;
import
Router
from
'
./Router.js
'
;
export
default
class
AboutView
extends
View
{
element
;
export
class
AboutView
extends
View
{
constructor
(
element
)
{
super
(
element
);
this
.
element
=
document
.
querySelector
(
'
.about
'
);
}
showFileContent
(
html
)
{
this
.
element
.
innerHTML
=
html
;
}
OnClickSupport
(
event
)
{
event
.
preventDefault
();
Router
.
navigate
(
'
/help
'
);
}
show
()
{
super
.
show
();
fetch
(
'
./about.html
'
)
.
then
(
response
=>
response
.
text
())
.
then
(
responseText
=>
this
.
showFileContent
(
responseText
))
.
then
(()
=>
this
.
element
.
querySelector
(
'
.button
'
)
.
addEventListener
(
'
click
'
,
event
=>
this
.
OnClickSupport
(
event
))
);
.
then
(
responseText
=>
this
.
showFileContent
(
responseText
))
;
}
showFileContent
(
html
)
{
this
.
element
.
innerHTML
=
html
;
super
.
show
(
);
}
}
This diff is collapsed.
Click to expand it.
src/GameListView.js
+
18
−
24
View file @
e8d54df1
...
...
@@ -34,42 +34,36 @@ export default class GameListView extends View {
* @param {string} ordering ordre d'affichage des résultats
*/
renderGameList
(
search
=
''
,
ordering
)
{
// calcul de la fonction de tri selon le paramètre ordering
let
sortingFunction
;
switch
(
ordering
)
{
case
'
-metacritic
'
:
sortingFunction
=
(
a
,
b
)
=>
b
.
metacritic
-
a
.
metacritic
;
break
;
case
'
-released
'
:
sortingFunction
=
(
a
,
b
)
=>
b
.
released
.
localeCompare
(
a
.
released
);
break
;
}
// parcours du tableau + génération du code HTML de la gameList
let
html
=
''
;
this
.
element
.
querySelector
(
'
.results
'
).
classList
.
add
(
'
is-loading
'
);
this
.
element
.
querySelector
(
'
.button submit
'
).
setAttribute
(
'
disabled
'
,
''
);
fetch
(
`https://api.rawg.io/api/games?search=
${
search
}
&ordering=
${
ordering
}
&key=7ed131e6be6b455ba809caad17f4f260
`
`https://api.rawg.io/api/games?
key=7ed131e6be6b455ba809caad17f4f260&
search=
${
search
}
&ordering=
${
ordering
}
`
)
.
then
(
response
=>
response
.
text
())
.
then
(()
=>
this
.
element
.
querySelector
(
'
.button submit
'
)
.
setAttribute
(
''
,
'
disabled
'
)
)
.
then
(
res
=>
JSON
.
parse
(
res
))
.
then
(
donne
=>
donne
.
results
.
forEach
(
game
=>
{
html
+=
renderGameThumbnail
(
game
);
})
.
then
(
responseText
=>
JSON
.
parse
(
responseText
))
.
then
(
games
=>
games
.
results
.
forEach
(
game
=>
(
html
+=
renderGameThumbnail
(
game
)))
)
.
then
(()
=>
(
this
.
element
.
querySelector
(
'
.results
'
).
innerHTML
=
html
))
.
then
(()
=>
this
.
element
.
querySelector
(
'
.results
'
).
classList
.
remove
(
'
is-loading
'
)
);
/*data
/*// calcul de la fonction de tri selon le paramètre ordering
let sortingFunction;
switch (ordering) {
case '-metacritic':
sortingFunction = (a, b) => b.metacritic - a.metacritic;
break;
case '-released':
sortingFunction = (a, b) => b.released.localeCompare(a.released);
break;
}
// parcours du tableau + génération du code HTML de la gameList
let html = '';
data
.filter(game => game.name.toLowerCase().includes(search.toLowerCase())) // recherche
.sort(sortingFunction) // tri
.forEach(game => (html += renderGameThumbnail(game))); // génération du HTML
...
...
This diff is collapsed.
Click to expand it.
src/main.js
+
2
−
1
View file @
e8d54df1
import
GameListView
from
'
./GameListView.js
'
;
import
HelpView
from
'
./HelpView.js
'
;
import
Router
from
'
./Router.js
'
;
import
AboutView
from
'
./AboutView.js
'
;
import
{
AboutView
}
from
'
./AboutView.js
'
;
import
View
from
'
./View.js
'
;
// Modification du footer
document
.
querySelector
(
'
body > footer > div:nth-of-type(2)
'
).
innerHTML
+=
...
...
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