Sélectionner une révision Git
picture_displayer.js
picture_displayer.js 8,97 Kio
function intListToString(intList) {
var tab = intList.split('_')
var result = "";
for (elem of tab) {
result = result.concat(String.fromCharCode(elem))
}
return result
}
var displayer = {
startdisplay: function(idToDat, whereToDisplay) {
var liste = $('#'+idToDat+" li");
$('#'+whereToDisplay).html('<div id="'+whereToDisplay+'row" class="row no-gutters"></div>');
liste.each(function() {
// console.log("__");
// console.log($(this).text());
var currentID = intListToString($(this).text());
// console.log(currentID);
requestHandler.retrieveJsonFromUrl('https://images-api.nasa.gov/search?nasa_id='+currentID, function(json) {
var real_im = json.collection.items[0];
$('#'+whereToDisplay+'row').append('<div class="view container">'+
'<div class="hover-container" style="margin: 3px">'+
'<img class="img-fluid" style="margin: 4px" src='+real_im.links[0].href+'>'+
'<div class="content">'+
'<div class="text scrollbar">'+
'<h4>'+real_im.data[0].title+'</h4>'+
'<p style="font-size: 15px">'+real_im.data[0].description+'</p>'+
'</div>'+
'<div class="actionrow" style="left: -120px;">'+
'<form method="POST" action="download.php" target="_blank">'+
'<input type="hidden" name="urlget" value="'+correctionURLLink(real_im.href)+'">'+
'<input type="hidden" name="nasa_id" value="'+currentID+'">'+
'<input type="hidden" name="title" value="'+real_im.data[0].title+'">'+
'<input type="hidden" name="preview" value="'+real_im.links[0].href+'"">'+
'<input type="image" name="submit" alt="Submit" class="download" width="13%" src="./ressources/icons/dwnld.png" onmouseover="this.src=\'./ressources/icons/dwnldVert.png\'" onmouseout="this.src=\'./ressources/icons/dwnld.png\'">'+
'</form>'+
'</div>'+
'</div>'+
'</div>'+
'</div>');
});
});
}
}
var displayerMoyReview = {
startdisplay: function(idToDat, whereToDisplay) {
var liste = $('#'+idToDat+" li");
$('#'+whereToDisplay).html('<div id="'+whereToDisplay+'row" class="row no-gutters"></div>');
liste.each(function() {
// console.log("__");
var texte_li = $(this).text();
var tab = texte_li.split(",");
if( tab[1].length > 3 )
tab[1] = tab[1].substring(0,3);
var valeurMoy = parseFloat( tab[1] );
if( valeurMoy >= 4.9 )
var color ="";
else
{
if( valeurMoy >= 4.0 )
var color = "yellow";
else
{
if( valeurMoy >= 3.0 )
var color = "white";
else
var color = "red";
}
}
var place = parseInt( tab[2] );
if( place > 1 )
tab[2] += "eme"
else
tab[2] += "er"
// console.log("ascii:" + tab[0] + ", " + tab[1]);
var currentID = intListToString(tab[0]);
// console.log("decode:" +currentID);
// console.log(currentID);
requestHandler.retrieveJsonFromUrl('https://images-api.nasa.gov/search?nasa_id='+currentID, function(json) {
var real_im = json.collection.items[0];
$('#'+whereToDisplay+'row').append('<div class="view container">'+
'<div class="hover-container" style="margin: 3px">'+
'<img class="img-fluid" style="margin: 4px" src='+real_im.links[0].href+'>'+
'<div class="content">'+
'<div class="text scrollbar">'+
'<h4>'+real_im.data[0].title+'</h4>'+
'<p style="font-size: 15px">'+real_im.data[0].description+'</p>'+
'</div>'+
'<div class="actionrow" style="margin-bottom:15px;">'+
'<form method="POST" action="download.php" target="_blank">'+
'<input type="hidden" name="urlget" value="'+correctionURLLink(real_im.href)+'">'+
'<input type="hidden" name="nasa_id" value="'+currentID+'">'+
'<input type="hidden" name="title" value="'+real_im.data[0].title+'">'+
'<input type="hidden" name="preview" value="'+real_im.links[0].href+'"">'+
'<table style="margin-right:5%">'+
'<tbody><tr><td align="left" width="10%">'+
'<input type="image" name="submit" alt="Submit" class="download" width="100%" src="./ressources/icons/dwnld.png" onmouseover="this.src=\'./ressources/icons/dwnldVert.png\'" onmouseout="this.src=\'./ressources/icons/dwnld.png\'">'+
'</td>'+
'<td width="51%">'+
'</td>'+
'<td width="29%" style="color:'+color+'; font-size:170%;font-family: abang">'+tab[1]+
'</td>'+
'<td align="right" width="10%" style="color:'+color+'; font-size:170%;font-family: abang">'+tab[2]+
'</td>'+
'</tr></tbody></table>'+
'</form>'+
'</div>'+
'</div>'+
'</div>'+
'</div>');
});
});
},
troncate: function(moy) {
var length = 3;
return moy.substring(0, length)
}
}
var displayerNbCDC = {
startdisplay: function(idToDat, whereToDisplay) {
/*var liste = $('#'+idToDat+" li");
$('#'+whereToDisplay).html('<div id="'+whereToDisplay+'row" class="row"></div>');
liste.each(function() {
var currentID = intListToString(this.getElementsByClassName('idPhoto')[0].innerHTML);
var nbCDC = this.getElementsByClassName('nbCDC')[0].innerHTML;
//console.log("id : "+currentID+" ; nbCDC : "+nbCDC);
requestHandler.retrieveJsonFromUrl('https://images-api.nasa.gov/asset/'+currentID, function(json) {
$('#'+whereToDisplay+'row').append('<div class="col"><img width=300 src="'+json.collection.items[2].href+'"><p>Cette photo a '+nbCDC+' coups de coeur</p></div>');
});
});*/
var liste = $('#'+idToDat+" li");
$('#'+whereToDisplay).html('<div id="'+whereToDisplay+'row" class="row"></div>');
liste.each(
function() {
// console.log("__");
var texte_li = $(this).text();
var tab = texte_li.split(",");
// console.log("ascii:" + tab[0] + ", " + tab[1]);
var currentID = intListToString(tab[0]);
var nbCDC = parseInt( tab[1]);
if( nbCDC >= 25 )
var color = "yellow"
else
{
if( nbCDC >= 10 )
var color = "blue";
else
var color = "white";
}
var place = parseInt( tab[2] );
if( place > 1 )
tab[2] += "eme"
else
tab[2] += "er"
// console.log("decode:" +currentID);
// console.log(currentID);
requestHandler.retrieveJsonFromUrl('https://images-api.nasa.gov/search?nasa_id='+currentID, function(json) {
var real_im = json.collection.items[0];
$('#'+whereToDisplay+'row').append('<div class="view container">'+
'<div class="hover-container" style="margin: 3px">'+
'<img class="img-fluid" style="margin: 4px" src='+real_im.links[0].href+'>'+
'<div class="content">'+
'<div class="text scrollbar">'+
'<h4>'+real_im.data[0].title+'</h4>'+
'<p style="font-size: 15px">'+real_im.data[0].description+'</p>'+
'</div>'+
'<div class="actionrow" style="margin-bottom:15px;">'+
'<form method="POST" action="download.php" target="_blank">'+
'<input type="hidden" name="urlget" value="'+correctionURLLink(real_im.href)+'">'+
'<input type="hidden" name="nasa_id" value="'+currentID+'">'+
'<input type="hidden" name="title" value="'+real_im.data[0].title+'">'+
'<input type="hidden" name="preview" value="'+real_im.links[0].href+'"">'+
'<table style="margin-right:5%">'+
'<tbody><tr><td align="left" width="10%">'+
'<input type="image" name="submit" alt="Submit" class="download" width="100%" src="./ressources/icons/dwnld.png" onmouseover="this.src=\'./ressources/icons/dwnldVert.png\'" onmouseout="this.src=\'./ressources/icons/dwnld.png\'">'+
'</td>'+
'<td width="51%">'+
'</td>'+
'<td width="29%" style="color:'+color+'; font-size:170%;font-family: abang">'+tab[1]+
'</td>'+
'<td align="right" width="10%" style="color:'+color+'; font-size:170%;font-family: abang">'+tab[2]+
'</td>'+
'</tr></tbody></table>'+
'</form>'+
'</div>'+
'</div>'+
'</div>'+
'</div>');
});
}
);
}
}
function affiche_dans_lordre(whereToDisplay, tab, currentID, nbCDC ) {
}
var requestHandler = {
retrieveJsonFromUrl: function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(xhr.response);
} else {
console.log("erreur, le status de la réponse indique une anomalie");
callback(xhr.response);
}
};
xhr.send();
},
retrieveJsonFromUrlWithPassedParameter: function(url, callback, pass) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(xhr.response, pass);
} else {
console.log("erreur, le status de la réponse indique une anomalie");
callback(xhr.response, pass);
}
};
xhr.send();
}
}
function startDisplayer(IDsource, IDdestination) {
console.log("démarrage");
displayer.startdisplay(IDsource, IDdestination);
}
function startDisplayerNbCDC(IDsource, IDdestination) {
console.log("démarrage displayer CDC");
displayerNbCDC.startdisplay(IDsource, IDdestination);
}
function startDisplayerMoyReview(IDsource, IDdestination) {
console.log("démarrage du displayer Moyenne des reviews");
displayerMoyReview.startdisplay(IDsource, IDdestination);
}