Commit d16dff83 authored by Benzakein Jeremy's avatar Benzakein Jeremy

get all people in data tables

parent 2157bcee
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Node Server",
"program": "${workspaceFolder}\\server.js"
}
]
}
\ No newline at end of file
......@@ -25,19 +25,19 @@
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item active">
<li class="nav-item">
<a class="nav-link" href="test.html">Test Image API</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="people.html">People</a>
</li>
<li class="nav-item active">
<li class="nav-item">
<a class="nav-link" href="rapport.html">Rapport</a>
</li>
</ul>
</div>
</nav>
<div class="jumbotron jumbotron-fluid bg-warning">
<div class="jumbotron jumbotron-fluid bg-warning custom-jumbo", id="addRow">
<h1 class="display-3">One random person from Star Wars</h1>
<hr class="my-2">
<table class="table" id="peopleTable">
......
......@@ -25,3 +25,8 @@ body{
#imgContainer{
max-width: 20%;
}
.custom-jumbo{
padding-left: 20px;
padding-right: 20px;
}
/* jshint esversion: 8 */
$(() => {
$('#peopleTable').DataTable({
scrollCollapse: true
});
index = 2
getPerson(index).then(result=>{
console.log(result);
$tbody = $('#peopleTableBody');
$tbody.append("<tr id='person" + index + "'><td></td><td>" + result.name + "</td><td>" + result.birth_year + "</td></tr>");
}).catch(err=>{
console.error(err);
});
});
const getPeopleCount = async (index) => {
let count = 0;
await $.ajax('/getPeopleCount')
......@@ -26,6 +14,11 @@ const getPeopleCount = async (index) => {
const getPerson = async (index) => {
let person = null;
//I am limited to 3 API call per second by the bing image search API
//HotFix: setTimeout .34 second
await setTimeout(()=>{},340);
await $.ajax('/getPerson/'+index)
.done(function(data){
person =JSON.parse(data);
......@@ -34,4 +27,54 @@ const getPerson = async (index) => {
console.log(e);
});
return person;
};
\ No newline at end of file
};
let datatable;
$(() => {
//initialise sorting, and searching in datatable
datatable = $('#peopleTable').DataTable({
scrollCollapse: true
});
for (let index = 1; index < 80; index++) {
getPerson(index).then(person=>{
console.log(person);
var t = $('#peopleTable').DataTable();
t.row.add([
"null",
person.name,
person.birthYear
]).draw(true);
//$tbody = $('#peopleTableBody');
//$tbody.append("<tr id='person" + index + "'><td></td><td>" + person.name + "</td><td>" + person.birthYear + "</td></tr>");
}).catch(err => {
console.error(err);
});
}
});
// $(document).ready(function() {
// var t = $('#peopleTable').DataTable();
// var counter = 1;
// $('#addRow').on( 'click', function () {
// t.row.add( [
// counter +'.1',
// counter +'.2',
// counter +'.3',
// counter +'.4',
// counter +'.5'
// ] ).draw( false );
// counter++;
// } );
// // Automatically add a first row of data
// $('#addRow').click();
// } );
......@@ -54,9 +54,9 @@ const getImageFromName = async (name)=>{
};
class Person{
constructor(name, bithYear, height, mass,) {
constructor(name, birthYear, height, mass,) {
this.name = name;
this.bithYear = bithYear;
this.birthYear = birthYear;
this.height = height;
this.mass = mass;
}
......
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