Skip to content

Commit 46c76f2

Browse files
committed
filter system added
1 parent bf42a1d commit 46c76f2

File tree

1 file changed

+58
-20
lines changed

1 file changed

+58
-20
lines changed

src/components/dashboard/DashboardTests.jsx

+58-20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var quiz_list = {}
77
var quiz_displayed = ""
88
var role_value = ""
99

10+
var subject_selected = "All"
11+
1012
export default class DashboardTests extends React.Component {
1113

1214
constructor(e) {
@@ -49,9 +51,15 @@ export default class DashboardTests extends React.Component {
4951
// this.display_quiz_details()
5052
}
5153

54+
filter() {
55+
subject_selected = $("#filter").val()
56+
quiz_displayed = false
57+
$("#quiz-details").remove()
58+
$("#table").append(`<tbody id='quiz-details' className="text-sm font-medium divide-y divide-slate-100"></tbody>`)
59+
this.display_quiz_details()
60+
}
61+
5262
display_quiz_details() {
53-
// console.clear()
54-
// console.log(quiz_displayed)
5563

5664
if (quiz_displayed === false) {
5765

@@ -75,11 +83,11 @@ export default class DashboardTests extends React.Component {
7583
`)
7684
}
7785
for (var i = 0; i < ids.length; i++) {
86+
7887
var data = quiz_list[ids[i]]
7988
var location = `path1=questions/&path2=`
8089
// console.log(location)
8190

82-
8391
try {
8492
var time = data.time
8593
var start_exam_hour = parseInt(time.split("-")[0].split(":")[0])
@@ -98,9 +106,9 @@ export default class DashboardTests extends React.Component {
98106
catch (err) {
99107
console.log(err)
100108
}
101-
102-
$("#quiz-details").append(`
103-
<tr>
109+
if (subject_selected === "All" || subject_selected === data.subject) {
110+
$("#quiz-details").append(`
111+
<tr id="display-quiz">
104112
<td class="p-2">
105113
<div class="flex items-center">
106114
<div class="flex items-center">
@@ -125,11 +133,11 @@ export default class DashboardTests extends React.Component {
125133
`)
126134

127135

128-
if (eaxm_year >= year && exam_mon > month || exam_date >= date) {
129-
if (exam_mon === month && exam_date === date) {
130136

131-
if (start_exam_hour <= hour && end_exam_hour >= hour) {
132-
if (end_exam_min >= min) {
137+
if (eaxm_year >= year && exam_mon > month || exam_date >= date) {
138+
if (exam_mon === month && exam_date === date) {
139+
140+
if (start_exam_hour <= hour && end_exam_hour >= hour) {
133141
$(`#status-${i}`).append(`<div class="text-center text-yellow-500 bg-yellow-200 p-1 rounded-full">In Progress</div>`)
134142
$(`#view-quiz${i}`).on("click", (e) => { this.view_quiz(e, location) })
135143
}
@@ -140,21 +148,16 @@ export default class DashboardTests extends React.Component {
140148

141149
}
142150
else {
143-
$(`#status-${i}`).append(`<div class="text-center text-red-500 bg-red-200 p-1 rounded-full">Closed</div>`)
151+
$(`#status-${i}`).append(`<div class="text-center text-green-500 bg-green-200 p-1 rounded-full">Active</div>`)
144152
if (role_value === "View") $(`#view-quiz${i}`).on("click", (e) => { this.view_quiz(e, location) })
145153
}
146-
147154
}
148155
else {
149-
$(`#status-${i}`).append(`<div class="text-center text-green-500 bg-green-200 p-1 rounded-full">Active</div>`)
156+
$(`#status-${i}`).append(`<div class="text-center text-red-500 bg-red-200 p-1 rounded-full">Closed</div>`)
150157
if (role_value === "View") $(`#view-quiz${i}`).on("click", (e) => { this.view_quiz(e, location) })
151158
}
152-
}
153-
else {
154-
$(`#status-${i}`).append(`<div class="text-center text-red-500 bg-red-200 p-1 rounded-full">Closed</div>`)
155-
if (role_value === "View") $(`#view-quiz${i}`).on("click", (e) => { this.view_quiz(e, location) })
156-
}
157159

160+
}
158161
}
159162
quiz_displayed = !quiz_displayed
160163
}
@@ -179,14 +182,49 @@ export default class DashboardTests extends React.Component {
179182
render() {
180183
return (
181184
<div className="col-span-full xl:col-span-8 bg-white shadow-lg rounded-sm border border-slate-200">
182-
<header className="px-5 py-4 border-b border-slate-100">
185+
<header className="px-5 py-4 border-b border-slate-100 flex justify-between">
183186
<h2 className="font-semibold text-slate-800">QUIZS</h2>
187+
188+
189+
<div style={{
190+
"minWidth": "250px",
191+
"display": "flex",
192+
"justifyContent": "space-evenly",
193+
"alignItems": 'center'
194+
}}>
195+
<label className="text-gray-600 font-medium" htmlFor="filter">
196+
Subject:
197+
</label>
198+
199+
<select
200+
id="filter"
201+
name="filter"
202+
className="bg-gray-200 p-2 rounded-md outline-0 focus:bg-gray-300"
203+
204+
>
205+
<option value="All">All</option>
206+
<option value="English">English</option>
207+
<option value="Science">Science</option>
208+
<option value="Social Studies">Social Studies</option>
209+
<option value="Mathematics">Mathematics</option>
210+
<option value="Artificial Intelligence">Computer</option>
211+
</select>
212+
213+
<button style={{ borderRadius: "10px" }} type="submit" className="bg-green-600 rounde-md p-3 text-white hover:bg-yellow-500"
214+
onClick={(e) => { this.filter() }}>
215+
Filter
216+
</button>
217+
</div>
218+
219+
184220
</header>
221+
222+
185223
<div className="p-3">
186224

187225
{/* Table */}
188226
<div style={{ maxHeight: "340px", minHeight: "100px" }} className="overflow-x-auto overflow-y-auto">
189-
<table className="table-auto w-full">
227+
<table id="table" className="table-auto w-full">
190228
{/* Table header */}
191229
<thead className="text-xs uppercase text-slate-400 bg-slate-50 rounded-sm">
192230
<tr>

0 commit comments

Comments
 (0)