@@ -63,7 +63,7 @@ Template.user_page.onRendered(function () {
63
63
64
64
Template . user_page . helpers ( {
65
65
current_user :function ( ) {
66
- route = FlowRouter . current ( ) ;
66
+ const route = FlowRouter . current ( ) ;
67
67
return Meteor . users . findOne ( { _id : route . params . _id } ) ;
68
68
} ,
69
69
get_user_name ( id ) {
@@ -77,6 +77,10 @@ Template.user_page.helpers({
77
77
check_current_user ( ) {
78
78
return Meteor . userId ( ) == Template . instance ( ) . data . userId ;
79
79
} ,
80
+ get_playlist ( ) {
81
+ const route = FlowRouter . current ( ) ;
82
+ return Meteor . users . findOne ( { _id : route . params . _id } ) . playlist ;
83
+ } ,
80
84
init ( ) {
81
85
gapi . client . setApiKey ( 'AIzaSyBDDItQMbwlcF6q2bcZKKOyoISQxuhUk4Q' ) ;
82
86
gapi . client . load ( 'youtube' , 'v3' , function ( ) {
@@ -108,34 +112,57 @@ Template.user_page.events({
108
112
part : 'snippet' ,
109
113
maxResults : 5
110
114
} ) ;
111
-
112
115
request . execute ( function ( response ) {
113
-
114
- // var str = JSON.stringify(response.result);
115
- // Meteor.users.update({ _id: Meteor.userId() }, {
116
- // $set:{
117
- // song_id: response.items[0].id.videoId,
118
- // song_name: response.items[0].snippet.title,
119
- // }
120
- // });
121
116
var options_str = '<li></li>' ;
122
117
response . items . forEach ( function ( item ) {
123
- options_str += '<li style="cursor: pointer" class="song_li" song_id="' + item . id . videoId + '" song_name="' + item . snippet . title + '">' +
124
- '<div style="display: inline-block"><img src="' + item . snippet . thumbnails . default . url + '"/></div>' +
125
- '<div style="display: inline-block; position: relative;top: -40px;font-size:large; padding: 10px">' + item . snippet . title + '</div></li>' ;
118
+ options_str +=
119
+ '<li style="class="song_li" song_id="' + item . id . videoId + '" song_name="' + item . snippet . title + '">' +
120
+ '<div style="display: inline-block">' +
121
+ '<img src="' + item . snippet . thumbnails . default . url + '"/>' +
122
+ '</div>' +
123
+ '<div style="display: inline-block; position: relative;top: -40px; font-size:large; padding: 10px;max-width: 325px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">' +
124
+ item . snippet . title +
125
+ '</div>' +
126
+ '<br/>' +
127
+ '<button class="add_to_playlist">Add to playlist</button> ' +
128
+ '<button class="play">Play</button>' +
129
+ '</li>' ;
126
130
} ) ;
127
-
128
131
$ ( '#search-container' ) . html ( '<br/><ul>' + options_str + '</ul>' ) ;
129
132
} ) ;
130
133
} ,
131
- 'click .song_li ' ( ) {
134
+ 'click .play ' ( ) {
132
135
Meteor . users . update ( { _id : Meteor . userId ( ) } , {
133
136
$set :{
134
137
song_id : $ ( event . target ) . parent ( 'li' ) . attr ( 'song_id' ) ,
135
138
song_name : $ ( event . target ) . parent ( 'li' ) . attr ( 'song_name' ) ,
136
139
}
137
140
} ) ;
138
141
} ,
142
+ 'click .add_to_playlist' ( ) {
143
+ Meteor . users . update ( { _id : Meteor . userId ( ) } ,
144
+ {
145
+ $addToSet : {
146
+ playlist : {
147
+ song_id : $ ( event . target ) . parent ( 'li' ) . attr ( 'song_id' ) ,
148
+ song_name : $ ( event . target ) . parent ( 'li' ) . attr ( 'song_name' )
149
+ }
150
+ }
151
+ }
152
+ ) ;
153
+ } ,
154
+ 'click .remove_from_playlist' ( ) {
155
+ Meteor . users . update ( { _id : Meteor . userId ( ) } ,
156
+ {
157
+ $pull : {
158
+ playlist : {
159
+ song_id : $ ( event . target ) . attr ( 'song_id' ) ,
160
+ song_name : $ ( event . target ) . attr ( 'song_name' )
161
+ }
162
+ }
163
+ }
164
+ ) ;
165
+ } ,
139
166
'keyup #query' ( ) {
140
167
if ( event . keyCode == 13 ) {
141
168
var q = $ ( '#query' ) . val ( ) ;
@@ -145,15 +172,22 @@ Template.user_page.events({
145
172
part : 'snippet' ,
146
173
maxResults : 5
147
174
} ) ;
148
-
149
175
request . execute ( function ( response ) {
150
176
var options_str = '<li></li>' ;
151
177
response . items . forEach ( function ( item ) {
152
- options_str += '<li style="cursor: pointer" class="song_li" song_id="' + item . id . videoId + '" song_name="' + item . snippet . title + '">' +
153
- '<div style="display: inline-block"><img src="' + item . snippet . thumbnails . default . url + '"/></div>' +
154
- '<div style="display: inline-block; position: relative;top: -40px;font-size:large; padding: 10px">' + item . snippet . title + '</div></li>' ;
178
+ options_str +=
179
+ '<li style="class="song_li" song_id="' + item . id . videoId + '" song_name="' + item . snippet . title + '">' +
180
+ '<div style="display: inline-block">' +
181
+ '<img src="' + item . snippet . thumbnails . default . url + '"/>' +
182
+ '</div>' +
183
+ '<div style="display: inline-block; position: relative;top: -40px; font-size:large; padding: 10px;max-width: 325px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">' +
184
+ item . snippet . title +
185
+ '</div>' +
186
+ '<br/>' +
187
+ '<button class="add_to_playlist">Add to playlist</button> ' +
188
+ '<button class="play">Play</button>' +
189
+ '</li>' ;
155
190
} ) ;
156
-
157
191
$ ( '#search-container' ) . html ( '<br/><ul>' + options_str + '</ul>' ) ;
158
192
} ) ;
159
193
}
0 commit comments