Use new properties in /api/v1/challenges (#1844)

- Switch the challenges page in core to use the new API information in `/api/v1/challenges` to mark solves and display solve counts
- Closes #1811
This commit is contained in:
Kevin Chung
2021-03-22 20:32:37 -04:00
committed by GitHub
parent b07ba13a12
commit 0fdb038c6c
4 changed files with 7 additions and 31 deletions

View File

@@ -26,6 +26,7 @@
- Add styling for the `<blockquote>` element.
- Change `colorHash` function to use HSL color values to avoid generating too light/dark colors
- Fix scoreboard table identifier to switch between User/Team depending on configured user mode
- Switch the challenges page in core to use the new API information in `/api/v1/challenges` to mark solves and display solve counts
- Switch to using Bootstrap's scss in `core/main.scss` to allow using Bootstrap variables
- Consolidate Jinja error handlers into a single function and better handle issues where error templates can't be found

View File

@@ -11,11 +11,6 @@ import hljs from "highlight.js";
dayjs.extend(relativeTime);
const api_func = {
teams: x => CTFd.api.get_team_solves({ teamId: x }),
users: x => CTFd.api.get_user_solves({ userId: x })
};
CTFd._internal.challenge = {};
let challenges = [];
let solves = [];
@@ -232,31 +227,15 @@ function renderSubmissionResponse(response) {
}
function markSolves() {
return api_func[CTFd.config.userMode]("me").then(function(response) {
const solves = response.data;
for (let i = solves.length - 1; i >= 0; i--) {
const btn = $('button[value="' + solves[i].challenge_id + '"]');
challenges.map(challenge => {
if (challenge.solved_by_me) {
const btn = $(`button[value="${challenge.id}"]`);
btn.addClass("solved-challenge");
btn.prepend("<i class='fas fa-check corner-button-check'></i>");
}
});
}
function loadUserSolves() {
if (CTFd.user.id == 0) {
return Promise.resolve();
}
return api_func[CTFd.config.userMode]("me").then(function(response) {
const solves = response.data;
for (let i = solves.length - 1; i >= 0; i--) {
const chal_id = solves[i].challenge_id;
solves.push(chal_id);
}
});
}
function getSolves(id) {
return CTFd.api.get_challenge_solves({ challengeId: id }).then(response => {
const data = response.data;
@@ -289,7 +268,6 @@ function loadChals() {
$challenges_board.empty();
for (let i = challenges.length - 1; i >= 0; i--) {
challenges[i].solves = 0;
if ($.inArray(challenges[i].category, categories) == -1) {
const category = challenges[i].category;
categories.push(category);
@@ -354,15 +332,12 @@ function loadChals() {
$(".challenge-button").click(function(_event) {
loadChal(this.value);
getSolves(this.value);
});
});
}
function update() {
return loadUserSolves() // Load the user's solved challenge ids
.then(loadChals) // Load the full list of challenges
.then(markSolves);
return loadChals().then(markSolves);
}
$(() => {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long