Last active
March 23, 2020 21:19
-
-
Save rickychilcott/2eb189d76215ffc68abf868c78ae3c2a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<!-- Copy from here --> | |
<h3><strong>Federal Support</strong></h3> | |
<div class="federal-results"></div> | |
<h3><strong>State Support</strong></h3> | |
<div class="state-results"></div> | |
<h3><strong>Local Support</strong></h3> | |
<div class="local-results"></div> | |
<!-- js libraries --> | |
<script src="https://code.jquery.com/jquery-3.4.1.min.js" | |
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js" | |
integrity="sha256-kzv+r6dLqmz7iYuR2OdwUgl4X5RVsoENBzigdF5cxtU=" crossorigin="anonymous"></script> | |
<!-- helper functions --> | |
<script> | |
function getResults(table, opts, callbackFn) { | |
var base = "appEJu7NJiuzEGPIu" | |
var params = [ | |
"api_key=key5dzzIyfKw3Xs0B", | |
"view=Grid%20view", | |
"sort%5B0%5D%5Bfield%5D=" + encodeURIComponent(opts.sortField), | |
"sort%5B0%5D%5Bdirection%5D=" + encodeURIComponent(opts.sortDirection) | |
] | |
var url = ["https://api.airtable.com/v0", base, table].join("/") + "?" + params.join("&") | |
$.ajax({ | |
url: url, | |
tryCount: 0, | |
retryLimit: 5, | |
success: function (data, status) { | |
var records = _.map(data.records, "fields") | |
var groupedRecords = _.groupBy(records, opts.groupBy) | |
callbackFn(groupedRecords) | |
} | |
}) | |
} | |
function buildResource(url, title, description, attachments) { | |
var resourceTemplate = "<li>" | |
resourceTemplate += "<a href=\"" | |
resourceTemplate += url | |
resourceTemplate += "\">" | |
resourceTemplate += title | |
resourceTemplate += "</a>" | |
resourceTemplate += "<span> - " + description + "</span>" | |
if (_.isArray(attachments)) { | |
resourceTemplate += "<br />" | |
resourceTemplate += "<strong>Attachments: </strong>" | |
_.each(attachments, function (attachment) { | |
var small = attachment.thumbnails.small | |
resourceTemplate += "<br />" | |
resourceTemplate += "<a target=\"_blank\" href=\"" + attachment.url + "\">" | |
resourceTemplate += "<img src=\"" + small.url + "\"" | |
resourceTemplate += "width=\"" + small.width + "\"" | |
resourceTemplate += "height=\"" + small.height + "\">" | |
resourceTemplate += "</a>" | |
}) | |
} | |
resourceTemplate += "</li>" | |
return resourceTemplate | |
} | |
</script> | |
<!-- Pull results and display --> | |
<script> | |
getResults("Federal%20Resources", { sortField: "Federal Organization", sortDirection: "asc", groupBy: "Federal Organization" }, function (groupedRecords, status) { | |
_.mapKeys(groupedRecords, function (records, organizationName) { | |
var template = "<h4><strong>" + organizationName + "</strong></h4>\n"; | |
template += "<ul>\n" | |
_.each(records, function (record) { | |
template += buildResource(record["Resource Url"], record["Page Title"], record["Description"], record["Attachments"]) | |
}) | |
template += "</ul>\n" | |
$("div.federal-results").append(template) | |
}) | |
}) | |
getResults("State%20Resources", { sortField: "State Organization", sortDirection: "asc", groupBy: "State Organization" }, function (groupedRecords, status) { | |
_.mapKeys(groupedRecords, function (records, organizationName) { | |
var template = "<h4><strong>" + organizationName + "</strong></h4>\n"; | |
template += "<ul>\n" | |
_.each(records, function (record) { | |
template += buildResource(record["Resource Url"], record["Page Title"], record["Description"], record["Attachments"]) | |
}) | |
template += "</ul>\n" | |
$("div.state-results").append(template) | |
}) | |
}) | |
getResults("Local%20Resources", { sortField: "Center", sortDirection: "asc", groupBy: "Center" }, function (groupedRecords, status) { | |
_.mapKeys(groupedRecords, function (records, sbdcName) { | |
var template = "<h4><strong>" + sbdcName + "</strong></h4>\n"; | |
template += "<ul>\n" | |
_.each(records, function (record) { | |
console.log(record) | |
template += buildResource(record["Resource Url"], record["Local Resource"], record["Description"], record["Attachments"]) | |
}) | |
template += "</ul>\n" | |
$("div.local-results").append(template) | |
}) | |
}) | |
</script> | |
<!-- To here --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment