<commit_before>const renderScoreboardTeamScore = _.template(
  $("#scoreboard-teamscore-template")
    .remove()
    .text()
);
const renderScoreboard = _.template(
  $("#scoreboard-template")
    .remove()
    .text()
);
const renderScoreboardPage = _.template(
  $("#scoreboard-page-template")
    .remove()
    .text()
);

window.reloadGraph = function() {
  const reload = function() {
    $(".progression-graph").empty();
    const active_tab = $("ul#scoreboard-tabs li.active").data();
    if (active_tab.sid !== undefined) {
      window.drawTopTeamsProgressionGraph(
        `#${active_tab.sid}-progression`,
        {'scoreboard_id': active_tab.sid}
      );
    }
    else if (active_tab.gid !== undefined) {
      window.drawTopTeamsProgressionGraph(
        `#${active_tab.gid}-progression`,
        {'group_id': active_tab.gid}
      );
    }
  };
  setTimeout(reload, 100);
};

const render_scoreboard = function(board_key, search) {
  // Re-render the scoreboard display, including the paginator

  // Build the scoreboard page endpoint URL
  var scoreboard_endpoint = '/api/v1/'
  if (board_key.hasOwnProperty('group_id')) {
    scoreboard_endpoint += 'groups/' + board_key.group_id + '/scoreboard';
  } else {
    scoreboard_endpoint += 'scoreboards/' + board_key.scoreboard_id + '/scoreboard';
  }
  if (search !== undefined) {
    scoreboard_endpoint += '?search=' + search
  }

  // If non-group scoreboard, get scoreboard metadata
  if (board_key.hasOwnProperty('scoreboard_id')) {
    var scoreboard_metadata_endpoint = '/api/v1/scoreboards/' + board_key.scoreboard_id;
  } else {
    var scoreboard_metadata_endpoint = null
  }

  // Fetch the scoreboard page and re-render the scoreboard display
  $.when(
    apiCall("GET", "/api/v1/team"),
    apiCall("GET", scoreboard_endpoint),
    (function() {
      if (scoreboard_metadata_endpoint !== null) {
        return apiCall("GET", scoreboard_metadata_endpoint)
      } else {
        return null
      }
    })()
  )
  .done(function(team_data, scoreboard_data, scoreboard_metadata) {
    var scoreboard_properties = {
      scorepage: scoreboard_data[0].scoreboard,
      current_page: scoreboard_data[0].current_page,
      total_pages: scoreboard_data[0].total_pages,
      scoreboard_name: null,
      scoreboard_sponsor: null,
      scoreboard_logo: null,
      user_tid: team_data[0].tid
    }
    if (scoreboard_metadata !== null) {
      scoreboard_properties = Object.assign(scoreboard_properties, {
        scoreboard_name: scoreboard_metadata[0].name,
        scoreboard_sponsor: scoreboard_metadata[0].sponsor,
        scoreboard_logo: scoreboard_metadata[0].logo
      })
    }
    var scoreboardContent = renderScoreboard(scoreboard_properties)
    $("#scoreboard-container").html(scoreboardContent).promise().then(
      function(){
        // Once content has loaded, set up paginator
        $("#pagination").bootstrapPaginator({
          totalPages: scoreboard_data[0].total_pages,
          bootstrapMajorVersion: 3,
          numberOfPages: 10,
          currentPage: scoreboard_data[0].current_page,
          onPageClicked(e, eOriginal, type, page) {
            render_scoreboard_page(board_key, "", page);
          }
        });
      }
    )
  })
  .fail(jqXHR =>
    apiNotify({ status: 0, message: jqXHR.responseJSON.message })
  );
};

const render_scoreboard_page = function(board_key, search, page) {
  // Re-render only the scoreboard page, keeping search field and pagination
  var searchValue = $("#search").val()

  // Build the scoreboard page endpoint URL
  var scoreboard_endpoint = '/api/v1/'
  if (board_key.hasOwnProperty('group_id')) {
    scoreboard_endpoint += 'groups/' + board_key.group_id + '/scoreboard';
  } else {
    scoreboard_endpoint += 'scoreboards/' + board_key.scoreboard_id + '/scoreboard';
  }
  scoreboard_endpoint += '?page=' + page<commit_msg>Fix pagination of search results<commit_after>const renderScoreboardTeamScore = _.template(
  $("#scoreboard-teamscore-template")
    .remove()
    .text()
);
const renderScoreboard = _.template(
  $("#scoreboard-template")
    .remove()
    .text()
);
const renderScoreboardPage = _.template(
  $("#scoreboard-page-template")
    .remove()
    .text()
);

window.reloadGraph = function() {
  const reload = function() {
    $(".progression-graph").empty();
    const active_tab = $("ul#scoreboard-tabs li.active").data();
    if (active_tab.sid !== undefined) {
      window.drawTopTeamsProgressionGraph(
        `#${active_tab.sid}-progression`,
        {'scoreboard_id': active_tab.sid}
      );
    }
    else if (active_tab.gid !== undefined) {
      window.drawTopTeamsProgressionGraph(
        `#${active_tab.gid}-progression`,
        {'group_id': active_tab.gid}
      );
    }
  };
  setTimeout(reload, 100);
};

const render_scoreboard = function(board_key, search) {
  // Re-render the scoreboard display, including the paginator

  // Build the scoreboard page endpoint URL
  var scoreboard_endpoint = '/api/v1/'
  if (board_key.hasOwnProperty('group_id')) {
    scoreboard_endpoint += 'groups/' + board_key.group_id + '/scoreboard';
  } else {
    scoreboard_endpoint += 'scoreboards/' + board_key.scoreboard_id + '/scoreboard';
  }
  if (search !== undefined) {
    scoreboard_endpoint += '?search=' + search
  }

  // If non-group scoreboard, get scoreboard metadata
  if (board_key.hasOwnProperty('scoreboard_id')) {
    var scoreboard_metadata_endpoint = '/api/v1/scoreboards/' + board_key.scoreboard_id;
  } else {
    var scoreboard_metadata_endpoint = null
  }

  // Fetch the scoreboard page and re-render the scoreboard display
  $.when(
    apiCall("GET", "/api/v1/team"),
    apiCall("GET", scoreboard_endpoint),
    (function() {
      if (scoreboard_metadata_endpoint !== null) {
        return apiCall("GET", scoreboard_metadata_endpoint)
      } else {
        return null
      }
    })()
  )
  .done(function(team_data, scoreboard_data, scoreboard_metadata) {
    var scoreboard_properties = {
      scorepage: scoreboard_data[0].scoreboard,
      current_page: scoreboard_data[0].current_page,
      total_pages: scoreboard_data[0].total_pages,
      scoreboard_name: null,
      scoreboard_sponsor: null,
      scoreboard_logo: null,
      user_tid: team_data[0].tid
    }
    if (scoreboard_metadata !== null) {
      scoreboard_properties = Object.assign(scoreboard_properties, {
        scoreboard_name: scoreboard_metadata[0].name,
        scoreboard_sponsor: scoreboard_metadata[0].sponsor,
        scoreboard_logo: scoreboard_metadata[0].logo
      })
    }
    var scoreboardContent = renderScoreboard(scoreboard_properties)
    $("#scoreboard-container").html(scoreboardContent).promise().then(
      function(){
        // Once content has loaded, set up paginator
        $("#pagination").bootstrapPaginator({
          totalPages: scoreboard_data[0].total_pages,
          bootstrapMajorVersion: 3,
          numberOfPages: 10,
          currentPage: scoreboard_data[0].current_page,
          onPageClicked(e, eOriginal, type, page) {
            let query = $("#search").val();
            render_scoreboard_page(board_key, query, page);
          }
        });
      }
    )
  })
  .fail(jqXHR =>
    apiNotify({ status: 0, message: jqXHR.responseJSON.message })
  );
};

const render_scoreboard_page = function(board_key, search, page) {
  // Re-render only the scoreboard page, keeping search field and pagination
  var searchValue = $("#search").val()

  // Build the scoreboard page endpoint URL
  var scoreboard_endpoint = '/api/v1/'
  if (board_key.hasOwnProperty('group_id')) {
    scoreboard_endpoint += 'groups/' + board_key.group_id + '/scoreboard';
  } else {
    scoreboard_endpoint += 'scoreboards/' + board_key.scoreboard_id + '/scoreboard';
  }
  scoreboard_endpoint += '?page=' + page
{'fraction_non_alphanumeric': 0.1314512008175779, 'fraction_numerical': 0.005109862033725089, 'mean_word_length': 3.3158765159867696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2251253', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2390, 'n_words': 459}