Просмотр исходного кода

W3.7: apply user filtering of images.

Frederic G. MARAND 9 лет назад
Родитель
Сommit
f1a9a22836
3 измененных файлов с 12 добавлено и 8 удалено
  1. 2 1
      .eslintrc.js
  2. 1 4
      image_share.html
  3. 9 3
      image_share.js

+ 2 - 1
.eslintrc.js

@@ -13,7 +13,8 @@ module.exports = {
     "Mongo": true,
     "Template": true,
     "Images": true,
-    "Accounts": true
+    "Accounts": true,
+    "Session": true
   },
 
   "plugins": ["react"],

+ 1 - 4
image_share.html

@@ -19,7 +19,6 @@
 </body>
 
 <template name="image_add_form">
-
   <div class="modal fade" id="image_add_form">
     <div class="modal-dialog">
       <div class="modal-content">
@@ -38,9 +37,7 @@
         </div>
       </div>
     </div>
-
   </div>
-
 </template>
 
 <template name="images">
@@ -57,7 +54,7 @@
           <div class="caption">
             <h3>Rating: {{ rating }}</h3>
             <p>{{ img_alt }}</p>
-            <p>User: {{ getUser createdBy }}</p>
+            <p>User: <a href="#" class="js-set-image-filter">{{ getUser createdBy }}</a></p>
             <p>{{> starsRating mutable=true class="js-rate-image" id=image_id }}</p>
             <button class="js-del-image btn btn-warning">delete</button>
           </div>

+ 9 - 3
image_share.js

@@ -7,7 +7,11 @@ if (Meteor.isClient) {
   });
 
   Template.images.helpers({
-    images: Images.find({}, { sort: { createdOn: -1, rating: -1 }}),
+    images: function () {
+      const createdBy = Session.get("userFilter");
+      const selector = createdBy ? { createdBy } : {};
+      return Images.find(selector, { sort: { createdOn: -1, rating: -1 }});
+    },
     image_id: function () {
       return "rating-" + this._id;
     },
@@ -47,10 +51,12 @@ if (Meteor.isClient) {
         { $set: { rating: rating }}
       );
     },
-    "click .js-show-image-form": function (event) {
+    "click .js-show-image-form": function () {
       $("#image_add_form").modal("show");
+    },
+    "click .js-set-image-filter": function () {
+      Session.set("userFilter", this.createdBy);
     }
-
   });
 
   Template.image_add_form.events({