From 3aa37dff459e7a5bbcac4ab32e816eedc8926de7 Mon Sep 17 00:00:00 2001 From: Khadim Date: Wed, 27 Sep 2023 22:20:16 +0200 Subject: [PATCH] add frontend calls --- web/ts/api/admin-lecture-list.ts | 18 ++++++++++++++++++ web/ts/data-store/admin-lecture-list.ts | 18 +++++++++++++++++- web/ts/edit-course.ts | 4 ++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/web/ts/api/admin-lecture-list.ts b/web/ts/api/admin-lecture-list.ts index 94d8e853b..bdd4fd82a 100644 --- a/web/ts/api/admin-lecture-list.ts +++ b/web/ts/api/admin-lecture-list.ts @@ -17,6 +17,11 @@ export interface UpdateLectureMetaRequest { isChatEnabled?: boolean; } +export interface UpdateLectureDateTimeRequest { + startDate: Date; + endTime: Date; +} + export class LectureFile { readonly id: number; readonly fileType: number; @@ -282,6 +287,19 @@ export const AdminLectureList = { await post(`/api/course/${courseId}/updateLectureSeries/${lectureId}`); }, + /** + * Updates date time of a lecture. + * @param courseId + * @param lectureId + * @param request + */ + updateDateTime: async function (courseId: number, lectureId: number, request: UpdateLectureDateTimeRequest) { + await post(`/api/course/${courseId}/updateDateTime/${lectureId}`, { + startDate: request.startDate, + endTime: request.endTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), + }); + }, + /** * Add sections to a lecture * @param lectureId diff --git a/web/ts/data-store/admin-lecture-list.ts b/web/ts/data-store/admin-lecture-list.ts index c460a0cb5..b637d57d4 100644 --- a/web/ts/data-store/admin-lecture-list.ts +++ b/web/ts/data-store/admin-lecture-list.ts @@ -2,7 +2,7 @@ import { StreamableMapProvider } from "./provider"; import { AdminLectureList, Lecture, - LectureFile, + LectureFile, UpdateLectureDateTimeRequest, UpdateLectureMetaRequest, VideoSection, videoSectionSort, @@ -113,6 +113,22 @@ export class AdminLectureListProvider extends StreamableMapProvider { + if (s.lectureId === lectureId) { + return { + ...s, + start: payload.startDate, + end: payload.endTime, + }; + } + return s; + }); + await this.triggerUpdate(courseId); + } + async uploadAttachmentFile(courseId: number, lectureId: number, file: File) { const res = await AdminLectureList.uploadAttachmentFile(courseId, lectureId, file); const newFile = new LectureFile({ diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index 55bbf0e54..98cb20f4f 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -413,7 +413,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { * Save changes send them to backend and commit change set. */ async saveEdit() { - const { courseId, lectureId, name, description, lectureHallId, isChatEnabled, videoSections } = + const { courseId, lectureId, name, description, lectureHallId, isChatEnabled, videoSections, start, end } = this.lectureData; const changedKeys = this.changeSet.changedKeys(); @@ -433,7 +433,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { // Save new date and time if (changedKeys.includes("start") || changedKeys.includes("end")) { - + await DataStore.adminLectureList.updateDateTime(courseId, lectureId, { startDate: new Date(start), endTime: new Date(end) }); } // Saving VideoSections