forked from hackohio/ohio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hackohio#126 from Ethan-Wolfe/master
Dynamically updating community events
- Loading branch information
Showing
4 changed files
with
83 additions
and
36 deletions.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Spreadsheet URL | ||
const sheetURL = 'https://docs.google.com/spreadsheets/d/1fbtCptVlhUuUrm-JdBelXlSyyLAlgQDUDIV8NMVpxNU/edit#gid=0'; | ||
|
||
const numOfEventsToShow = 3; | ||
|
||
// Load into table | ||
var target = $("#sheetrock-load"); | ||
target.empty(); | ||
target.sheetrock({ | ||
url: sheetURL, | ||
query: "select * where dateDiff(C, now()) >= -1 order by C asc", | ||
callback: sheetrockCallback, | ||
reset: false // Set = true if refreshing data | ||
}); | ||
|
||
function sheetrockCallback() { | ||
var table = $("#sheetrock-load"); | ||
var rows = table.find("tr"); | ||
|
||
// Iterate through event data - skipping 0 because its the header | ||
var lastEvent = $("#community-header"); | ||
var lim = numOfEventsToShow+1 < rows.length ? numOfEventsToShow+1 : rows.length; | ||
for (var i=1; i<lim; i++) { | ||
var event = parseEvent(jQuery.makeArray(rows[i].children)); | ||
lastEvent.after(event) | ||
lastEvent = $("#community .community-event").last(); | ||
} | ||
|
||
// Un-comment once we create view all page | ||
/* | ||
if (numOfEventsToShow+1 < rows.length) { | ||
lastEvent.after(` | ||
<br /> | ||
<div class="center"> | ||
<a href="#" class="red">View all events >></a> | ||
</div> | ||
`); | ||
} | ||
*/ | ||
} | ||
|
||
function parseEvent(data) { | ||
var title = $(data[0]).text(); | ||
var organization = $(data[1]).text(); | ||
|
||
var date = $(data[2]).text(); | ||
var dateExtRaw = $(data[3]).text(); | ||
if (dateExtRaw) { | ||
// Overly complicated regexp to extract multiple dates in a string into an array of dates | ||
// var datesExt = dateExtRaw.match(/([^,]*,[^,]*),?/g).map(x => x.trim().replace(/(^,)|(,$)/g, "")); | ||
date = dateExtRaw; | ||
} | ||
|
||
var startTime = $(data[4]).text(); | ||
if (startTime) startTime = "@ "+startTime; | ||
var endTime = $(data[5]).text(); | ||
if (endTime) endTime = "- "+endTime; | ||
|
||
var location = $(data[6]).text(); | ||
var learnMore = $(data[7]).text(); | ||
return ` | ||
<br /> | ||
<div class="community-event"> | ||
<div class="red-bar"></div> | ||
<h3 class="name"> | ||
${title}<br /> | ||
<span class="event-subtext">${organization}</span> | ||
</h3> | ||
<h4 class="date">${date} ${startTime} ${endTime}</h4> | ||
<h4 class="location">${location}</h4> | ||
<h4 class="learn-more"><a href="${learnMore}" class="red">Learn more >></a></h4> | ||
</div> | ||
`; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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