Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4fea996
created model and collection for movies
Sofia15 Jun 13, 2017
20e1608
movie_list_view for movie list
Sofia15 Jun 13, 2017
78f7d97
fixed error, list doesn't show
Sofia15 Jun 14, 2017
815f985
List of movie's titles displayed
lmelgarejos Jun 14, 2017
dc0c0e8
Added click events to add movies, claer fiels in form as well
lmelgarejos Jun 14, 2017
bcf642a
Revert "Added click events to add movies, claer fiels in form as well"
Sofia15 Jun 14, 2017
e1140bd
search movie
Sofia15 Jun 15, 2017
e1012e4
update files names and added 'rental' model and collection in order t…
lmelgarejos Jun 19, 2017
32523e3
Added form for the search
lmelgarejos Jun 19, 2017
80eec62
Trying to get query to work, but 500 error showing in console :(
lmelgarejos Jun 19, 2017
dd9d00f
change url to try to get query to work
lmelgarejos Jun 19, 2017
83a857a
Query is not working
lmelgarejos Jun 19, 2017
d66dbd6
fixing internal error
Sofia15 Jun 19, 2017
b659b2d
fixing merge conflict
lmelgarejos Jun 19, 2017
157132a
merge conflict
lmelgarejos Jun 19, 2017
6d9790e
merge conflict
lmelgarejos Jun 19, 2017
348d7c0
add video store model
Sofia15 Jun 20, 2017
8143153
make movie_list_view use video_store model
Sofia15 Jun 20, 2017
1bcc0b8
search function added
Sofia15 Jun 20, 2017
98a3320
merge conflict cleaned
Sofia15 Jun 20, 2017
624a6ae
Solving merge conflict
lmelgarejos Jun 21, 2017
4531614
commiting to check out another branch
lmelgarejos Jun 21, 2017
da1aa62
search working, and display all the movies related with the search term
lmelgarejos Jun 21, 2017
4948806
add button created working on create function
Sofia15 Jun 21, 2017
0d18f72
Merge branch 'master' of https://github.com/Sofia15/VideoStoreConsumer
lmelgarejos Jun 21, 2017
dbedbca
finish base requirements
lmelgarejos Jun 21, 2017
0a9cf50
Working on check out, but could not make it work
lmelgarejos Jun 27, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,5 @@ Icon
Network Trash Folder
Temporary Items
.apdisk

.env
36 changes: 34 additions & 2 deletions build/css/styles.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
@include foundation-everything;

main {
background: lightblue;
background: lightgrey;
}

header {
background-color: lightgreen;
background-color: darkblue;
padding: 0.5rem;
color: white;
align-content: center;
}

#to-the-right {
/*float: right;*/
font-family: cursive;
}

#word-to-search {
font-size: 2em;
color: darkblue;
font-style: italic;
}

.search-movie {
float: right;
/*padding: 20px;*/
/*margin: right 50px;*/
margin: 20px;

}

.add-movie {

}

li {
font-size: 2em;
color: darkblue;
font-style: oblique;
font-family: fantasy;
}

#completed-checkbox {
Expand Down
69 changes: 56 additions & 13 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/_settings.css">
<link rel="stylesheet" type="text/css" href="css/foundation.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<title>Backbone Baseline</title>
</head>
<body>

<script src="/app.bundle.js"></script>

</body>
</html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/_settings.css">
<link rel="stylesheet" type="text/css" href="css/foundation.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<title>Backbone Baseline</title>
</head>
<body>

<header>
<h1>Movies!!</h1>
</header>
<main>
<form class="search-movie-form">
<div class="medium-12 columns">
<label for="name"><p id="word-to-search">Type a word to find movies relate with it</p></label>
<input type="text" name="title"></input>
</div>
<button type="button" class="search-movie button">Search</button>

</form>
<section id='movie' class="row"></section>
<section id='movie-list' class="row">
<ul class="movie-cards row"> </ul>
</section>
<section id='new-movie'></section>
</main>

<!-- TEMPLATES -->

<script id="movie-search-card-template" type="text/template">
<div class="columns small-12 medium-6 large-3">
<li><%- movie.title %></li>
<img src = "<%- movie.image_url %>" />
<button type="button" class="add-movie button">add</button>
</div>
</script>

<script id="movie-card-template" type="text/template">
<ul>
<div class="columns small-12 medium-6 large-3">
<li> <%- movie.title %></li>
<img src = "<%- movie.image_url %>" />
<p id='to-the-right'> Overview: <%- movie.overview %></p>
<button type="button" class="checkout-movie button">Check out</button>
<button type="button" class="checkin-movie button">Check in</button>
<button type="button" class="add-movie button">add</button>

</div>
</ul>
</script>

<script src="/app.bundle.js"></script>

</body>
</html>
27 changes: 23 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
// /src/app.js

// Import jQuery & Underscore
import $ from 'jquery';
import _ from 'underscore';

// ready to go
import MovieList from './collections/movie_list';
import MovieListView from './views/movie_list_view';
import VideoStore from './models/video_store';


$(document).ready(function() {

$('section.main-content').append('<p>Hello World!</p>');
var movieList = new MovieList();
movieList.fetch();

var searchList = new MovieList();

var videoStore = new VideoStore({
library: movieList,
searchResults: searchList
});

var movieListViewParams = {
el: $('main'),
model: videoStore
};

var myMovieListView = new MovieListView(movieListViewParams);
myMovieListView.render();
//initializing a new view

});
20 changes: 20 additions & 0 deletions src/collections/movie_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Backbone from 'backbone';

import Movie from '../models/movie';

var MovieList = Backbone.Collection.extend({
model: Movie,
initialize: function() {
this.query = undefined;
},
url: function() {
var url = "http://localhost:3000/movies";
if (this.query !== undefined) {
return url + "?query=" + this.query;
} else {
return url;
}
}
});

export default MovieList;
16 changes: 16 additions & 0 deletions src/collections/rental_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Backbone from 'backbone';
import Rental from '../models/rental';

var RentalsList = Backbone.Collection.extend({
model: Rental,

url: 'http://localhost:3000/rentals/',

overdueUrl: function() {
this.url = this.url + "overdue";
return this;
}

});

export default RentalsList;
9 changes: 9 additions & 0 deletions src/models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Backbone from 'backbone';

var Movie = Backbone.Model.extend({
initialize: function() {
// console.log("Created new movie");
}
});

export default Movie;
28 changes: 28 additions & 0 deletions src/models/rental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Backbone from 'backbone';

var Rental = Backbone.Model.extend({

url: 'http://localhost:3000/rentals/',

initialize: function(params) {
if (!this.has('due_date')) {
var dueDate= new Date();
dueDate.setDate(dueDate.getDate() + 5);
this.set('due_date', dueDate);
}
},

checkoutUrl: function(movieTitle){
this.url = this.url + movieTitle + "/check-out";
console.log("Inside of checkoutUrl");
return this;
},

checkinUrl: function(movieTitle){
this.url = this.url + movieTitle + "/return";
console.log("Inside of checkinUrl");
return this;
}
});

export default Rental;
11 changes: 11 additions & 0 deletions src/models/video_store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import Backbone from 'backbone';

var VideoStore = Backbone.Model.extend({
initialize: function(params) {
// this.set("library", params.library);
// this.set("searchResults", params.searchResults);
}
});

export default VideoStore;
111 changes: 111 additions & 0 deletions src/views/movie_list_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import $ from 'jquery';
import _ from 'underscore';
import Backbone from 'backbone';
import MovieView from './movie_view';
import Movie from '../models/movie';

var MovieListView = Backbone.View.extend({

initialize: function(params) {
this.movieTemplate = _.template($('#movie-card-template').html());
this.movieSearchTemplate = _.template($('#movie-search-card-template').html());

this.movieList = [];

this.model.get("library").forEach(function(rawMovie){
this.addMovie(rawMovie);
}, this);

this.input = {
title: this.$('.search-movie-form input[name="title"]')
};

this.listenTo(this.model.get("library"), 'add', this.addMovie);
this.listenTo(this.model.get("library"), 'update', this.render);

this.searchList = [];

this.listenTo(this.model.get("searchResults"), 'add', this.addSearchResult);
this.listenTo(this.model.get("searchResults"), 'update', this.render);

this.showSearchResults = false;

},

render: function() {
$('#movie-list').empty();
var movieList;
if (this.showSearchResults){
movieList = this.searchList;
} else {
movieList = this.movieList;
}

movieList.forEach(function(movie){
movie.render();
$('#movie-list').append(movie.$el);
// this.$('#movie-list').append(MovieView.render().$el);
this.listenTo(movie, 'add', this.addToLibrary);
}, this);
return this;
},

addToLibrary: function(movie) {
var that = this;
movie.save(undefined, {
success: function(){
that.showSearchResults = false;
that.model.get('library').fetch();
}
});

},

addMovie: function(movie){
var movie = new MovieView ({
model: movie,
template: this.movieTemplate
});
this.movieList.push(movie);
},

addSearchResult: function(movie){
var movie = new MovieView ({
model: movie,
template: this.movieSearchTemplate
});
this.searchList.push(movie);
},

events: {
'click .search-movie': 'searchMovie',
},

getInput: function() {
var movie = {
title: this.input.title.val()
};
return movie;
},

searchMovie: function(movie) {
this.searchList = [];
this.showSearchResults = true;
this.model.get("searchResults").query = this.getInput()["title"];
this.model.get("searchResults").fetch();

// var _this = this;
// var searchMovie = new SearchMovie([], {query:this.getInput()["title"]});
// searchMovie.fetch({
// success: function(collection, response, options){
// var movie = collection.shift();
// _this.addMovie(movie);
// _this.render();
// // $('#movie-list').append(movie.$el);
// }
// });

}
});

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

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

render: function() {
var html = this.template({movie: this.model.attributes});
this.$el.html(html);
this.delegateEvents();
return this;
},

events: {
'click .add-movie': 'addMovieRental'
},

addMovieRental: function() {
this.trigger('add', this.model);
event.stopPropagation();
}

});

export default MovieView;
Loading