-
-
Notifications
You must be signed in to change notification settings - Fork 846
Refactor JavaScript so that Project Meetings page sources meeting data from vrms_data.json #7873
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
Merged
mugdhchauhan
merged 3 commits into
hackforla:gh-pages
from
innith:Refactor-JavaScript-so-that-Project-Meetings-page-sources-meeting-data-from-vrms_data.json-#6059
Mar 4, 2025
Merged
Changes from all commits
Commits
Show all changes
3 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { getEventData, insertEventSchedule } from "./utility/api-events.js"; | ||
| /** | ||
| * This type of function is called an IIFE function. The main function is the primarily controller that loads the recurring events on this page. | ||
| * Refer: https://developer.mozilla.org/en-US/docs/Glossary/IIFE | ||
| */ | ||
| (async function main() { | ||
| const eventData = await getEventData(); | ||
|
|
||
| // If the document is still loading, add an EventListener. There is no race conditiion because JavaScript has run-to-completion semantics | ||
| if (document.readyState === "loading") { | ||
| document.addEventListener( | ||
| "DOMContentLoaded", | ||
| function () { insertEventSchedule(eventData, "project-meetings") } | ||
| ); | ||
| } | ||
|
|
||
| // If the document is not in the loading state, the DOM content has loaded and the event schedule can be populated | ||
| else { insertEventSchedule(eventData, "project-meetings") } | ||
|
|
||
| //Displays/Inserts the user's time zone in the DOM | ||
| document | ||
| .querySelector("#userTimeZone") | ||
| .insertAdjacentHTML("afterbegin", timeZoneText()); | ||
| })(); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,123 @@ | ||
| import { getEventData, insertEventSchedule } from "./utility/api-events.js"; | ||
| import { vrmsDataFetch, localeTimeIn12Format } from "./utility/vrms-events.js" | ||
| /** | ||
| * This type of function is called an IIFE function. The main function is the primarily controller that loads the recurring events on this page. | ||
| * Refer: https://developer.mozilla.org/en-US/docs/Glossary/IIFE | ||
| */ | ||
| (async function main() { | ||
| const eventData = await getEventData(); | ||
| (function main() { | ||
| const eventData = vrmsDataFetch("events"); | ||
|
|
||
| // If the document is still loading, add an EventListener. There is no race conditiion because JavaScript has run-to-completion semantics | ||
| if (document.readyState === "loading") | ||
| { | ||
| if (document.readyState === "loading") { | ||
| document.addEventListener( | ||
| "DOMContentLoaded", | ||
| function(){insertEventSchedule(eventData, "project-meetings")} | ||
| "DOMContentLoaded", | ||
| function () { insertEventSchedule(eventData, "project-meetings") } | ||
| ); | ||
| } | ||
|
|
||
| // If the document is not in the loading state, the DOM content has loaded and the event schedule can be populated | ||
| else {insertEventSchedule(eventData, "project-meetings")} | ||
| else { insertEventSchedule(eventData, "project-meetings") } | ||
|
|
||
| //Displays/Inserts the user's time zone in the DOM | ||
| document | ||
| .querySelector("#userTimeZone") | ||
| .insertAdjacentHTML("afterbegin", timeZoneText()); | ||
| })(); | ||
|
|
||
| /** | ||
| * Inserts the recurring events into the html | ||
| * @param {Object} eventData - An array objects of the type returned by displayObject() | ||
| * @param {String} page - page that is using eventData ("events" or "project-meetings") | ||
| */ | ||
| function insertEventSchedule(eventData, page) { | ||
|
|
||
| const formatedEvents = formatEventData(eventData) | ||
|
|
||
| for (const [key, value] of Object.entries(formatedEvents)) { | ||
| let placeToInsert = document.querySelector(`#${key}-List`); | ||
| placeToInsert.innerHTML = ""; | ||
| // check if the day has any events | ||
| if (!value.length) { | ||
| placeToInsert.insertAdjacentHTML( | ||
| "beforeend", | ||
| `<li>There are no meetings scheduled.</li>` | ||
| ); | ||
| } else { | ||
| value.forEach((event) => { | ||
| if (event) { | ||
| // If a project doesn't have an hflaWebsiteUrl, redirect to the project's Github page | ||
| if (event.hflaWebsiteUrl == "") { | ||
| event.hflaWebsiteUrl = event.githubUrl | ||
| } | ||
| let eventHtml; | ||
| // insert the correct html for the current page | ||
| if (page === "events") { | ||
| eventHtml = `<li>${event.start} - ${event.end} </li><li><a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName}${event.dsc.length > 0 ? "*" : ""}</li>`; | ||
| } else { | ||
| if (event.dsc != "") event.meetingName += ", "; | ||
| eventHtml = `<li>${event.start} - ${event.end} <a href="${event.hflaWebsiteUrl}">${event.name}</a> ${event.meetingName} ${event.dsc}</li>`; | ||
| } | ||
| placeToInsert.insertAdjacentHTML("beforeend", eventHtml); | ||
| } | ||
mugdhchauhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Formats event data | ||
| * @param {Object} data - array of event objects | ||
| * @return {Object} filtered and sorted data | ||
| */ | ||
| function formatEventData(data) { | ||
| const filteredData = filterVrmsData(data); | ||
| return filteredData | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Filters out the needed data from the vrmsData returned from vrmsDataFetch | ||
| */ | ||
| function filterVrmsData(responseData) { | ||
| const return_obj = { | ||
| Monday: [], | ||
| Tuesday: [], | ||
| Wednesday: [], | ||
| Thursday: [], | ||
| Friday: [], | ||
| Saturday: [], | ||
| Sunday: [], | ||
| }; | ||
| responseData.forEach((item) => { | ||
| let day_of_week = getDayString(item.date); | ||
| return_obj[day_of_week].push(display_object(item)); | ||
mugdhchauhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| return return_obj; | ||
| } | ||
|
|
||
| /** | ||
| * @param {Date} date - A valid javscript time string. Example: "2020-05-13T02:00:00.000Z" | ||
| * @return {String} - The name of the day represented by the time string. Example 2020-05-13 was a wednesday. I.e rv = 'Wednesday' | ||
| */ | ||
| function getDayString(date) { | ||
| let new_date = new Date(date); | ||
| let options = { weekday: "long" }; | ||
| return new Intl.DateTimeFormat("en-US", options).format(new_date); | ||
| } | ||
|
|
||
| /** | ||
| * Function that represent the individual object extracted from the api | ||
| */ | ||
| function display_object(item) { | ||
| if (item?.project?.name !== "Hack4LA" && !/^Test\b/i.test(item?.project?.name)) { | ||
| const rv_object = { | ||
| meetingName: item.name, | ||
| name: item.project.name, | ||
| dsc: item.description, | ||
| start: localeTimeIn12Format(item.startTime), | ||
| end: localeTimeIn12Format(item.endTime), | ||
| hflaWebsiteUrl: item.project.hflaWebsiteUrl, | ||
| githubUrl: item.project.githubUrl, | ||
| }; | ||
| return rv_object; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.