Spaces:
Running
Running
Update index.html
Browse files- index.html +88 -1
index.html
CHANGED
|
@@ -169,4 +169,91 @@
|
|
| 169 |
<h2 id="syllTitle" style="color: var(--brass); font-weight: 300;"></h2>
|
| 170 |
<form id="syllForm">
|
| 171 |
<textarea id="syllArea" rows="12" placeholder="ENTRY_DATA..."></textarea>
|
| 172 |
-
<input type="hidden" id="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
<h2 id="syllTitle" style="color: var(--brass); font-weight: 300;"></h2>
|
| 170 |
<form id="syllForm">
|
| 171 |
<textarea id="syllArea" rows="12" placeholder="ENTRY_DATA..."></textarea>
|
| 172 |
+
<input type="hidden" id="syllId">
|
| 173 |
+
<button type="submit" class="action-btn">SAVE_CHANGES</button>
|
| 174 |
+
</form>
|
| 175 |
+
</div>
|
| 176 |
+
</div>
|
| 177 |
+
|
| 178 |
+
<script type="module">
|
| 179 |
+
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
|
| 180 |
+
import { getDatabase, ref, onValue, push, remove, update } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-database.js";
|
| 181 |
+
|
| 182 |
+
const firebaseConfig = {
|
| 183 |
+
apiKey: "AIzaSyCBGYdGdPjYJiKsTMjVYZ9mf9F82ns7g4Q",
|
| 184 |
+
authDomain: "pikachu-rxppbp.firebaseapp.com",
|
| 185 |
+
databaseURL: "https://pikachu-rxppbp.firebaseio.com",
|
| 186 |
+
projectId: "pikachu-rxppbp",
|
| 187 |
+
storageBucket: "pikachu-rxppbp.appspot.com",
|
| 188 |
+
messagingSenderId: "241970333280",
|
| 189 |
+
appId: "1:241970333280:web:704e8930bd591c138d6505"
|
| 190 |
+
};
|
| 191 |
+
|
| 192 |
+
const app = initializeApp(firebaseConfig);
|
| 193 |
+
const database = getDatabase(app);
|
| 194 |
+
const examsRef = ref(database, 'exams');
|
| 195 |
+
let dataStore = [];
|
| 196 |
+
|
| 197 |
+
onValue(examsRef, (snapshot) => {
|
| 198 |
+
const data = snapshot.val();
|
| 199 |
+
dataStore = data ? Object.entries(data).map(([id, v]) => ({ id, ...v })) : [];
|
| 200 |
+
render();
|
| 201 |
+
});
|
| 202 |
+
|
| 203 |
+
function render() {
|
| 204 |
+
const grid = document.getElementById('examsGrid');
|
| 205 |
+
grid.innerHTML = dataStore.sort((a,b)=>a.date-b.date).map(e => {
|
| 206 |
+
const now = new Date(); now.setHours(0,0,0,0);
|
| 207 |
+
const target = new Date(e.date); target.setHours(0,0,0,0);
|
| 208 |
+
const diff = Math.ceil((target - now) / 86400000);
|
| 209 |
+
|
| 210 |
+
let val = diff < 0 ? 'OK' : diff;
|
| 211 |
+
let label = diff < 0 ? 'COMPLETED' : (diff === 1 ? 'DAY LEFT' : 'DAYS LEFT');
|
| 212 |
+
|
| 213 |
+
return `
|
| 214 |
+
<div class="brushed-plate" onclick="showSyll('${e.id}')">
|
| 215 |
+
<button class="del" onclick="event.stopPropagation(); window.delEx('${e.id}')">×</button>
|
| 216 |
+
<div class="card-header">${e.name}</div>
|
| 217 |
+
<div>
|
| 218 |
+
<div class="digit-flipper">${val}</div>
|
| 219 |
+
<div class="label-text">${label}</div>
|
| 220 |
+
</div>
|
| 221 |
+
<footer>${new Date(e.date).toDateString()}</footer>
|
| 222 |
+
</div>`;
|
| 223 |
+
}).join('');
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
window.delEx = (id) => { if(confirm("Delete entry?")) remove(ref(database, `exams/${id}`)); };
|
| 227 |
+
|
| 228 |
+
window.showSyll = (id) => {
|
| 229 |
+
const e = dataStore.find(x => x.id === id);
|
| 230 |
+
document.getElementById('syllTitle').innerText = e.name;
|
| 231 |
+
document.getElementById('syllArea').value = e.syllabus || '';
|
| 232 |
+
document.getElementById('syllId').value = id;
|
| 233 |
+
document.getElementById('syllModal').classList.add('active');
|
| 234 |
+
};
|
| 235 |
+
|
| 236 |
+
document.getElementById('openBtn').onclick = () => document.getElementById('addModal').classList.add('active');
|
| 237 |
+
window.onclick = (e) => { if(e.target.classList.contains('modal')) e.target.classList.remove('active'); };
|
| 238 |
+
|
| 239 |
+
document.getElementById('addForm').onsubmit = (e) => {
|
| 240 |
+
e.preventDefault();
|
| 241 |
+
push(examsRef, {
|
| 242 |
+
name: document.getElementById('nameIn').value,
|
| 243 |
+
date: new Date(document.getElementById('dateIn').value).getTime(),
|
| 244 |
+
syllabus: ''
|
| 245 |
+
});
|
| 246 |
+
document.getElementById('addModal').classList.remove('active');
|
| 247 |
+
document.getElementById('addForm').reset();
|
| 248 |
+
};
|
| 249 |
+
|
| 250 |
+
document.getElementById('syllForm').onsubmit = (e) => {
|
| 251 |
+
e.preventDefault();
|
| 252 |
+
update(ref(database, `exams/${document.getElementById('syllId').value}`), {
|
| 253 |
+
syllabus: document.getElementById('syllArea').value
|
| 254 |
+
});
|
| 255 |
+
document.getElementById('syllModal').classList.remove('active');
|
| 256 |
+
};
|
| 257 |
+
</script>
|
| 258 |
+
</body>
|
| 259 |
+
</html>
|