From cbb90f67dfe90ff588aa6ff049883775b9843a86 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Fri, 21 Sep 2018 11:49:56 +0100 Subject: [PATCH 01/12] basic search functionality --- index.html | 25 ++++++++++++++ scripts/scripts.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++ styles.css | 35 +++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 index.html create mode 100644 scripts/scripts.js create mode 100644 styles.css diff --git a/index.html b/index.html new file mode 100644 index 00000000..c8354a4e --- /dev/null +++ b/index.html @@ -0,0 +1,25 @@ + + + + + + + + Project Cinema + + +
+ +
+
+
+ +
+
+ + + + diff --git a/scripts/scripts.js b/scripts/scripts.js new file mode 100644 index 00000000..4bf29a38 --- /dev/null +++ b/scripts/scripts.js @@ -0,0 +1,83 @@ +//API key: 210776d9 + +//http://www.omdbapi.com/?apikey=210776d9&[searchparameters] + + +const bodyElement = document.querySelector("body") +const searchTextElement = document.querySelector(".search__text") +const searchResultsElement = document.querySelector(".results") + +bodyElement.addEventListener("submit", event => { + event.preventDefault() + if (event.target.matches(".search")){ + apiUrls.updateURL("s", searchTextElement.value) + apiUrls.fetchResults(apiUrls.getURL()) + } +}) + +bodyElement.addEventListener("click", event => { + console.log(event.target) + if (event.target.matches(".search__result")){ + console.log("clicked on film") + } +}) + +const apiUrls = { + searchParameters: { + s: "", + type: "", + page: "" + }, + + movieParameters: { + i: "", + plot: "" + }, + + + + updateURL: function(parameter, update) { + this.searchParameters[parameter] = `&${parameter}=${update}`; + + }, + + getURL: function() { + const customURL = `http://www.omdbapi.com/?apikey=210776d9${this.searchParameters.s}` + return customURL +}, + + fetchResults: function(apiURL){ + fetch(apiURL) + .then(response => response.json()) + .then(body => { + console.log(body.Search) + body.Search.forEach(result => { + searchResultsElement.appendChild(searchTemplate(result)) + + }) + }) + + } + +}; + + +const pageHandlers = { + +} + +function searchTemplate (result){ + const searchResultElement = document.createElement("div") + const template = ` +
+ +

${result.Title}

+
(${result.Year})
+
${result.Type}
+
+ ` + searchResultElement.innerHTML = template + return searchResultElement + + +} diff --git a/styles.css b/styles.css new file mode 100644 index 00000000..dea16299 --- /dev/null +++ b/styles.css @@ -0,0 +1,35 @@ +body { + margin: 0; + display: flex; + flex-direction: column; + box-sizing: border-box; + width: 100vw; + +} + +.search__result{ + display: flex; + flex-direction: row; + background-color: grey; + margin: 1rem; + height: 10vh; + width: 30vw; +} + +.result__poster{ + height: 90%; + width: auto; + +} + +.result__title{ + +} + +.result__year{ + +} + +.result__type{ + +} From bb1d891f2bcfb43d50991d97d01505fffc342114 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Fri, 21 Sep 2018 12:56:05 +0100 Subject: [PATCH 02/12] have basic functionality for displaying full film details --- index.html | 3 +++ scripts/scripts.js | 52 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index c8354a4e..0fef056b 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,9 @@
+
+
+
diff --git a/scripts/scripts.js b/scripts/scripts.js index 4bf29a38..40865e9d 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -6,6 +6,7 @@ const bodyElement = document.querySelector("body") const searchTextElement = document.querySelector(".search__text") const searchResultsElement = document.querySelector(".results") +const filmDisplayElement = document.querySelector(".film-display") bodyElement.addEventListener("submit", event => { event.preventDefault() @@ -15,10 +16,11 @@ bodyElement.addEventListener("submit", event => { } }) +//closest instead of matches, pay attention in case of bugs bodyElement.addEventListener("click", event => { - console.log(event.target) - if (event.target.matches(".search__result")){ - console.log("clicked on film") + if (event.target.closest(".search__result")){ + apiUrls.updateMovieURL("i", event.target.dataset.id) + apiUrls.fetchMovie(apiUrls.getMovieURL()) } }) @@ -41,11 +43,20 @@ const apiUrls = { }, + updateMovieURL: function(parameter, update){ + this.movieParameters[parameter] = `&${parameter}=${update}`; + + }, + getURL: function() { const customURL = `http://www.omdbapi.com/?apikey=210776d9${this.searchParameters.s}` return customURL }, + getMovieURL: function(){ + return `http://www.omdbapi.com/?apikey=210776d9${this.movieParameters.i}` + }, + fetchResults: function(apiURL){ fetch(apiURL) .then(response => response.json()) @@ -57,11 +68,21 @@ const apiUrls = { }) }) - } + }, -}; + fetchMovie: function(apiURL){ + fetch(apiURL) + .then(response => response.json()) + .then(body => { + filmDisplayElement.appendChild(fullFilmTemplate(body)) + }) + +} + +} + const pageHandlers = { } @@ -70,14 +91,25 @@ function searchTemplate (result){ const searchResultElement = document.createElement("div") const template = `
- -

${result.Title}

-
(${result.Year})
-
${result.Type}
+ +

${result.Title}

+
(${result.Year})
+
${result.Type}
` searchResultElement.innerHTML = template return searchResultElement +} - +function fullFilmTemplate (result){ + const filmInfoElement = document.createElement("div") + const template = ` +
+

${result.Title}

+

${result.Actors}

+

${result.Plot}

+

+ ` + filmInfoElement.innerHTML = template + return filmInfoElement } From 84ba401b7921460496d6692c5493b3a4d351ef05 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Fri, 21 Sep 2018 15:58:21 +0100 Subject: [PATCH 03/12] navbar added --- index.html | 15 ++++++++++++- scripts/scripts.js | 27 ++++++++++++++++++++-- styles.css | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 0fef056b..43996cba 100644 --- a/index.html +++ b/index.html @@ -9,18 +9,31 @@
+
-
+
+
diff --git a/scripts/scripts.js b/scripts/scripts.js index 40865e9d..67f705ba 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -7,10 +7,16 @@ const bodyElement = document.querySelector("body") const searchTextElement = document.querySelector(".search__text") const searchResultsElement = document.querySelector(".results") const filmDisplayElement = document.querySelector(".film-display") +const modal = document.querySelector(".modal") +const displaySearchButton = document.querySelector(".search__display-bar") +const searchBarElement = document.querySelector(".nav__search") +const homeNavBar = document.querySelector(".nav__home") + bodyElement.addEventListener("submit", event => { event.preventDefault() if (event.target.matches(".search")){ + modal.style.display = "block" apiUrls.updateURL("s", searchTextElement.value) apiUrls.fetchResults(apiUrls.getURL()) } @@ -19,11 +25,30 @@ bodyElement.addEventListener("submit", event => { //closest instead of matches, pay attention in case of bugs bodyElement.addEventListener("click", event => { if (event.target.closest(".search__result")){ + modal.style.display = "none" + searchResultsElement.innerHTML = "" + filmDisplayElement.innerHTML = "" + toggleNavBar() apiUrls.updateMovieURL("i", event.target.dataset.id) apiUrls.fetchMovie(apiUrls.getMovieURL()) } + if (event.target.matches(".search__display-bar")){ + toggleNavBar() + + } }) +//look into actual toggle functionality with BEM +function toggleNavBar(){ + if (homeNavBar.style.display === "flex"){ + searchBarElement.style.display = "flex" + homeNavBar.style.display = "none" + }else{ + searchBarElement.style.display = "none" + homeNavBar.style.display = "flex" + } +} + const apiUrls = { searchParameters: { s: "", @@ -61,13 +86,11 @@ const apiUrls = { fetch(apiURL) .then(response => response.json()) .then(body => { - console.log(body.Search) body.Search.forEach(result => { searchResultsElement.appendChild(searchTemplate(result)) }) }) - }, fetchMovie: function(apiURL){ diff --git a/styles.css b/styles.css index dea16299..49423dea 100644 --- a/styles.css +++ b/styles.css @@ -7,13 +7,65 @@ body { } +nav > div { + height: 10vh; + background-color: black; +} + +.nav__home{ + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.logo{ + color: yellow; +} + + + +.nav__search{ + display: none; + flex-direction: row; + justify-content: space-between; + align-items: center; +} + + + +.modal{ + display: none; + position: fixed; + z-index: 1; + left: 0; + top: 0; + height: 100%; + width: 100%; + overflow: auto; + background-color: rgba(0,0,0,0.5) +} + +.modal__content{ + background-color: #f4f4f4; + margin: 20% auto; + padding: 2em; + width: 70%; + box-shadow: 0 5px 8px 0 rgba(0,0,0,0.2), 0 7px 20px 0 rgba(0,0,0,0.17); + border: 1px solid black; + display: flex; + flex-direction: column; + align-content: center; +} + .search__result{ display: flex; flex-direction: row; - background-color: grey; + justify-content: center; margin: 1rem; height: 10vh; - width: 30vw; + width: 95%; + border: 1px black solid; + background-color: white; } .result__poster{ From b1c0db105ddaf307bb9e6569b93f334e98c8d1bb Mon Sep 17 00:00:00 2001 From: DanGRT Date: Fri, 21 Sep 2018 17:28:15 +0100 Subject: [PATCH 04/12] started to make accomodations for API returning errors, final commit of day --- scripts/scripts.js | 163 ++++++++++++++++++++++----------------------- styles.css | 24 ++++++- 2 files changed, 104 insertions(+), 83 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 67f705ba..1a62cd61 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -2,50 +2,49 @@ //http://www.omdbapi.com/?apikey=210776d9&[searchparameters] +//feature idea: News API to check for stories about film -const bodyElement = document.querySelector("body") -const searchTextElement = document.querySelector(".search__text") -const searchResultsElement = document.querySelector(".results") -const filmDisplayElement = document.querySelector(".film-display") -const modal = document.querySelector(".modal") -const displaySearchButton = document.querySelector(".search__display-bar") -const searchBarElement = document.querySelector(".nav__search") -const homeNavBar = document.querySelector(".nav__home") - +const bodyElement = document.querySelector("body"); +const searchTextElement = document.querySelector(".search__text"); +const searchResultsElement = document.querySelector(".results"); +const filmDisplayElement = document.querySelector(".film-display"); +const modal = document.querySelector(".modal"); +const displaySearchButton = document.querySelector(".search__display-bar"); +const searchBarElement = document.querySelector(".nav__search"); +const homeNavBar = document.querySelector(".nav__home"); bodyElement.addEventListener("submit", event => { - event.preventDefault() - if (event.target.matches(".search")){ - modal.style.display = "block" - apiUrls.updateURL("s", searchTextElement.value) - apiUrls.fetchResults(apiUrls.getURL()) + event.preventDefault(); + if (event.target.matches(".search")) { + modal.style.display = "block"; + apiUrls.updateURL("s", searchTextElement.value); + apiUrls.fetchResults(apiUrls.getURL()); } -}) +}); //closest instead of matches, pay attention in case of bugs bodyElement.addEventListener("click", event => { - if (event.target.closest(".search__result")){ - modal.style.display = "none" - searchResultsElement.innerHTML = "" - filmDisplayElement.innerHTML = "" - toggleNavBar() - apiUrls.updateMovieURL("i", event.target.dataset.id) - apiUrls.fetchMovie(apiUrls.getMovieURL()) + if (event.target.closest(".search__result")) { + modal.style.display = "none"; + searchResultsElement.innerHTML = ""; + filmDisplayElement.innerHTML = ""; + toggleNavBar(); + apiUrls.updateMovieURL("i", event.target.dataset.id); + apiUrls.fetchMovie(apiUrls.getMovieURL()); } - if (event.target.matches(".search__display-bar")){ - toggleNavBar() - + if (event.target.matches(".search__display-bar")) { + toggleNavBar(); } -}) +}); //look into actual toggle functionality with BEM -function toggleNavBar(){ - if (homeNavBar.style.display === "flex"){ - searchBarElement.style.display = "flex" - homeNavBar.style.display = "none" - }else{ - searchBarElement.style.display = "none" - homeNavBar.style.display = "flex" +function toggleNavBar() { + if (homeNavBar.style.display === "flex") { + searchBarElement.style.display = "flex"; + homeNavBar.style.display = "none"; + } else { + searchBarElement.style.display = "none"; + homeNavBar.style.display = "flex"; } } @@ -61,78 +60,78 @@ const apiUrls = { plot: "" }, - - updateURL: function(parameter, update) { this.searchParameters[parameter] = `&${parameter}=${update}`; - }, - updateMovieURL: function(parameter, update){ + updateMovieURL: function(parameter, update) { this.movieParameters[parameter] = `&${parameter}=${update}`; - }, getURL: function() { - const customURL = `http://www.omdbapi.com/?apikey=210776d9${this.searchParameters.s}` - return customURL -}, + const customURL = `http://www.omdbapi.com/?apikey=210776d9${ + this.searchParameters.s + }`; + return customURL; + }, - getMovieURL: function(){ - return `http://www.omdbapi.com/?apikey=210776d9${this.movieParameters.i}` + getMovieURL: function() { + return `http://www.omdbapi.com/?apikey=210776d9${this.movieParameters.i}`; }, - fetchResults: function(apiURL){ + fetchResults: function(apiURL) { fetch(apiURL) - .then(response => response.json()) - .then(body => { - body.Search.forEach(result => { - searchResultsElement.appendChild(searchTemplate(result)) - - }) - }) + .then(response => response.json()) + .then(body => { + if (body.hasOwnProperty("Error")) { + //TODO: needs to be filled out + console.log("error"); + } else { + body.Search.forEach(result => { + searchResultsElement.appendChild(searchTemplate(result)); + }); + } + }); }, - fetchMovie: function(apiURL){ + fetchMovie: function(apiURL) { fetch(apiURL) - .then(response => response.json()) - .then(body => { - filmDisplayElement.appendChild(fullFilmTemplate(body)) - - - }) - -} - -} - -const pageHandlers = { + .then(response => response.json()) + .then(body => { + filmDisplayElement.appendChild(fullFilmTemplate(body)); + }); + } +}; -} +const pageHandlers = {}; -function searchTemplate (result){ - const searchResultElement = document.createElement("div") +function searchTemplate(result) { + const searchResultElement = document.createElement("div"); const template = `
- -

${result.Title}

-
(${result.Year})
-
${result.Type}
+ +

${result.Title}

+
(${result.Year})
+
${result.Type}
- ` - searchResultElement.innerHTML = template - return searchResultElement + `; + searchResultElement.innerHTML = template; + return searchResultElement; } -function fullFilmTemplate (result){ - const filmInfoElement = document.createElement("div") +function fullFilmTemplate(result) { + const filmInfoElement = document.createElement("div"); const template = `
-

${result.Title}

-

${result.Actors}

-

${result.Plot}

+

+

${result.Title}

+

(${result.Year})

+
+ +

Cast: ${result.Actors}

+

${result.Plot}

- ` - filmInfoElement.innerHTML = template - return filmInfoElement + `; + filmInfoElement.innerHTML = template; + return filmInfoElement; } diff --git a/styles.css b/styles.css index 49423dea..ee490e4b 100644 --- a/styles.css +++ b/styles.css @@ -61,7 +61,8 @@ nav > div { display: flex; flex-direction: row; justify-content: center; - margin: 1rem; + align-items: center; + margin: 0.5rem; height: 10vh; width: 95%; border: 1px black solid; @@ -71,10 +72,12 @@ nav > div { .result__poster{ height: 90%; width: auto; + align-self: flex-start; } .result__title{ + align-self: center; } @@ -85,3 +88,22 @@ nav > div { .result__type{ } + +.film-display{ + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.film-display__header{ + display: flex; + flex-direction: row; + justify-content: space-around; +} + +.film-display__poster{ + width: 60%; + height: auto; + align-self: center; +} From e188850592869d858ebe5bd8494cae1c80478860 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Sat, 22 Sep 2018 12:56:04 +0100 Subject: [PATCH 05/12] formatted film display, started work on getting related news --- index.html | 2 +- scripts/scripts.js | 40 +++++++++++++++++++++++++++++++++++----- styles.css | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 43996cba..2ec65a9d 100644 --- a/index.html +++ b/index.html @@ -30,7 +30,7 @@ -
+
diff --git a/scripts/scripts.js b/scripts/scripts.js index 1a62cd61..874d9ea2 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -7,7 +7,7 @@ const bodyElement = document.querySelector("body"); const searchTextElement = document.querySelector(".search__text"); const searchResultsElement = document.querySelector(".results"); -const filmDisplayElement = document.querySelector(".film-display"); +const filmDisplayElement = document.querySelector(".film-container"); const modal = document.querySelector(".modal"); const displaySearchButton = document.querySelector(".search__display-bar"); const searchBarElement = document.querySelector(".nav__search"); @@ -76,7 +76,7 @@ const apiUrls = { }, getMovieURL: function() { - return `http://www.omdbapi.com/?apikey=210776d9${this.movieParameters.i}`; + return `http://www.omdbapi.com/?apikey=210776d9${this.movieParameters.i}&plot=long`; }, fetchResults: function(apiURL) { @@ -98,8 +98,18 @@ const apiUrls = { fetch(apiURL) .then(response => response.json()) .then(body => { + console.log(body) filmDisplayElement.appendChild(fullFilmTemplate(body)); }); + }, + + + fetchNews: function(apiURL){ + fetch(apiURL) + .then(response => response.json()) + .then(body => { + + }) } }; @@ -124,12 +134,32 @@ function fullFilmTemplate(result) { const template = `
-

${result.Title}

+

${result.Title}

(${result.Year})

- -

Cast: ${result.Actors}

+
+ +
${result.Genre} | ${result.Runtime} | ${result.Rated} + Director: ${result.Director} + Written By: ${result.Writer} +
+
+ Cast: ${result.Actors}

${result.Plot}

+

+
Ratings & Awards
+ ${result.Awards} + ${result.Ratings[0].Source}: ${result.Ratings[0].Value} + ${result.Ratings[1].Source}: ${result.Ratings[1].Value} + ${result.Ratings[2].Source}: ${result.Ratings[2].Value} +
+
+
Miscellaneous
+ Released: ${result.Released}, Box Office: ${result.BoxOffice}. DVD: ${result.DVD} + ${result.Country} | ${result.Language} | ${result.Production} + ${result.Website} +

`; filmInfoElement.innerHTML = template; diff --git a/styles.css b/styles.css index ee490e4b..21d5f548 100644 --- a/styles.css +++ b/styles.css @@ -94,16 +94,55 @@ nav > div { flex-direction: column; justify-content: center; align-items: center; + border: 1px solid black; + padding: 0.5rem; + background-color: #F5FFFA + } .film-display__header{ + display: flex; + flex-direction: row; + justify-content: space-between; +} + +.film-display__info{ display: flex; flex-direction: row; justify-content: space-around; } .film-display__poster{ - width: 60%; + width: 40%; height: auto; align-self: center; } + +.film-display__key-facts{ + display: flex; + flex-direction: column; + margin: 0.5rem; + justify-content: space-between; +} + + +.film-display__cast{ + margin-top: 1rem; +} + +.film-display__ratings{ + display: flex; + flex-direction: column; + justify-content: space-between; + background-color: #FFFAFA; + padding: 0.25rem; +} + +.film-display__misc{ + display: flex; + flex-direction: column; + justify-content: space-between; + background-color: #FFFAFA; + padding: 0.25rem; + +} From 1aac11b996dca5cc9284e8c41cea5772b5b03319 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Sat, 22 Sep 2018 15:55:10 +0100 Subject: [PATCH 06/12] added Recent News functionality, needs further refining --- scripts/scripts.js | 36 ++++++++++++++++++++++++++++++++---- styles.css | 27 ++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 874d9ea2..25700a67 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -98,18 +98,21 @@ const apiUrls = { fetch(apiURL) .then(response => response.json()) .then(body => { - console.log(body) + const newsApiString = `https://newsapi.org/v2/everything?q=${body.Title}&apiKey=9ed005ef4eb94baf913fce701c69972f` filmDisplayElement.appendChild(fullFilmTemplate(body)); + this.fetchNews(newsApiString) }); }, - +//tried writing this as pure but no luck fetchNews: function(apiURL){ - fetch(apiURL) + fetch(apiURL) .then(response => response.json()) .then(body => { - + filmNewsElement = filmNewsTemplate(body) + filmDisplayElement.appendChild(filmNewsElement) }) + } }; @@ -165,3 +168,28 @@ function fullFilmTemplate(result) { filmInfoElement.innerHTML = template; return filmInfoElement; } + +function filmNewsTemplate(body){ + const filmNewsElement = document.createElement("div") + filmNewsElement.className = "film-display__news-container" + filmNewsElement.innerHTML = `

Recent News

` + const newsStories = body.articles.map(story => { + return ` + ${story.title} + + ${convertDateForDisplay(story.publishedAt)} | + ${story.source.name} + + ` + }) + filmNewsElement.innerHTML += newsStories.join("") + return filmNewsElement + + +} + + +function convertDateForDisplay(date) { + const inputDate = new Date(date); + return inputDate.toLocaleString(); +} diff --git a/styles.css b/styles.css index 21d5f548..07b6b1a7 100644 --- a/styles.css +++ b/styles.css @@ -141,8 +141,33 @@ nav > div { .film-display__misc{ display: flex; flex-direction: column; - justify-content: space-between; + justify-content: space-between; background-color: #FFFAFA; padding: 0.25rem; } + +.film-display__news-container{ + display: flex; + flex-direction: column; + align-items: space-between; + +} + +.film-display__news-item{ + display: flex; + flex-direction: column; +} + + +a:link{ + color: #136CB2; + text-decoration: none; +} +a:hover{ + color: black; +} + +a:visited{ + color: #70579D; +} From cc5586c23fc66677e296283f5286b418d0cb78f1 Mon Sep 17 00:00:00 2001 From: DanGRT Date: Sat, 22 Sep 2018 18:32:04 +0100 Subject: [PATCH 07/12] added some styling, made a landing page --- index.html | 12 ++++++++-- scripts/scripts.js | 8 +++++-- styles.css | 59 +++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 2ec65a9d..0c0f01ee 100644 --- a/index.html +++ b/index.html @@ -5,14 +5,16 @@ + + Project Cinema
+
+ + +

Welcome to Project Cinema

+