From 2d5dd501f0e7176fa071b4b2b5f16fae8a947cc1 Mon Sep 17 00:00:00 2001 From: Charlie Heiner Date: Tue, 19 Dec 2017 23:24:27 -0800 Subject: [PATCH 1/2] getting favorites to append to favorites html section but with hard coded query so far --- models/image.js | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/models/image.js b/models/image.js index d21ac45..d58a4e9 100644 --- a/models/image.js +++ b/models/image.js @@ -36,9 +36,10 @@ const API_URL = 'http://localhost:3000/api/v1'; } Image.fetchFaves = () =>{ + Image.all = []; $.get(`${API_URL}/favorites`) - .then(Image.loadAll) + .then(Image.loadFaves) .fail(console.error); console.log("this is in fetchFaves", Image.all); @@ -48,38 +49,23 @@ const API_URL = 'http://localhost:3000/api/v1'; } Image.loadFaves = (data) => { - Image.faves = data.map(obj => new Image(obj)); - console.log(ImageFaves.all); - app.Image.faves.map(image => $('#favorites-wrapper').append(image.toHtml())); + Image.all = data.map(obj => new Image(obj)); + console.log('this is in loadFaves', data); + console.log('this is image.all in loadFaves', Image.all) + $('#favorites-wrapper').empty(); + app.Image.all.map(image => $('#favorites-wrapper').append(image.toHtml())); + } Image.loadAll = (data) => { Image.all = data.map(obj => new Image(obj)); - console.log(Image.all); + console.log('this is in loadAll', Image.all); app.imageView.append(); Image.all = []; - - - // app.imageView.initDiscoverPage(); } Image.saveImage = (image) =>{ - // const rover = $('#rover option:selected').text(); - // const img_id = $(this).find('img').attr('id'); - // const img_num = img_id.slice(1); - // const src = $(this).find('img').attr('src'); - - $.post(`${API_URL}/favorites`, image) - // { - // image_id: img_num, - // rover: rover, - // camera: $('#camera option:selected').text(), - // url: src, - // user: $('#user').val() - - // }) - } Image.prototype.toHtml = function () { From 04d8820ed7f3911b2888b9910a108d21a5d765cf Mon Sep 17 00:00:00 2001 From: Charlie Heiner Date: Wed, 20 Dec 2017 00:07:35 -0800 Subject: [PATCH 2/2] sending user name with query to server to return user faves --- index.html | 2 +- models/image.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 516cdfe..0934d61 100644 --- a/index.html +++ b/index.html @@ -93,7 +93,7 @@
- +
diff --git a/models/image.js b/models/image.js index d58a4e9..c90c04a 100644 --- a/models/image.js +++ b/models/image.js @@ -38,7 +38,10 @@ const API_URL = 'http://localhost:3000/api/v1'; Image.fetchFaves = () =>{ Image.all = []; - $.get(`${API_URL}/favorites`) + const user = { + user: $('#userInput').val() + } + $.get(`${API_URL}/favorites`, user) .then(Image.loadFaves) .fail(console.error);