Permalink
Browse files

Update from `browser-template`

Refresh for cohort 024.
Also, ensure that starter code here is in sync with solution code on
`jquery-ajax-get-collection`.
  • Loading branch information...
caleb-pearce committed Mar 22, 2018
1 parent 5beb9bc commit cfd36ec03a9b8fc2ef81da7b3774f86d85c0d5a0
@@ -1,15 +1,21 @@
tmp
dist
vendor.js
specs.js
application.js
_SpecRunner.html

# Created by https://www.gitignore.io/api/macos,linux
# Created by https://www.gitignore.io/api/osx,linux

### macOS ###
### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
# Thumbnails
._*
._
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
@@ -41,57 +47,58 @@ Temporary Items
# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# End of https://www.gitignore.io/api/macos,linux
tmp
dist
vendor.js
specs.js
application.js
_SpecRunner.html
*.woff2
*.woff
*.svg
*.ttf
*.eot
public/
# Created by https://www.gitignore.io/api/osx,linux
### OSX ###
._
# End of https://www.gitignore.io/api/osx,linux

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity


# End of https://www.gitignore.io/api/node
@@ -4,7 +4,7 @@ const config = require('../config.js')

const index = function () {
return $.ajax({
url: config.apiOrigin + '/books',
url: config.apiUrl + '/books',
method: 'GET'
})
}
@@ -2,10 +2,19 @@

const onSuccess = function (data) {
console.table(data.books)
data.books.forEach(book => {
const bookHTML = (`
<h4>Title: ${book.title}</h4>
<p>Author: ${book.author}</p>
<br>
`)

$('#content').append(bookHTML)
})
}

const onError = function (response) {
console.error(response)
const onError = function (err) {
console.error(err)
}

module.exports = {
@@ -1,10 +1,17 @@
'use strict'

const config = {
apiOrigins: {
development: 'https://ga-library-api.herokuapp.com',
production: 'https://ga-library-api.herokuapp.com'
}
let apiUrl
const apiUrls = {
production: '<replace-with-heroku-url>',
development: 'https://ga-library-api.herokuapp.com'
}

module.exports = config
if (window.location.hostname === 'localhost') {
apiUrl = apiUrls.development
} else {
apiUrl = apiUrls.production
}

module.exports = {
apiUrl
}
@@ -0,0 +1,4 @@
const element = document.createElement('div')
element.id = 'myDiv'
element.innerHTML = 'Hello World!'
document.body.appendChild(element)
@@ -1,21 +1,13 @@
'use strict'

const setAPIOrigin = require('../../lib/set-api-origin')
const config = require('./config')

$(() => {
setAPIOrigin(location, config)
})

// use require with a reference to bundle the file and use it in this file
// const example = require('./example')

// use require without a reference to ensure a file is bundled
// require('./example')

const bookEvents = require('./books/events')
const bookEvents = require('./books/events.js')

// On document ready
$(() => {
$('#books-search').on('submit', bookEvents.onGetBooks)
})
File renamed without changes.
@@ -0,0 +1,12 @@
curl --include --request GET "https://ga-library-api.herokuapp.com/books"

echo

# Alternatively
# API="${API_ORIGIN:-https://ga-library-api.herokuapp.com}"
# URL_PATH="/books"
# curl "${API}${URL_PATH}" \
# --include \
# --request GET
#
# echo
@@ -1,4 +1,4 @@
# Forms
# getFormFields

Developers should use `getFormFields` to retrieve data from html forms for API
requests.
@@ -13,17 +13,19 @@ The object returned can be used to validate the form data.
'use strict'
const ajaxDefaults = {
url: 'http://localhost:4741',
url: 'http://localhost:4741'
}
const myRequest = (data, success, fail) => {
$.ajax(Object.assign({ method: 'POST', data }, ajaxDefaults))
.done(success)
.fail(fail)
const myRequest = (data) => {
return $.ajax({
method: 'POST',
data: data,
url: ajaxDefaults.url
})
}
module.exports = {
myRequest,
myRequest
}
```

@@ -42,7 +44,7 @@ const failure = (err) => {
module.exports = {
success,
failure,
failure
}
```

@@ -59,7 +61,9 @@ $(() => {
$('#my-form').on('submit', function (e) {
let data = getFormFields(this)
e.preventDefault()
api.myRequest(data, ui.success, ui.failure)
api.myRequest(data)
.then(ui.success)
.catch(ui.failure)
})
})
```
@@ -14,6 +14,6 @@
"serve": ["server"],
"s": ["server"],
"make-standard": ["eslint:fix"],
"nag": ["eslint:all", "jsonlint:all"],
"test": ["build", "jasmine"]
"nag": ["eslint:all", "jsonlint:all", "sasslint:all"],
"test": ["mocha_phantomjs"]
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,3 @@
{
"all": ["<%= paths.src.spec %>"]
}
@@ -9,10 +9,7 @@
"Gruntfile.js"
],
"spec": [
"spec/**/*.spec.js"
],
"lib": [
"lib/**/*.js"
"spec/**/*.html"
]
},

@@ -29,5 +26,11 @@
"spec/**/*.json",
"grunt/*.json"
]
},

"sass": {
"all": [
"assets/styles/**/*.scss"
]
}
}
@@ -0,0 +1,5 @@
{
"all": {
"src": ["<%= paths.sass.all %>"]
}
}
@@ -33,10 +33,10 @@ module.exports = {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015']
presets: ['env']
}
},
{
@@ -66,7 +66,7 @@ module.exports = {
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg|png|jpg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
test: /\.(ttf|eot|svg|png|jpg|gif)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit cfd36ec

Please sign in to comment.