Commit f48e3da5 authored by Benzakein Jeremy's avatar Benzakein Jeremy

last changes

parent 61d00864
......@@ -44,7 +44,7 @@
<h1 class="display-3">Star People</h1>
<p class="lead">Un Trombinoscope des personnages de Star Wars</p>
<hr class="my-4">
<p>StarPeople est une plateforme pour chercher des information sur tous les personnages principaux comme secondaires de l'univers de Star Wars</p>
<p>StarPeople est une plateforme pour chercher des informations sur tous les personnages principaux comme secondaires de l'univers de Star Wars</p>
<hr>
<div class="row">
<p><div class="col-6">Pour lire le rapport</div><div class="col-3"> <a class="btn btn-dark" href="rapport.html">Cliquer ICI</a></div></p>
......
......@@ -24,6 +24,7 @@ const getPerson = async (index) => {
});
return person;
};
const createRow = (obj) => {
datatable.row.add([
obj.img,
......@@ -39,15 +40,17 @@ const getAllPeople = async () => {
//if page has been seen before, no need to call the API again
const t_start = performance.now();
let allPeople = {};
const count = await getPeopleCount();
let saved_data = sessionStorage.getItem('peopleSaved');
if (saved_data!=null){
saved_data = JSON.parse(saved_data);
allPeople = saved_data;
for (let person_index in saved_data){
createRow(saved_data[person_index]);
allPeople = JSON.parse(saved_data);
for (let person_index in allPeople){
createRow(allPeople[person_index]);
}
if (Object.keys(saved_data).length == count){
console.log('getAllPeople took' + (performance.now() - t_start) / 1000 + " seconds");
return saved_data;
......@@ -76,7 +79,6 @@ let datatable;
$(() => {
//initialise paging, sorting, and searching in datatable
datatable = $('#peopleTable').DataTable({
//the table doesnt
stateSave: true,
"lengthMenu": [
[5, 10, 25, -1],
......@@ -120,7 +122,7 @@ $(() => {
});
});
//DOESNT WORK
//definition of a custom sorting method for datatable so that it sorts masses and heights correctly
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"custom-str-pre": function (a) {
......
......@@ -2,7 +2,6 @@
$('#getImage').click(function (e) {
$('#imgContainer').text("");
e.preventDefault();
let searchTerm = removeAccents($('#searchQuery').val());
$.get("/getPortrait/" + searchTerm, resultImgUrl => {
......@@ -14,6 +13,7 @@ $('#getImage').click(function (e) {
});
});
$('#searchQuery').keypress(function (e) {
//Trigger the search if user pressed the "Enter" key
if(e.charcode == "13") $('#getImage').click();
......
......@@ -16,14 +16,14 @@ app.get('/StarPeople/*.*', function (req, res) {
app.get('/getPeopleCount',(req, res)=>{
services.getPeopleCount().then(result=>{
res.send(JSON.stringify(result));
res.send(result);
});
});
app.get('/getPortrait/*', (req, res) => {
let name = req.url.split('/').pop();
services.getImageFromName(name).then(resultURL=>{
services.getImageFromName(name)
.then(resultURL=>{
res.send(resultURL);
});
});
......
......@@ -12,6 +12,7 @@ exports.getPeopleCount = async ()=>{
return result.count;
});
};
exports.getPers = async (index) => {
let personObj;
if(index == 17) return null;
......@@ -24,6 +25,7 @@ exports.getPers = async (index) => {
let h =(pers.height != "unknown")? pers.height+" cm":pers.height;
let m =(pers.mass != "unknown")? pers.mass+" kg":pers.mass;
personObj = new Person(n, by, h, m);
return pers.getHomeworld();
})
.then(hw=>{
......@@ -43,35 +45,36 @@ exports.getPers = async (index) => {
}
};
exports.getImageFromName = async (name)=>{
//replace this value with your valid subscription key.
exports.getImageFromName = async (name) => {
const serviceKey = "e88b02b0a83143d294ac278ced6c1c13";
const defaultPic = "https://forums.roku.com/styles/canvas/theme/images/no_avatar.jpg";
//instantiate the image search client
const credentials = new CognitiveServicesCredentials(serviceKey);
const imageSearchClient = new Search.ImageSearchClient(credentials);
let result = defaultPic;
await imageSearchClient.imagesOperations.search(name)
.then(searchResult =>{
if (searchResult == null || searchResult.value.length == 0) {
console.error("No image results were found.");
} else {
const resultLength = searchResult.value.length;
/*
selcting a random picture from the search results
selecting the first element did not always give me a relevant picture
picking them at random, we found more relevant images
*/
let randomIndex = Math.floor(Math.random()*resultLength);
result = searchResult.value[randomIndex].contentUrl;
}
})
.catch(err =>{
console.error("No image results were found.");
console.error(err);
});
return result;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment