Skip to content

Commit

Permalink
Merge branch 'pepf-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Jul 13, 2014
2 parents 1fa5b7d + fa7de85 commit 1500513
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 18 deletions.
3 changes: 3 additions & 0 deletions client/lib/globalhelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Handlebars.registerHelper('username', function(user){
}
});

//avatar as responsive image
Handlebars.registerHelper('avatar', function(id){
if(Meteor.users.findOne(id) == null) { return; }
var avatar = Meteor.users.findOne(id).profile.avatar;
Expand All @@ -41,6 +42,8 @@ Handlebars.registerHelper('avatar', function(id){
return '<img class="img-circle img-responsive avatar" src="'+url+'">';
});



Handlebars.registerHelper('currentRoute', function() {
var currentRoute = Router.current();
if (!currentRoute) { return ''; } else {
Expand Down
15 changes: 15 additions & 0 deletions client/stylesheets/fusic.import.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@ img.avatar {
background-color:@gray-lighter;
width:300px;
height:100%;
}

div.avatar {
background-size:cover;
width:30px;
height:30px;
border-radius:100%;
margin:5%;
float:left;
opacity:0.75;
&:hover {
opacity:1.0;
cursor:pointer;
}

}
30 changes: 28 additions & 2 deletions client/views/userProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
</div>
{{/if}}

<div class="col-md-12">
<h2>Friends</h2>
<div class="col-md-9">
<h2>Friends <span class="badge">{{this.profile.friends.length}}</span></h2>
{{#each userFriends}}
<div class="avatar" style="background-image:url('{{avatarUrl}}')"></div>
{{/each}}
</div>

</div>
Expand All @@ -40,6 +43,7 @@ <h2>Your playlists</h2>
<h1>{{this.username}}</h1>
<p>Joined: {{fromNow createdAt}}</p>
<p>Likes {{loveCount}} songs</p>
{{>addRemoveFriend}}
</div>
{{/if}}
</div>
Expand Down Expand Up @@ -82,3 +86,25 @@ <h1>{{this.username}}</h1>
</div>
</div>
</template>

<template name="addRemoveFriend">
<div class="button-group">
{{#if isFriend}}
<button class="btn btn-success dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-ok"></span>
<span class="glyphicon glyphicon-user"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a data-action="remove-friend"><span class="glyphicon glyphicon-trash"></span>Remove friend</a></li>
</ul>
{{else}}
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-user"></span>
<span class="glyphicon glyphicon-plus"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a data-action="add-friend"><span class="glyphicon glyphicon-plus"></span> Add as friend</a></li>
</ul>
{{/if}}
</div>
</template>
33 changes: 33 additions & 0 deletions client/views/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ Template.userProfile.rendered = function() {
Session.setDefault("showEditAvatarBar",false);
}

Template.userProfile.userFriends = function() {
return Meteor.users.find({_id: {$in: this.profile.friends}});
}
Template.userProfile.avatarUrl = function() {
if(this.profile.avatar) {
return this.profile.avatar;
} else {
return "/img/avatar.jpg";
}
}

Template.userProfile.events = {
'click [data-action="set-username"]': function() {
var newname = $("input#new-username").val();
Expand All @@ -17,6 +28,9 @@ Template.userProfile.events = {
},
'click [data-action="edit-avatar"]': function() {
Session.set("showEditAvatarBar",!Session.get("showEditAvatarBar"));
},
'click div.avatar': function() {
Router.go('userProfile', {_id: this._id});
}
}

Expand All @@ -40,3 +54,22 @@ Template.editAvatar.events = {
Session.set("showEditAvatarBar",false);
}
}

Template.addRemoveFriend.isFriend = function() {
return _.contains(Meteor.user().profile.friends,this._id);
}

Template.addRemoveFriend.events = {
'click [data-action="add-friend"]': function() {
Meteor.users.update(
{ _id: Meteor.userId() },
{ $addToSet : { 'profile.friends': this._id }}
);
},
'click [data-action="remove-friend"]': function() {
Meteor.users.update(
{ _id: Meteor.userId() },
{ $pull : { 'profile.friends': this._id }}
);
}
}
93 changes: 93 additions & 0 deletions collections.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,96 @@
SimpleSchema.debug = true;


//User Profile Schema
UserProfile = new SimpleSchema({
firstName: {
type: String,
regEx: /^[a-zA-Z-]{2,25}$/,
optional: true
},
lastName: {
type: String,
regEx: /^[a-zA-Z]{2,25}$/,
optional: true
},
birthday: {
type: Date,
optional: true
},
gender: {
type: String,
allowedValues: ['Male', 'Female'],
optional: true
},
website: {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true
},
bio: {
type: String,
optional: true
},
lovedSongs: {
type: [String],
},
avatar: {
type: String,
regEx: SimpleSchema.RegEx.Url,
optional: true
},
friends: {
type: [String]
},
following: {
optional:true,
type: [String],
},
playing: {
optional:true,
type: [Object]
}


});

//User Schema
UserSchema = new SimpleSchema({
_id: {
type: String,
regEx: SimpleSchema.RegEx.Id
},
username: {
type: String,
regEx: /^[a-z0-9A-Z_]{3,15}$/
},
emails: {
type: [Object]
},
"emails.$.address": {
type: String,
regEx: SimpleSchema.RegEx.Email
},
"emails.$.verified": {
type: Boolean
},
createdAt: {
type: Date
},
profile: {
type: UserProfile,
optional: true
},
services: {
type: Object,
optional: true,
blackbox: true
}
});

Meteor.users.attachSchema(UserSchema);

//Playlist Schema
Playlists = new Meteor.Collection('playlists', {
schema: {
owner: {
Expand Down Expand Up @@ -76,8 +167,10 @@ Playlists = new Meteor.Collection('playlists', {
}
});

//Songcache
Songs = new Meteor.Collection('songs');

//PlayCounts schema
PlayCounts = new Meteor.Collection('playCounts', {
schema: {
songId: {
Expand Down
8 changes: 4 additions & 4 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ Router.map(function() {
this.route('userProfile', {
path:'/profile/:_id',
waitOn: function() {
return [
Meteor.subscribe('userData',this.params._id),
Meteor.subscribe('playlistsByUser', this.params._id)];
return
Meteor.subscribe('playlistsByUser', this.params._id);
},
data: function () {
var user = Meteor.users.findOne(this.params._id);
var playlists = Playlists.find( {owner: user._id} );

var playlists = Playlists.find( {owner: this.params._id} );
user.userPlaylists = playlists;
return user;
},
Expand Down
15 changes: 3 additions & 12 deletions server/lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Meteor.publish("allusers", function () {
return Meteor.users.find({},
{fields: {'username': 1, 'profile': 1}});
{fields: {'username': 1, 'profile': 1, 'createdAt':1}});
});

Meteor.publish("allplaylists", function () {
Expand All @@ -11,22 +11,13 @@ Meteor.publish("playlist", function (id) {
return Playlists.find({_id: id});
});

//songs by id
Meteor.publish("songs", function (ids) {
check(ids, [String]);
return Songs.find({_id: {$in: ids}});
});

Meteor.publish("userData", function (id) {
check(id,String);
return Meteor.users.find({_id: id},
{fields: {'_id':1,
'username': 1,
'profile': 1,
'createdAt':1,
'emails':1
}});
});

//Playlists from one user
Meteor.publish("playlistsByUser", function(userId) {
return Playlists.find({owner:userId},
{ sort: {createdAt: 1},
Expand Down

0 comments on commit 1500513

Please sign in to comment.