-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
167 lines (159 loc) · 5.22 KB
/
function.js
File metadata and controls
167 lines (159 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
function setData() {
const urlParams = new URLSearchParams(window.location.search);
const quizId = urlParams.get("id");
fetch(`https://apict.pnu.app/quiz/${quizId}/subject`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
})
.then((response) => {
if (!response.ok) {
throw new Error("네트워크 응답이 옳지 않습니다.");
console.log("problemId: ", problemId);
}
return response.json();
})
.then((data) => {
const subjectManage = document.getElementById("subjectManage");
subjectManage.onclick = function () {
location.href = `course.html?id=${quizId}&&title=${data.title}`;
};
const mistakeNote = document.getElementById("mistakeNote");
mistakeNote.onclick = function () {
location.href = "note.html";
};
const gradeStat = document.getElementById("gradeStat");
document.getElementById("subjectName").innerHTML = data.title;
document.getElementById("progressBar").value = data.progress;
document.getElementById("percentNum").innerHTML = data.progress + "%";
document.getElementsByClassName("cheerPhrase")[0].innerHTML = data.text;
});
var recentjsonData = "{ 'quiz_id': " + quizId + " }";
fetch(`https://apict.pnu.app/subject/chapter/quiz/${quizId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
})
.then((response) => {
if (!response.ok) {
throw new Error("네트워크 응답이 옳지 않습니다.");
console.log("recentId: ", recentId);
}
return response.json();
})
.then((data) => {
document.getElementById("quizTitle").innerHTML = data.chapter.title;
createContainer(data.problem);
console.log(data.problem);
});
}
function loadHeader() {
fetch("./header.html")
.then((response) => response.text())
.then((data) => {
document.getElementById("header").innerHTML = data;
});
}
function submitAns(id) {
const submitAns = document.getElementById(`submitAns${id}`);
const quizAnswer = document.getElementById(`quizAnswer${id}`);
const modal = document.getElementById("loading-modal");
if (quizAnswer.value.length == 0) return;
// submitAns.style.display = "none";
var jsonData = `{ "user_answer": "${quizAnswer.value}" }`;
modal.style.display = "block";
fetch(`https://apict.pnu.app/subject/chapter/quiz/problem/${id}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify({ user_answer: quizAnswer.value }),
})
.then((response) => {
if (!response.ok) {
throw new Error("네트워크 응답이 옳지 않습니다.");
}
return response.json();
})
.then((data) => {
// submitAns.disabled = true;
quizAnswer.disabled = true;
const quizTF = document.getElementById(`quizTF${id}`);
quizTF.style.display = "block";
var judgeTF = data.is_correct;
if (judgeTF == true) {
judgeTF = "정답입니다.";
quizTF.style.color = "#3333ff";
} else {
judgeTF = "오답입니다.<br>" + data.feedback;
quizTF.style.color = "#cc0000";
}
quizTF.innerHTML = judgeTF;
document.getElementById(`clearAns${id}`).style.display = "block";
document.getElementById(`viewAns${id}`).style.display = "block";
})
.finally(() => {
modal.style.display = "none";
});
}
function clearAns(id) {
const quizAnswer = document.getElementById(`quizAnswer${id}`);
const quizTF = document.getElementById(`quizTF${id}`);
const quizSolution = document.getElementById(`quizSolution${id}`);
fetch(`https://apict.pnu.app/subject/chapter/quiz/problem/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
});
quizAnswer.disabled = false;
quizAnswer.value = "";
quizTF.innerHTML = "";
quizTF.style.display = "none";
quizSolution.innerHTML = "";
quizSolution.style.display = "none";
}
function viewAns(id) {
const viewAns = document.getElementById(`viewAns${id}`);
const quizSolution = document.getElementById(`quizSolution${id}`);
const modal = document.getElementById("loading-modal");
// viewAns.disabled = true;
// viewAns.style.display = "none";
modal.style.display = "block";
fetch(`https://apict.pnu.app/subject/chapter/quiz/problem/${id}/solution`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
})
.then((response) => {
if (!response.ok) {
throw new Error("네트워크 응답이 옳지 않습니다.");
console.log("quizId: ", quizId);
}
return response.json();
})
.then((data) => {
quizSolution.style.display = "block";
quizSolution.innerHTML = data.solution;
})
.finally(() => {
modal.style.display = "none";
});
}
function setStat() {}
function loadModal() {
fetch("./modal.html")
.then((response) => response.text())
.then((data) => {
document.getElementById("modal").innerHTML = data;
})
.catch((error) => console.error("Error fetching modal.html: ", error));
}