style: fix linting issues met ESLint
This commit is contained in:
parent
a30c4d0d32
commit
aa1a85e64e
24 changed files with 76 additions and 90 deletions
|
@ -12,9 +12,9 @@ const attachmentService = {
|
|||
language: learningObjectId.language,
|
||||
version: learningObjectId.version,
|
||||
}, attachmentName);
|
||||
} else {
|
||||
}
|
||||
return attachmentRepo.findByMostRecentVersionOfLearningObjectAndName(learningObjectId.hruid, learningObjectId.language, attachmentName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,23 +68,15 @@ async function fetchLearningObjects(
|
|||
const nodes: LearningObjectNode[] = learningPathResponse.data[0].nodes;
|
||||
|
||||
if (!full) {
|
||||
return nodes.map((node) => {
|
||||
return node.learningobject_hruid;
|
||||
});
|
||||
return nodes.map((node) => node.learningobject_hruid);
|
||||
}
|
||||
|
||||
return await Promise.all(
|
||||
nodes.map(async (node) => {
|
||||
return dwengoApiLearningObjectProvider.getLearningObjectById({
|
||||
nodes.map(async (node) => dwengoApiLearningObjectProvider.getLearningObjectById({
|
||||
hruid: node.learningobject_hruid,
|
||||
language: learningPathId.language
|
||||
});
|
||||
})
|
||||
).then((objects) => {
|
||||
return objects.filter((obj): obj is FilteredLearningObject => {
|
||||
return obj !== null;
|
||||
});
|
||||
});
|
||||
}))
|
||||
).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null));
|
||||
} catch (error) {
|
||||
console.error('❌ Error fetching learning objects:', error);
|
||||
return [];
|
||||
|
@ -98,7 +90,7 @@ const dwengoApiLearningObjectProvider: LearningObjectProvider = {
|
|||
async getLearningObjectById(
|
||||
id: LearningObjectIdentifier
|
||||
): Promise<FilteredLearningObject | null> {
|
||||
let metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata`;
|
||||
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata`;
|
||||
const metadata = await fetchWithLogging<LearningObjectMetadata>(
|
||||
metadataUrl,
|
||||
`Metadata for Learning Object HRUID "${id.hruid}" (language ${id.language})`,
|
||||
|
|
|
@ -11,9 +11,9 @@ import databaseLearningObjectProvider from "./database-learning-object-provider"
|
|||
function getProvider(id: LearningObjectIdentifier): LearningObjectProvider {
|
||||
if (id.hruid.startsWith(getEnvVar(EnvVars.UserContentPrefix))) {
|
||||
return databaseLearningObjectProvider;
|
||||
} else {
|
||||
}
|
||||
return dwengoApiLearningObjectProvider;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ class ExternProcessor extends StringProcessor {
|
|||
|
||||
// If a seperate youtube-processor would be added, this code would need to move to that processor
|
||||
// Converts youtube urls to youtube-embed urls
|
||||
let match = /(.*youtube.com\/)watch\?v=(.*)/.exec(externURL)
|
||||
const match = /(.*youtube.com\/)watch\?v=(.*)/.exec(externURL)
|
||||
if (match) {
|
||||
externURL = match[1] + "embed/" + match[2];
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ class GiftProcessor extends StringProcessor {
|
|||
|
||||
let html = "<div class='learning-object-gift'>\n";
|
||||
let i = 1;
|
||||
for (let question of quizQuestions) {
|
||||
for (const question of quizQuestions) {
|
||||
html += ` <div class='gift-question' id='gift-q${i}'>\n`;
|
||||
html += " " + this.renderQuestion(question, i).replaceAll(/\n(.+)/g, "\n $1"); // replace for indentation.
|
||||
html += " " + this.renderQuestion(question, i).replaceAll(/\n(.+)/g, "\n $1"); // Replace for indentation.
|
||||
html += ` </div>\n`;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ export class MultipleChoiceQuestionRenderer extends GIFTQuestionRenderer<Multipl
|
|||
renderedHtml += `<p class='gift-stem' id='gift-q${questionNumber}-stem'>${question.stem.text}</p>\n`;
|
||||
}
|
||||
let i = 0;
|
||||
for (let choice of question.choices) {
|
||||
for (const choice of question.choices) {
|
||||
renderedHtml += `<div class="gift-choice-div">\n`;
|
||||
renderedHtml += ` <input type='radio' id='gift-q${questionNumber}-choice-${i}' name='gift-q${questionNumber}-choices' value="${i}"/>\n`;
|
||||
renderedHtml += ` <label for='gift-q${questionNumber}-choice-${i}'>${choice.text}</label>\n`;
|
||||
|
|
|
@ -11,7 +11,7 @@ class BlockImageProcessor extends InlineImageProcessor {
|
|||
}
|
||||
|
||||
override renderFn(imageUrl: string){
|
||||
let inlineHtml = super.render(imageUrl);
|
||||
const inlineHtml = super.render(imageUrl);
|
||||
return DOMPurify.sanitize(`<div>${inlineHtml}</div>`);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,53 +56,53 @@ function extractLearningObjectIdFromHref(href: string): LearningObjectIdentifier
|
|||
},
|
||||
|
||||
// When the syntax for a link is used => [text](href "title")
|
||||
// render a custom link when the prefix for a learning object is used.
|
||||
// Render a custom link when the prefix for a learning object is used.
|
||||
link(link: Link): string {
|
||||
const href = link.href;
|
||||
const title = link.title || "";
|
||||
const text = marked.parseInline(link.text); // There could for example be an image in the link.
|
||||
|
||||
if (href.startsWith(prefixes.learningObject)) {
|
||||
// link to learning-object
|
||||
// Link to learning-object
|
||||
const learningObjectId = extractLearningObjectIdFromHref(href);
|
||||
return `<a href="${getUrlStringForLearningObjectHTML(learningObjectId)}" target="_blank" title="${title}">${text}</a>`;
|
||||
} else {
|
||||
// any other link
|
||||
}
|
||||
// Any other link
|
||||
if (!isValidHttpUrl(href)) {
|
||||
throw new ProcessingError("Link is not a valid HTTP URL!");
|
||||
}
|
||||
//<a href="https://kiks.ilabt.imec.be/hub/tmplogin?id=0101" title="Notebooks Werking"><img src="Knop.png" alt="" title="Knop"></a>
|
||||
return `<a href="${href}" target="_blank" title="${title}">${text}</a>`;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
// When the syntax for an image is used => 
|
||||
// render a learning object, pdf, audio or video if a prefix is used.
|
||||
// Render a learning object, pdf, audio or video if a prefix is used.
|
||||
image(img: Image): string {
|
||||
const href = img.href;
|
||||
if (href.startsWith(prefixes.learningObject)) {
|
||||
// embedded learning-object
|
||||
// Embedded learning-object
|
||||
const learningObjectId = extractLearningObjectIdFromHref(href);
|
||||
return `
|
||||
<learning-object hruid="${learningObjectId.hruid}" language="${learningObjectId.language}" version="${learningObjectId.version}"/>
|
||||
`; // Placeholder for the learning object since we cannot fetch its HTML here (this has to be a sync function!)
|
||||
} else if (href.startsWith(prefixes.pdf)) {
|
||||
// embedded pdf
|
||||
let proc = new PdfProcessor();
|
||||
// Embedded pdf
|
||||
const proc = new PdfProcessor();
|
||||
return proc.render(href.split(/\/(.+)/, 2)[1]);
|
||||
} else if (href.startsWith(prefixes.audio)) {
|
||||
// embedded audio
|
||||
let proc = new AudioProcessor();
|
||||
// Embedded audio
|
||||
const proc = new AudioProcessor();
|
||||
return proc.render(href.split(/\/(.+)/, 2)[1]);
|
||||
} else if (href.startsWith(prefixes.extern) || href.startsWith(prefixes.video) || href.startsWith(prefixes.notebook)) {
|
||||
// embedded youtube video or notebook (or other extern content)
|
||||
let proc = new ExternProcessor();
|
||||
// Embedded youtube video or notebook (or other extern content)
|
||||
const proc = new ExternProcessor();
|
||||
return proc.render(href.split(/\/(.+)/, 2)[1]);
|
||||
} else {
|
||||
// embedded image
|
||||
let proc = new InlineImageProcessor();
|
||||
}
|
||||
// Embedded image
|
||||
const proc = new InlineImageProcessor();
|
||||
return proc.render(href)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class MarkdownProcessor extends StringProcessor {
|
|||
}
|
||||
|
||||
replaceLinks(html: string) {
|
||||
let proc = new InlineImageProcessor();
|
||||
const proc = new InlineImageProcessor();
|
||||
html = html.replace(/<img.*?src="(.*?)".*?(alt="(.*?)")?.*?(title="(.*?)")?.*?>/g, (
|
||||
match: string,
|
||||
src: string,
|
||||
|
@ -35,9 +35,7 @@ class MarkdownProcessor extends StringProcessor {
|
|||
altText: string,
|
||||
title: string,
|
||||
titleText: string
|
||||
) => {
|
||||
return proc.render(src);
|
||||
});
|
||||
) => proc.render(src));
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class ProcessingService {
|
|||
learningObject: LearningObject,
|
||||
fetchEmbeddedLearningObjects?: (loId: LearningObjectIdentifier) => Promise<LearningObject | null>
|
||||
): Promise<string> {
|
||||
let html = this.processors.get(learningObject.contentType)!.renderLearningObject(learningObject);
|
||||
const html = this.processors.get(learningObject.contentType)!.renderLearningObject(learningObject);
|
||||
if (fetchEmbeddedLearningObjects) {
|
||||
// Replace all embedded learning objects.
|
||||
return replaceAsync(
|
||||
|
|
|
@ -22,7 +22,7 @@ import {LearningPathTransition} from "../../entities/content/learning-path-trans
|
|||
*/
|
||||
async function getLearningObjectsForNodes(nodes: LearningPathNode[]): Promise<Map<LearningPathNode, FilteredLearningObject>> {
|
||||
// Fetching the corresponding learning object for each of the nodes and creating a map that maps each node to
|
||||
// its corresponding learning object.
|
||||
// Its corresponding learning object.
|
||||
const nullableNodesToLearningObjects = new Map<LearningPathNode, FilteredLearningObject | null>(
|
||||
await Promise.all(
|
||||
nodes.map(node =>
|
||||
|
@ -58,7 +58,7 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
|
|||
const image = learningPath.image ? learningPath.image.toString("base64") : undefined;
|
||||
|
||||
return {
|
||||
_id: `${learningPath.hruid}/${learningPath.language}`, // for backwards compatibility with the original Dwengo API.
|
||||
_id: `${learningPath.hruid}/${learningPath.language}`, // For backwards compatibility with the original Dwengo API.
|
||||
__order: order,
|
||||
hruid: learningPath.hruid,
|
||||
language: learningPath.language,
|
||||
|
|
|
@ -43,7 +43,7 @@ function transitionPossible(transition: LearningPathTransition, submitted: objec
|
|||
*/
|
||||
const learningPathPersonalizingService = {
|
||||
async calculatePersonalizedTrajectory(nodes: LearningPathNode[], pathFor: {student?: Student, group?: Group}): Promise<LearningPathNode[]> {
|
||||
let trajectory: LearningPathNode[] = [];
|
||||
const trajectory: LearningPathNode[] = [];
|
||||
|
||||
// Always start with the start node.
|
||||
let currentNode = nodes.filter(it => it.startNode)[0];
|
||||
|
@ -51,17 +51,17 @@ const learningPathPersonalizingService = {
|
|||
|
||||
while (true) {
|
||||
// At every node, calculate all the possible next transitions.
|
||||
let lastSubmission = await getLastRelevantSubmission(currentNode, pathFor);
|
||||
let submitted = lastSubmission === null ? null : JSON.parse(lastSubmission.content);
|
||||
let possibleTransitions = currentNode.transitions
|
||||
const lastSubmission = await getLastRelevantSubmission(currentNode, pathFor);
|
||||
const submitted = lastSubmission === null ? null : JSON.parse(lastSubmission.content);
|
||||
const possibleTransitions = currentNode.transitions
|
||||
.filter(it => transitionPossible(it, submitted));
|
||||
|
||||
if (possibleTransitions.length === 0) { // If there are none, the trajectory has ended.
|
||||
return trajectory;
|
||||
} else { // Otherwise, take the first possible transition.
|
||||
} // Otherwise, take the first possible transition.
|
||||
currentNode = possibleTransitions[0].node;
|
||||
trajectory.push(currentNode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue