-
Notifications
You must be signed in to change notification settings - Fork 42
Ampers: Nicoleta Brandolini #19
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
base: master
Are you sure you want to change the base?
Changes from all commits
ac40f7b
7c7435d
24703a3
a33f22f
e4a64c1
880dcd3
dfdf218
6639d83
6e391a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Trek</title> | ||
| <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/foundation/6.2.3/foundation.min.css"> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
|
|
||
| <body> | ||
| <header> | ||
| <h1>Trek the World</h1> | ||
| <button id="load" class="button">See All Trips</button> | ||
| </header> | ||
|
|
||
| <section id="status-message"></section> | ||
|
|
||
| <main class="row"> | ||
| <section class="small-6 columns trips-container"> | ||
| <table id="table"> | ||
| <thead> | ||
| <tr> | ||
| <th>Trip Id</th> | ||
| <th>Trip Name</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody id="tbody"></tbody> | ||
| </table> | ||
| </section> | ||
|
|
||
| <section class="small-6 columns trips-container"> | ||
| <table id="details"> | ||
| <thead> | ||
| <tr> | ||
| <th> | ||
| Trip Details | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody id="trip-info"></tbody> | ||
| </table> | ||
|
|
||
| <button id="reservation-form" class="button">Reserve Trip</button> | ||
|
|
||
| </section> | ||
| </main> | ||
|
|
||
| <footer> | ||
| <h5>Nicoleta Brandolini @2018</h5> | ||
| </footer> | ||
|
|
||
| <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="trek.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| .trip-details cell medium-8 medium-cell-block-y { | ||
|
|
||
| } | ||
|
|
||
| body { | ||
| text-align: center; | ||
| padding: 2rem; | ||
| height: 100%; | ||
| background-image: url('images/background.png'); | ||
| background-attachment: fixed; | ||
| background-position: center; | ||
| background-repeat: no-repeat; | ||
| background-size: cover; | ||
| } | ||
|
|
||
| #status-message { | ||
| font-size: 1rem; | ||
| color: white; | ||
| padding-bottom: 20px; | ||
| } | ||
|
|
||
| h1 { | ||
| font-size: 4rem; | ||
| color: #077b93; | ||
| } | ||
|
|
||
| th { | ||
| color: #077b93 | ||
| } | ||
|
|
||
| .button { | ||
| font-size: 1rem; | ||
| background-color: #077b93; | ||
| margin: 15px; | ||
| padding: 10px; | ||
| } | ||
|
|
||
| footer { | ||
| color: white; | ||
| padding: 20px 0 10px 0; | ||
| } | ||
|
|
||
| .submit-container { | ||
| color: #077b93 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| const URL = 'https://ada-backtrek-api.herokuapp.com/trips'; | ||
|
|
||
| const reportStatus = (message) => { | ||
| $('#status-message').html(message); | ||
| }; | ||
|
|
||
| // LOAD TRIPS | ||
| const loadTrips = () => { | ||
| const tripsList = $('#tbody'); | ||
| tripsList.empty(); | ||
|
|
||
| reportStatus('Loading trips! Please wait...'); | ||
| $('#table').show(); | ||
|
|
||
| axios.get(URL) | ||
| .then((response) => { | ||
| response.data.forEach((trip) => { | ||
| tripsList.append(`<tr id="${trip.id}"><td>${trip.id}</td> | ||
| <td>${trip.name}</td></tr>`); | ||
| }); | ||
| reportStatus('Trips Loaded!'); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus('Error: ${error.message}'); | ||
| }); | ||
| }; | ||
|
|
||
| // LOAD ONE TRIP | ||
|
|
||
| const loadTrip = (id) => { | ||
| const tripInfo = $('#trip-info'); | ||
| tripInfo.empty(); | ||
| const reservationForm = $('#reservation-form'); | ||
| reservationForm.empty(); | ||
|
|
||
| reportStatus('Loading trip info! Please wait...'); | ||
| $('#details').show(); | ||
|
|
||
| // GET TRIP DETAILS FROM API | ||
|
|
||
| axios.get(URL + `/${id}`) | ||
| .then((response) => { | ||
| // console.log(response); | ||
| tripInfo.append(`<tr><td><strong>Name: </strong> ${response.data.name}</td></tr> | ||
| <tr><td><strong>Trip ID: </strong>${response.data.id}</td></tr> | ||
| <tr><td><strong>Continent: </strong>${response.data.continent}</td></tr> | ||
| <tr><td><strong>Category: </strong>${response.data.category}</td></tr> | ||
| <tr><td><strong>Weeks: </strong>${response.data.weeks}</td></tr> | ||
| <tr><td><strong>Cost: </strong>${response.data.cost.toFixed(2)}</td></tr> | ||
| <tr><td><strong>About: </strong></br>${response.data.about}</td></tr>`); | ||
| reportStatus('Trip Info Loaded!'); | ||
| reservationForm.append(`<div > | ||
| <label for="name">Trip:${response.data.name}</label> | ||
| </div>`); | ||
| reservationForm.append(`<div> | ||
| <label for="name">Name: </label> | ||
| <input type="text" name="user-name" /> | ||
| </div> | ||
| <div> | ||
| <label for="email">Email: </label> | ||
| <input type="text" name="email" /> | ||
| </div> | ||
| <div class="submit-container"> | ||
| <input type="submit" name="add-reservation" value="Reserve" class="reserve" id="reserve${response.data.id}"/> | ||
|
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. Out of curiosity, why do you make the |
||
| </div>`); | ||
|
|
||
| }) | ||
| .catch((error) => { | ||
| reportStatus('Error: ${error.message}'); | ||
| }); | ||
| }; | ||
|
|
||
| //RESERVE TRIP | ||
|
|
||
| const reserveTrip = (id) => { | ||
| reportStatus(''); | ||
|
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. Do you need this? |
||
| reportStatus('Reserving The Trip...'); | ||
|
|
||
| let userData = { | ||
| 'name': $('input[name="user-name"]').val(), | ||
| 'email': $('input[name="email"]').val(), | ||
| }; | ||
|
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. Since this is JavaScript, all property names (keys) are assumed to be strings, so you can write this as: let userData = {
name: $('input[name="user-name"]').val(),
email: $('input[name="email"]').val(),
}; |
||
|
|
||
| axios.post(URL + `/${id}/reservations`, userData) | ||
| .then((response) => { | ||
| reportStatus(`Successfully reserved this trip with the name ${response.data.name}`); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| }); | ||
|
|
||
| $('input[name="user-name"]').val(''); | ||
| $('input[name="email"]').val(''); | ||
| }; | ||
|
|
||
| // ACTION | ||
| $(document).ready(() => { | ||
| $('#load').click(loadTrips); | ||
| $('#tbody').on('click', 'tr', function () { | ||
|
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. something with the ID |
||
| let id = $(this).attr('id'); | ||
| loadTrip(id); | ||
| }); | ||
|
|
||
| $('#reservation-form').on('click', '.reserve', function () { | ||
| let id = $(this).attr('id').substr(7); | ||
| reserveTrip(id); | ||
| }); | ||
| }); | ||
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.
same comment as below, but: the ID
#tableisn't a very helpful ID name! Which table is it?