forked from AdaGold/BackTREK
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Pipes - Kee - BackTREK #47
Open
anemonekey
wants to merge
7
commits into
Ada-C8:master
Choose a base branch
from
anemonekey: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
7 commits
Select commit
Hold shift + click to select a range
64fece8
Added trip model, collection, and basic layout
anemonekey 6b4b06d
Can see list of all trips; working on showing single trip details
anemonekey 3fa1d5f
Edited and deleted a few files
anemonekey 76fcefc
Finished wave 1 display requirements
anemonekey c478ce2
Working on add trip module
anemonekey d3cba78
Working on posting additional trips
anemonekey 92ed1e4
Trying to fix add trip functionality
anemonekey 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
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 |
---|---|---|
|
@@ -6,8 +6,91 @@ import _ from 'underscore'; | |
import './css/foundation.css'; | ||
import './css/style.css'; | ||
|
||
console.log('it loaded!'); | ||
// do i need you? -- I THINK SO | ||
import Trip from './app/models/trip'; | ||
import TripList from './app/collections/trip_list'; | ||
|
||
// ALL THE FIELDS | ||
const TRIP_FIELDS = ['id', 'name', 'continent', 'about', 'category', 'weeks', 'cost']; | ||
|
||
const tripList = new TripList(); | ||
let trip = new Trip(); | ||
|
||
let tripTemplate; | ||
let tripDetails; | ||
|
||
// RENDERS | ||
const render = function render(tripList) { | ||
const tripTbody = $('#trip-list'); | ||
tripTbody.html(''); | ||
|
||
tripList.forEach((trip) => { | ||
const generatedHtml = tripTemplate(trip.attributes); | ||
tripTbody.append(generatedHtml); | ||
}); | ||
}; | ||
|
||
const renderDetails = function renderDetails(trip){ | ||
const detailsDiv = $('#trip-details'); | ||
detailsDiv.html(''); | ||
trip.fetch({ | ||
success: (model) => { | ||
const generatedHTML = $(tripDetails(trip.attributes)); | ||
detailsDiv.append(generatedHTML); | ||
console.log(trip); | ||
}, | ||
error: (status, response) => { | ||
const errors = ($.parseJSON(response.responseText))['errors']; | ||
} | ||
}); | ||
console.log(trip); | ||
}; | ||
|
||
// JQUERY | ||
$(document).ready( () => { | ||
$('main').html('<h1>Hello World!</h1>'); | ||
// my templates | ||
tripTemplate = _.template($('#trip-template').html()); | ||
tripDetails = _.template($('#detail-template').html()); | ||
|
||
console.log(`About to fetch data from ${ tripList.url }`); | ||
|
||
tripList.on('update', render); | ||
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. You also need an:
Otherwise it sorts, but doesn't display the results on the screen! |
||
tripList.fetch(); | ||
|
||
trip.on('click', renderDetails); | ||
trip.fetch(); | ||
|
||
TRIP_FIELDS.forEach((field) => { | ||
const headerElement = $(`th.sort.${ field }`); | ||
headerElement.on('click', (event) => { | ||
tripList.comparator = field; | ||
tripList.sort(); | ||
}) | ||
}); | ||
|
||
// Show individual trip details | ||
$('tbody#trip-list').on('click', 'a', function() { | ||
let tripID = $(this).attr('data-id'); | ||
trip = tripList.get(tripID); | ||
trip.on('click', renderDetails(trip)); | ||
}); | ||
|
||
// Listen for form submissions | ||
$('#add-trip-form').on('submit', (event) => { | ||
event.preventDefault(); | ||
|
||
const tripData = readForm(); | ||
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. You don't HAVE a |
||
const trip = tripList.add(tripData); | ||
console.log(tripData); | ||
console.log(trip); | ||
|
||
const newTrip = new Trip(formData); | ||
trip.save({}, { | ||
success: console.log("Success!"), | ||
error: console.log("Oh no!") | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); |
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,17 @@ | ||
import Backbone from 'backbone'; | ||
import Trip from '../models/trip'; | ||
|
||
const TripList = Backbone.Collection.extend({ | ||
model: Trip, | ||
url: 'https://ada-backtrek-api.herokuapp.com/trips/', | ||
parse: function(response) { | ||
return response; | ||
}, | ||
comparator: 'name', | ||
|
||
initialize: function () { | ||
this.model = Trip; | ||
} | ||
}); | ||
|
||
export default TripList; |
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,10 @@ | ||
import Backbone from 'backbone'; | ||
|
||
const Trip = Backbone.Model.extend({ | ||
urlRoot: `https://ada-backtrek-api.herokuapp.com/trips`, | ||
parse: function(response) { | ||
return response; | ||
}, | ||
}); | ||
|
||
export default Trip; |
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 |
---|---|---|
@@ -1,2 +1,74 @@ | ||
|
||
/* Your styles go here! */ | ||
|
||
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css'); | ||
@import url('https://fonts.googleapis.com/css?family=Judson|Quando'); | ||
|
||
/*---------- test ----------*/ | ||
/** { border: 1px solid red !important; }*/ | ||
|
||
|
||
|
||
html { box-sizing: border-box; } | ||
*, *:before, *:after { box-sizing: inherit; } | ||
html, body { height: 100%; } | ||
body { | ||
width: 100%; | ||
padding: 0; | ||
font-size: 16px; | ||
background: linear-gradient(to bottom, #6790c6 0%,#343789 100%); | ||
background-repeat: no-repeat; | ||
background-attachment: fixed; | ||
font-family: 'Quando', serif; | ||
} | ||
h1, h2, button { font-family: 'Judson', serif; } | ||
a:hover, | ||
button:hover { | ||
cursor: pointer; | ||
} | ||
header, main, footer { width: 100%; max-width: 100%; } | ||
.row { margin: 0; max-width: 100%; } | ||
.row .row { margin: 0; } | ||
|
||
div.add-wrapper { text-align: right; } | ||
|
||
/*header.header { margin: 0.5% 2% 1%; }*/ | ||
section.main-content { margin-top: 1%; } | ||
|
||
i.fa { margin-right: 2%; } | ||
i.fa-search { margin: 0; } | ||
|
||
|
||
h1.col { | ||
margin-left: 1%; | ||
padding: 0; | ||
color: #fefefe; | ||
} | ||
|
||
|
||
|
||
/*---------- table ----------*/ | ||
table#trip-table { margin-top: 5%; } | ||
table#trip-table { width: 100%; overflow: scroll; } | ||
|
||
/*---------- form ----------*/ | ||
input#search-query { margin: 0; } | ||
select#search-select { width: 100%; } | ||
|
||
/*---------- trip details ----------*/ | ||
div#trip-details { | ||
margin-top: 5%; | ||
background: #fafafa; | ||
/*padding: 2% 4%;*/ | ||
border-radius: 4px; | ||
} | ||
div#trip-details div { padding: 2% 4% 1%;} | ||
h2.detail-name { | ||
margin-bottom: 2%; | ||
padding: 1% 1% 2%; | ||
border-bottom: 2px solid #ededed; | ||
} | ||
|
||
|
||
|
||
/*---------- footer ----------*/ | ||
p.copyright { text-align: center; } |
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 don't seem to have any JavaScript catching this form's submit action, so it causes a page reload.