Skip to content

Commit

Permalink
Keep users in the database.
Browse files Browse the repository at this point in the history
  • Loading branch information
PxlBuzzard committed Feb 15, 2014
1 parent e5c0b24 commit 6868110
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
standard-app-packages
preserve-inputs
http
highcharts-with-exporting
autopublish
1 change: 1 addition & 0 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Meteor.subscribe('songs');
Meteor.subscribe('accounts');
22 changes: 16 additions & 6 deletions client/views/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
<h3>Meteor: Last.FM check</h3>
<input type="text" id="userName" value="{{userName}}"></input>
<input type="button" value="Fetch" id="fetchButton" />

<ul>
{{#each recentTracks}}
<li>{{name}}, {{artist.text}}</li>
{{/each}}
</ul>

<div id="chart-graph"></div>

<h2>Users List</h2> {{ accountCount }}
<ul>
{{#each accounts}}
<li>{{user}}</li>
{{/each}}
</ul>

<h2>Recent Tracks</h2>
<ul>
{{#each recentTracks}}
<li>{{name}}, {{artist.text}}</li>
{{/each}}
</ul>
</template>
67 changes: 66 additions & 1 deletion client/views/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Template.hello.events({
window.alert("Error: " + err.reason);
console.log("error occured on receiving data on server. ", err);
} else if(respJson) {
console.log("respJson: ", respJson);
//console.log("respJson: ", respJson);
page++;
//window.alert(respJson.length + ' tracks received.');
if(Session.get('recentTracks'))
Expand All @@ -32,3 +32,68 @@ Template.hello.recentTracks = function () {
Template.hello.userName = function() {
return userName;
};

Template.hello.accounts = function() {
return Accounts.find();
};

Template.hello.accountCount = function() {
return Accounts.find().count();
};

Template.hello.graph = $(function () {

// Get the JSON and create the chart
json = {};
for(var i = 0; i < Session.get('recentTracks').length; ++i) {
//json.push({ Session.get('recentTracks')[i].date.uts });
//json[i] = Session.get('recentTracks')[i].date.uts;

//json[Session.get('recentTracks').artist['#text']] += (1 / Session.get('recentTracks').length) * 100;
}


$('#chart-graph').highcharts({

chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
type: 'pie',
name: 'Bands and such',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
});
15 changes: 15 additions & 0 deletions collections/accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Accounts = new Meteor.Collection('accounts');

Meteor.methods({
createNewAccount: function(json) {
//scrub the json
delete json.tracks;

// save the meta
Accounts.insert(json);
},

updatePages: function(json) {

}
});
8 changes: 7 additions & 1 deletion collections/songs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Meteor.methods({
var result = HTTP.get(url, {timeout:30000});
if(result.statusCode === 200) {
var respJson = JSON.parse(result.content);
console.log(respJson.recenttracks['@attr'].user);

// grab the metadata about page numbers and update database
if (!Accounts.findOne({user: respJson.recenttracks['@attr'].user}))
Meteor.call('createNewAccount', respJson.recenttracks['@attr']);

// go down to track list
respJson = respJson.recenttracks.track;

// clean last fm json
Expand All @@ -15,7 +22,6 @@ Meteor.methods({
delete respJson[i].artist['#text'];
}

console.log("response received.");
return respJson;
} else {
console.log("Response issue: ", result.statusCode);
Expand Down

0 comments on commit 6868110

Please sign in to comment.