Finalna wersja wczytywania uczniow.
This commit is contained in:
parent
d53c68eeb0
commit
3ad0353d9c
25
index.html
25
index.html
|
@ -2,7 +2,6 @@
|
|||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Ocena Zachowania</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
</head>
|
||||
|
@ -65,17 +64,15 @@
|
|||
<button onclick="changeDay(1)">Następny Dzień</button>
|
||||
</div>
|
||||
<div class="select-class">
|
||||
<p>Wybierz klase:</p>
|
||||
|
||||
<p>Wybierz klasę:</p>
|
||||
<select id="select-class">
|
||||
<!-- Opcje zostaną wygenerowane dynamicznie -->
|
||||
</select>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th rowSpan="2"><select class="select-class" id="select-class">
|
||||
<option value="">Klasa 1</option>
|
||||
<option value="">Klasa 2</option>
|
||||
<option value="">Klasa 3</option>
|
||||
</select></th>
|
||||
<th rowspan="2">Imię i nazwisko</th>
|
||||
<th colspan="3">Frekwencja</th>
|
||||
<th colspan="4">Olimpiady</th>
|
||||
<th colspan="2">Konkursy Szkolne</th>
|
||||
|
@ -103,7 +100,6 @@
|
|||
<th>Wolontariat</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody id="student-table">
|
||||
<!-- Dane uczniów będą generowane dynamicznie -->
|
||||
</tbody>
|
||||
|
@ -116,17 +112,12 @@
|
|||
</div>
|
||||
|
||||
<footer style="margin: 20px">
|
||||
K. Michalak
|
||||
</br>
|
||||
F. Kowalski
|
||||
</br>
|
||||
K. Michalak<br>
|
||||
F. Kowalski<br>
|
||||
Led and Authored by M. Pabiszczak
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
<script type="module" src="js/script.js"></script>
|
||||
|
||||
<script src="js/script.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
192
js/script.js
192
js/script.js
|
@ -11,99 +11,82 @@ async function fetchJSONFile(filePath) {
|
|||
}
|
||||
}
|
||||
|
||||
// Funkcja do wczytania pliku class.json
|
||||
// Obiekt do przechowywania danych klas i uczniów
|
||||
const classData = {};
|
||||
|
||||
// Funkcja do wczytania pliku class.json i danych uczniów
|
||||
async function loadClasses() {
|
||||
const classFilePath = '/data/class.json';
|
||||
const classes = await fetchJSONFile(classFilePath);
|
||||
|
||||
if (classes) {
|
||||
console.log('Classes loaded:', classes);
|
||||
const section_by_id = document.getElementById("select-class");
|
||||
section_by_id.innerHTML = ""; // Wyczyść istniejące opcje
|
||||
|
||||
var section_HTML = ""
|
||||
|
||||
// Iterowanie po wszystkich klasach i wczytywanie plików z danymi uczniów
|
||||
for (const classInfo of classes) {
|
||||
const studentsFilePath = '/data/'+ classInfo.file_path;
|
||||
const studentsData = await fetchJSONFile(studentsFilePath);
|
||||
const studentsFilePath = '/data/' + classInfo.file_path;
|
||||
const studentsDataForClass = await fetchJSONFile(studentsFilePath);
|
||||
|
||||
// Wczytywanie klas do elementu select w html
|
||||
|
||||
const section_by_id = document.getElementById("select-class")
|
||||
|
||||
if (!section_HTML.includes(classInfo.class)) {
|
||||
const section_option = "<option>" + "Klasa: " + classInfo.class + "</option>"
|
||||
section_HTML += section_option;
|
||||
console.log("DODANO KLASE ", classInfo.class, " DO SELECT")
|
||||
section_by_id.innerHTML = section_HTML
|
||||
}
|
||||
|
||||
//Literowanie studentow i dodawanie do tabeli
|
||||
|
||||
if (studentsData) {
|
||||
console.log(`Students loaded for class ${classInfo.class}:`, studentsData);
|
||||
// Tutaj możesz przechowywać dane lub je przetwarzać według potrzeb
|
||||
processClassData(classInfo, studentsData);
|
||||
|
||||
const classKey = classInfo.class + "-" + classInfo.group;
|
||||
|
||||
// Utwórz i dodaj opcję do selecta
|
||||
const option = document.createElement("option");
|
||||
option.value = classKey;
|
||||
option.text = "Klasa: " + classInfo.class + " Grupa: " + classInfo.group;
|
||||
section_by_id.appendChild(option);
|
||||
|
||||
if (studentsDataForClass) {
|
||||
processClassData(classInfo, studentsDataForClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const classData = []
|
||||
|
||||
// Funkcja do przetwarzania danych o klasach i uczniach
|
||||
function processClassData(classInfo, studentsData) {
|
||||
console.log(`Class: ${classInfo.class}, Group: ${classInfo.group}, Students Count: ${classInfo.student_count}`);
|
||||
console.log('Student Data:', studentsData);
|
||||
classData.push(studentsData)
|
||||
// Możesz tutaj np. wyświetlić dane w interfejsie lub przeprowadzić dodatkowe operacje
|
||||
function processClassData(classInfo, studentsDataForClass) {
|
||||
const classKey = classInfo.class + "-" + classInfo.group;
|
||||
classData[classKey] = studentsDataForClass;
|
||||
}
|
||||
|
||||
// Uruchomienie wczytywania klas
|
||||
loadClasses();
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
let currentDay = 0;
|
||||
const baseDate = new Date();
|
||||
|
||||
//Pobieranie studentow na podstawie aktualnie wybranej klasy
|
||||
// Globalna tablica studentsData
|
||||
let studentsData = [];
|
||||
|
||||
// Nasłuchiwanie na zmianę klasy i ładowanie uczniów
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.getElementById('select-class').addEventListener('change', function() {
|
||||
var selectedClass = this.value;
|
||||
var lastCharacter = selectedClass.slice(-1); // Pobiera ostatni znak
|
||||
console.log("Aktualnie wybrana klasa: ", lastCharacter, " Liczba studentow: ");
|
||||
|
||||
if (studentsData && studentsData.students) {
|
||||
// Literowanie po studentach i wyświetlanie ich danych
|
||||
loadClasses().then(() => {
|
||||
const selectClassElement = document.getElementById('select-class');
|
||||
|
||||
studentsData.students.forEach(student => {
|
||||
if(studentsData.header.class == classInfo.class){
|
||||
console.log('Imię: ', student.first_name)
|
||||
}
|
||||
selectClassElement.addEventListener('change', function() {
|
||||
var selectedClass = this.value;
|
||||
console.log("Aktualnie wybrana klasa: ", selectedClass);
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('Nie udało się pobrać danych studentów.');
|
||||
// Pobierz dane uczniów dla wybranej klasy
|
||||
let classStudentsData = classData[selectedClass];
|
||||
|
||||
if (classStudentsData && classStudentsData.students) {
|
||||
console.log("Dane uczniów dla klasy:", classStudentsData.students);
|
||||
// Zaktualizuj tablicę studentsData
|
||||
studentsData = classStudentsData.students.map(student => ({
|
||||
name: student.first_name + " " + student.last_name,
|
||||
behavior: {}
|
||||
}));
|
||||
// Wygeneruj tabelę
|
||||
generateTable();
|
||||
// Załaduj dane dla aktualnego dnia
|
||||
loadDayData();
|
||||
} else {
|
||||
console.error("Nie znaleziono danych dla klasy: ", selectedClass);
|
||||
}
|
||||
});
|
||||
|
||||
// Automatycznie wywołaj 'change' dla pierwszej klasy w select
|
||||
if (selectClassElement.options.length > 0) {
|
||||
selectClassElement.selectedIndex = 0;
|
||||
selectClassElement.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
//Pobranie uczniow klasy
|
||||
});
|
||||
});
|
||||
|
||||
const studentsData = [
|
||||
{ name: "Jan Kowalski", behavior: {} },
|
||||
{ name: "Anna Nowak", behavior: {} },
|
||||
{ name: "Piotr Wiśniewski", behavior: {} },
|
||||
{ name: "Katarzyna Zielińska", behavior: {} }
|
||||
];
|
||||
|
||||
function showTab(tabName) {
|
||||
const tabs = document.querySelectorAll('.tab');
|
||||
tabs.forEach(tab => tab.classList.remove('active'));
|
||||
|
@ -116,57 +99,43 @@ function showTab(tabName) {
|
|||
}
|
||||
}
|
||||
|
||||
async function changeClass() {
|
||||
await loadClasses()
|
||||
let classesNames = []
|
||||
for (const classInfo of classData) {
|
||||
console.log(classInfo)
|
||||
classesNames.push(classInfo.header.class + "-" + classInfo.header.group)
|
||||
}
|
||||
console.log("lol")
|
||||
console.log(classesNames)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function generateTable() {
|
||||
changeClass()
|
||||
const table = document.getElementById('student-table');
|
||||
table.innerHTML = '';
|
||||
|
||||
//xd
|
||||
|
||||
studentsData.forEach(student => {
|
||||
console.log("Przetwarzany student:", student);
|
||||
const studentId = student.name.replace(/\s+/g, '-');
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
|
||||
|
||||
|
||||
<td>${student.name}</td>
|
||||
<td><input type="checkbox" id="frekwencja-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="brak-godzin-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="min-85-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-szkolny-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-rejonowy-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-wojewodzki-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-ogolnopolski-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="udzial-konkurs-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="wyroznienie-konkurs-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="reprezentacja-indywidualna-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="reprezentacja-zespolowa-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="udzial-zawody-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="organizacja-imprez-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="funkcja-klasa-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="uroczystosci-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="poczta-sztandar-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="pomoc-nauczyciel-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="wolontariat-${student.name.replace(' ', '-')}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="frekwencja-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="brak-godzin-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="min-85-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-szkolny-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-rejonowy-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-wojewodzki-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="etap-ogolnopolski-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="udzial-konkurs-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="wyroznienie-konkurs-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="reprezentacja-indywidualna-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="reprezentacja-zespolowa-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="udzial-zawody-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="organizacja-imprez-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="funkcja-klasa-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="uroczystosci-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="poczta-sztandar-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="pomoc-nauczyciel-${studentId}" onchange="calculateStats()"></td>
|
||||
<td><input type="checkbox" id="wolontariat-${studentId}" onchange="calculateStats()"></td>
|
||||
`;
|
||||
table.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
let currentDay = 0;
|
||||
const baseDate = new Date();
|
||||
|
||||
// Zmiana dnia i ładowanie danych
|
||||
function changeDay(direction) {
|
||||
saveDayData();
|
||||
currentDay += direction;
|
||||
|
@ -178,7 +147,7 @@ function changeDay(direction) {
|
|||
|
||||
function loadDayData() {
|
||||
studentsData.forEach(student => {
|
||||
const studentId = student.name.replace(' ', '-');
|
||||
const studentId = student.name.replace(/\s+/g, '-');
|
||||
const behavior = student.behavior[`day${currentDay}`] || {};
|
||||
|
||||
document.getElementById(`frekwencja-${studentId}`).checked = behavior.frekwencja || false;
|
||||
|
@ -206,7 +175,7 @@ function loadDayData() {
|
|||
|
||||
function saveDayData() {
|
||||
studentsData.forEach(student => {
|
||||
const studentId = student.name.replace(' ', '-');
|
||||
const studentId = student.name.replace(/\s+/g, '-');
|
||||
const behavior = {
|
||||
frekwencja: document.getElementById(`frekwencja-${studentId}`).checked,
|
||||
brak_godzin: document.getElementById(`brak-godzin-${studentId}`).checked,
|
||||
|
@ -224,7 +193,7 @@ function saveDayData() {
|
|||
funkcja_klasa: document.getElementById(`funkcja-klasa-${studentId}`).checked,
|
||||
uroczystosci: document.getElementById(`uroczystosci-${studentId}`).checked,
|
||||
poczta_sztandar: document.getElementById(`poczta-sztandar-${studentId}`).checked,
|
||||
pomoc_nauciciel: document.getElementById(`pomoc-nauczyciel-${studentId}`).checked,
|
||||
pomoc_nauczyciel: document.getElementById(`pomoc-nauczyciel-${studentId}`).checked,
|
||||
wolontariat: document.getElementById(`wolontariat-${studentId}`).checked
|
||||
};
|
||||
|
||||
|
@ -260,7 +229,7 @@ function calculateStats() {
|
|||
Object.keys(student.behavior).forEach(day => {
|
||||
const behavior = student.behavior[day];
|
||||
|
||||
let dayPoints = 0; // Startowa liczba punktów
|
||||
let dayPoints = 0;
|
||||
if (behavior.frekwencja) dayPoints += frekwencjaPoints;
|
||||
if (behavior.brak_godzin) dayPoints += brakGodzinPoints;
|
||||
if (behavior.min_85) dayPoints += min85Points;
|
||||
|
@ -277,7 +246,7 @@ function calculateStats() {
|
|||
if (behavior.funkcja_klasa) dayPoints += funkcjaKlasyPoints;
|
||||
if (behavior.uroczystosci) dayPoints += uroczystosciPoints;
|
||||
if (behavior.poczta_sztandar) dayPoints += pocztaSztandarPoints;
|
||||
if (behavior.pomoc_nauciciel) dayPoints += pomocNauczycielaPoints;
|
||||
if (behavior.pomoc_nauczyciel) dayPoints += pomocNauczycielaPoints;
|
||||
if (behavior.wolontariat) dayPoints += wolontariatPoints;
|
||||
|
||||
totalPoints += dayPoints;
|
||||
|
@ -300,6 +269,3 @@ function getGrade(points) {
|
|||
|
||||
// Ustawienie daty na dziś
|
||||
document.getElementById('current-date').innerText = baseDate.toLocaleDateString();
|
||||
|
||||
// Generowanie tabeli przy starcie
|
||||
generateTable();
|
Loading…
Reference in New Issue