Skip to content
Merged
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
19 changes: 18 additions & 1 deletion models/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const API_URL = 'http://localhost:3000/api/v1';
this.url = obj.url;
}
Image.all = [];
Image.faves = [];

Image.fetchImages = (cb) => {
let camShort = '';
Expand All @@ -34,10 +35,26 @@ const API_URL = 'http://localhost:3000/api/v1';
.fail(console.error);
}

Image.fetchFaves = () =>{
Image.all = [];
$.get(`${API_URL}/favorites`)
.then(Image.loadAll)
.fail(console.error);

}
Image.loadFaves = (data) => {
Image.faves = data.map(obj => new Image(obj));
console.log(ImageFaves.all);
}

Image.loadAll = (data) => {
Image.all = data.map(obj => new Image(obj));
console.log(Image.all);
app.imageView.initDiscoverPage();
app.imageView.append();
Image.all = [];


// app.imageView.initDiscoverPage();
}

Image.saveImage = (image) =>{
Expand Down
51 changes: 29 additions & 22 deletions views/imageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@ var app = app || {};
e.preventDefault();
app.Image.fetchImages();
})
app.Image.all.map(image => $('#gallery-wrapper').append(image.toHtml()));

$('.favImage').on('submit', function (event) {
event.preventDefault();

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');

const image = {
image_id: img_num,
rover: rover,
camera: $('#camera option:selected').text(),
url: src,
user: $('#user').val()
}




app.Image.saveImage(image);

});


};
};
imageView.append = () => {

$('#gallery-wrapper').empty();
app.Image.all.map(image => $('#gallery-wrapper').append(image.toHtml()));
$('.favImage').on('submit', function (event) {
event.preventDefault();

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');

const image = {
image_id: img_num,
rover: rover,
camera: $('#camera option:selected').text(),
url: src,
user: $('#user').val()
}
app.Image.saveImage(image);

});
}

imageView.initHomePage = () => {
$('main section').hide();
Expand All @@ -54,6 +57,10 @@ var app = app || {};
$('main section').hide();
$('#favePhotos').show();

$('#getFaves').on('submit', (e) => {
e.preventDefault();
app.Image.fetchFaves();
})


}
Expand Down