-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
147 additions
and
22 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
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,55 @@ | ||
fetchCalendarData().then(data => { | ||
var e = document.getElementById("calendar"); | ||
e.innerHTML = e.innerHTML || ""; | ||
var locale = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; | ||
data.slice(0,3).forEach(el => { | ||
e.innerHTML += `<div class="list-group-item"> | ||
<div class="d-flex w-100 justify-content-between"> | ||
<h2 class="mb-1">${el.name}</h5> | ||
<small>in ${el.daysUntil} days</small> | ||
</div> | ||
<p class="mb-1 ${el.membersOnly ? "text-bg-warning" : "text-bg-success"}">${el.membersOnly ? "Members Only" : "Open To The Public"}</p> | ||
<p class="mb-1">${el.start.toLocaleDateString("en-us",locale)} from ${String(el.start.getHours()).padStart(2,'0')}:${String(el.start.getMinutes()).padStart(2,'0')} until ${String(el.end.getHours()).padStart(2,'0')}:${String(el.end.getMinutes()).padStart(2,'0')}</p> | ||
<small>${el.description}</small> | ||
</div>`; | ||
}); | ||
}); | ||
|
||
async function fetchCalendarData() { | ||
// Define the API URL | ||
const apiUrl = 'https://profile.thelab.ms/api/events'; | ||
|
||
// Make a GET request | ||
return fetch(apiUrl) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
var now = new Date(Date.now()); | ||
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate()); | ||
data.forEach(element => { | ||
var start = new Date(element.start * 1000); | ||
var end = new Date(element.end * 1000); | ||
var durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate()); | ||
var diffTime = Math.abs(durationDay - today); | ||
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | ||
element.start = start; | ||
element.end = end; | ||
element.daysUntil = diffDays; | ||
}); | ||
data = data.sort((a,b) => { | ||
if (a.daysUntil > b.daysUntil) return 1; | ||
else if (b.daysUntil > a.daysUntil) return -1; | ||
else if (a.name > b.name) return -1; | ||
else if (b.name > a.name) return 1; | ||
return 0; | ||
}); | ||
return data; | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
} |
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,55 @@ | ||
fetchCalendarData().then(data => { | ||
var e = document.getElementById("calendar"); | ||
e.innerHTML = e.innerHTML || ""; | ||
var locale = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }; | ||
data.forEach(el => { | ||
e.innerHTML += `<div class="list-group-item"> | ||
<div class="d-flex w-100 justify-content-between"> | ||
<h2 class="mb-1">${el.name}</h5> | ||
<small>in ${el.daysUntil} days</small> | ||
</div> | ||
<p class="mb-1 ${el.membersOnly ? "text-bg-warning" : "text-bg-success"}">${el.membersOnly ? "Members Only" : "Open To The Public"}</p> | ||
<p class="mb-1">${el.start.toLocaleDateString("en-us",locale)} from ${String(el.start.getHours()).padStart(2,'0')}:${String(el.start.getMinutes()).padStart(2,'0')} until ${String(el.end.getHours()).padStart(2,'0')}:${String(el.end.getMinutes()).padStart(2,'0')}</p> | ||
<small>${el.description}</small> | ||
</div>`; | ||
}); | ||
}); | ||
|
||
async function fetchCalendarData() { | ||
// Define the API URL | ||
const apiUrl = 'https://profile.thelab.ms/api/events'; | ||
|
||
// Make a GET request | ||
return fetch(apiUrl) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
var now = new Date(Date.now()); | ||
var today = new Date(now.getFullYear(),now.getMonth(),now.getDate()); | ||
data.forEach(element => { | ||
var start = new Date(element.start * 1000); | ||
var end = new Date(element.end * 1000); | ||
var durationDay = new Date(start.getFullYear(),start.getMonth(), start.getDate()); | ||
var diffTime = Math.abs(durationDay - today); | ||
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); | ||
element.start = start; | ||
element.end = end; | ||
element.daysUntil = diffDays; | ||
}); | ||
data = data.sort((a,b) => { | ||
if (a.daysUntil > b.daysUntil) return 1; | ||
else if (b.daysUntil > a.daysUntil) return -1; | ||
else if (a.name > b.name) return -1; | ||
else if (b.name > a.name) return 1; | ||
return 0; | ||
}); | ||
return data; | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
} |
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,16 @@ | ||
--- | ||
layout: basic | ||
title: "Calendar" | ||
date: 2018-11-28T15:15:34+10:00 | ||
header_transparent: false | ||
permalink: "/calendar/" | ||
description: "Upcoming Events" | ||
hero: | ||
enabled: false | ||
buttons: | ||
enabled: false | ||
--- | ||
|
||
<div id="calendar" class="list-group"></div> | ||
|
||
<script type="text/javascript" src="{{ '/assets/js/calendar.js' | relative_url }}"></script> |
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