forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Trek-Cara-Octors #44
Open
MississippiBrenn
wants to merge
6
commits into
Ada-C9:master
Choose a base branch
from
MississippiBrenn: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
Trek-Cara-Octors #44
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf39822
Wave 1 complete, showing list of all trips
MississippiBrenn 09fb038
wave 2
MississippiBrenn e104555
Able to view trip and reserve trip
MississippiBrenn e66f7c5
Adding initial CSS
MississippiBrenn 79e5f08
final CSS
MississippiBrenn 708f3b0
created .gitignore file
MississippiBrenn 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 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 @@ | ||
node_modules/ |
This file contains 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,74 @@ | ||
|
||
#main{ | ||
font-family: Arial; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: flex-start; | ||
text-align: center; | ||
} | ||
|
||
#status-message{ | ||
height: 20px; | ||
} | ||
|
||
|
||
header{ | ||
align-self: left; | ||
font-weight: bold; | ||
font-size: 2em; | ||
border-bottom: 5px, solid, grey; | ||
} | ||
|
||
h1{ | ||
font-weight: bold; | ||
font-size: 2em; | ||
border-bottom: solid 1px; | ||
} | ||
|
||
|
||
|
||
#trip-details{ | ||
text-align: left; | ||
margin: 1em; | ||
} | ||
|
||
.current-trips{ | ||
padding: 0; | ||
border:solid; | ||
} | ||
|
||
div{ | ||
margin: 1em; | ||
} | ||
|
||
#load{ | ||
align-self: left; | ||
margin:1em; | ||
padding:1em; | ||
} | ||
|
||
|
||
|
||
#trip-list li{ | ||
padding: 2em; | ||
border: solid 1px; | ||
list-style: none; | ||
} | ||
|
||
ul{ | ||
width:100%; | ||
padding-left: 0px; | ||
} | ||
|
||
h2{ | ||
text-align: center; | ||
} | ||
|
||
article{ | ||
border: solid; | ||
margin: .5em; | ||
} | ||
|
||
.hidden{ | ||
display: none; | ||
} |
This file contains 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,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Trek Trip Planning</title> | ||
<script | ||
src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
<link rel="stylesheet" href="index.css" type="text/css"> | ||
</head> | ||
|
||
|
||
|
||
<body> | ||
|
||
<h1>Trek</h1> | ||
<section id='status-message'> </section> | ||
<button type="button" name="button" id="load">Get Trips!</button> | ||
|
||
<main id="main"> | ||
|
||
<aside class="current-trips hidden" id ="current-trips"> | ||
<h2>All Trips</h2> | ||
|
||
<ul id="trip-list"></ul> | ||
</aside> | ||
|
||
<aside class="view-trip hidden" id="view-trip"> | ||
<article id="trip-details"> | ||
<h2>Trip Details</h2> | ||
|
||
<tablebody id="tablebody"> | ||
|
||
</tablebody> | ||
</article> | ||
<article id="reserve-trip"> | ||
<h2>Reserve Trip</h2> | ||
<form id="reserve-form"> | ||
<div> | ||
<label for="name">Name</label> | ||
<input type="text" name="name" /> | ||
</div> | ||
|
||
<div> | ||
<label for="age">Age</label> | ||
<input type="number" name="age" /> | ||
</div> | ||
|
||
<div> | ||
<label for="email">Email</label> | ||
<input type="text" name="email" /> | ||
</div> | ||
|
||
<input type="submit" name="add-reservation" class="button" value="Reserve" /> | ||
</form> | ||
</article> | ||
</aside> | ||
</main> | ||
|
||
</body> | ||
|
||
<script type="text/javascript" src="index.js"></script> | ||
|
||
</html> |
This file contains 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,150 @@ | ||
const URL = 'https://ada-backtrek-api.herokuapp.com/trips/' | ||
|
||
|
||
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); | ||
}; | ||
|
||
const loadTrips = () => { | ||
reportStatus('Loading trips ...'); | ||
|
||
|
||
const tripList = $('#trip-list'); | ||
tripList.empty(); | ||
$('#current-trips').removeClass('hidden') | ||
|
||
axios.get(URL) | ||
.then((response) => { | ||
console.log(response); | ||
reportStatus(`Successfully loaded`); | ||
response.data.forEach((trip) => { | ||
|
||
let id = trip.id | ||
|
||
tripList.append(`<li class="trip" id="${id}">${trip.name}</li>`); | ||
|
||
|
||
}); | ||
//only returns one element | ||
|
||
}) | ||
|
||
.catch((error) => { | ||
reportStatus(`Encountered an error while loading trips: ${error.message}`); | ||
reportError(error.message, error.response.data.errors) | ||
console.log(error); | ||
|
||
}); | ||
|
||
}; | ||
|
||
const clickTrip = (trip) => { | ||
console.log(trip) | ||
|
||
$('#view-trip').removeClass('hidden') | ||
|
||
axios.get(URL+trip) | ||
.then((response) => { | ||
console.log(response); | ||
reportStatus(`Successfully loaded`); | ||
|
||
console.log('appending to table body'); | ||
|
||
$('#tablebody').append(`<p>Name: ${response.data.name}</p>`); | ||
$('#tablebody').append(`<p>Id: ${response.data.id}</p>`); $('#tablebody').append(`<p>Continent: ${response.data.continent}</p>`); | ||
$('#tablebody').append(`<p>About: ${response.data.about}</p>`); | ||
$('#tablebody').append(`<p>Category: </category>${response.data.category}</p>`); | ||
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. It might make sense to break the code to render trip details out into a separate function - as is, this function is doing two things (making the request, and rendering data). See also http://callbackhell.com/ |
||
$('#tablebody').append(`<p>Week: ${response.data.weeks}</p>`); | ||
$('#tablebody').append(`<p>Cost: ${response.data.cost}</p>`); | ||
|
||
|
||
|
||
}) | ||
|
||
.catch((error) => { | ||
reportStatus(`Encountered an error while loading trips: ${error.message}`); | ||
reportError(error.message, error.response.data.errors) | ||
console.log(error); | ||
|
||
}); | ||
|
||
}; | ||
|
||
const FORM_FIELDS = ['name', 'age', 'email']; | ||
const inputField = name => $(`#reserve-form input[name="${name}"]`); | ||
|
||
const readFormData = () => { | ||
const getInput = name => { | ||
const input = inputField(name).val(); | ||
return input ? input : undefined; | ||
}; | ||
|
||
const formData = {}; | ||
FORM_FIELDS.forEach((field) => { | ||
formData[field] = getInput(field); | ||
console.log('formData') | ||
}); | ||
|
||
console.log(formData) | ||
return formData; | ||
}; | ||
|
||
const clearForm = () => { | ||
FORM_FIELDS.forEach((field) => { | ||
inputField(field).val(''); | ||
}); | ||
} | ||
|
||
const createReservation = (id) => { | ||
|
||
const tripData = readFormData(); | ||
console.log(tripData); | ||
|
||
reportStatus('Sending trip data...'); | ||
|
||
let url = URL + id + '/reservations' | ||
|
||
axios.post(url, tripData) | ||
.then((response) => { | ||
console.log('success') | ||
reportStatus(`Successfully made a reservation for ${response.data.name}!`); | ||
clearForm(); | ||
}) | ||
.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}`); | ||
} | ||
}); | ||
}; | ||
|
||
|
||
|
||
$(document).ready(() => { | ||
$('#load').click(loadTrips); | ||
$('ul').on('click', 'li', function() { | ||
console.log(this.id) | ||
clickTrip(this.id) | ||
$('#reserve-form').submit((event) => { | ||
event.preventDefault(); | ||
createReservation(this.id); | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.
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.
You probably want to empty the
view-trip
section here too. As is, if you click on more than one trip the details for all the trips display on the screen at once.