From 3de3dff1c1e8fc3e65eaf7bf650821c30d07002b Mon Sep 17 00:00:00 2001 From: TinnaLiu Date: Mon, 27 Feb 2023 18:44:17 -0800 Subject: [PATCH] feat: customized oer and license support --- src/ProblemLayout/Problem.js | 54 ++++++++++++++++++++++++++++-------- src/config/config.js | 4 ++- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/ProblemLayout/Problem.js b/src/ProblemLayout/Problem.js index 7ea8212a37c..de757001e0c 100644 --- a/src/ProblemLayout/Problem.js +++ b/src/ProblemLayout/Problem.js @@ -285,9 +285,40 @@ class Problem extends React.Component { return this.context.problemIDs[this.context.problemIDs.indexOf(this.state.problem.id) + offset] || "/" } + getOerLicense = () => { + const { lesson, problem } = this.props; + var oerArray, licenseArray; + var oerLink, oerName; + var licenseLink, licenseName; + + if (problem.oer != null && problem.oer.includes(" <")) { + oerArray = problem.oer.split(" <"); + } else if (lesson.courseOER != null && lesson.courseOER.includes(" ")) { + oerArray = lesson.courseOER.split(" <"); + } else { + oerArray = ["https://OATutor.io", "OATutor>"]; + } + + oerLink = oerArray[0]; + oerName = oerArray[1].substring(0, oerArray[1].length - 1); + + if (problem.license != null && problem.license.includes(" ")) { + licenseArray = problem.license.split(" <"); + } else if (lesson.courseLicense != null && lesson.courseLicense.includes(" ")) { + licenseArray = lesson.courseLicense.split(" <"); + } else { + licenseArray = ["", ""]; + } + + licenseLink = licenseArray[0]; + licenseName = licenseArray[1].substring(0, licenseArray[1].length - 1); + return [oerLink, oerName, licenseLink, licenseName]; + } + render() { - const { classes, lesson } = this.props; + const { classes, lesson, problem } = this.props; + const [oerLink, oerName, licenseLink, licenseName] = this.getOerLicense(); if (this.state.problem == null) { return (
); @@ -356,18 +387,19 @@ class Problem extends React.Component {