Skip to content

Commit 5f8844d

Browse files
committed
Now with top 10 movies from API.
1 parent 13a6994 commit 5f8844d

File tree

2 files changed

+32
-138
lines changed

2 files changed

+32
-138
lines changed

days/093-096-vuejs/movie_exploder/js/fake_data.js

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
movies_temp = {
22
"keyword": "top_10",
33
"hits": [
4-
{
5-
"imdb_code": "tt0691996",
6-
"title": "Towering Inferno",
7-
"director": "John Blanchard",
8-
"keywords": [],
9-
"duration": 65,
10-
"genres": [
11-
"comedy"
12-
],
13-
"rating": "",
14-
"year": 0,
15-
"imdb_score": 9.5
16-
},
174
{
185
"imdb_code": "tt0111161",
196
"title": "The Shawshank Redemption",
@@ -73,125 +60,6 @@ movies_temp = {
7360
"year": 0,
7461
"imdb_score": 9.1
7562
},
76-
{
77-
"imdb_code": "tt3082898",
78-
"title": "Kickboxer: Vengeance",
79-
"director": "John Stockwell",
80-
"keywords": [],
81-
"duration": 90,
82-
"genres": [
83-
"action"
84-
],
85-
"rating": "",
86-
"year": 2016,
87-
"imdb_score": 9.1
88-
},
89-
{
90-
"imdb_code": "tt0468569",
91-
"title": "The Dark Knight",
92-
"director": "Christopher Nolan",
93-
"keywords": [
94-
"psychopath",
95-
"urban setting",
96-
"based on comic book",
97-
"star died before release",
98-
"dc comics"
99-
],
100-
"duration": 152,
101-
"genres": [
102-
"drama",
103-
"thriller",
104-
"action",
105-
"crime"
106-
],
107-
"rating": "PG-13",
108-
"year": 2008,
109-
"imdb_score": 9.0
110-
},
111-
{
112-
"imdb_code": "tt0071562",
113-
"title": "The Godfather: Part II",
114-
"director": "Francis Ford Coppola",
115-
"keywords": [
116-
"corrupt politician",
117-
"revenge",
118-
"lake tahoe nevada",
119-
"1950s",
120-
"melancholy"
121-
],
122-
"duration": 220,
123-
"genres": [
124-
"drama",
125-
"crime"
126-
],
127-
"rating": "R",
128-
"year": 1974,
129-
"imdb_score": 9.0
130-
},
131-
{
132-
"imdb_code": "tt2802850",
133-
"title": "Fargo",
134-
"director": "",
135-
"keywords": [
136-
"anthology",
137-
"minnesota",
138-
"insurance salesman",
139-
"police officer",
140-
"death"
141-
],
142-
"duration": 53,
143-
"genres": [
144-
"drama",
145-
"thriller",
146-
"crime"
147-
],
148-
"rating": "TV-MA",
149-
"year": 0,
150-
"imdb_score": 9.0
151-
},
152-
{
153-
"imdb_code": "tt0167260",
154-
"title": "The Lord of the Rings: The Return of the King",
155-
"director": "Peter Jackson",
156-
"keywords": [
157-
"epic",
158-
"battle",
159-
"king",
160-
"orc",
161-
"ring"
162-
],
163-
"duration": 192,
164-
"genres": [
165-
"drama",
166-
"action",
167-
"adventure",
168-
"fantasy"
169-
],
170-
"rating": "PG-13",
171-
"year": 2003,
172-
"imdb_score": 8.9
173-
},
174-
{
175-
"imdb_code": "tt0108052",
176-
"title": "Schindler's List",
177-
"director": "Steven Spielberg",
178-
"keywords": [
179-
"nazi",
180-
"german soldier",
181-
"jew",
182-
"german",
183-
"jewish"
184-
],
185-
"duration": 185,
186-
"genres": [
187-
"drama",
188-
"history",
189-
"biography"
190-
],
191-
"rating": "R",
192-
"year": 1993,
193-
"imdb_score": 8.9
194-
}
19563
],
19664
"truncated_results": true
19765
}
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,62 @@
1-
// noinspection ES6ModulesDependencies
21

32
const base_url = "http://movie_service.talkpython.fm/api/"
43

4+
// noinspection ES6ModulesDependencies
55
app = new Vue({
66
el: '#app',
77
data: {
88
search_text: null,
9-
movies: movies_temp.hits,
10-
genres: genres_temp,
11-
selected_genre: genres_temp[0],
12-
no_genre: genres_temp[0],
9+
movies: [],
10+
genres: [],
11+
selected_genre: null,
12+
no_genre: "Top movies by genre",
1313
},
1414
methods: {
1515
search: function () {
1616
let text = this.search_text
17+
// noinspection JSUnusedGlobalSymbols
18+
this.selected_genre = this.no_genre
1719
this.load_movies(base_url + "search/" + text)
1820
},
1921
top_10: function () {
20-
console.log("Would have loaded top 10")
22+
// noinspection JSUnusedGlobalSymbols
23+
this.selected_genre = this.no_genre
24+
this.load_movies(base_url + "movie/top")
2125
},
2226
load_genre: function (genre) {
2327
console.log("Would load " + genre)
2428
},
2529
load_movies: function (url) {
2630
let that = this
31+
// noinspection ES6ModulesDependencies, JSUnresolvedVariable
2732
axios.get(url)
2833
.then(function (response) { // handle success
2934
that.movies = response.data.hits
3035
})
3136
.catch(function (error) { // handle error
3237
console.log("ERROR! " + error);
3338
})
39+
},
40+
load_all_genres: function() {
41+
let that = this
42+
// noinspection ES6ModulesDependencies, JSUnresolvedVariable
43+
axios.get(base_url + 'movie/genre/all')
44+
.then(function (response) { // handle success
45+
let genres = response.data
46+
genres.unshift(that.no_genre)
47+
that.genres = genres
48+
that.selected_genre = that.no_genre
49+
})
50+
.catch(function (error) { // handle error
51+
console.log("ERROR! " + error);
52+
})
53+
},
54+
init: function() {
55+
this.load_all_genres()
56+
this.top_10()
3457
}
3558
}
3659
})
60+
61+
app.init()
62+

0 commit comments

Comments
 (0)