From 859555c096689d03560779fc857629365da4e378 Mon Sep 17 00:00:00 2001 From: Khadim Date: Thu, 14 Sep 2023 17:56:37 +0200 Subject: [PATCH 1/2] fix delete lecture --- web/ts/api/admin-lecture-list.ts | 11 ++++++++++- web/ts/data-store/admin-lecture-list.ts | 11 +++++++++++ web/ts/edit-course.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/web/ts/api/admin-lecture-list.ts b/web/ts/api/admin-lecture-list.ts index 68b744e04..c7f2d6ac9 100644 --- a/web/ts/api/admin-lecture-list.ts +++ b/web/ts/api/admin-lecture-list.ts @@ -292,7 +292,16 @@ export const AdminLectureList = { */ delete: async function (courseId: number, lectureIds: number[]): Promise { 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 { + return await del(`/api/course/${courseId}/deleteLectureSeries/${lectureId}`); + }, }; diff --git a/web/ts/data-store/admin-lecture-list.ts b/web/ts/data-store/admin-lecture-list.ts index 582c33a0a..077a71984 100644 --- a/web/ts/data-store/admin-lecture-list.ts +++ b/web/ts/data-store/admin-lecture-list.ts @@ -69,6 +69,17 @@ export class AdminLectureListProvider extends StreamableMapProvider 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 = diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index 36b1014a1..bb53157a2 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -191,6 +191,14 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { DataStore.adminLectureList.deleteAttachment(this.lectureData.courseId, this.lectureData.lectureId, id); }, + 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 */ From d375cf72cb47ead798b039579519893d448ba07f Mon Sep 17 00:00:00 2001 From: Khadim Date: Thu, 14 Sep 2023 17:58:06 +0200 Subject: [PATCH 2/2] reenable page reload on create --- web/ts/edit-course.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index bb53157a2..039559e60 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -855,10 +855,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);