Procházet zdrojové kódy

Add "further reading" to the saved lectures.

Lee Morgan před 5 roky
rodič
revize
acb9782d4c
3 změnil soubory, kde provedl 53 přidání a 3 odebrání
  1. 18 1
      controllers/learn.js
  2. 4 0
      models/lecture.js
  3. 31 2
      views/learn/newLecture.html

+ 18 - 1
controllers/learn.js

@@ -51,6 +51,10 @@ module.exports = {
         title: String
         video: String
         description: String
+        furtherReading: [{
+            text: String
+            link: String
+        }]
         exercises: [String]
         documents: [{
             title: String
@@ -67,21 +71,34 @@ module.exports = {
                 if(req.body.uploader !== course.owner._id.toString()) throw "badOwner";
                 if(req.body.password !== course.owner.password) throw "badPass";
 
+
                 let exercises = [];
                 if(req.body.exercises !== "~"){
                     exercises = req.body.exercises.split("~");
                     exercises.splice(exercises.length - 1, 1);
                 }
 
+                let furtherReading = req.body.furtherReading.split("\r\n");
+                furtherReading.splice(furtherReading.length-1, 1);
+                let readings = [];
+                for(let i = 0; i < furtherReading.length; i+=2){
+                    readings.push({
+                        text: furtherReading[i],
+                        link: furtherReading[i+1]
+                    });
+                }
+
                 let lecture = new Lecture({
                     course: course._id,
                     title: req.body.title,
                     video: req.body.video,
                     description: req.body.description,
+                    furtherReading: readings,
                     exercises: exercises,
                     documents: []
                 });
 
+                
                 if(req.files !== null){
                     let files = req.files.documents;
                     if(files.length === undefined){
@@ -106,7 +123,7 @@ module.exports = {
                         }
                     }
                 }
-
+                
                 return lecture.save();
             })
             .then((lecture)=>{

+ 4 - 0
models/lecture.js

@@ -18,6 +18,10 @@ const LectureSchema = new mongoose.Schema({
         type: String,
         required: true,
     },
+    furtherReading: [{
+        text: String,
+        link: String
+    }],
     documents: [{
         name: String,
         link: String

+ 31 - 2
views/learn/newLecture.html

@@ -21,7 +21,7 @@
                 max-width: 250px;
             }
 
-            #exercises{
+            #exercises, #furtherReading{
                 display: flex;
                 flex-direction: column;
             }
@@ -74,12 +74,16 @@
 
             <h2>Exercises</h2>
             <button id="exerciseButton" type="button">Add Exercise</button>
-            
             <div id="exercises">
                 <label>Exercise 1<input type="text"></label>
             </div>
 
+            <h2>Further Reading</h2>
+            <button id="furtherButton" type="button">Add Link</button>
+            <div id="furtherReading"></div>
+
             <input id="hidden" name="exercises" type="hidden">
+            <input id="readingsHidden" name="furtherReading" type="hidden">
 
             <input type="submit" value="Submit">
         </form>
@@ -115,6 +119,25 @@
                 label.appendChild(input);
             }
 
+            //Add further reading
+            let furtherCount = 0;
+            let furtherDiv = document.getElementById("furtherReading");
+
+            document.getElementById("furtherButton").onclick = ()=>{
+                furtherCount++;
+                let label = document.createElement("label");
+                label.innerText = `Link ${furtherCount}`;
+                furtherDiv.appendChild(label);
+
+                let inputText = document.createElement("input");
+                inputText.type = "text";
+                label.appendChild(inputText);
+
+                let inputLink = document.createElement("input");
+                inputLink.type = "text";
+                label.appendChild(inputLink);
+            }
+
             //Submit
             let form = document.getElementById("form");
             form.onsubmit = ()=>{
@@ -124,7 +147,13 @@
                     exercises += `${div.children[i].children[0].value}~`;
                 }
 
+                let readings = ""
+                for(let i = 0; i < furtherDiv.children.length; i++){
+                    readings += `${furtherDiv.children[i].children[0].value}\n${furtherDiv.children[i].children[1].value}\n`;
+                }
+
                 document.getElementById("hidden").value = exercises;
+                document.getElementById("readingsHidden").value = readings;
 
                 form.submit();
             }