Skip to content

Commit

Permalink
Merge branch 'improvement/refactor-course-mgmt' into improvement/refa…
Browse files Browse the repository at this point in the history
…ctor-course-sections
  • Loading branch information
mono424 committed Sep 15, 2023
2 parents bf11272 + d375cf7 commit 8755076
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
11 changes: 10 additions & 1 deletion web/ts/api/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,16 @@ export const AdminLectureList = {
*/
delete: async function (courseId: number, lectureIds: number[]): Promise<Response> {
return await post(`/api/course/${courseId}/deleteLectures`, {
streamIDs: lectureIds,
streamIDs: lectureIds.map((id) => `${id}`),
});
},

/**
* Delete lecture series of a lecture
* @param courseId
* @param lectureId
*/
deleteSeries: async function (courseId: number, lectureId: number): Promise<Response> {
return await del(`/api/course/${courseId}/deleteLectureSeries/${lectureId}`);
},
};
11 changes: 11 additions & 0 deletions web/ts/data-store/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export class AdminLectureListProvider extends StreamableMapProvider<number, Lect
await this.triggerUpdate(courseId);
}

async deleteSeries(courseId: number, lectureId: number) {
await AdminLectureList.deleteSeries(courseId, lectureId);

const lectures = await this.getData(courseId);
const seriesIdentifier = lectures.find((l) => l.lectureId === lectureId)?.seriesIdentifier ?? null;
const lectureIds = lectures.filter((l) => l.seriesIdentifier === seriesIdentifier).map((l) => l.lectureId);

this.data[courseId] = lectures.filter((s) => !lectureIds.includes(s.lectureId));
await this.triggerUpdate(courseId);
}

async updateMeta(courseId: number, lectureId: number, props: UpdateMetaProps) {
const updateSeries = props?.options?.saveSeries === true;
const seriesIdentifier =
Expand Down
12 changes: 10 additions & 2 deletions web/ts/edit-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ export function lectureEditor(lecture: Lecture): AlpineComponent {
section.startSeconds < 60
);
},

deleteLecture() {
DataStore.adminLectureList.delete(this.lectureData.courseId, [this.lectureData.lectureId]);
},

deleteLectureSeries() {
DataStore.adminLectureList.deleteSeries(this.lectureData.courseId, this.lectureData.lectureId);
},

/**
* Opens the series lecture editor UI
Expand Down Expand Up @@ -884,10 +892,10 @@ export function createLectureForm(args: { s: [] }) {
postData("/api/course/" + this.courseID + "/createLecture", payload)
.then(async (res) => {
const { ids } = await res.json();
/*const url = new URL(window.location.href);
const url = new URL(window.location.href);
url.hash = `lectures:${ids.join(",")}`;
window.location.assign(url);
window.location.reload();*/
window.location.reload();
})
.catch((e) => {
console.log(e);
Expand Down

0 comments on commit 8755076

Please sign in to comment.