Update 13 files

- /TeacherDashboard/index.html
- /TeacherDashboard/TeacherDashboard.code-workspace
- /TeacherDashboard/components/resourceModal.html
- /TeacherDashboard/components/subjectModal.html
- /TeacherDashboard/components/topicModal.html
- /TeacherDashboard/js/main.js
- /TeacherDashboard/js/subjects/colors.js
- /TeacherDashboard/js/subjects/subjectManager.js
- /TeacherDashboard/js/subjects/SubjectModel.js
- /TeacherDashboard/js/subjects/SubjectStorage.js
- /TeacherDashboard/js/topics/TopicModel.js
- /TeacherDashboard/js/topics/topicManager.js
- /TeacherDashboard/styles/main.css
This commit is contained in:
Kelvi Yawo Jules Agbessi Awuklu
2024-12-13 13:43:58 +01:00
committed by Matthias Grief
parent 3977f48367
commit 2369f7158d
13 changed files with 1055 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
export class SubjectStorage {
constructor() {
this.storageKey = 'teacherDash_subjects';
}
async getAllSubjects() {
try {
const data = localStorage.getItem(this.storageKey);
return data ? JSON.parse(data) : [];
} catch (error) {
console.error('Error loading subjects:', error);
return [];
}
}
async saveSubject(subject) {
try {
const subjects = await this.getAllSubjects();
const existingIndex = subjects.findIndex(s => s.id === subject.id);
if (existingIndex >= 0) {
subjects[existingIndex] = subject;
} else {
subjects.push(subject);
}
localStorage.setItem(this.storageKey, JSON.stringify(subjects));
return subject;
} catch (error) {
throw new Error('Failed to save subject: ' + error.message);
}
}
async deleteSubject(subjectId) {
const subjects = await this.getAllSubjects();
const filtered = subjects.filter(s => s.id !== subjectId);
localStorage.setItem(this.storageKey, JSON.stringify(filtered));
}
}