From b0a1318093237fd04100e00a178e0e9acdccf205 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Thu, 3 Mar 2016 11:54:38 -0800 Subject: [PATCH 01/30] end of step 1 sprint 1 --- package.json | 6 +++++- public/js/app.js | 39 ++++++++++++++++++++++++++++++++++----- views/index.html | 6 +++--- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0d3e4f8..3aff7f2 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ }, "homepage": "https://github.com/tgaff/tunely#readme", "dependencies": { - "express": "^4.13.3" + "express": "^4.13.3", + "body-parser": "^1.14.1", + "method-override": "^2.3.4", + "ejs": "^2.3.3", + "mongoose": "^4.0.7" } } diff --git a/public/js/app.js b/public/js/app.js index 164eb55..662964a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -9,24 +9,28 @@ /* hard-coded data! */ var sampleAlbums = []; sampleAlbums.push({ + id: 1, artistName: 'Ladyhawke', name: 'Ladyhawke', releaseDate: '2008, November 18', genres: [ 'new wave', 'indie rock', 'synth pop' ] }); sampleAlbums.push({ + id: 2, artistName: 'The Knife', name: 'Silent Shout', releaseDate: '2006, February 17', genres: [ 'synth pop', 'electronica', 'experimental' ] }); sampleAlbums.push({ + id: 3, artistName: 'Juno Reactor', name: 'Shango', releaseDate: '2000, October 9', genres: [ 'electronic', 'goa trance', 'tribal house' ] }); sampleAlbums.push({ + id: 4, artistName: 'Philip Wesley', name: 'Dark Night of the Soul', releaseDate: '2008, September 12', @@ -39,6 +43,7 @@ sampleAlbums.push({ $(document).ready(function() { console.log('app.js loaded!'); + renderAlbum(sampleAlbums); }); @@ -51,7 +56,7 @@ function renderAlbum(album) { var albumHtml = " " + - "
" + + "
" + "
" + "
" + "
" + @@ -64,15 +69,15 @@ function renderAlbum(album) { "
    " + "
  • " + "

    Album Name:

    " + - " " + "HARDCODED ALBUM NAME" + "" + + " " + "" + "
  • " + "
  • " + "

    Artist Name:

    " + - " " + "HARDCODED ARTIST NAME" + "" + + " " + "" + "
  • " + "
  • " + "

    Released date:

    " + - " " + "HARDCODED RELEASE DATE" + "" + + " " + "" + "
  • " + "
" + "
" + @@ -88,5 +93,29 @@ function renderAlbum(album) { "
" + " "; - // render to the page with jQuery + + // var panelBody = $("#albums"); + + // for(var i=0; iAlbums
  • Album Name:

    - Ladyhawke +
  • Artist Name:

    - Ladyhawke +
  • Released date:

    - 2008, November 18 +
From 7ccf0ce8e34b25e0d5e3293fee1bf1ce471f9877 Mon Sep 17 00:00:00 2001 From: nreddy216 Date: Thu, 3 Mar 2016 11:55:03 -0800 Subject: [PATCH 02/30] add space --- public/js/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/js/app.js b/public/js/app.js index 164eb55..c04a7f7 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -89,4 +89,6 @@ function renderAlbum(album) { " "; // render to the page with jQuery + + } From d3a4312def8d04807701b9a2d05ad0963147ac35 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Thu, 3 Mar 2016 12:14:55 -0800 Subject: [PATCH 03/30] Finishes Step 1 Sprint 1 --- public/js/app.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 662964a..53e13e1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -102,6 +102,7 @@ function renderAlbum(album) { // albumDiv.attr("id", "album-"+i); // } + // render to the page with jQuery sampleAlbums.forEach(function(album) { // console.log(album); @@ -111,10 +112,10 @@ function renderAlbum(album) { var $albumReleaseDate = $(".album-releaseDate"); $albumDiv.append(albumHtml); - $albumDiv.attr("data-album-id", album.id); - $albumName.html(album.name); - $artistName.html(album.artistName); - $albumReleaseDate.html(album.releaseDate); + + $albumName.last().html(album.name); + $artistName.last().html(album.artistName); + $albumReleaseDate.last().html(album.releaseDate); }); From 711e6646a47c99de594ba35edbb800d1027ab88a Mon Sep 17 00:00:00 2001 From: nreddy216 Date: Thu, 3 Mar 2016 12:16:00 -0800 Subject: [PATCH 04/30] did nothing --- public/js/app.js | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 53bf8b3..145347f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -96,27 +96,4 @@ function renderAlbum(album) { // render to the page with jQuery - // var panelBody = $("#albums"); - - // for(var i=0; i Date: Thu, 3 Mar 2016 12:17:13 -0800 Subject: [PATCH 05/30] merging --- public/js/app.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 662964a..278a8ed 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -104,17 +104,12 @@ function renderAlbum(album) { // render to the page with jQuery sampleAlbums.forEach(function(album) { - // console.log(album); - var $albumDiv = $("#albums"); - var $albumName = $(".album-name"); - var $artistName = $(".artist-name"); - var $albumReleaseDate = $(".album-releaseDate"); - - $albumDiv.append(albumHtml); - $albumDiv.attr("data-album-id", album.id); - $albumName.html(album.name); - $artistName.html(album.artistName); - $albumReleaseDate.html(album.releaseDate); + $("#albums").append(albumHtml); + $(".album-name").html("ciao"); + $(".artist-name").html(sampleAlbums.artistName); + $(".album-releaseDate").html(sampleAlbums.releaseDate); + + }); From 55014da744793b98e36caa9a65a37880f02421d1 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Thu, 3 Mar 2016 12:34:15 -0800 Subject: [PATCH 06/30] adds /api/albums --- public/js/app.js | 6 +----- server.js | 4 ++++ views/index.html | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 53e13e1..8fa79f6 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -9,28 +9,24 @@ /* hard-coded data! */ var sampleAlbums = []; sampleAlbums.push({ - id: 1, artistName: 'Ladyhawke', name: 'Ladyhawke', releaseDate: '2008, November 18', genres: [ 'new wave', 'indie rock', 'synth pop' ] }); sampleAlbums.push({ - id: 2, artistName: 'The Knife', name: 'Silent Shout', releaseDate: '2006, February 17', genres: [ 'synth pop', 'electronica', 'experimental' ] }); sampleAlbums.push({ - id: 3, artistName: 'Juno Reactor', name: 'Shango', releaseDate: '2000, October 9', genres: [ 'electronic', 'goa trance', 'tribal house' ] }); sampleAlbums.push({ - id: 4, artistName: 'Philip Wesley', name: 'Dark Night of the Soul', releaseDate: '2008, September 12', @@ -105,7 +101,7 @@ function renderAlbum(album) { // render to the page with jQuery sampleAlbums.forEach(function(album) { - // console.log(album); + console.log(album); var $albumDiv = $("#albums"); var $albumName = $(".album-name"); var $artistName = $(".artist-name"); diff --git a/server.js b/server.js index 5da137b..6cc4fd5 100644 --- a/server.js +++ b/server.js @@ -73,6 +73,10 @@ app.get('/api', function api_index (req, res){ }); }); +app.get('/api/albums', function album_index (req, res) { + res.json({albums}); +}); + /********** * SERVER * **********/ diff --git a/views/index.html b/views/index.html index ad68369..8b28e5d 100644 --- a/views/index.html +++ b/views/index.html @@ -38,15 +38,15 @@

Albums

-
+ -
+ - +
From 706009defe1b0c95c1899dc5a23d4b24cca8613b Mon Sep 17 00:00:00 2001 From: 93lucasp Date: Thu, 3 Mar 2016 12:35:16 -0800 Subject: [PATCH 07/30] merging1 --- views/index.html | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/views/index.html b/views/index.html index ad68369..46a1dd7 100644 --- a/views/index.html +++ b/views/index.html @@ -46,31 +46,7 @@

Albums

-
-
- album image -
- -
-
    -
  • -

    Album Name:

    - -
  • - -
  • -

    Artist Name:

    - -
  • - -
  • -

    Released date:

    - -
  • -
-
- -
+ " + @@ -124,5 +125,36 @@ function renderAlbum(album) { }); } +function buildSongsHtml (songs) { + var songStr = ""; + songs.forEach(function(song) { + songStr += ("(" + song.trackNumber + ") " + song.name + "– "); + }); + var songHtml = + "
  • " + + "

    Songs:

    " + + "" + songStr + "" + + "
  • "; + return songHtml; +} + + + + + + + + + + + + + + + + + + + + -// $.ajax('/api/albums'); diff --git a/seed.js b/seed.js index b213a5d..9194e8a 100644 --- a/seed.js +++ b/seed.js @@ -33,17 +33,45 @@ var albumsList =[ } ]; +var sampleSongs = []; + +sampleSongs.push({ name: 'Swamped', + trackNumber: 1 +}); +sampleSongs.push({ name: "Heaven's a Lie", + trackNumber: 2 +}); +sampleSongs.push({ name: 'Daylight Dancer', + trackNumber: 3 +}); +sampleSongs.push({ name: 'Humane', + trackNumber: 4 +}); +sampleSongs.push({ name: 'Self Deception', + trackNumber: 5 +}); +sampleSongs.push({ name: 'Aeon', + trackNumber: 6 +}); +sampleSongs.push({ name: 'Tight Rope', + trackNumber: 7 +}); + + albumsList.forEach(function(album) { + album.songs = sampleSongs; + }); + + Album.remove({}, function(err, albums){ Album.create(albumsList, function(err, albums){ if (err) { - return console.log('ERROR', err); - } - else{ - console.log("all albums:", albums); - console.log("created", albums.length, "albums"); - process.exit(); - mongoose.connection.close(); + return console.log('ERROR', err); + } else { + console.log("all albums:", albums); + console.log("created", albums.length, "albums"); + process.exit(); + mongoose.connection.close(); } }); From 8580c63abcd6668aa94bcb0ed1412e0169b5abe6 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 08:31:15 -0800 Subject: [PATCH 18/30] fixes a typo error --- public/js/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index ad8c7d5..047d52a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -70,8 +70,7 @@ function renderAlbum(album) { "
  • " + "

    Released date:

    " + " " + "" + - "
  • " + - buildSongsHtml(album.songs); + " " + buildSongsHtml(album.songs) + " " + "
    " + "
    " + From 4183fe85672aab6ad8524865d0ed9d475a8fe33f Mon Sep 17 00:00:00 2001 From: 93lucasp Date: Fri, 4 Mar 2016 09:16:47 -0800 Subject: [PATCH 19/30] Request Ajax completed and bug fixed --- public/js/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 312efe6..c4804fd 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -5,7 +5,7 @@ * */ -var Album = require('./models/album'); +// var Album = require('./models/album'); /* hard-coded data! */ // var sampleAlbums = []; @@ -37,8 +37,8 @@ var Album = require('./models/album'); $(document).ready(function() { - console.log('app.js loaded!'); - renderAlbum(sampleAlbums); + + renderAlbum(albums); }); @@ -94,7 +94,7 @@ function renderAlbum(album) { // }); $.getJSON( "/api/albums", function( data ) { - console.log("here are my albums:", data); + console.log("here are my albums:", data.albums); data.albums.forEach(function(album) { From 589a30aa787752e38090a15a45526361d3ba5e7a Mon Sep 17 00:00:00 2001 From: nreddy216 Date: Fri, 4 Mar 2016 09:29:48 -0800 Subject: [PATCH 20/30] changed placeholder text --- views/index.ejs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/views/index.ejs b/views/index.ejs index 3386586..604221a 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -27,7 +27,7 @@ - +
    @@ -42,7 +42,7 @@
    - +
    @@ -51,7 +51,7 @@
    - +
    @@ -60,7 +60,7 @@
    - +
    @@ -69,7 +69,7 @@
    - +
    @@ -77,7 +77,7 @@
    - +
    @@ -111,7 +111,7 @@
    - + From 3e13c93196717e74957f3c5bef28208b7074effa Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 09:34:32 -0800 Subject: [PATCH 21/30] adds model updates --- public/js/app.js | 50 ++++++++++++++++++++++++------------------------ server.js | 32 ------------------------------- 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 047d52a..ca3444c 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -8,31 +8,31 @@ var Album = require('./models/album'); /* hard-coded data! */ -// var sampleAlbums = []; -// sampleAlbums.push({ -// artistName: 'Ladyhawke', -// name: 'Ladyhawke', -// releaseDate: '2008, November 18', -// genres: [ 'new wave', 'indie rock', 'synth pop' ] -// }); -// sampleAlbums.push({ -// artistName: 'The Knife', -// name: 'Silent Shout', -// releaseDate: '2006, February 17', -// genres: [ 'synth pop', 'electronica', 'experimental' ] -// }); -// sampleAlbums.push({ -// artistName: 'Juno Reactor', -// name: 'Shango', -// releaseDate: '2000, October 9', -// genres: [ 'electronic', 'goa trance', 'tribal house' ] -// }); -// sampleAlbums.push({ -// artistName: 'Philip Wesley', -// name: 'Dark Night of the Soul', -// releaseDate: '2008, September 12', -// genres: [ 'piano' ] -// }); +var sampleAlbums = []; +sampleAlbums.push({ + artistName: 'Ladyhawke', + name: 'Ladyhawke', + releaseDate: '2008, November 18', + genres: [ 'new wave', 'indie rock', 'synth pop' ] + }); +sampleAlbums.push({ + artistName: 'The Knife', + name: 'Silent Shout', + releaseDate: '2006, February 17', + genres: [ 'synth pop', 'electronica', 'experimental' ] + }); +sampleAlbums.push({ + artistName: 'Juno Reactor', + name: 'Shango', + releaseDate: '2000, October 9', + genres: [ 'electronic', 'goa trance', 'tribal house' ] + }); +sampleAlbums.push({ + artistName: 'Philip Wesley', + name: 'Dark Night of the Soul', + releaseDate: '2008, September 12', + genres: [ 'piano' ] + }); /* end of hard-coded data */ diff --git a/server.js b/server.js index 866faa8..05662a5 100644 --- a/server.js +++ b/server.js @@ -23,37 +23,6 @@ app.use(express.static(__dirname + '/public')); * DATABASE * ************/ -/* hard-coded data */ -// var albums = []; -// albums.push({ -// _id: 132, -// artistName: 'Nine Inch Nails', -// name: 'The Downward Spiral', -// releaseDate: '1994, March 8', -// genres: [ 'industrial', 'industrial metal' ] -// }); -// albums.push({ -// _id: 133, -// artistName: 'Metallica', -// name: 'Metallica', -// releaseDate: '1991, August 12', -// genres: [ 'heavy metal' ] -// }); -// albums.push({ -// _id: 134, -// artistName: 'The Prodigy', -// name: 'Music for the Jilted Generation', -// releaseDate: '1994, July 4', -// genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ] -// }); -// albums.push({ -// _id: 135, -// artistName: 'Johnny Cash', -// name: 'Unchained', -// releaseDate: '1996, November 5', -// genres: [ 'country', 'rock' ] -// }); - /********** @@ -71,7 +40,6 @@ app.get('/', function homepage (req, res) { - /* * JSON API Endpoints */ From fd38fd1d341b83deb234982bec692a4ca616c120 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 11:00:10 -0800 Subject: [PATCH 22/30] non-functional sprint3 branch --- public/js/app.js | 94 +++++++++++++++++++++++------------------------- seed.js | 6 ++-- 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index bafe581..7629a7f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -7,43 +7,15 @@ // var Album = require('./models/album'); -/* hard-coded data! */ -var sampleAlbums = []; -sampleAlbums.push({ - artistName: 'Ladyhawke', - name: 'Ladyhawke', - releaseDate: '2008, November 18', - genres: [ 'new wave', 'indie rock', 'synth pop' ] - }); -sampleAlbums.push({ - artistName: 'The Knife', - name: 'Silent Shout', - releaseDate: '2006, February 17', - genres: [ 'synth pop', 'electronica', 'experimental' ] - }); -sampleAlbums.push({ - artistName: 'Juno Reactor', - name: 'Shango', - releaseDate: '2000, October 9', - genres: [ 'electronic', 'goa trance', 'tribal house' ] - }); -sampleAlbums.push({ - artistName: 'Philip Wesley', - name: 'Dark Night of the Soul', - releaseDate: '2008, September 12', - genres: [ 'piano' ] - }); -/* end of hard-coded data */ - $(document).ready(function() { - renderAlbum(albums); + renderAlbum(); }); // this function takes a single album and renders it to the page -function renderAlbum(album) { +function renderAlbum() { var albumHtml = @@ -70,7 +42,7 @@ function renderAlbum(album) { "
  • " + "

    Released date:

    " + " " + "" + - "
  • " + buildSongsHtml(album.songs) + + " " + buildSongsHtml() + " " + " " + " " + @@ -93,14 +65,18 @@ function renderAlbum(album) { // alert( "Load was performed." ); // }); + $.getJSON( "/api/albums", function( data ) { - console.log("here are my albums:", data.albums); + // console.log("here are my albums:", data.albums); data.albums.forEach(function(album) { - - console.log(album); + // console.log(album.songs[1].trackNumber); + buildSongsHtml(album); + + + // console.log(album); var $albumDiv = $("#albums"); $albumDiv.append(albumHtml); @@ -116,32 +92,52 @@ $.getJSON( "/api/albums", function( data ) { }); -}); - + }); +} +// $.getJSON( "/api/albums", function( data ) { + +// function buildSongsHtml(songs) { +// var songText = " – "; +// data.albums.songs.forEach(function(song) { +// songText = songText + "(" + song.trackNumber + ") " + song.name + " – "; +// }); +// var songsHtml = +// "
  • " + +// "

    Songs:

    " + +// " " + songText + "" + +// "
  • "; +// return songsHtml; +// } +// }); + + + - -} -function buildSongsHtml (songs) { +function buildSongsHtml (album) { var songStr = ""; - songs.forEach(function(song) { - songStr += ("(" + song.trackNumber + ") " + song.name + "– "); - }); - var songHtml = - "
  • " + - "

    Songs:

    " + - "" + songStr + "" + - "
  • "; - return songHtml; -} +// console.log(songs); + album.songs.forEach(function(song) { + // console.log(song.trackNumber); + songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; + + var songHtml = + "
  • " + + "

    Songs:

    " + + "" + songStr + "" + + "
  • "; + console.log(songHtml); + return songHtml; + }); +} diff --git a/seed.js b/seed.js index 9194e8a..254c8af 100644 --- a/seed.js +++ b/seed.js @@ -57,10 +57,10 @@ sampleSongs.push({ name: 'Tight Rope', trackNumber: 7 }); - albumsList.forEach(function(album) { - album.songs = sampleSongs; - }); +albumsList.forEach(function(album) { + album.songs = sampleSongs; +}); Album.remove({}, function(err, albums){ From 6368572aef4a19f530d456410395e07b6d88a197 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 11:34:35 -0800 Subject: [PATCH 23/30] adds songs onto albums --- public/js/app.js | 83 ++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 63 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 7629a7f..3c15b49 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -5,19 +5,22 @@ * */ -// var Album = require('./models/album'); - - +//MAIN FUNCTION $(document).ready(function() { - - renderAlbum(); + //AJAX REQUEST TO ALBUMS API + $.getJSON( "/api/albums", function( data ) { + //Data.albums is an array of all the albums + data.albums.forEach(function(album) { + //we are added an entire div to the Albums div with our data embedded in jQuery + renderAlbum(album); + }); + }); }); // this function takes a single album and renders it to the page -function renderAlbum() { - - +function renderAlbum(album) { + //our HTML that we are appending in a forEach loop var albumHtml = " " + "
    " + @@ -42,7 +45,8 @@ function renderAlbum() { "
  • " + "

    Released date:

    " + " " + "" + - "
  • " + buildSongsHtml() + + " " + + buildSongsHtml(album.songs) + " " + "
    " + " " + @@ -59,24 +63,7 @@ function renderAlbum() { - -// $.get( "ajax/test.html", function( data ) { -// $( ".result" ).html( data ); -// alert( "Load was performed." ); -// }); - - -$.getJSON( "/api/albums", function( data ) { - // console.log("here are my albums:", data.albums); - - - data.albums.forEach(function(album) { - - // console.log(album.songs[1].trackNumber); - buildSongsHtml(album); - - - // console.log(album); + //getting album div in order to append the HTML var $albumDiv = $("#albums"); $albumDiv.append(albumHtml); @@ -90,53 +77,24 @@ $.getJSON( "/api/albums", function( data ) { $albumReleaseDate.last().html(album.releaseDate); - }); - - }); -} - - - - -// $.getJSON( "/api/albums", function( data ) { - -// function buildSongsHtml(songs) { -// var songText = " – "; -// data.albums.songs.forEach(function(song) { -// songText = songText + "(" + song.trackNumber + ") " + song.name + " – "; -// }); -// var songsHtml = -// "
  • " + -// "

    Songs:

    " + -// " " + songText + "" + -// "
  • "; -// return songsHtml; -// } -// }); - +} -function buildSongsHtml (album) { +function buildSongsHtml (songs) { var songStr = ""; -// console.log(songs); - album.songs.forEach(function(song) { - // console.log(song.trackNumber); + + songs.forEach(function(song) { songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; - + + }); var songHtml = "
  • " + "

    Songs:

    " + "" + songStr + "" + "
  • "; - - console.log(songHtml); - return songHtml; - - }); - } @@ -154,4 +112,3 @@ function buildSongsHtml (album) { - From eae30f2f34611a79ff4bd3b3754636a1c7d8793b Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 11:57:15 -0800 Subject: [PATCH 24/30] adds album id's to divs' --- public/js/app.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 3c15b49..384615b 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -61,8 +61,6 @@ function renderAlbum(album) { " " + " "; - - //getting album div in order to append the HTML var $albumDiv = $("#albums"); @@ -71,17 +69,18 @@ function renderAlbum(album) { var $albumName = $(".album-name"); var $artistName = $(".artist-name"); var $albumReleaseDate = $(".album-releaseDate"); + // var $deleteButton = $(""); + var $albumId = album._id; + $albumDiv.attr('id', $albumId); + // console.log($albumId); $albumName.last().html(album.name); $artistName.last().html(album.artistName); $albumReleaseDate.last().html(album.releaseDate); - - - - } + function buildSongsHtml (songs) { var songStr = ""; @@ -104,6 +103,18 @@ function buildSongsHtml (songs) { + + + + + + + + + + + + From c0d395c606c817922dd48328dd942f935cb783dc Mon Sep 17 00:00:00 2001 From: 93lucasp Date: Fri, 4 Mar 2016 12:29:38 -0800 Subject: [PATCH 25/30] add modal --- public/js/app.js | 28 +++++++++++++++++++++++++--- views/index.ejs | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 384615b..d2d645e 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -14,7 +14,9 @@ $(document).ready(function() { //we are added an entire div to the Albums div with our data embedded in jQuery renderAlbum(album); }); + handleNewSongButtonClick(); }); + }); @@ -23,7 +25,7 @@ function renderAlbum(album) { //our HTML that we are appending in a forEach loop var albumHtml = " " + - "
    " + + "
    " + "
    " + "
    " + "
    " + @@ -55,6 +57,7 @@ function renderAlbum(album) { "
    " + // end of panel-body " " + "
    " + @@ -70,14 +73,15 @@ function renderAlbum(album) { var $artistName = $(".artist-name"); var $albumReleaseDate = $(".album-releaseDate"); // var $deleteButton = $(""); - var $albumId = album._id; - $albumDiv.attr('id', $albumId); + // console.log($albumId); $albumName.last().html(album.name); $artistName.last().html(album.artistName); $albumReleaseDate.last().html(album.releaseDate); + + } @@ -96,6 +100,24 @@ function buildSongsHtml (songs) { return songHtml; } +function handleNewSongButtonClick() { + $('#albums').on('click', '.add-song', function(e) { + + + + + var id= $(this).parents('.album').data('album-id'); // "5665ff1678209c64e51b4e7b" + console.log('id',id); + console.log(id); + $('#songModal').modal(); + $('#songModal').data('album-id', id); +}); + // get the current album's id from the row the button is in + // set the album-id data attribute on the modal (jquery) + + // display the modal +} + diff --git a/views/index.ejs b/views/index.ejs index 604221a..8d1f3a2 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -101,6 +101,8 @@

    Albums

    +
    +
    From 46adde36b0aece6aa8d1f0d7a7cc9c4ddb939f43 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Fri, 4 Mar 2016 13:11:31 -0800 Subject: [PATCH 26/30] about to pull --- public/js/app.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 384615b..c15c32e 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -69,10 +69,8 @@ function renderAlbum(album) { var $albumName = $(".album-name"); var $artistName = $(".artist-name"); var $albumReleaseDate = $(".album-releaseDate"); - // var $deleteButton = $(""); - var $albumId = album._id; - $albumDiv.attr('id', $albumId); - // console.log($albumId); + var $deleteButton = ""; + $albumName.last().html(album.name); $artistName.last().html(album.artistName); From c7d41e1ae5d5d2ae7bfed748e45dbf4866957ad0 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Sun, 6 Mar 2016 12:35:51 -0800 Subject: [PATCH 27/30] removes previous functionality, adds ajax work --- public/js/app.js | 163 ++++++++++++++++++++++++----------------- public/js/secondApp.js | 74 +++++++++++++++++++ 2 files changed, 168 insertions(+), 69 deletions(-) create mode 100644 public/js/secondApp.js diff --git a/public/js/app.js b/public/js/app.js index 4ab3772..9113731 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -8,21 +8,46 @@ //MAIN FUNCTION $(document).ready(function() { //AJAX REQUEST TO ALBUMS API - $.getJSON( "/api/albums", function( data ) { - //Data.albums is an array of all the albums - data.albums.forEach(function(album) { - //we are added an entire div to the Albums div with our data embedded in jQuery - renderAlbum(album); - }); - handleNewSongButtonClick(data.albums); - }); + // $.getJSON( "/api/albums", function( data ) { + // //Data.albums is an array of all the albums + // data.albums.forEach(function(album) { + // //we are added an entire div to the Albums div with our data embedded in jQuery + // renderAlbum(album); + // }); + // handleNewSongButtonClick(data.albums); + // }); + var $albums = $('#albums'); + + $.ajax({ + type: 'GET', + url: '/api/albums', + success: function(data){ + $.each(data.albums, function(i, album) { + console.log(album); + renderAlbum(album); + }); + }, + error: function(err) { + alert("error loading " + err); + } + }); + + $.ajax({ + + }); + +//end of document ready }); + + // this function takes a single album and renders it to the page function renderAlbum(album) { - //our HTML that we are appending in a forEach loop + // console.log('rendering album:', album); + console.log(album); + var albumHtml = " " + "
    " + @@ -38,17 +63,19 @@ function renderAlbum(album) { "
      " + "
    • " + "

      Album Name:

      " + - " " + "" + + " " + album.name + "" + "
    • " + "
    • " + "

      Artist Name:

      " + - " " + "" + + " " + album.artistName + "" + "
    • " + "
    • " + "

      Released date:

      " + - " " + "" + - "
    • " + - buildSongsHtml(album.songs) + + " " + album.releaseDate + "" + + " " + + "
    • " + + " " + + "
    • " + "
    " + "
    " + "
    " + @@ -57,92 +84,90 @@ function renderAlbum(album) { "
    " + // end of panel-body " " + "
    " + " " + " "; - //getting album div in order to append the HTML + // getting album div in order to append the HTML var $albumDiv = $("#albums"); $albumDiv.append(albumHtml); - var $albumName = $(".album-name"); - var $artistName = $(".artist-name"); - var $albumReleaseDate = $(".album-releaseDate"); + // var $albumName = $(".album-name"); + // var $artistName = $(".artist-name"); + // var $albumReleaseDate = $(".album-releaseDate"); - var $deleteButton = ""; + // var $deleteButton = ""; - $albumName.last().html(album.name); - $artistName.last().html(album.artistName); - - $albumReleaseDate.last().html(album.releaseDate); + // $albumName.last().html(album.name); + // $artistName.last().html(album.artistName); + // $albumReleaseDate.last().html(album.releaseDate); } -function buildSongsHtml (songs) { - var songStr = ""; +// function buildSongsHtml (songs) { +// var songStr = ""; - songs.forEach(function(song) { - songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; +// songs.forEach(function(song) { +// songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; - }); - var songHtml = - "
  • " + - "

    Songs:

    " + - "" + songStr + "" + - "
  • "; - return songHtml; -} +// }); +// var songHtml = +// "
  • " + +// "

    Songs:

    " + +// "" + songStr + "" + +// "
  • "; +// return songHtml; +// } -function handleNewSongButtonClick(albums) { - $('#albums').on('click', '.add-song', function(e) { +// function handleNewSongButtonClick(albums) { +// $('#albums').on('click', '.add-song', function(e) { - var id= $(this).parents('.album').data('album-id'); // "5665ff1678209c64e51b4e7b" +// var id= $(this).parents('.album').data('album-id'); // "5665ff1678209c64e51b4e7b" - $('#songModal').attr('album-id', id); - $('#songModal').modal(); +// $('#songModal').attr('album-id', id); +// $('#songModal').modal(); - handleNewSongSubmit(albums, id); +// handleNewSongSubmit(albums, id); - }); -} +// }); +// } -function handleNewSongSubmit(albums, id) { - $('#saveSong').on('click', function(event) { - event.preventDefault(); +// function handleNewSongSubmit(albums, id) { +// $('#saveSong').on('click', function(event) { +// event.preventDefault(); - var album = albums.filter(function(selectedAlbum){ +// var album = albums.filter(function(selectedAlbum){ - if(id == selectedAlbum._id){ - return selectedAlbum; - // console.log(selectedAlbum._id); - } - }); +// if(id == selectedAlbum._id){ +// return selectedAlbum; +// // console.log(selectedAlbum._id); +// } +// }); - console.log(album[0].songs); - - - var $songName = $("#songName").val(); - var $trackNumber = $("#trackNumber").val(); - - var songObject = { - name: $songName, - trackNumber: $trackNumber - }; - // console.log(songObject); - // $.postJSON( "/api/albums", function( data ) { - album[0].songs.push(songObject); - // }); - }); -} +// console.log(album[0].songs); + + +// var $songName = $("#songName").val(); +// var $trackNumber = $("#trackNumber").val(); + +// var songObject = { +// name: $songName, +// trackNumber: $trackNumber +// }; +// // console.log(songObject); +// // $.postJSON( "/api/albums", function( data ) { +// album[0].songs.push(songObject); +// // }); +// }); +// } diff --git a/public/js/secondApp.js b/public/js/secondApp.js new file mode 100644 index 0000000..c625b90 --- /dev/null +++ b/public/js/secondApp.js @@ -0,0 +1,74 @@ +/* CLIENT-SIDE JS + * + * You may edit this file as you see fit. Try to separate different components + * into functions and objects as needed. + * + */ + + +$(document).ready(function() { + console.log('app.js loaded!'); + + var $albums = $('#albums'); + $.ajax({ + type: "GET", + url: '/api/albums', + success: function(albums){ + $.each(albums, function() { + $albums.append(album.Html); + }); + } + }); +}); + + + + + +// this function takes a single album and renders it to the page +function renderAlbum(album) { + console.log('rendering album:', album); + + var albumHtml = + " " + + "
    " + + "
    " + + "
    " + + "
    " + + " " + + "
    " + + "
    " + + " album image" + + "
    " + + "
    " + + "
      " + + "
    • " + + "

      Album Name:

      " + + " " + album.name + "" + + "
    • " + + "
    • " + + "

      Artist Name:

      " + + " " + album.artistName + "" + + "
    • " + + "
    • " + + "

      Released date:

      " + + " " + album.releaseDate + "" + + "
    • " + + "
    " + + "
    " + + "
    " + + " " + + + "
    " + // end of panel-body + + " " + + + "
    " + + "
    " + + " "; + + // render to the page with jQuery + + +} \ No newline at end of file From 6f658ebfaa1057545b0dd5421cdc7c5b5325bfc9 Mon Sep 17 00:00:00 2001 From: nreddy216 Date: Sun, 6 Mar 2016 13:37:37 -0800 Subject: [PATCH 28/30] added route and semi functional delete button --- public/js/app.js | 73 ++++++++++++++++++++---------------------------- server.js | 16 +++++++++++ 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 9113731..dc475a1 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -12,11 +12,11 @@ $(document).ready(function() { // //Data.albums is an array of all the albums // data.albums.forEach(function(album) { // //we are added an entire div to the Albums div with our data embedded in jQuery - // renderAlbum(album); + // renderAlbum(album); // }); // handleNewSongButtonClick(data.albums); // }); - + var $albums = $('#albums'); $.ajax({ @@ -33,9 +33,23 @@ $(document).ready(function() { } }); - $.ajax({ - }); + // DELETE method + $('#albums').delegate('.deleteBtn','click', function(){ + $.ajax({ + type: 'DELETE', + url: '/api/albums/' + $(this).attr('delete-album-id'), + success: function(){ + console.log("YAY DELETE"); + }, + error: function(){ + console.log("SOMETHING AINT WORKING"); + } + }); + }) + + + //end of document ready }); @@ -84,6 +98,9 @@ function renderAlbum(album) { "
    " + // end of panel-body " " + " " + @@ -92,9 +109,9 @@ function renderAlbum(album) { // getting album div in order to append the HTML var $albumDiv = $("#albums"); - + $albumDiv.append(albumHtml); - + // var $albumName = $(".album-name"); // var $artistName = $(".artist-name"); // var $albumReleaseDate = $(".album-releaseDate"); @@ -103,11 +120,10 @@ function renderAlbum(album) { // $albumName.last().html(album.name); // $artistName.last().html(album.artistName); - // $albumReleaseDate.last().html(album.releaseDate); + // $albumReleaseDate.last().html(album.releaseDate); } - // function buildSongsHtml (songs) { // var songStr = ""; @@ -115,10 +131,10 @@ function renderAlbum(album) { // songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; // }); -// var songHtml = -// "
  • " + -// "

    Songs:

    " + -// "" + songStr + "" + +// var songHtml = +// "
  • " + +// "

    Songs:

    " + +// "" + songStr + "" + // "
  • "; // return songHtml; // } @@ -127,7 +143,7 @@ function renderAlbum(album) { // function handleNewSongButtonClick(albums) { // $('#albums').on('click', '.add-song', function(e) { - + // var id= $(this).parents('.album').data('album-id'); // "5665ff1678209c64e51b4e7b" // $('#songModal').attr('album-id', id); @@ -151,7 +167,7 @@ function renderAlbum(album) { // } // }); - + // console.log(album[0].songs); @@ -168,32 +184,3 @@ function renderAlbum(album) { // // }); // }); // } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/server.js b/server.js index 05662a5..f64e5ba 100644 --- a/server.js +++ b/server.js @@ -88,6 +88,22 @@ app.post('/', function create (req, res) { }); }); +//SHOW INDIVIDUAL ALBUM +app.get('/api/albums/:id', function show_api_album (req, res){ + var id = req.params.id; + var album = Album.find({_id: id}, function(err, album){ + if (err){ + console.log("ERROR WITH API ID", err); + } + else{ + res.json({album: album}); + } + }); + +}) + + + /********** * SERVER * From 8146b0dd176dbdca332a4436e07441468d8a2514 Mon Sep 17 00:00:00 2001 From: nscalf561 Date: Sun, 6 Mar 2016 14:22:28 -0800 Subject: [PATCH 29/30] adds create album functionality --- public/js/app.js | 101 +++++++++++++++++++++++++++++------------ public/js/secondApp.js | 74 ------------------------------ server.js | 10 ++-- views/index.ejs | 4 +- 4 files changed, 79 insertions(+), 110 deletions(-) delete mode 100644 public/js/secondApp.js diff --git a/public/js/app.js b/public/js/app.js index 9113731..348436a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -7,24 +7,18 @@ //MAIN FUNCTION $(document).ready(function() { - //AJAX REQUEST TO ALBUMS API - // $.getJSON( "/api/albums", function( data ) { - // //Data.albums is an array of all the albums - // data.albums.forEach(function(album) { - // //we are added an entire div to the Albums div with our data embedded in jQuery - // renderAlbum(album); - // }); - // handleNewSongButtonClick(data.albums); - // }); var $albums = $('#albums'); + + //this is the get call to occupy the index page with data from the db $.ajax({ type: 'GET', + // we're pulling the data from our own api url: '/api/albums', + // data here is the JSON of albums from '/api/albums' success: function(data){ $.each(data.albums, function(i, album) { - console.log(album); renderAlbum(album); }); }, @@ -33,8 +27,37 @@ $(document).ready(function() { } }); - $.ajax({ - + // #singlebutton is the name of the submit button to make a new album + $('#singlebutton').on('click', function(event) { + event.preventDefault(); + + var $name = $('#name').val(); + var $artistName = $('#artistName').val(); + var $releaseDate = $('#releaseDate').val(); + var $genres = $('#genres').val(); + var $description = $('#description').val(); + + // here we grab the info from the form to make a new album and create + // a new object, newAlbum, with the input info + var newAlbum = { + name: $name, + artistName: $artistName, + releaseDate: $releaseDate, + genres: $genres, + description: $description + }; + + $.ajax({ + type: 'POST', + url: '/api/albums', + data: newAlbum, + success: function(newAlbum){ + renderAlbum(newAlbum); + }, + error: function(err) { + alert("woah, hang on there a minute. We've got an issue: " + err); + } + }); }); //end of document ready @@ -45,10 +68,16 @@ $(document).ready(function() { // this function takes a single album and renders it to the page function renderAlbum(album) { - // console.log('rendering album:', album); - console.log(album); + // This defines a songStr that we will fill with the name and track number of each song, + // we will then add this onto the end of the album information + var songStr = ""; + // This loops through each song on the album and adds it to songStr + album.songs.forEach(function(song) { + songStr = songStr + "(" + song.trackNumber + ") " + song.name + " – "; + }); - var albumHtml = + // albumTemplate is the layout for what will be rendered for new albums + var albumTemplate = " " + "
    " + "
    " + @@ -73,8 +102,10 @@ function renderAlbum(album) { "

    Released date:

    " + " " + album.releaseDate + "" + " " + - "
  • " + - " " + + "
  • " + + "

    Songs:

    " + + " " + songStr + "" + + " " + "
  • " + " " + "
    " + @@ -90,11 +121,20 @@ function renderAlbum(album) { "
    " + " "; - // getting album div in order to append the HTML - var $albumDiv = $("#albums"); - - $albumDiv.append(albumHtml); - + // getting album div in order to append the HTML + // var $albumDiv = $("#albums"); + // Here we are appending the above template with album info filled in + $("#albums").append(albumTemplate); + + + // var $songs = $(".songsSpan"); + + // var modalBtn = $(".songModalButton"); + // $songs.delegate('.songModalButton', 'click', function() { + // $(this).modal(); + // }); + + // var $albumName = $(".album-name"); // var $artistName = $(".artist-name"); // var $albumReleaseDate = $(".album-releaseDate"); @@ -107,20 +147,21 @@ function renderAlbum(album) { } - +//this will build out our songs in each album and append it to the list // function buildSongsHtml (songs) { // var songStr = ""; +// // console.log(songs); // songs.forEach(function(song) { // songStr = songStr + "(" + song.trackNumber + ") " + song.name + "– "; - // }); -// var songHtml = -// "
  • " + -// "

    Songs:

    " + -// "" + songStr + "" + -// "
  • "; -// return songHtml; +// // var songHtml = +// // "
  • " + +// // "

    Songs:

    " + +// // "" + songStr + "" + +// // "
  • "; +// // console.log(songHtml); +// return songStr; // } diff --git a/public/js/secondApp.js b/public/js/secondApp.js deleted file mode 100644 index c625b90..0000000 --- a/public/js/secondApp.js +++ /dev/null @@ -1,74 +0,0 @@ -/* CLIENT-SIDE JS - * - * You may edit this file as you see fit. Try to separate different components - * into functions and objects as needed. - * - */ - - -$(document).ready(function() { - console.log('app.js loaded!'); - - var $albums = $('#albums'); - $.ajax({ - type: "GET", - url: '/api/albums', - success: function(albums){ - $.each(albums, function() { - $albums.append(album.Html); - }); - } - }); -}); - - - - - -// this function takes a single album and renders it to the page -function renderAlbum(album) { - console.log('rendering album:', album); - - var albumHtml = - " " + - "
    " + - "
    " + - "
    " + - "
    " + - " " + - "
    " + - "
    " + - " album image" + - "
    " + - "
    " + - "
      " + - "
    • " + - "

      Album Name:

      " + - " " + album.name + "" + - "
    • " + - "
    • " + - "

      Artist Name:

      " + - " " + album.artistName + "" + - "
    • " + - "
    • " + - "

      Released date:

      " + - " " + album.releaseDate + "" + - "
    • " + - "
    " + - "
    " + - "
    " + - " " + - - "
    " + // end of panel-body - - " " + - - "
    " + - "
    " + - " "; - - // render to the page with jQuery - - -} \ No newline at end of file diff --git a/server.js b/server.js index 05662a5..3a07aaf 100644 --- a/server.js +++ b/server.js @@ -67,7 +67,7 @@ app.get('/api/albums', function album_index (req, res) { }); //CREATE -app.post('/', function create (req, res) { +app.post('/api/albums', function create (req, res) { var name = req.body.name; var artistName = req.body.artistName; @@ -76,19 +76,21 @@ app.post('/', function create (req, res) { var description = req.body.description; Album.create({name: name, artistName: artistName, releaseDate: releaseDate, - genres: genres, description: description}, function(err, albums){ + genres: genres, description: description}, function(err, album){ if(err){ console.log("OH FUCK AN ERROR! ", err); } else { // res.render(__dirname + '/views/index'); - // res.json({albums: albums}); + res.json(album); - res.redirect('/'); + // res.redirect('/'); } }); }); + + /********** * SERVER * **********/ diff --git a/views/index.ejs b/views/index.ejs index 7a1e547..10ae019 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -32,7 +32,7 @@
    - +
    @@ -51,7 +51,7 @@
    - +
    From 699458d48ae388e6f1b3965da35af72d2d8c9d56 Mon Sep 17 00:00:00 2001 From: nreddy216 Date: Sun, 6 Mar 2016 14:22:43 -0800 Subject: [PATCH 30/30] delete route and method working --- public/js/app.js | 8 ++++++-- server.js | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index dc475a1..e02a05f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -14,7 +14,6 @@ $(document).ready(function() { // //we are added an entire div to the Albums div with our data embedded in jQuery // renderAlbum(album); // }); - // handleNewSongButtonClick(data.albums); // }); var $albums = $('#albums'); @@ -36,10 +35,15 @@ $(document).ready(function() { // DELETE method $('#albums').delegate('.deleteBtn','click', function(){ + // var $album = $(this).closest('.album'); + + var $albumId = $(this).attr('delete-album-id'); + $.ajax({ type: 'DELETE', - url: '/api/albums/' + $(this).attr('delete-album-id'), + url: '/api/albums/' + $albumId, success: function(){ + $('[data-album-id='+ $albumId + ']').remove(); console.log("YAY DELETE"); }, error: function(){ diff --git a/server.js b/server.js index f64e5ba..c6d2f65 100644 --- a/server.js +++ b/server.js @@ -100,7 +100,23 @@ app.get('/api/albums/:id', function show_api_album (req, res){ } }); -}) +}); + +//DELETE INDIVIDUAL ALBUM +app.delete('/api/albums/:id', function delete_album (req, res){ + var id = req.params.id; + console.log("DELETE ALBUM: ", id); + + Album.remove({_id: id}, function(err){ + if(err){ + console.log("ERROR WITH DELETE", err); + } + else{ + console.log("REMOVING ALBUM: " + id + " THIS WORKED"); + res.status(200).send(); + } + }); +});