forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 42
Ampers: Alex #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
brownav
wants to merge
15
commits into
Ada-C9:master
Choose a base branch
from
brownav: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
Ampers: Alex #25
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4a50fe
basic html with classes and ids
brownav 15b104a
click retrieves list of all trips
brownav 2756541
all trips rendered in a basic table isntead of list
brownav dcfa0a4
adds bootstrap, adds table styling
brownav bdcaf7c
heading and table spacing/styling
brownav ee0a101
adds details box for selected trip
brownav 2536b32
adds box sizing and spacing styling
brownav 2072434
changes button style and adds background image
brownav 327c2db
refactors finding id for trip
brownav 691c1c7
reservation form basics renders
brownav 375174e
renders all components for reservation, needs styling
brownav dadb476
reservation styling
brownav 5225c05
reserve section captures user input
brownav 81e2044
makes reservation and confirms
brownav 2f2f06e
final styling
brownav 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,42 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <!-- Required meta tags --> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
|
|
||
| <!-- Bootstrap CSS --> | ||
| <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous"> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <title>Trek</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <section id="status-message"></section> | ||
| <h1>Trek</h1> | ||
| <button id="get-trips" type="button" class="btn btn-success">See All Trips</button> | ||
| <main> | ||
| <section class="all-trips"> | ||
| <div class="list-container"> | ||
| <table id="trips-table" class="table table-bordered"> | ||
| </table> | ||
| </div> | ||
| </section> | ||
|
|
||
| <div class="column2"> | ||
| <section class='details-container'> | ||
| <div id='details'></div> | ||
| </section> | ||
|
|
||
| <section class="reservation-container"> | ||
| </section> | ||
| </div> | ||
| </main> | ||
|
|
||
| <script src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
| <script type="text/javascript" src="index.js"></script> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> | ||
| <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script> | ||
| </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,91 @@ | ||
| const URL = 'https://ada-backtrek-api.herokuapp.com/trips/' | ||
|
|
||
| const reportStatus = (message) => { | ||
| $('#status-message').html(message); | ||
| } | ||
|
|
||
| const loadTrips = () => { | ||
| $('#trips-table').empty(); | ||
| reportStatus("Loading trips...") | ||
|
|
||
| axios.get(URL) | ||
| .then((response) => { | ||
| $('#trips-table').append("<tr><th>All Trips</th></tr>") | ||
|
|
||
| response.data.forEach((trip) => { | ||
| $('#trips-table').append(`<tr><td>${trip.name}</td></tr>`); | ||
|
|
||
| $('td').click(function() { | ||
| if (this.innerText === trip.name){ | ||
| showTrip(trip.id); | ||
| } | ||
| }) | ||
| }) | ||
| reportStatus('Trips loaded!'); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Error: ${error.message}`); | ||
| }) | ||
| }; | ||
|
|
||
| const showTrip = (id) => { | ||
| const tripInfo = $('#details'); | ||
| tripInfo.empty(); | ||
| tripInfo.append(`<h2>Trip Details</h2>`) | ||
| reportStatus('Retrieving trip...') | ||
|
|
||
| axios.get(URL + id) | ||
| .then((response) => { | ||
| let tripData = ["name", "continent", "category", "weeks", "cost", "about"]; | ||
|
|
||
| tripData.forEach((item) => { | ||
| let info = response.data[item]; | ||
| tripInfo.append(`<p> <strong>${item}:</strong> ${info} </p>`); | ||
| }) | ||
| reportStatus('Trip retrieved!') | ||
| showReservation(response.data); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Error: ${error.message}`); | ||
| }) | ||
| }; | ||
|
|
||
| const showReservation = (trip) => { | ||
| $('.reservation-container').empty(); | ||
|
|
||
| $('.reservation-container').append(`<form></form>`); | ||
| $(`form`).append(`<h2>Reserve Trip</h2>`); | ||
| $(`form`).append(`<label for="name">Your Name:</label>`); | ||
| $(`form`).append(`<input type="text" name="name"></input><br/>`); | ||
| $(`form`).append(`<label for="email">Email:</label>`); | ||
| $(`form`).append(`<input type="text" name="email"></input>`); | ||
| $(`form`).append(`<p><strong>Trip:</strong> ${trip.name}</p>`); | ||
| $(`form`).append(`<input type="submit" class="btn btn-success" name="reserve" value="Reserve"></input>`); | ||
|
|
||
| $('form').submit(function() { | ||
| const formData = { | ||
| name: $('input[name="name"]').val(), | ||
| email: $('input[name="email"]').val() | ||
| } | ||
| reserveTrip(event, trip, formData); | ||
| }) | ||
| }; | ||
|
|
||
| const reserveTrip = function reserveTrip(event, trip, formData) { | ||
| event.preventDefault(); | ||
| const postURL = URL + trip.id + '/' + 'reservations'; | ||
| reportStatus('Making reservation...'); | ||
|
|
||
| axios.post(postURL, formData) | ||
| .then((response) => { | ||
| console.log(response.data); | ||
| reportStatus(`Trip to ${trip.name} for ${formData.name} reserved!`); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Error: ${error.message}`); | ||
| }) | ||
| }; | ||
|
|
||
| $(document).ready(() => { | ||
| $('#get-trips').click(loadTrips); | ||
| }) |
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,80 @@ | ||
| body { | ||
| font-family: sans-serif; | ||
| background-color: #f5f7f2; | ||
| background-image: url("http://www.flymetotaiwan.com/wp-content/uploads/2015/10/Background.jpg"); | ||
| } | ||
|
|
||
| h1, h2 { | ||
| padding: .5em; | ||
| padding-bottom: .25em; | ||
| border-bottom: solid 1px black; | ||
| margin: 0; | ||
| } | ||
|
|
||
| h2 { | ||
| margin-bottom: .5em; | ||
| } | ||
|
|
||
| .table { | ||
| max-width: 20%; | ||
| text-align: center; | ||
| border: black; | ||
| } | ||
|
|
||
| .btn.btn-success { | ||
| margin-bottom: 2em; | ||
| margin-top: 1em; | ||
| margin-left: 1em; | ||
| } | ||
|
|
||
| td:hover { | ||
| background-color: rgb(220, 242, 191); | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| p::first-letter { | ||
| text-transform: uppercase; | ||
| } | ||
|
|
||
| main { | ||
| display: flex; | ||
| flex-direction: row; | ||
| } | ||
|
|
||
| .list-container { | ||
| padding-left: 1em; | ||
| padding-right: 1em; | ||
| } | ||
|
|
||
| .details-container { | ||
| border: 1px solid #dee2e6; | ||
| margin-right: 1em; | ||
| height: max-content; | ||
| } | ||
|
|
||
| .reservation-container { | ||
| border: 1px solid #dee2e6; | ||
| margin-top: 1em; | ||
| margin-right: 1em; | ||
| height: max-content; | ||
| } | ||
|
|
||
| .column2 { | ||
| display: flex; | ||
| flex-direction: column; | ||
| /* width: 100%; */ | ||
| } | ||
|
|
||
| label { | ||
| font-weight: bold; | ||
| padding-right: .5em; | ||
| } | ||
|
|
||
| p, label, input { | ||
| padding-left: .5em; | ||
| } | ||
|
|
||
| #status-message { | ||
| background-color: rgb(220, 242, 191); | ||
| padding-left: .5em; | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
Neat, but I didn't see you using popper.js