Преглед изворни кода

Create fontend for updating a gallery.

Lee Morgan пре 5 година
родитељ
комит
b3a79e5f56
3 измењених фајлова са 73 додато и 0 уклоњено
  1. 17 0
      controllers/gallery.js
  2. 2 0
      routes.js
  3. 54 0
      views/gallery/editGallery.html

+ 17 - 0
controllers/gallery.js

@@ -79,5 +79,22 @@ module.exports = {
             .catch((err)=>{
                 return res.json("ERROR: could not fetch gallery");
             });
+    },
+
+    /*
+    POST: updates a gallery
+    req.body = {
+        title: String
+        tags: String
+        location: String
+    }
+    req.files = {
+        images: [Image]
+    }
+    req.params.id = String (id of gallery)
+    */
+    updateGallery: function(req, res){
+        console.log(req.body);
+        console.log(req.files.images);
     }
 }

+ 2 - 0
routes.js

@@ -51,6 +51,8 @@ module.exports = function(app){
     app.get("/gallery/new", (req, res)=>{res.sendFile(`${views}/gallery/new.html`)});
     app.post("/gallery/new", gallery.create);
     app.get("/gallery/retrieve", gallery.getGalleries);
+    app.get("/gallery/edit/:id", (req, res)=>{res.sendFile(`${views}/gallery/editGallery.html`)});
+    app.post("/gallery/update/:id", gallery.updateGallery);
     app.get("/gallery/json/:id", gallery.getGallery);
     app.get("/gallery/:id", (req, res)=>{res.sendFile(`${views}/gallery/index.html`)});
 

+ 54 - 0
views/gallery/editGallery.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>Lee Morgan</title>
+        <style>
+            form{
+                display: flex;
+                flex-direction: column;
+            }
+        </style>
+    </head>
+    <body>
+        <form
+            id="form"
+            method="post"
+            enctype="multipart/form-data"
+        >
+            <label>Title
+                <input id="titleInput" name="title" type="text" required>
+            </label>
+
+            <label>Tags
+                <input id="tagInput" name="tags" type="text" required>
+            </label>
+
+            <label>Location
+                <input id="locationInput" name="location" type="tags" required>
+            </label>
+            
+            <label>New Images
+                <input name="images" type="file" multiple>
+            </label>
+
+            <input type="submit" value="Submit">
+        </form>
+
+        <script>
+            let id = window.location.href.split("/");
+            id = id[id.length-1];
+
+            fetch(`/gallery/json/${id}`)
+                .then(response => response.json())
+                .then((gallery)=>{
+                    document.getElementById("titleInput").value = gallery.title;
+                    document.getElementById("tagInput").value = gallery.tags.toString();
+                    document.getElementById("locationInput").value = gallery.location.coordinates.toString().replaceAll(",", ", ");
+                })
+                .catch((err)=>{console.log(err)});
+
+            let form = document.getElementById("form");
+        </script>
+    </body>
+</html>