async function showTable()

in dashboard-web-app/src/main/resources/static/app.js [50:82]


async function showTable() {
    console.log("Refreshing Product table content");

    var response = await window.fetch('api/locations', {
        method:"GET"
    });

    var locations = await response.json();

    var headTable = '<tr><th></th>';
    Object.keys(locations).sort().forEach(function(location) {
        headTable += '<th>' + location + '</th>';
    });
    headTable += "</tr>";

    var response2 = await window.fetch('api/products', {
        method:"GET"
    });

    var products = await response2.json();

    Object.keys(products).forEach(function(productItem) {
        headTable += '<tr>';
        var product = products[productItem];
        headTable += '<td>' + product['description'] + '</td>';
        Object.keys(product.countByLocation).sort().forEach(function(countPerLocation) {
            headTable += '<td>' + product.countByLocation[countPerLocation] + '</td>';
        });
        headTable += '</tr>';
    });

    $('#product-table').html(headTable);
}