Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions models/album.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var AlbumSchema = new mongoose.Schema({
artistName: String,
name: String,
releaseDate: String,
genre: [ String ]
});

var Album = mongoose.model('Album', AlbumSchema);
module.exports = Album;
2 changes: 2 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
var mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/tunely");

module.exports.album = require("./album.js");
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "An app for tracking your music collection",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
Expand All @@ -18,5 +19,8 @@
"homepage": "https://github.com/tgaff/tunely#readme",
"dependencies": {
"express": "^4.13.3"
},
"directories": {
"doc": "docs"
}
}
28 changes: 20 additions & 8 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
*/


/* hard-coded data! */
var sampleAlbums = [];
sampleAlbums.push({
Expand Down Expand Up @@ -34,20 +33,15 @@ sampleAlbums.push({
});
/* end of hard-coded data */




$(document).ready(function() {
console.log('app.js loaded!');
renderAlbum(sampleAlbums[0]);
});





// this function takes a single album and renders it to the page
function renderAlbum(album) {
console.log('rendering album:', album);


var albumHtml =
" <!-- one album -->" +
Expand Down Expand Up @@ -89,4 +83,22 @@ function renderAlbum(album) {
" <!-- end one album -->";

// render to the page with jQuery
sampleAlbums.forEach(function (element) {
$('#albums').append(albumHtml);
});
}

//Step 2

$.ajax({
method: 'GET',
url: '/api/albums',
success: function show_albums (data) {
sampleAlbums.forEach(function (element){
$("#albums").append("<p>" + "Artist Name: " + element.artistName + "</p>" );
$("#albums").append("<p>" + "Name: " + element.name + "</p>");
$("#albums").append("<p>" + "Release Date: " + element.releaseDate + "</p>");
$("#albums").append("<p>" + "Genres: " + element.genres + "</p><br>");
});
}
});
27 changes: 26 additions & 1 deletion seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,33 @@

var db = require("./models");

var Album = require("./models/album.js");

var albumsList =[
// put data here!
{
artistName: 'Nine Inch Nails',
name: 'The Downward Spiral',
releaseDate: '1994, March 8',
genres: [ 'industrial', 'industrial metal' ]
},
{
artistName: 'Metallica',
name: 'Metallica',
releaseDate: '1991, August 12',
genres: [ 'heavy metal' ]
},
{
artistName: 'The Prodigy',
name: 'Music for the Jilted Generation',
releaseDate: '1994, July 4',
genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ]
},
{
artistName: 'Johnny Cash',
name: 'Unchained',
releaseDate: '1996, November 5',
genres: [ 'country', 'rock' ]
}
];

db.Album.remove({}, function(err, albums){
Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ app.get('/', function homepage (req, res) {
res.sendFile(__dirname + '/views/index.html');
});

app.get('/api/albums', function albums_api (req, res){
res.json({albums: albums});
});


/*
* JSON API Endpoints
Expand Down
51 changes: 0 additions & 51 deletions views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,6 @@ <h2>Albums</h2>
<!-- albums! -->
<div id='albums'>




<!-- one album -->
<div class="row album">

<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">


<!-- begin album internal row -->
<div class='row'>
<div class="col-md-3 col-xs-12 thumbnail album-art">
<img src="http://placehold.it/800x800" alt="album image">
</div>

<div class="col-md-9 col-xs-12">
<ul class="list-group">
<li class="list-group-item">
<h4 class='inline-header'>Album Name:</h4>
<span class='album-name'>Ladyhawke</span>
</li>

<li class="list-group-item">
<h4 class='inline-header'>Artist Name:</h4>
<span class='artist-name'>Ladyhawke</span>
</li>

<li class="list-group-item">
<h4 class='inline-header'>Released date:</h4>
<span class='album-releaseDate'>2008, November 18</span>
</li>
</ul>
</div>

</div>
<!-- end of album internal row -->

<div class='panel-footer'>
</div>

</div>
</div>
</div>
</div>
<!-- end one album -->




</div>
</section>

Expand Down