Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isaac Del Rosario & Marisa Morris - Carets #1

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2794a90
created the movie model and collection and views for each
Dec 18, 2017
c68a437
Added a basic header and template for each movie (hid overview for th…
hisaacdelr Dec 18, 2017
7b69674
added instances of movie and movielist instances to app.js& added url…
Dec 18, 2017
6f35fa1
added render function in movie_list_view.js
Dec 18, 2017
5314e3e
Created render logic for Movie view and renamed wrong variable names
hisaacdelr Dec 18, 2017
a81bdc5
render the MovieListView when .fetch is finished
hisaacdelr Dec 18, 2017
58cfe9e
added button to add add a movie to inventory.
Dec 19, 2017
3677f2a
removed button
Dec 19, 2017
5677b12
added a listener for the search form inside MovieListView
hisaacdelr Dec 19, 2017
3272e81
Merge branch 'master' of https://github.com/HelloMarisaMorris/VideoSt…
hisaacdelr Dec 19, 2017
e80a53b
added searchMovies function
Dec 19, 2017
6166069
created searchMovies function for submitting the search form
hisaacdelr Dec 19, 2017
6bebad1
added template for searched movies and addionals render function for …
Dec 19, 2017
8ddbac3
removed fetch fix because when you fetch, the render in the MovieList…
hisaacdelr Dec 19, 2017
0c4cca1
fixed merge conflicts
hisaacdelr Dec 19, 2017
c636852
button to view internal api inventory working.
Dec 19, 2017
53e1a30
Merge branch 'master' of https://github.com/HelloMarisaMorris/VideoSt…
Dec 19, 2017
b69e724
added function to add a movie from the external API to the rails API
Dec 20, 2017
e01961e
got rid of console.logs
hisaacdelr Dec 20, 2017
0e34782
got rid of extra dependencies
hisaacdelr Dec 20, 2017
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
35 changes: 34 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,43 @@
</head>
<body>
<main id="main-content">

<header>
<h1 class="site-title">SuperDuperVideo</h1>
<form id="search-movies">
<label for="query">Search For A Movie:</label>
<input type="text" name="query" />
<input type="submit" value="Search Movie" class="button"></input>
</form>
<button class="button view-inventory">View Current Inventory</button>
</header>

<section id="movie" class="movie row">
<!-- RENDER ALL MOVIE TEMPLATES -->
</section>

</main>

<footer>
<div class="columns small-12 medium-11 medium-offset-1">
<p class="footer-copy">&copy; 2017, Ada Developers Academy</p>
</div>
</footer>

<script src="/app.bundle.js"></script>
<script type="text/template" id="movie-template">
<img src="<%= image_url %>" alt="<%= title %> poster">
<h3><%= title %></h3>
<h4><%= overview %></h4>
<p><%= release_date %></p>
</script>

<script type="text/template" id="search-template">
<img src="<%= image_url %>" alt="<%= title %> poster">
<h3><%= title %></h3>
<h4><%= overview %></h4>
<p><%= release_date %></p>
<button class="button add-to-inventory">Add to Inventory</button>
</script>

</body>
</html>
24 changes: 18 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import 'css/_settings.css';
import 'foundation-sites/dist/css/foundation.css';
import './css/styles.css';

// Import jQuery & Underscore
import $ from 'jquery';
import _ from 'underscore';
import 'foundation-sites/dist/css/foundation.css';

// collections
import MovieList from './collections/movie_list';

// views
import MovieListView from './views/movie_list_view';

import './css/_settings.css';
import './css/styles.css';

// ready to go
$(document).ready(function() {
const movies = new MovieList();
const movieListView = new MovieListView({
model: movies,
template: _.template($('#movie-template').html()),
searchTemplate: _.template($('#search-template').html()),
el: ('#main-content')
});

$('#main-content').append('<p>Hello World!</p>');

movies.fetch();
});
12 changes: 12 additions & 0 deletions src/collections/movie_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Backbone from 'backbone';
import Movie from 'models/movie';

const MovieList = Backbone.Collection.extend({
model: Movie,
url: 'http://localhost:3000/movies/',
parse(response) {
return response;
},
});

export default MovieList;
5 changes: 5 additions & 0 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ main {
background: lightblue;
}

.movie h4{
/* hide the overview */
display: none;
}

header {
background-color: lightgreen;
padding: 0.5rem;
Expand Down
7 changes: 7 additions & 0 deletions src/models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Backbone from 'backbone';

const Movie = Backbone.Model.extend({

});

export default Movie;
52 changes: 52 additions & 0 deletions src/views/movie_list_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Backbone from 'backbone';
import MovieView from '../views/movie_view';

const MovieListView = Backbone.View.extend({
initialize(params) {
// console.log(params);
this.template = params.template;
this.searchTemplate = params.searchTemplate;
this.listenTo(this.model,"update", this.render);
this.listenTo(this,"showSearched", this.renderSearch);

this.listenTo(this.model,"currentInv", this.render);
},
render() {
this.$('#movie').empty();

this.model.each((movie) => {
const movieView = new MovieView({
model: movie,
template: this.template,
tagName: 'article',
className: 'movie',
});
this.$('#movie').prepend(movieView.render().$el);
});
return this;
},

renderSearch() {
this.template = this.searchTemplate;
},

events: {
'submit #search-movies': 'searchMovies',
'click button.view-inventory': 'showInventory',
},

searchMovies: function(event) {
event.preventDefault();
const query = this.$('input[name=query]').val();
this.model.fetch({data: {"query": query}});
this.trigger('showSearched', this);
},

showInventory: function(event) {
event.stopImmediatePropagation();
this.model.fetch();
this.trigger('currentInv');
},
});

export default MovieListView;
24 changes: 24 additions & 0 deletions src/views/movie_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Backbone from 'backbone';

const MovieView = Backbone.View.extend({
initialize(params){
this.template = params.template;
this.listenTo(this.model, 'change', this.render);
},

render(){
const compiledTemplate = this.template(this.model.toJSON());
this.$el.html(compiledTemplate);
return this;
},
events: {
'click .add-to-inventory': 'addMovie',
},
addMovie: function(event) {
event.preventDefault();
this.model.save(this.model.attributes,{type: 'POST'});

},
});

export default MovieView;