Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Frontend: ClassPage: Limit the exam num of chart.
Browse files Browse the repository at this point in the history
  • Loading branch information
saitewasreset committed Dec 5, 2023
1 parent 88637fc commit 063ed99
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions frontend/js/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ClassPage {
this.classListByExamId = {};
this.classAnalysis = {};
this.overallData = {};
this.validExamList = [];
}

async doGetExamInfo() {
Expand Down Expand Up @@ -231,6 +232,45 @@ class ClassPage {
return data;
}

async doGetValidExamList(class_id) {
const response = await fetch(`${protocolPrefix}${host}/api/scores/data/basic_info/by_class/${class_id}/valid_exam`);
return await response.json();
}

async updateValidExamList(class_id) {
const validExamList = await this.doGetValidExamList(class_id);
if (validExamList["code"] === 200) {
this.validExamList = validExamList["data"]["validExams"];
} else {
// TODO: Show error message if request failed?
}
}

getBeginValidExamIdLst(examId, count) {
let tempLst = this.validExamList;
tempLst.reverse();
if (tempLst.length > 0) {
let flag = 0;
let current = 0;
let resultLst = [];
for (const id of tempLst) {
if (id === examId) {
flag = 1;
}
if (current >= count) {
break;
}
if (flag) {
resultLst.push(id);
current ++;
}
}
return resultLst.reverse();
} else {
return -1;
}
}

showClassAnalysisBySubject(classId, subjectId, thisBtn) {
const subjectSelectionDiv = document.querySelector(".subject-selection-div");
const childButtonLst = subjectSelectionDiv.children;
Expand Down Expand Up @@ -307,7 +347,12 @@ class ClassPage {
let lastTenAvgLst = [];
let lastTenAvgRankLst = [];
let lastTenStdLst = [];
for (const [examId, chartData] of Object.entries(data["data"]["chartData"])) {

const examSelection = document.querySelector("#exam-selection");
const thisExam = Number(examSelection.value);
const showExamLst = this.getBeginValidExamIdLst(thisExam, 10);
for (const examId of showExamLst) {
let chartData = data["data"]["chartData"][examId];
labels.push(this.examIdToName[examId]);
classAvgLst.push(chartData["avgScore"]);
gradeAvgLst.push(chartData["gradeAvgScore"]);
Expand Down Expand Up @@ -572,13 +617,14 @@ class ClassPage {
submitButton.textContent = "Loading...";
submitButton.disabled = true;
this.getValidNum();
this.getOverallData(examSelection.value).then(() => {
this.getClassAnalysis(examSelection.value, classSelection.value).then(() => {
submitButton.disabled = false;
submitButton.textContent = "查询";
this.updateValidExamList(classSelection.value).then(() => {
this.getOverallData(examSelection.value).then(() => {
this.getClassAnalysis(examSelection.value, classSelection.value).then(() => {
submitButton.disabled = false;
submitButton.textContent = "查询";
});
});
});

});
}
}
Expand Down

0 comments on commit 063ed99

Please sign in to comment.