| 1 | import React, { useState, useEffect } from "react";
|
|---|
| 2 | import axios from "axios";
|
|---|
| 3 | import { useParams, useNavigate } from "react-router-dom";
|
|---|
| 4 |
|
|---|
| 5 | import NavbarKlasen from "../../../components/navbarKlasen/NavbarKlasen.jsx";
|
|---|
| 6 |
|
|---|
| 7 | const PredmetenNastavnik_ViewOcenkiZaStudent = () => {
|
|---|
| 8 | const { studentId } = useParams();
|
|---|
| 9 | const { classId } = useParams();
|
|---|
| 10 | const navigate = useNavigate();
|
|---|
| 11 | const [data, setData] = useState(null);
|
|---|
| 12 | const [loading, setLoading] = useState(true);
|
|---|
| 13 | const [teachersMap, setTeachersMap] = useState({});
|
|---|
| 14 |
|
|---|
| 15 | useEffect(() => {
|
|---|
| 16 | const fetchFullData = async () => {
|
|---|
| 17 | try {
|
|---|
| 18 | setLoading(true);
|
|---|
| 19 | const response = await axios.get(
|
|---|
| 20 | `http://localhost:8080/api/users/ucenici/${studentId}/ocenki`,
|
|---|
| 21 | { withCredentials: true }
|
|---|
| 22 | );
|
|---|
| 23 |
|
|---|
| 24 | const gradesData = response.data;
|
|---|
| 25 |
|
|---|
| 26 | if (!gradesData || !gradesData.predmeti) {
|
|---|
| 27 | setData(gradesData);
|
|---|
| 28 | setLoading(false);
|
|---|
| 29 | return;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | setData(gradesData);
|
|---|
| 33 |
|
|---|
| 34 | const teacherIds = new Set();
|
|---|
| 35 |
|
|---|
| 36 | gradesData.predmeti.forEach((predmet) => {
|
|---|
| 37 | (predmet.usniOcenki || []).forEach((o) =>
|
|---|
| 38 | teacherIds.add(o.vnesena_Od)
|
|---|
| 39 | );
|
|---|
| 40 | (predmet.pismeniOcenki || []).forEach((o) =>
|
|---|
| 41 | teacherIds.add(o.vnesena_Od)
|
|---|
| 42 | );
|
|---|
| 43 | (predmet.krajniOcenki || []).forEach((o) =>
|
|---|
| 44 | teacherIds.add(o.vnesena_Od)
|
|---|
| 45 | );
|
|---|
| 46 | });
|
|---|
| 47 |
|
|---|
| 48 | const teacherMap = {};
|
|---|
| 49 | await Promise.all(
|
|---|
| 50 | Array.from(teacherIds).map(async (tId) => {
|
|---|
| 51 | if (!tId) return;
|
|---|
| 52 | try {
|
|---|
| 53 | const tRes = await axios.get(
|
|---|
| 54 | `http://localhost:8080/api/users/nastavnici/${tId}`,
|
|---|
| 55 | { withCredentials: true }
|
|---|
| 56 | );
|
|---|
| 57 | teacherMap[tId] = `${tRes.data.ime} ${tRes.data.prezime}`;
|
|---|
| 58 | } catch (e) {
|
|---|
| 59 | console.warn(`Наставникот со ID ${tId} не е најден.`);
|
|---|
| 60 | teacherMap[tId] = "Непознат наставник";
|
|---|
| 61 | }
|
|---|
| 62 | })
|
|---|
| 63 | );
|
|---|
| 64 |
|
|---|
| 65 | setTeachersMap(teacherMap);
|
|---|
| 66 | } catch (err) {
|
|---|
| 67 | console.error("Грешка при вчитување на податоците:", err);
|
|---|
| 68 | } finally {
|
|---|
| 69 | setLoading(false);
|
|---|
| 70 | }
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | if (studentId) fetchFullData();
|
|---|
| 74 | }, [studentId]);
|
|---|
| 75 |
|
|---|
| 76 | if (loading) return <div className="container">Вчитување...</div>;
|
|---|
| 77 | if (!data)
|
|---|
| 78 | return <div className="container">Нема податоци за овој ученик.</div>;
|
|---|
| 79 |
|
|---|
| 80 | const handleVnesiUsnaOcenka = () => {
|
|---|
| 81 | navigate(
|
|---|
| 82 | `/predmetenNastavnikDashboard/klas/${classId}/student/${studentId}/grades/insertUsnaOcenka`
|
|---|
| 83 | );
|
|---|
| 84 | };
|
|---|
| 85 |
|
|---|
| 86 | const handleVnesiPismenaOcenka = () => {
|
|---|
| 87 | navigate(
|
|---|
| 88 | `/predmetenNastavnikDashboard/klas/${classId}/student/${studentId}/grades/insertPismenaOcenka`
|
|---|
| 89 | );
|
|---|
| 90 | };
|
|---|
| 91 | const handleVnesiKrajnaOcenka = () => {
|
|---|
| 92 | navigate(
|
|---|
| 93 | `/predmetenNastavnikDashboard/klas/${classId}/student/${studentId}/grades/insertKrajnaOcenka`
|
|---|
| 94 | );
|
|---|
| 95 | };
|
|---|
| 96 |
|
|---|
| 97 | return (
|
|---|
| 98 | <>
|
|---|
| 99 | <NavbarKlasen />
|
|---|
| 100 | {console.log(classId)}
|
|---|
| 101 | <div className="container">
|
|---|
| 102 | <div className="container">
|
|---|
| 103 | <div className="container">
|
|---|
| 104 | <h1>
|
|---|
| 105 | Оценки за {data.ime} {data.prezime}
|
|---|
| 106 | </h1>
|
|---|
| 107 | </div>
|
|---|
| 108 | <div className="container d-flex flex-row justify-content-between">
|
|---|
| 109 | <nav className="navbar navbar-expand-lg ">
|
|---|
| 110 | <span className="nav-item active">Сите оценки</span>
|
|---|
| 111 | <button
|
|---|
| 112 | className="nav-item btn btn-primary"
|
|---|
| 113 | onClick={handleVnesiUsnaOcenka}
|
|---|
| 114 | >
|
|---|
| 115 | Внеси усна оценка
|
|---|
| 116 | </button>
|
|---|
| 117 | <button
|
|---|
| 118 | className="nav-item btn btn-primary"
|
|---|
| 119 | onClick={handleVnesiPismenaOcenka}
|
|---|
| 120 | >
|
|---|
| 121 | Внеси писмена оценка
|
|---|
| 122 | </button>
|
|---|
| 123 | <button
|
|---|
| 124 | className="nav-item btn btn-primary"
|
|---|
| 125 | onClick={handleVnesiKrajnaOcenka}
|
|---|
| 126 | >
|
|---|
| 127 | Внеси крајна оценка
|
|---|
| 128 | </button>
|
|---|
| 129 | </nav>
|
|---|
| 130 | </div>
|
|---|
| 131 |
|
|---|
| 132 | {data.predmeti.map((predmet) => (
|
|---|
| 133 | <div
|
|---|
| 134 | key={predmet.predmetId}
|
|---|
| 135 | className="bg-secondary p-3 mb-5 rounded"
|
|---|
| 136 | >
|
|---|
| 137 | <h2 className="text-white text-center fw-bold">
|
|---|
| 138 | Предмет: {predmet.predmetIme}
|
|---|
| 139 | </h2>
|
|---|
| 140 |
|
|---|
| 141 | <div>
|
|---|
| 142 | <h3 className="text-center text-white">Усни оценки</h3>
|
|---|
| 143 | <table className="table">
|
|---|
| 144 | <thead className="table-dark">
|
|---|
| 145 | <tr>
|
|---|
| 146 | <th scope="col">#</th>
|
|---|
| 147 | <th scope="col">Оценка</th>
|
|---|
| 148 | <th scope="col">датум</th>
|
|---|
| 149 | <th scope="col">Забелешка</th>
|
|---|
| 150 | <th scope="col">Тема</th>
|
|---|
| 151 | <th scope="col">Освоени поени/Мах поени</th>
|
|---|
| 152 | <th scope="col">вид</th>
|
|---|
| 153 | <th scope="col">Внесена од</th>
|
|---|
| 154 | </tr>
|
|---|
| 155 | </thead>
|
|---|
| 156 | <tbody>
|
|---|
| 157 | {predmet.usniOcenki.length > 0 ? (
|
|---|
| 158 | predmet.usniOcenki.map((o, index) => (
|
|---|
| 159 | <tr key={o.id}>
|
|---|
| 160 | <th scope="row">{index + 1}</th>
|
|---|
| 161 | <td>{o.ocenka}</td>
|
|---|
| 162 | <td>{o.datum}</td>
|
|---|
| 163 | <td>{o.zabeleska}</td>
|
|---|
| 164 | <td>{o.tema}</td>
|
|---|
| 165 | <td>
|
|---|
| 166 | {o.osvoeni_poeni}/{o.max_poeni}
|
|---|
| 167 | </td>
|
|---|
| 168 | <td>{o.vid_isprasuvanje}</td>
|
|---|
| 169 | <td>{teachersMap[o.vnesena_Od]}</td>
|
|---|
| 170 | </tr>
|
|---|
| 171 | ))
|
|---|
| 172 | ) : (
|
|---|
| 173 | <tr>
|
|---|
| 174 | <td scope="row">/</td>
|
|---|
| 175 | <td>/</td>
|
|---|
| 176 | <td>/</td>
|
|---|
| 177 | <td>/</td>
|
|---|
| 178 | <td>/</td>
|
|---|
| 179 | <td>/</td>
|
|---|
| 180 | <td>/</td>
|
|---|
| 181 | <td>/</td>
|
|---|
| 182 | </tr>
|
|---|
| 183 | )}
|
|---|
| 184 | </tbody>
|
|---|
| 185 | </table>
|
|---|
| 186 | </div>
|
|---|
| 187 |
|
|---|
| 188 | <div>
|
|---|
| 189 | <h3 className="text-white text-center">Писмени оценки</h3>
|
|---|
| 190 | <table className="table">
|
|---|
| 191 | <thead className="table-dark">
|
|---|
| 192 | <tr>
|
|---|
| 193 | <th scope="col">#</th>
|
|---|
| 194 | <th scope="col">Оценка</th>
|
|---|
| 195 | <th scope="col">датум</th>
|
|---|
| 196 | <th scope="col">Забелешка</th>
|
|---|
| 197 | <th scope="col">Тема</th>
|
|---|
| 198 | <th scope="col">Освоени поени/Мах поени</th>
|
|---|
| 199 | <th scope="col">вид</th>
|
|---|
| 200 | <th scope="col">Внесена од</th>
|
|---|
| 201 | </tr>
|
|---|
| 202 | </thead>
|
|---|
| 203 | <tbody>
|
|---|
| 204 | {predmet.pismeniOcenki.length > 0 ? (
|
|---|
| 205 | predmet.pismeniOcenki.map((o, index) => (
|
|---|
| 206 | <tr key={o.id}>
|
|---|
| 207 | <th scope="row">{index + 1}</th>
|
|---|
| 208 | <td>{o.ocenka}</td>
|
|---|
| 209 | <td>{o.datum}</td>
|
|---|
| 210 | <td>{o.zabeleska}</td>
|
|---|
| 211 | <td>{o.tema}</td>
|
|---|
| 212 | <td>
|
|---|
| 213 | {o.osvoeni_poeni}/{o.max_poeni}
|
|---|
| 214 | </td>
|
|---|
| 215 | <td>{o.vid}</td>
|
|---|
| 216 | <td>{teachersMap[o.vnesena_Od]}</td>
|
|---|
| 217 | </tr>
|
|---|
| 218 | ))
|
|---|
| 219 | ) : (
|
|---|
| 220 | <tr>
|
|---|
| 221 | <th scope="row">/</th>
|
|---|
| 222 | <td>/</td>
|
|---|
| 223 | <td>/</td>
|
|---|
| 224 | <td>/</td>
|
|---|
| 225 | <td>/</td>
|
|---|
| 226 | <td>/</td>
|
|---|
| 227 | <td>/</td>
|
|---|
| 228 | <td>/</td>
|
|---|
| 229 | </tr>
|
|---|
| 230 | )}
|
|---|
| 231 | </tbody>
|
|---|
| 232 | </table>
|
|---|
| 233 | </div>
|
|---|
| 234 |
|
|---|
| 235 | <div>
|
|---|
| 236 | <h3 className="text-white text-center">Крајни Оценки</h3>
|
|---|
| 237 | <table className="table">
|
|---|
| 238 | <thead className="table-dark">
|
|---|
| 239 | <tr>
|
|---|
| 240 | <th scope="col">#</th>
|
|---|
| 241 | <th scope="col">Оценка</th>
|
|---|
| 242 | <th scope="col">датум</th>
|
|---|
| 243 | <th scope="col">Забелешка</th>
|
|---|
| 244 | <th scope="col">вид</th>
|
|---|
| 245 | <th scope="col">Внесена од</th>
|
|---|
| 246 | </tr>
|
|---|
| 247 | </thead>
|
|---|
| 248 | <tbody>
|
|---|
| 249 | {predmet.krajniOcenki.length > 0 ? (
|
|---|
| 250 | predmet.krajniOcenki.map((o, index) => (
|
|---|
| 251 | <tr key={o.id}>
|
|---|
| 252 | <th scope="row">{index + 1}</th>
|
|---|
| 253 | <td>{o.ocenka}</td>
|
|---|
| 254 | <td>{o.datum}</td>
|
|---|
| 255 | <td>{o.zabeleska}</td>
|
|---|
| 256 | <td>{o.tip}</td>
|
|---|
| 257 | <td>{teachersMap[o.vnesena_Od]}</td>
|
|---|
| 258 | </tr>
|
|---|
| 259 | ))
|
|---|
| 260 | ) : (
|
|---|
| 261 | <tr>
|
|---|
| 262 | <th scope="row">/</th>
|
|---|
| 263 | <td>/</td>
|
|---|
| 264 | <td>/</td>
|
|---|
| 265 | <td>/</td>
|
|---|
| 266 | <td>/</td>
|
|---|
| 267 | <td>/</td>
|
|---|
| 268 | </tr>
|
|---|
| 269 | )}
|
|---|
| 270 | </tbody>
|
|---|
| 271 | </table>
|
|---|
| 272 | </div>
|
|---|
| 273 | </div>
|
|---|
| 274 | ))}
|
|---|
| 275 | </div>
|
|---|
| 276 | </div>
|
|---|
| 277 | </>
|
|---|
| 278 | );
|
|---|
| 279 | };
|
|---|
| 280 |
|
|---|
| 281 | export default PredmetenNastavnik_ViewOcenkiZaStudent;
|
|---|