Parcourir la source

Create the main page for the galleries list.

Lee Morgan il y a 5 ans
Parent
commit
8ab75dc883
5 fichiers modifiés avec 143 ajouts et 12 suppressions
  1. 1 0
      routes.js
  2. 86 0
      views/gallery/galleries.html
  3. 55 5
      views/gallery/index.css
  4. 1 5
      views/main/index.css
  5. 0 2
      views/main/index.html

+ 1 - 0
routes.js

@@ -44,6 +44,7 @@ module.exports = function(app){
 
     //GALLERY
     app.get("/gallery/style", (req, res)=>{res.sendFile(`${views}/gallery/index.css`)});
+    app.get("/gallery", (req, res)=>{res.sendFile(`${views}/gallery/galleries.html`)});
     app.get("/gallery/new", (req, res)=>{res.sendFile(`${views}/gallery/new.html`)});
     app.post("/gallery/new", gallery.create);
     app.get("/gallery/retrieve", gallery.getGalleries);

+ 86 - 0
views/gallery/galleries.html

@@ -0,0 +1,86 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>Lee Morgan -gallery-</title>
+        <link rel="stylesheet" href="/gallery/style">
+    </head>
+    <body id="galleryBody">
+        <h1>Gallery</h1>
+
+        <div id="tags"></div>
+
+        <div id="container"></div>
+
+        <template id="card">
+            <a class="card">
+                <h2></h2>
+
+                <img>
+            </a>
+        </template>
+        
+        <script>
+            let container = document.getElementById("container");
+            let template = document.getElementById("card").content.children[0];
+
+            let populateGalleries = (galleries)=>{
+                while(container.children.length > 0){
+                    container.removeChild(container.firstChild);
+                }
+
+                for(let i = 0; i < galleries.length; i++){
+                    let card = template.cloneNode(true);
+                    card.href = `/gallery/${galleries[i]._id}`;
+                    card.children[0].innerText = galleries[i].title;
+                    card.children[1].src = galleries[i].images[0];
+                    card.children[1].alt = `${galleries[i].title} thumbnail`;
+                    container.appendChild(card);
+                }
+            }
+            
+            let searchTags = (galleries, tag)=>{
+                let galleryList = [];
+
+                for(let i = 0; i < galleries.length; i++){
+                    for(let j = 0; j < galleries[i].tags.length; j++){
+                        if(galleries[i].tags[j].toLowerCase() === tag.toLowerCase()){
+                            galleryList.push(galleries[i]);
+                            break;
+                        }
+                    }
+                }
+
+                return galleryList;
+            }
+
+            fetch("/gallery/retrieve")
+                .then(response => response.json())
+                .then((response)=>{
+                    let tagsContainer = document.getElementById("tags");
+                    let tags = [];
+
+                    populateGalleries(response);
+
+                    let tag = document.createElement("button");
+                    tag.innerText = "All";
+                    tag.onclick = ()=>{populateGalleries(response)};
+                    tagsContainer.appendChild(tag);
+
+                    for(let i = 0; i < response.length; i++){
+                        for(let j = 0; j < response[i].tags.length; j++){
+                            if(tags.includes(response[i].tags[j].toLowerCase())) continue;
+
+                            tags.push(response[i].tags[j].toLowerCase());
+                            
+                            let tag = document.createElement("button");
+                            tag.innerText = response[i].tags[j];
+                            tag.onclick = ()=>{populateGalleries(searchTags(response, response[i].tags[j]))};
+                            tagsContainer.appendChild(tag);
+                        }
+                    }
+                })
+                .catch((err)=>{});
+        </script>
+    </body>
+</html>

+ 55 - 5
views/gallery/index.css

@@ -7,7 +7,6 @@ body{
 h1{
     margin: 25px 0;
     text-align: center;
-    border-bottom: 2px solid black;
 }
 
 #tags{
@@ -17,12 +16,26 @@ h1{
     margin: auto;
 }
 
-    #tags > *{
+    #tags *{
+        display: flex;
+        align-items: center;
         background: #152730;
         color: #5FECE0;
-        border-radius: 25px;
-        padding: 2px 10px;
-        margin: 0 5px;
+        border-radius: 20px;
+        padding: 0 25px;
+        margin: 10px;
+        border: none;
+        font-size: 20px;
+        min-width: 75px;
+        height: 30px;
+    }
+
+    #tags button{
+        cursor: pointer;
+    }
+
+    #tags button:hover{
+        box-shadow: 0 0 5px black;
     }
 
 #images{
@@ -87,4 +100,41 @@ h1{
 
     #previousImg{
         left: 50px;
+    }
+
+#galleryBody{
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+}
+
+    #container{
+        display: flex;
+        justify-content: center;
+        flex-wrap: wrap;
+    }
+
+.card{
+    display: flex;
+    flex-direction: column;
+    justify-content: space-around;
+    align-items: center;
+    text-align: center;
+    background: white;
+    width: 300px;
+    height: 300px;
+    cursor: pointer;
+    margin: 10px;
+    padding: 25px;
+    text-decoration: none;
+    color: black;
+}
+
+    .card:hover{
+        box-shadow: 0 0 3px black;
+    }
+
+    .card img{
+        max-height: 75%;
+        max-width: 75%;
     }

+ 1 - 5
views/main/index.css

@@ -106,10 +106,6 @@ body{
     overflow-y: auto;
 }
 
-    #gallery h2{
-        margin-top: 25px;
-    }
-
     #galleryTags{
         display: flex;
         justify-content: center;
@@ -129,7 +125,7 @@ body{
             min-width: 75px;
             border-radius: 20px;
             height: 30px;
-            border: 1px solid black;
+            border: none;
             padding: 0 25px;
             margin: 10px;
             cursor: pointer;

+ 0 - 2
views/main/index.html

@@ -159,8 +159,6 @@
             </div>
 
             <div id="gallery" style="display:none">
-                <h2>Tags</h2>
-
                 <div id="galleryTags"></div>
 
                 <div id="galleryContainer"></div>