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
Aruna(ampers) #21
Open
aruna79
wants to merge
5
commits into
Ada-C9:master
Choose a base branch
from
aruna79: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
Aruna(ampers) #21
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Binary file not shown.
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,45 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Trips</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> | ||
<div id="header">TREK</div> | ||
|
||
</header> | ||
|
||
<main class="tripcontainer"> | ||
<div class="buttoncontainer"> | ||
<section id="status-message"></section> | ||
<section class="button"> | ||
<button id="load" class="button">Get trips!</button> | ||
</section> | ||
</div> | ||
<div class="triplist"> | ||
<ul id="trip-list"></ul> | ||
|
||
</div> | ||
<div class="tripdetail"> | ||
<h4>Trip Details</h4> | ||
<section id="trip"></section> | ||
</div> | ||
<div class="tripreservation"> | ||
<h4>Reserve Trip</h4> | ||
<section id="reservation"> | ||
|
||
|
||
</div> | ||
</main> | ||
|
||
<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> | ||
|
||
</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,100 @@ | ||
const URL = 'https://ada-backtrek-api.herokuapp.com/trips/'; | ||
|
||
const reportStatus = (message) => { | ||
$('#status-message').html(message); | ||
} | ||
|
||
const loadTrips = () => { | ||
|
||
const tripList = $('#trip-list'); | ||
tripList.empty(); | ||
|
||
reportStatus('Loading Trips! Please Wait...'); | ||
|
||
axios.get(URL) | ||
.then((response) => { | ||
response.data.forEach((trip) => { | ||
tripList.append(`<li id="${trip.id}">${trip.name}</li>`); | ||
}); | ||
reportStatus('Trips Loaded!'); | ||
}) | ||
.catch((error) => { | ||
reportStatus(`Error: ${error.message}`); | ||
}) | ||
} | ||
const loadTrip = (id) => { | ||
|
||
const tripInfo = $('#trip'); | ||
tripInfo.empty(); | ||
const reservationInfo = $('#reservation'); | ||
reservationInfo.empty(); | ||
|
||
reportStatus('Loading Trip Details! Please Wait...') | ||
|
||
axios.get(URL + `${id}`) | ||
.then((response) => { | ||
|
||
let data = response.data; | ||
console.log(data.name); | ||
|
||
|
||
tripInfo.append(`<li><strong>Name: </strong>${data.name}</li>`); | ||
tripInfo.append(`<li>Continent: ${data.continent}</li>`); | ||
tripInfo.append(`<li>Category:${data.category}</li>`); | ||
tripInfo.append(`<li>Weeks: ${data.weeks}</li>`); | ||
tripInfo.append(`<li>Cost: ${data.cost}</li>`); | ||
tripInfo.append(`<li>About:${data.about}</li>`); | ||
console.log(tripInfo); | ||
|
||
reservationInfo.append( | ||
`<label class="user"> Name:</label> | ||
<input type="text" name="name" class="form"/><br>` | ||
|
||
); | ||
reservationInfo.append( | ||
`<label class="user">Email:</label> | ||
<input type="text" name="email" class="form"/><br>` | ||
); | ||
reservationInfo.append(`<label>Trip: ${data.name}</label><br>`); | ||
reservationInfo.append( | ||
`<input type="submit" name="reserve-trip" class="reserve" id="reserve${data.id}"/>` | ||
); | ||
reportStatus('Trip Details Loaded!'); | ||
}) | ||
.catch((error) => { | ||
reportStatus(`Error: ${error.message}`); | ||
}) | ||
} | ||
const reservationData = (id) => { | ||
let tripData = {name: $(`input[name="name"]`).val(), | ||
email:$(`input[name="email"]`).val() | ||
} | ||
console.log(reservationData); | ||
|
||
reportStatus('Reserving a trip...'); | ||
|
||
axios.post(URL + `${id}/reservations`, tripData) | ||
.then((response) => { | ||
console.log('The post req was succesful') | ||
reportStatus(`Successfully reserved this trip ${response.data.name}!`); | ||
|
||
}) | ||
.catch((error) => { | ||
console.log(error.response); | ||
|
||
reportStatus(`Encountered an error: ${error.message}`); | ||
}); | ||
|
||
}; | ||
$(document).ready(() => { | ||
$('#load').click(loadTrips); | ||
$('#trip-list').on('click', 'li', function() { | ||
let id = $(this).attr('id'); | ||
loadTrip(id); | ||
}); | ||
$('#reservation').on('click', '.reserve', function(){ | ||
let id = $(this).attr('id').substr(7); | ||
console.log(id); | ||
reservationData(id); | ||
}); | ||
}) |
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,50 @@ | ||
|
||
body{ | ||
|
||
/* background-color: lightblue; */ | ||
background-image: url("trips.jpeg"); | ||
height: 100%; | ||
padding: 2rem; | ||
|
||
background-attachment: fixed; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
background-size: cover; | ||
} | ||
|
||
|
||
|
||
header{ | ||
|
||
|
||
} | ||
*{ | ||
list-style-type: none; | ||
} | ||
.tripcontainer{ | ||
display: grid; | ||
grid-template-columns: auto auto; | ||
align-content: space-around; | ||
/* border: 1px solid black; */ | ||
font-size: 12px; | ||
|
||
|
||
} | ||
.buttoncontainer{ | ||
grid-column: 1/3; | ||
border: 1px solid black; | ||
} | ||
.triplist{ | ||
grid-row: 2/5; | ||
border: 1px solid black; | ||
text-decoration: underline; | ||
|
||
} | ||
.tripdetail{ | ||
border: 1px solid black; | ||
padding:5px; | ||
} | ||
.tripreservation{ | ||
border: 1px solid black; | ||
padding:5px; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
You should loop through the validation errors (if any) here as well as the error message.