Jelajahi Sumber

W4.8: added a parametric route image/:id.

Frederic G. MARAND 8 tahun lalu
induk
melakukan
ee099d3220
3 mengubah file dengan 43 tambahan dan 4 penghapusan
  1. 4 0
      client/image_share.css
  2. 20 2
      client/image_share.html
  3. 19 2
      client/main.js

+ 4 - 0
client/image_share.css

@@ -10,3 +10,7 @@
 body {
   padding-top: 50px;
 }
+
+.single-img {
+  max-width: 100%;
+}

+ 20 - 2
client/image_share.html

@@ -5,8 +5,18 @@
 <body>
 </body>
 
+<template name="ApplicationLayout">
+  {{> yield "navbar" }}
+  {{> yield "main" }}
+</template>
+
 <template name="welcome">
-  <h1>Welcome to image share {{ username }} !</h1>
+  <div class="container">
+    <div class="jumbotron">
+      <h1>Welcome to image share {{ username }} !</h1>
+      <a href="/images" class="btn btn-info">ENTER</a>
+    </div>
+  </div>
 </template>
 
 <template name="navbar">
@@ -17,6 +27,13 @@
   </nav>
 </template>
 
+<template name="image">
+  <div class="container">
+    <h2>{{ img_alt }}</h2>
+    <a href="/images"><img src="{{ img_src }}" class="single-img" /></a>
+  </div>
+</template>
+
 <template name="image_add_form">
   <div class="modal fade" id="image_add_form">
     <div class="modal-dialog">
@@ -41,6 +58,7 @@
 
 <template name="images">
   <div class="container">
+    {{> image_add_form }}
     {{#if currentUser }}
       <button class="btn btn-success js-show-image-form">add image</button>
     {{/if}}
@@ -54,7 +72,7 @@
         <div class="col-xs-12 col-md-3" id="{{_id}}">
           <div class="thumbnail">
 
-            <img class="thumbnail-img js-image" src="{{img_src}}" alt="{{img_alt}}" />
+            <a href="/image/{{ _id }}"><img class="thumbnail-img js-image" src="{{img_src}}" alt="{{img_alt}}" /></a>
 
             <div class="caption">
               <h3>Rating: {{ rating }}</h3>

+ 19 - 2
client/main.js

@@ -1,10 +1,27 @@
 // Routing.
+Router.configure({
+  layoutTemplate: "ApplicationLayout"
+});
+
 Router.route("/", function () {
-  this.render("navbar");
+  this.render("welcome", { to: "main" });
 });
 
 Router.route("/images", function () {
-  this.render("images");
+  this.render("navbar", { to: "navbar" });
+  this.render("images", { to: "main" });
+});
+
+Router.route("/image/:id", function (vars) {
+  this.render("navbar", { to: "navbar" });
+  this.render("image", {
+    to: "main",
+    data: function () {
+      const id = this.params.id;
+      const doc = Images.findOne({ _id: id });
+      return doc;
+    }
+  });
 });
 
 // Infiniscroll.