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:
committed by
Matthias Grief
parent
3977f48367
commit
2369f7158d
39
TeacherDashboard/js/subjects/SubjectStorage.js
Normal file
39
TeacherDashboard/js/subjects/SubjectStorage.js
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user