mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-19 13:14:22 +01:00
Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1 c9887cb1 Fix team template git-subtree-dir: CTFd/themes/core-beta git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
This commit is contained in:
7
assets/js/users/list.js
Normal file
7
assets/js/users/list.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import Alpine from "alpinejs";
|
||||
import CTFd from "../index";
|
||||
|
||||
window.CTFd = CTFd;
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.start();
|
||||
79
assets/js/users/private.js
Normal file
79
assets/js/users/private.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import Alpine from "alpinejs";
|
||||
import CTFd from "../index";
|
||||
import { colorHash } from "@ctfdio/ctfd-js/ui";
|
||||
import { getOption as getUserScoreOption } from "../utils/graphs/echarts/userscore";
|
||||
import { embed } from "../utils/graphs/echarts";
|
||||
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.data("UserGraphs", () => ({
|
||||
solves: null,
|
||||
fails: null,
|
||||
awards: null,
|
||||
solveCount: 0,
|
||||
failCount: 0,
|
||||
awardCount: 0,
|
||||
|
||||
getSolvePercentage() {
|
||||
return ((this.solveCount / (this.solveCount + this.failCount)) * 100).toFixed(2);
|
||||
},
|
||||
|
||||
getFailPercentage() {
|
||||
return ((this.failCount / (this.solveCount + this.failCount)) * 100).toFixed(2);
|
||||
},
|
||||
|
||||
getCategoryBreakdown() {
|
||||
const categories = [];
|
||||
const breakdown = {};
|
||||
|
||||
this.solves.data.map(solve => {
|
||||
categories.push(solve.challenge.category);
|
||||
});
|
||||
|
||||
categories.forEach(category => {
|
||||
if (category in breakdown) {
|
||||
breakdown[category] += 1;
|
||||
} else {
|
||||
breakdown[category] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
const data = [];
|
||||
for (const property in breakdown) {
|
||||
const percent = Number((breakdown[property] / categories.length) * 100).toFixed(
|
||||
2
|
||||
);
|
||||
|
||||
data.push({
|
||||
name: property,
|
||||
count: breakdown[property],
|
||||
color: colorHash(property),
|
||||
percent,
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
async init() {
|
||||
this.solves = await CTFd.pages.users.userSolves("me");
|
||||
this.fails = await CTFd.pages.users.userFails("me");
|
||||
this.awards = await CTFd.pages.users.userAwards("me");
|
||||
|
||||
this.solveCount = this.solves.meta.count;
|
||||
this.failCount = this.fails.meta.count;
|
||||
this.awardCount = this.awards.meta.count;
|
||||
|
||||
embed(
|
||||
this.$refs.scoregraph,
|
||||
getUserScoreOption(
|
||||
CTFd.user.id,
|
||||
CTFd.user.name,
|
||||
this.solves.data,
|
||||
this.awards.data
|
||||
)
|
||||
);
|
||||
},
|
||||
}));
|
||||
|
||||
Alpine.start();
|
||||
79
assets/js/users/public.js
Normal file
79
assets/js/users/public.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import CTFd from "../index";
|
||||
|
||||
import Alpine from "alpinejs";
|
||||
import { colorHash } from "@ctfdio/ctfd-js/ui";
|
||||
import { getOption as getUserScoreOption } from "../utils/graphs/echarts/userscore";
|
||||
import { embed } from "../utils/graphs/echarts";
|
||||
|
||||
window.Alpine = Alpine;
|
||||
|
||||
Alpine.data("UserGraphs", () => ({
|
||||
solves: null,
|
||||
fails: null,
|
||||
awards: null,
|
||||
solveCount: 0,
|
||||
failCount: 0,
|
||||
awardCount: 0,
|
||||
|
||||
getSolvePercentage() {
|
||||
return ((this.solveCount / (this.solveCount + this.failCount)) * 100).toFixed(2);
|
||||
},
|
||||
|
||||
getFailPercentage() {
|
||||
return ((this.failCount / (this.solveCount + this.failCount)) * 100).toFixed(2);
|
||||
},
|
||||
|
||||
getCategoryBreakdown() {
|
||||
const categories = [];
|
||||
const breakdown = {};
|
||||
|
||||
this.solves.data.map(solve => {
|
||||
categories.push(solve.challenge.category);
|
||||
});
|
||||
|
||||
categories.forEach(category => {
|
||||
if (category in breakdown) {
|
||||
breakdown[category] += 1;
|
||||
} else {
|
||||
breakdown[category] = 1;
|
||||
}
|
||||
});
|
||||
|
||||
const data = [];
|
||||
for (const property in breakdown) {
|
||||
const percent = Number((breakdown[property] / categories.length) * 100).toFixed(
|
||||
2
|
||||
);
|
||||
data.push({
|
||||
name: property,
|
||||
count: breakdown[property],
|
||||
color: colorHash(property),
|
||||
percent,
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
async init() {
|
||||
this.solves = await CTFd.pages.users.userSolves(window.USER.id);
|
||||
this.fails = await CTFd.pages.users.userFails(window.USER.id);
|
||||
this.awards = await CTFd.pages.users.userAwards(window.USER.id);
|
||||
|
||||
this.solveCount = this.solves.meta.count;
|
||||
this.failCount = this.fails.meta.count;
|
||||
this.awardCount = this.awards.meta.count;
|
||||
|
||||
embed(
|
||||
this.$refs.scoregraph,
|
||||
getUserScoreOption(
|
||||
window.USER.id,
|
||||
window.USER.name,
|
||||
this.solves.data,
|
||||
this.awards.data
|
||||
)
|
||||
);
|
||||
},
|
||||
}));
|
||||
|
||||
Alpine.start();
|
||||
Reference in New Issue
Block a user