src/static/js/admin-stats.js
// Populate statistics on the stats page
Populate statistics on the stats page
Populate statistics on the stats page
async function populateStats() {
  const statsURL = "/api/adminStats";
  let stats = null;
  try {
    stats = await fetchJSON(statsURL);
  } catch (err) {
    showError("Failed to update stats");
  }
  if (stats) {
    hideError();
    clearElement("stats");
    hideElement("stats-status");
    for (const item in stats) {
      const statsLabel = newElement("div").addClass("stats-label").text(item);
      const statsValue = newElement("div")
        .addClass("stats-value")
        .text(stats[item].value);
      if (stats[item].id) {
        const newItemLink = newElement("a")
          .attr({ href: `#${stats[item].id}` })
          .append(statsLabel, statsValue);
        const newItemDiv = newElement("div").append(newItemLink);
        appendTo("stats", newItemDiv);
      } else {
        const newItemDiv = newElement("div").append(statsLabel, statsValue);
        appendTo("stats", newItemDiv);
      }
    }
  }
}
async function populateStats ( ) { const statsURL = "/api/adminStats" ; let stats = null ; try { stats = await fetchJSON ( statsURL ) ; } catch ( err ) { showError ( "Failed to update stats" ) ; } if ( stats ) { hideError ( ) ; clearElement ( "stats" ) ; hideElement ( "stats-status" ) ; for ( const item in stats ) { const statsLabel = newElement ( "div" ) . addClass ( "stats-label" ) . text ( item ) ; const statsValue = newElement ( "div" ) . addClass ( "stats-value" ) . text ( stats [ item ] . value ) ; if ( stats [ item ] . id ) { const newItemLink = newElement ( "a" ) . attr ( { href : ` ${ stats [ item ] . id } ` } ) . append ( statsLabel , statsValue ) ; const newItemDiv = newElement ( "div" ) . append ( newItemLink ) ; appendTo ( "stats" , newItemDiv ) ; } else { const newItemDiv = newElement ( "div" ) . append ( statsLabel , statsValue ) ; appendTo ( "stats" , newItemDiv ) ; } } } }
Populate statistics on the stats page
Populate statistics on the stats page