forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 47
Laura | nodes #25
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
Open
lauracodecreations
wants to merge
15
commits into
Ada-C10:master
Choose a base branch
from
lauracodecreations:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Laura | nodes #25
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bf9c054
see all of the trips
lauracodecreations c3ccdd6
refactored see all trips
lauracodecreations c4c9acd
grab the correct data from each trip
lauracodecreations b93bae2
show trip detail for trip 1
lauracodecreations 54558fd
show all trips details
lauracodecreations 6984361
make a reservation
lauracodecreations e8d0bc7
removed clearform because a second trip cleared my form information
lauracodecreations ec517e9
refactor code and added some css
lauracodecreations 316585e
added color and formated grid
lauracodecreations c535cfd
added bootstrap
lauracodecreations 6a1d809
more formatting and cleaning code
lauracodecreations a614aa1
aligned code
lauracodecreations 9e07c82
refactor code
lauracodecreations dce3b99
more css styling
lauracodecreations 32480b2
finished style: grid matches frame
lauracodecreations File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| .current-trips { | ||
| font-family: sans-serif; | ||
| } | ||
|
|
||
| #info { | ||
| display: grid; | ||
| width: 100%; | ||
| grid-template-columns: 1fr 1fr; | ||
| /* grid-auto-rows: minmax(100px, auto); */ | ||
| /* grid-template-rows: 50px 1fr 30px; */ | ||
| /* grid-template-columns: 150px 1fr; */ | ||
| grid-template-areas: | ||
| "header header" | ||
| "list details" | ||
| "list reservation" | ||
| } | ||
|
|
||
| #info-trip { | ||
| grid-area: details; | ||
| } | ||
|
|
||
| #reserve-trip { | ||
| grid-area: reservation; | ||
| } | ||
|
|
||
| .current-trips { | ||
| grid-area: list | ||
| } | ||
|
|
||
| header { | ||
| background-color: aquamarine; | ||
| padding-top: 5px; | ||
| border-top-width: 50px; | ||
| padding-bottom: 44px; | ||
| padding-top: 44px; | ||
| font-size: 60px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| ul div section:first-child { | ||
| grid-area: reservation; | ||
| text-align: center; | ||
| } | ||
|
|
||
|
|
||
| main section:first-child h1 { | ||
| grid-area: header; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| ul { | ||
| list-style-type:none; | ||
| } | ||
|
|
||
| section button { | ||
| grid-area: list | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Trips</title> | ||
| <script | ||
| src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
| <script type="text/javascript" src="index.js"></script> | ||
| <link rel="stylesheet" href="index.css"> | ||
|
|
||
| <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"> | ||
| <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <header>Trek</header> | ||
| <section id="status-message"></section> | ||
|
|
||
| <main> | ||
| <div id = "info"> | ||
| <section class="current-trips"> | ||
| <button id="load">See all trips!</button> | ||
| <ul id="trip-list"></ul> | ||
| </section> | ||
| <section id="info-trip"> | ||
| </section> | ||
| <section id="reserve-trip"> | ||
| </section> | ||
| </div> | ||
| </main> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| const URL = 'https://trektravel.herokuapp.com/trips'; | ||
|
|
||
| // | ||
| // Status Management | ||
| // | ||
| const reportStatus = (message) => { | ||
| $('#status-message').html(message); | ||
| }; | ||
|
|
||
| const reportError = (message, errors) => { | ||
| let content = `<p>${message}</p><ul>`; | ||
| for (const field in errors) { | ||
| for (const problem of errors[field]) { | ||
| content += `<li>${field}: ${problem}</li>`; | ||
| } | ||
| } | ||
| content += "</ul>"; | ||
| reportStatus(content); // print that content using reportStatus | ||
| }; | ||
|
|
||
| const loadTrips = () => { | ||
| reportStatus('Loading trips...'); | ||
|
|
||
| const tripList = $('#trip-list'); | ||
| tripList.empty(); | ||
|
|
||
| axios.get(URL) | ||
| .then((response) => { | ||
| reportStatus(`Successfully loaded ${response.data.length} trips`); | ||
| response.data.forEach((trip) => { | ||
| const div = $(`<div class="trip-${trip.id}"><button >${trip.name}</button></div>`) | ||
| tripList.append(div); | ||
| $('button', div).click(() => { // to only activate on button inside the div | ||
| loadTrip(`.trip-${trip.id}`); | ||
| createForm(`.trip-${trip.id}`); | ||
| $(`.trip-${trip.id}`).on('submit', '#trip-form', createReservation); | ||
| }) | ||
| }); | ||
|
|
||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trip: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| const loadTrip = (tripinfo) => { | ||
| let num = tripinfo.match(/\d/); | ||
| num = num.join(""); | ||
| // const trip = $(`${tripinfo}`); | ||
| const section = $('#info-trip'); | ||
| section.empty(); | ||
| axios.get(URL + "/" + num) | ||
| .then((response) => { | ||
| let data = {} | ||
| data["Id"] = response.data.id | ||
| data["Name"] = response.data.name | ||
| data["Continent"] = response.data.continent | ||
| data["Details"] = response.data.about | ||
| data["Category"] = response.data.category | ||
| data["Weeks"] = response.data.weeks | ||
| data["Cost"] = '$' + response.data.cost | ||
| const list = $('<ul></ul>') | ||
| Object.keys(data).forEach(function(key) { | ||
| list.append(`<li><strong>${key}</strong> : ${data[key]}</li`); | ||
| }); | ||
| //const section = $('<section></section>'); | ||
| section.append('<h2> Trip details </h2>') | ||
| section.append(list) | ||
| //trip.append(section) | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trip: ${error.message}`); | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| const createForm = (tripinfo) => { | ||
| event.preventDefault(); | ||
| // get id number | ||
| let num = tripinfo.match(/\d/); | ||
| num = num.join(""); | ||
| console.log(tripinfo) | ||
|
|
||
| //generate form | ||
| // Create a section element (not in the DOM) | ||
| const section = $('#reserve-trip'); | ||
| section.append('<h2>Reserve Trip</h2>'); | ||
|
|
||
| const form = $('<form id = "trip-form"></form>') | ||
| const divName = $('<div></div>') | ||
| divName.append('<label for="name">Name</label>'); | ||
| divName.append('<input type="text" name="name" />'); | ||
|
|
||
|
|
||
| const divEmail = $('<div></div>') | ||
| divEmail.append('<label for="email">Email</label>'); | ||
| divEmail.append('<input type="text" name="email" />') // for and name in a form should have the same name | ||
|
|
||
| form.append(divName) | ||
| form.append(divEmail) | ||
|
|
||
| form.append(`<input type="hidden" id="tripId" name="triptId" value=${num}>`) | ||
| form.append('<input type="submit" name="add-pet" value="Reserve" class="btn btn-info" />') | ||
|
|
||
| section.append(form) | ||
| } | ||
|
|
||
| const readFormData = () => { | ||
| const parsedFormData = {}; | ||
|
|
||
| const inputs = ["name","email"] | ||
|
|
||
| inputs.forEach((curInput) => { | ||
| const curData = $(`#trip-form input[name="${curInput}"]`).val(); | ||
| parsedFormData[curInput] = curData ? curData : undefined; | ||
| }); | ||
| let id = document.getElementById("tripId").value | ||
| parsedFormData["id"] = id | ||
| return parsedFormData; | ||
| }; | ||
|
|
||
| const createReservation = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| const tripData = readFormData(); | ||
| console.log(tripData) | ||
|
|
||
| reportStatus('Sending trip data...'); | ||
| let num = tripData["id"] | ||
| console.log(num) | ||
| //POST https://trektravel.herokuapp.com/trips/1/reservations | ||
| let URL_R = URL + "/" + num + "/reservations" | ||
| axios.post(URL_R, tripData) | ||
| .then((response) => { | ||
| reportStatus(`Successfully added a trip with ID ${response.data.id}!`); | ||
| }) | ||
| .catch((error) => { | ||
| console.log(error.response); | ||
| if (error.response.data && error.response.data.errors) { | ||
| reportError( | ||
| `Encountered an error: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| // this is the homepage! the trip will not be avaiable | ||
| $(document).ready(() => { | ||
| $('#load').click(loadTrips); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't have a callback set for the submit button! |
||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this looks really promising!