Spaces:
Running
Running
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 is the github auth key to access data
Browse files- admin-dashboard.html +14 -5
- attendance.html +7 -7
- config.js +8 -0
- reports.html +8 -8
- students-ate.html +7 -7
admin-dashboard.html
CHANGED
|
@@ -142,8 +142,9 @@
|
|
| 142 |
</div>
|
| 143 |
</div>
|
| 144 |
</div>
|
|
|
|
| 145 |
<script>
|
| 146 |
-
|
| 147 |
if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
|
| 148 |
alert('Please login first');
|
| 149 |
window.location.href = 'admin-login.html';
|
|
@@ -152,8 +153,12 @@
|
|
| 152 |
async function fetchAttendanceData() {
|
| 153 |
try {
|
| 154 |
// Fetch Form A data (Students who want to eat)
|
| 155 |
-
const formAResponse = await fetch(
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
const formAContent = atob(formAData.content);
|
| 158 |
|
| 159 |
// Parse and display Form A data
|
|
@@ -172,8 +177,12 @@ async function fetchAttendanceData() {
|
|
| 172 |
document.getElementById('formAData').innerHTML = formARows;
|
| 173 |
|
| 174 |
// Fetch Form B data (Students who have eaten)
|
| 175 |
-
const formBResponse = await fetch(
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
const formBContent = atob(formBData.content);
|
| 178 |
|
| 179 |
// Parse and display Form B data
|
|
|
|
| 142 |
</div>
|
| 143 |
</div>
|
| 144 |
</div>
|
| 145 |
+
<script src="config.js"></script>
|
| 146 |
<script>
|
| 147 |
+
// Check if user is logged in
|
| 148 |
if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
|
| 149 |
alert('Please login first');
|
| 150 |
window.location.href = 'admin-login.html';
|
|
|
|
| 153 |
async function fetchAttendanceData() {
|
| 154 |
try {
|
| 155 |
// Fetch Form A data (Students who want to eat)
|
| 156 |
+
const formAResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`, {
|
| 157 |
+
headers: {
|
| 158 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
|
| 159 |
+
}
|
| 160 |
+
});
|
| 161 |
+
const formAData = await formAResponse.json();
|
| 162 |
const formAContent = atob(formAData.content);
|
| 163 |
|
| 164 |
// Parse and display Form A data
|
|
|
|
| 177 |
document.getElementById('formAData').innerHTML = formARows;
|
| 178 |
|
| 179 |
// Fetch Form B data (Students who have eaten)
|
| 180 |
+
const formBResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`, {
|
| 181 |
+
headers: {
|
| 182 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
|
| 183 |
+
}
|
| 184 |
+
});
|
| 185 |
+
const formBData = await formBResponse.json();
|
| 186 |
const formBContent = atob(formBData.content);
|
| 187 |
|
| 188 |
// Parse and display Form B data
|
attendance.html
CHANGED
|
@@ -191,7 +191,7 @@
|
|
| 191 |
<p class="mt-1">Data will be saved to <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat" class="text-blue-600 hover:underline" target="_blank">GitHub repository</a></p>
|
| 192 |
</footer>
|
| 193 |
</div>
|
| 194 |
-
|
| 195 |
<script>
|
| 196 |
// Update current time and date
|
| 197 |
function updateDateTime() {
|
|
@@ -505,11 +505,11 @@ function updateDateTime() {
|
|
| 505 |
async function sendDataToGitHub(data) {
|
| 506 |
try {
|
| 507 |
// First get the current content and SHA of the file
|
| 508 |
-
const getResponse = await fetch(
|
| 509 |
-
|
| 510 |
'Accept': 'application/vnd.github.v3+json',
|
| 511 |
-
'Authorization':
|
| 512 |
-
|
| 513 |
});
|
| 514 |
|
| 515 |
let currentContent = '';
|
|
@@ -527,8 +527,8 @@ function updateDateTime() {
|
|
| 527 |
const newContent = currentContent + JSON.stringify(record) + '\n';
|
| 528 |
|
| 529 |
// Update the file
|
| 530 |
-
const response = await fetch(
|
| 531 |
-
|
| 532 |
headers: {
|
| 533 |
'Authorization': 'token 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',
|
| 534 |
'Content-Type': 'application/json',
|
|
|
|
| 191 |
<p class="mt-1">Data will be saved to <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat" class="text-blue-600 hover:underline" target="_blank">GitHub repository</a></p>
|
| 192 |
</footer>
|
| 193 |
</div>
|
| 194 |
+
<script src="config.js"></script>
|
| 195 |
<script>
|
| 196 |
// Update current time and date
|
| 197 |
function updateDateTime() {
|
|
|
|
| 505 |
async function sendDataToGitHub(data) {
|
| 506 |
try {
|
| 507 |
// First get the current content and SHA of the file
|
| 508 |
+
const getResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`, {
|
| 509 |
+
headers: {
|
| 510 |
'Accept': 'application/vnd.github.v3+json',
|
| 511 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
|
| 512 |
+
}
|
| 513 |
});
|
| 514 |
|
| 515 |
let currentContent = '';
|
|
|
|
| 527 |
const newContent = currentContent + JSON.stringify(record) + '\n';
|
| 528 |
|
| 529 |
// Update the file
|
| 530 |
+
const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`, {
|
| 531 |
+
method: 'PUT',
|
| 532 |
headers: {
|
| 533 |
'Authorization': 'token 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',
|
| 534 |
'Content-Type': 'application/json',
|
config.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Configuration for GitHub API access
|
| 2 |
+
const GITHUB_CONFIG = {
|
| 3 |
+
TOKEN: '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',
|
| 4 |
+
REPOS: {
|
| 5 |
+
ATTENDANCE: 'SMSS-Waste-Less/Waste-LessV5',
|
| 6 |
+
CONSUMED: 'WaffleExecutors/Waste-LessV5'
|
| 7 |
+
}
|
| 8 |
+
};
|
reports.html
CHANGED
|
@@ -75,13 +75,13 @@
|
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
</div>
|
|
|
|
| 78 |
<script>
|
| 79 |
-
|
| 80 |
-
const WANT_TO_EAT_URL =
|
| 81 |
-
const HAVE_EATEN_URL =
|
| 82 |
-
const WASTE_DATA_URL =
|
| 83 |
-
|
| 84 |
-
// Chart variables
|
| 85 |
let weeklyChart, mealChart;
|
| 86 |
|
| 87 |
// Fetch data from GitHub
|
|
@@ -90,8 +90,8 @@
|
|
| 90 |
const response = await fetch(url, {
|
| 91 |
headers: {
|
| 92 |
'Accept': 'application/vnd.github.v3+json',
|
| 93 |
-
'Authorization':
|
| 94 |
-
|
| 95 |
});
|
| 96 |
|
| 97 |
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
</div>
|
| 78 |
+
<script src="config.js"></script>
|
| 79 |
<script>
|
| 80 |
+
// API URLs
|
| 81 |
+
const WANT_TO_EAT_URL = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`;
|
| 82 |
+
const HAVE_EATEN_URL = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`;
|
| 83 |
+
const WASTE_DATA_URL = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/food_waste_data.json`;
|
| 84 |
+
// Chart variables
|
|
|
|
| 85 |
let weeklyChart, mealChart;
|
| 86 |
|
| 87 |
// Fetch data from GitHub
|
|
|
|
| 90 |
const response = await fetch(url, {
|
| 91 |
headers: {
|
| 92 |
'Accept': 'application/vnd.github.v3+json',
|
| 93 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
|
| 94 |
+
}
|
| 95 |
});
|
| 96 |
|
| 97 |
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
students-ate.html
CHANGED
|
@@ -163,7 +163,7 @@
|
|
| 163 |
<p class="mt-1">Data will be saved to <a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm" class="text-blue-600 hover:underline" target="_blank">GitHub repository</a></p>
|
| 164 |
</footer>
|
| 165 |
</div>
|
| 166 |
-
|
| 167 |
<script>
|
| 168 |
// Update current time and date
|
| 169 |
function updateDateTime() {
|
|
@@ -476,11 +476,11 @@ alert('Please select a student name');
|
|
| 476 |
async function sendDataToGitHub(data) {
|
| 477 |
try {
|
| 478 |
// First get the current content and SHA of the file
|
| 479 |
-
const getResponse = await fetch(
|
| 480 |
-
|
| 481 |
'Accept': 'application/vnd.github.v3+json',
|
| 482 |
-
'Authorization':
|
| 483 |
-
|
| 484 |
});
|
| 485 |
|
| 486 |
let currentContent = '';
|
|
@@ -498,8 +498,8 @@ alert('Please select a student name');
|
|
| 498 |
const newContent = currentContent + JSON.stringify(record) + '\n';
|
| 499 |
|
| 500 |
// Update the file
|
| 501 |
-
const response = await fetch(
|
| 502 |
-
|
| 503 |
headers: {
|
| 504 |
'Authorization': 'token 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',
|
| 505 |
'Content-Type': 'application/json',
|
|
|
|
| 163 |
<p class="mt-1">Data will be saved to <a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm" class="text-blue-600 hover:underline" target="_blank">GitHub repository</a></p>
|
| 164 |
</footer>
|
| 165 |
</div>
|
| 166 |
+
<script src="config.js"></script>
|
| 167 |
<script>
|
| 168 |
// Update current time and date
|
| 169 |
function updateDateTime() {
|
|
|
|
| 476 |
async function sendDataToGitHub(data) {
|
| 477 |
try {
|
| 478 |
// First get the current content and SHA of the file
|
| 479 |
+
const getResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`, {
|
| 480 |
+
headers: {
|
| 481 |
'Accept': 'application/vnd.github.v3+json',
|
| 482 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
|
| 483 |
+
}
|
| 484 |
});
|
| 485 |
|
| 486 |
let currentContent = '';
|
|
|
|
| 498 |
const newContent = currentContent + JSON.stringify(record) + '\n';
|
| 499 |
|
| 500 |
// Update the file
|
| 501 |
+
const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`, {
|
| 502 |
+
method: 'PUT',
|
| 503 |
headers: {
|
| 504 |
'Authorization': 'token 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',
|
| 505 |
'Content-Type': 'application/json',
|