Pārlūkot izejas kodu

added 'liked songs' area on profile page

AkiraLaine 9 gadi atpakaļ
vecāks
revīzija
72e9a84013

+ 17 - 1
app/client/client.js

@@ -61,6 +61,22 @@ Template.profile.helpers({
     },
     loaded: function() {
         return Session.get("loaded");
+    },
+    likedSongs: function(){
+        var user = Meteor.user();
+        var likedArr = [];
+        user.profile.liked.forEach(function(id){
+            Rooms.find().forEach(function(room){
+                Playlists.find({type: room.type}).forEach(function(pl){
+                    for(var i in pl.songs){
+                        if(pl.songs[i].mid === id){
+                            likedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist});
+                        }
+                    }
+                });
+            })
+        })
+        return likedArr;
     }
 });
 
@@ -1042,7 +1058,7 @@ Template.playlist.events({
                     $(el).parent(".pl-item").show();
                 }
             })
-            $(".pl-item #artist").each(function(i, el){
+            $(".pl-item #pl-artist").each(function(i, el){
                 if($(el).text().toLowerCase().indexOf(input) !== -1){
                     $(el).parent(".pl-item").show();
                 }

+ 1 - 1
app/client/templates/playlist.html

@@ -6,7 +6,7 @@
             {{#if current}}<i class="fa fa-arrow-right"></i>{{/if}}
             <p style="float:right;padding-right:10px;font-weight:900">{{formatTime duration}}</p>
             <strong>{{title}}</strong>
-            <p>{{artist}}</p>
+            <p id="pl-artist">{{artist}}</p>
         </li>
       {{/each}}
     </ul>

+ 13 - 1
app/client/templates/profile.html

@@ -6,7 +6,7 @@
         {{#if loaded}}
             <h1 id="profile-name">{{username}}</h1>
 
-            <div class="col-md-4 col-md-offset-4">
+            <div class="col-md-4">
                 <div class="panel panel-primary">
                     <div class="panel-heading">Basic Info</div>
                     <div class="panel-body">
@@ -17,6 +17,18 @@
                     </div>
                 </div>
             </div>
+            <div class="col-md-4">
+                <div class="panel panel-success">
+                    <div class="panel-heading">Liked Songs</div>
+                    <div class="panel-body">
+                        <ul>
+                            {{#each likedSongs}}
+                                <li>{{title}} - {{artist}}</li>
+                            {{/each}}
+                        </ul>
+                    </div>
+                </div>
+            </div>
         {{else}}
             {{> loading}}
         {{/if}}