forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Amy Lee -- Carets #40
Open
ayjlee
wants to merge
14
commits into
Ada-C8:master
Choose a base branch
from
ayjlee: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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c73065e
basic list view of all trips and button to view trips working
ayjlee 50e48e7
added fail and always promises to GET alltrips requests, attached the…
ayjlee 8ea22ca
refactored to have a function, getTrips, that performs the 'get all t…
ayjlee 588ff5d
wrote method findTrip to get details for oneTrip by tripID
ayjlee e6e47dd
added basic commands to clear trip-detail information or the list of …
ayjlee 3c9dc77
Added form and method to reserve
ayjlee 9a25de3
added a 'filter by' drop down selector, no added functionality yet
ayjlee 4862c50
added basic styling to header, addNewTrip form, seeAllTrips ul
ayjlee 62bc03c
basic styling to trip-detail section, added functionality to clear se…
ayjlee 28403ea
format cost to show two decimal places, like standard US currency
ayjlee ff4afe3
added picture to homepage
ayjlee fde73c8
added margins to form inputs and sections
ayjlee 220d38f
deleted notes to self
ayjlee 572155e
deleted code for unused optional enhancements. see previous commit fo…
ayjlee 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,111 @@ | ||
header { | ||
text-align: center; | ||
} | ||
|
||
h1, h2, h3 { | ||
font-family: 'Bevan', cursive; | ||
} | ||
|
||
ul { | ||
list-style: none; | ||
} | ||
|
||
body { | ||
background-color: #ffcf32; | ||
width: 100%; | ||
} | ||
|
||
li { | ||
padding: 20px; | ||
border: green dotted .5px; | ||
width: 80%; | ||
margin: 0px auto; | ||
} | ||
|
||
|
||
#trip-details h4 { | ||
-webkit-margin-before: 0.5em; | ||
-webkit-margin-after: 0.5em; | ||
} | ||
|
||
#trip-details p { | ||
-webkit-margin-before: 0; | ||
-webkit-margin-after: 0; | ||
} | ||
|
||
.trip-details { | ||
font-weight: lighter; | ||
/*color: lightgreen;*/ | ||
} | ||
|
||
#trip-details, #trip-list { | ||
margin-top: 20px; | ||
background-color: snow; | ||
} | ||
|
||
|
||
#message h3 { | ||
color: red; | ||
} | ||
|
||
button { | ||
color: black; | ||
background-color: transparent; | ||
box-sizing: border-box; | ||
padding: 2px 6px 3px; | ||
font-size: 1em; | ||
border: black solid 1px; | ||
text-align: center; | ||
} | ||
|
||
#new-trip-form { | ||
width: 80%; | ||
margin: 0px auto; | ||
padding-bottom: 10px; | ||
border-radius: 15px; | ||
/*text-align: center;*/ | ||
} | ||
|
||
#new-trip-form h3, #new-trip-form .button, .button { | ||
text-align: center; | ||
padding-top: 2%; | ||
} | ||
|
||
input { | ||
width: 60%; | ||
padding: 12px 20px; | ||
/*margin: 8px 0;*/ | ||
display: block; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
box-sizing: border-box; | ||
margin-top: 10px; | ||
} | ||
|
||
input:focus { | ||
border: 3px solid #555; | ||
} | ||
|
||
label { | ||
width: 20%; | ||
text-align: right; | ||
} | ||
|
||
label, input { | ||
display: inline-block; | ||
} | ||
|
||
#find-trip-btns { | ||
-webkit-margin-before: 0.35em; | ||
} | ||
|
||
#welcome-img { | ||
width: 100%; | ||
text-align: center; | ||
} | ||
|
||
#welcome-img img { | ||
margin: 15px auto; | ||
height: 60%; | ||
width: 60%; | ||
} |
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,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Trek</title> | ||
<link href="index.css" media="screen" rel="stylesheet" type="text/css"> | ||
<link href="https://fonts.googleapis.com/css?family=Bevan" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1> | ||
TREK | ||
</h1> | ||
<section id = "main-buttons"> | ||
|
||
<button id = "all-trips"> | ||
See All Trips | ||
</button> | ||
|
||
<button id = "add-trip"> | ||
Add New Trip | ||
</button> | ||
|
||
</section> | ||
</header> | ||
|
||
<section id= "message"> | ||
|
||
</section> | ||
<section id= "trip-details"> | ||
|
||
</section> | ||
<section id= "trip-list"> | ||
<!-- <section class = "filter-buttons"> | ||
<p>Filter By: | ||
<select id="filter-query"> | ||
<option selected value="default">Please Select</option> | ||
<option value="continent">Continent</option> | ||
<option value="budget">Budget</option> | ||
<option value="weeks">Weeks</option> | ||
<option value="category">Category</option> | ||
</select> | ||
</p> | ||
</section> --> | ||
|
||
<ul> | ||
</ul> | ||
</section> | ||
<section id= "welcome-img"> | ||
<img src="travel.png" alt= "travel-graphic" /> | ||
</section> | ||
|
||
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script> | ||
<script src="index.js" type= "text/javascript"></script> | ||
</body> | ||
</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,155 @@ | ||
/* eslint-disable */ | ||
const BASE_URL = 'https://trektravel.herokuapp.com/trips'; | ||
const continents = []; | ||
const getTrips = (url) => { | ||
$.get(url, (response) => { | ||
console.log('success!'); | ||
console.log(response); | ||
response.forEach((trip) => { | ||
const tripInfo = `<li data-id= ${trip.id} id = "trip-${trip.id}"><strong>${trip.name}</strong> - ${trip.weeks} week(s) in ${trip.continent} </li>`; | ||
$('#trip-list ul').append(tripInfo); | ||
if (!continents.includes(trip.continent.toLowerCase()) && trip.continent) { | ||
continents.push((trip.continent).toLowerCase()); | ||
}; | ||
}); | ||
}).fail(() => { | ||
$('#message').html('<h3> No trips found :( )</h3>'); | ||
}).always(() => { | ||
console.log('Adenture awaits you!'); | ||
}); | ||
}; | ||
const addTrip = () => { | ||
// TODO: Add "Cancel" button to clear add new trip form | ||
const newTripForm = ` | ||
<form id= "new-trip-form" action="https://trektravel.herokuapp.com/trips" method="post"> | ||
<h3> ADD NEW TRIP </h3> | ||
<section> | ||
<div class = "form-input"> | ||
<label>Name:</label> | ||
<input type="text" id="name" name="name"></input> | ||
</div> | ||
<div class = "form-input"> | ||
<label>Continent:</label> | ||
<input type="text" id="continent" name="continent"></input> | ||
</div> | ||
<div class = "form-input"> | ||
<label>About:</label> | ||
<input type="textfield" id="about" name="about"></input> | ||
</div> | ||
<div class = "form-input"> | ||
<label>Category:</label> | ||
<input type="text" id="category" name="category"></input> | ||
</div> | ||
<div class = "form-input"> | ||
<label>Weeks:</label> | ||
<input type="integer" id="weeks" name="weeks"></input> | ||
</div> | ||
<div class = "form-input"> | ||
<label>Cost:</label> | ||
<input type="float" id="cost" name="cost"></input> | ||
</section> | ||
</div> | ||
<section class="button"> | ||
<button type="submitReservation">Add This Trip</button> | ||
</section> | ||
</form>`; | ||
$('#trip-list').prepend(newTripForm); | ||
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. This particular form doesn't have any HTML that needs to be dynamically generated. Since the form will look the same in all cases, you may consider having this on the html already, and just using jQuery to hide()/show() it when appropriate |
||
$('form').on('submit', function(e) { | ||
e.preventDefault(); | ||
const formData = $(this).serialize(); | ||
const url = $(this).attr('action'); | ||
$.post(url, formData, (response) => { | ||
$('#message').html(`<h3 id= "status-message"> Successfully added new trip: ${response.name}</h3>`); | ||
console.log(`Success! New Trip added`); | ||
// $('#trip-details').empty(); | ||
}).fail(() => { | ||
$('#message').html('<h3 id= "status-message"> Error: Unable to create new trip</h3>'); | ||
console.log(`Try again.`); | ||
}); | ||
}); | ||
} | ||
const hideDetails = () => { | ||
console.log('you hid the details'); | ||
$('#trip-details').empty(); | ||
}; | ||
const reserveTrip = (tripID) => { | ||
console.log(`you are reserving this trip with id ${tripID}`); | ||
const reservationForm = `<form id= "reservation-form" action="https://trektravel.herokuapp.com/trips/${tripID}/reservations" method="post"> | ||
<section> | ||
<label>Name</label> | ||
<input type="text" id="name" name="name"></input> | ||
</section> | ||
|
||
<section class="button"> | ||
<button type="submitReservation">Reserve My Spot</button> | ||
</section> | ||
</form>`; | ||
$('#trip-details').append(reservationForm); | ||
$('form').submit(function(e) { | ||
e.preventDefault(); | ||
const formData = $(this).serialize(); | ||
const url = $(this).attr('action'); | ||
$.post(url, formData, (response) => { | ||
$('#message').html(`<h3 id= "status-message"> Successfully reserved this trip for ${response.name}</h3>`); | ||
console.log(`Success! You're on the list.`); | ||
$('#trip-info').toggle(); | ||
$('#trip-details form:last-child').empty(); | ||
}).fail(() => { | ||
$('#message').html('<h3 id= "status-message"> Sorry, there are no spots left for this trip.</h3>'); | ||
console.log(`Sorry, no spots left.`); | ||
}); | ||
}); | ||
}; | ||
const findTrip = (tripID) => { | ||
$.get(`https://trektravel.herokuapp.com/trips/${tripID}`, (response) => { | ||
console.log(response); | ||
const tripInfo = ` | ||
<section id= "trip-info"> | ||
<h3>${response.name.toUpperCase()}</h3> | ||
<p>Trip ID: ${response.id} | ||
</p> | ||
<p>Trip Destination: ${response.continent}</p> | ||
<p>Duration(in weeks): ${response.weeks}</p> | ||
<p>Category: ${response.category}</p> | ||
<p>Cost: $${(response.cost).toFixed(2)}</p> | ||
<h4>About:</h4> | ||
<p>${response.about}</p> | ||
<div id = "find-trip-btns"> | ||
<button id= "hide-details">Hide Details</button> | ||
<button id= "reserve-trip">Reserve this Trip</button> | ||
</div> | ||
</section> | ||
`; | ||
$('#trip-details').append(tripInfo); | ||
$('#hide-details').on('click', () => { | ||
hideDetails(); | ||
}); | ||
$('#reserve-trip').on('click', () => { | ||
reserveTrip(response.id); | ||
$('#trip-info').toggle(); | ||
}); | ||
}); | ||
}; | ||
|
||
$(document).ready(() => { | ||
// events | ||
$('#all-trips').on('click', () => { | ||
$('#trip-details').empty(); | ||
$('#message').empty(); | ||
$('#trip-list form').empty(); | ||
$('#welcome-img').toggle(); | ||
getTrips(BASE_URL); | ||
}); | ||
$('#trip-list ul').on('click', 'li', function() { | ||
const tripID = $(this).attr('data-id'); | ||
// $('#trip-details').toggle(); | ||
findTrip(tripID); | ||
$('#trip-list ul').empty(); | ||
}); | ||
$('#add-trip').on('click', () => { | ||
$('#trip-details').empty(); | ||
$('#trip-list ul').empty(); | ||
console.log('adding a trip'); | ||
addTrip(); | ||
}); | ||
}); |
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.
if
trip.continent
is null, the code breaks. Surprisingly enough, if you change the order of this conditional, then it'll work:In a conditional with an
&&
, iftrip.continent
is falsey, it won't bother evaluating the rest of the conditional