Skip to content

Commit

Permalink
Merge pull request #500 from tutors-sdk/fix-issue-499
Browse files Browse the repository at this point in the history
Fix issue 499; bug causing course to fail if empty folder in root
  • Loading branch information
edeleastar authored Sep 13, 2023
2 parents cd895c2 + 89d8444 commit e82e4c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/src/lib/services/models/lo-tree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isCompositeLo, type Course, type IconType, type Lo, type Panels, type Composite, type LoType, type Lab, type Units, type Unit, type Side } from "./lo-types";
import { convertLoToHtml } from "./markdown-utils";
import { allVideoLos, createCompanions, createToc, createWallBar, filterByType, flattenLos, initCalendar, injectCourseUrl, loadPropertyFlags } from "./lo-utils";
import { allVideoLos, createCompanions, createToc, createWallBar, filterByType, flattenLos, initCalendar, injectCourseUrl, loadPropertyFlags, removeUnknownLos } from "./lo-utils";

export function decorateCourseTree(course: Course, courseId: string = "", courseUrl = "") {
// define course properties
Expand All @@ -15,6 +15,7 @@ export function decorateCourseTree(course: Course, courseId: string = "", course
// inject course path into all routes
injectCourseUrl(allLos, courseId, courseUrl);

removeUnknownLos(course.los);
// Construct course tree
decorateLoTree(course, course);

Expand Down
40 changes: 25 additions & 15 deletions app/src/lib/services/models/lo-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Lo, Composite, Talk, LoType, Course, Topic, IconNav, Calendar, WeekType } from "./lo-types";
import { type Lo, type Composite, type Talk, type LoType, type Course, type Topic, type IconNav, type Calendar, type WeekType, isCompositeLo } from "./lo-types";

export function flattenLos(los: Lo[]): Lo[] {
let result: Lo[] = [];
Expand Down Expand Up @@ -50,22 +50,32 @@ export function injectCourseUrl(los: Lo[], id: string, url: string) {
});
}

export function removeUnknownLos(los: Lo[]) {
los.forEach((lo, index) => {
if (lo.type === "unknown") {
los.splice(index, 1);
}
});
}

export function createToc(course: Course) {
course.los.forEach((lo) => {
const topic = lo as Topic;
topic.toc = [];
topic.toc.push(...topic.panels.panelVideos, ...topic.panels.panelTalks, ...topic.panels.panelNotes, ...topic.units.units, ...topic.units.standardLos, ...topic.units.sides);

topic.toc.forEach((lo) => {
lo.parentLo = course;
lo.parentTopic = topic;
if (lo.type === "unit" || lo.type === "side") {
const composite = lo as Composite;
composite.los.forEach((subLo) => {
subLo.parentTopic = topic;
});
}
});
if (lo.type == "topic") {
const topic = lo as Topic;
topic.toc = [];
topic.toc.push(...topic.panels.panelVideos, ...topic.panels.panelTalks, ...topic.panels.panelNotes, ...topic.units.units, ...topic.units.standardLos, ...topic.units.sides);

topic.toc.forEach((lo) => {
lo.parentLo = course;
lo.parentTopic = topic;
if (lo.type === "unit" || lo.type === "side") {
const composite = lo as Composite;
composite.los.forEach((subLo) => {
subLo.parentTopic = topic;
});
}
});
}
});
}

Expand Down

0 comments on commit e82e4c3

Please sign in to comment.