src/static/js/admin-stats.js
// Create a row in the posts table
Create a row in the posts table
Create a row in the posts table
function createPostRow(post) {
  const postLink = newElement("a")
    .attr({
      href: `/post/${post.postID}`,
    })
    .text(post.postID);
  const postID = newElement("td").append(postLink);
  const location = newElement("td").text(post.location);
  const postUser = newElement("td").text(`${post.postUser}`);
  const program = newElement("td").text(post.program);
  const rating = newElement("td")
    .addClass("nowrap")
    .html(
      '<i class="fa fa-star checked"></i>'.repeat(post.rating) +
        '<i class="fa fa-star"></i>'.repeat(5 - post.rating)
    );
  const approved = newElement("td").html(
    post.approved ? '<i class="fas fa-check"></i>' : ""
  );
  const createTime = newElement("td").text(
    new Date(parseInt(post.createTime) * 1000).toLocaleString()
  );
  const favoriteHeart = newElement("span")
    .html(
      `<i id="favorite-${post.postID}" class="${
        post.adminFavorite ? "fas" : "far"
      } fa-heart"></i>`
    )
    .click(() => {
      toggleFavoritePost(post.postID);
      toggleFavoriteHeart(post.postID);
    });
  const favoriteButton = newElement("td").append(favoriteHeart);
  const editLink = newElement("a")
    .addClass("btn btn-primary")
    .attr({
      href: `/edit-post/${post.postID}`,
    })
    .html('<i class="fas fa-edit"></i>');
  const editPost = newElement("td").append(editLink);
  const deletePostButton = newElement("button")
    .addClass("btn btn-danger")
    .attr({
      type: "button",
    })
    .html('<i class="fas fa-trash-alt"></i>')
    .click(() => {
      currentPostID = post.postID;
      $("#deletePostReasonModal").modal("show");
    });
  const deletePost = newElement("td").append(deletePostButton);
  const row = newElement("tr").append(
    postID,
    location,
    postUser,
    program,
    rating,
    approved,
    createTime,
    favoriteButton,
    editPost,
    deletePost
  );
  return row;
}
function createPostRow ( post ) { const postLink = newElement ( "a" ) . attr ( { href : ` ${ post . postID } ` , } ) . text ( post . postID ) ; const postID = newElement ( "td" ) . append ( postLink ) ; const location = newElement ( "td" ) . text ( post . location ) ; const postUser = newElement ( "td" ) . text ( ` ${ post . postUser } ` ) ; const program = newElement ( "td" ) . text ( post . program ) ; const rating = newElement ( "td" ) . addClass ( "nowrap" ) . html ( '<i class="fa fa-star checked"></i>' . repeat ( post . rating ) + '<i class="fa fa-star"></i>' . repeat ( 5 - post . rating ) ) ; const approved = newElement ( "td" ) . html ( post . approved ? '<i class="fas fa-check"></i>' : "" ) ; const createTime = newElement ( "td" ) . text ( new Date ( parseInt ( post . createTime ) * 1000 ) . toLocaleString ( ) ) ; const favoriteHeart = newElement ( "span" ) . html ( ` ${ post . postID } ${ post . adminFavorite ? "fas" : "far" } ` ) . click ( ( ) => { toggleFavoritePost ( post . postID ) ; toggleFavoriteHeart ( post . postID ) ; } ) ; const favoriteButton = newElement ( "td" ) . append ( favoriteHeart ) ; const editLink = newElement ( "a" ) . addClass ( "btn btn-primary" ) . attr ( { href : ` ${ post . postID } ` , } ) . html ( '<i class="fas fa-edit"></i>' ) ; const editPost = newElement ( "td" ) . append ( editLink ) ; const deletePostButton = newElement ( "button" ) . addClass ( "btn btn-danger" ) . attr ( { type : "button" , } ) . html ( '<i class="fas fa-trash-alt"></i>' ) . click ( ( ) => { currentPostID = post . postID ; $ ( "#deletePostReasonModal" ) . modal ( "show" ) ; } ) ; const deletePost = newElement ( "td" ) . append ( deletePostButton ) ; const row = newElement ( "tr" ) . append ( postID , location , postUser , program , rating , approved , createTime , favoriteButton , editPost , deletePost ) ; return row ; }
Create a row in the posts table
Create a row in the posts table