Skip to content

Commit

Permalink
update tse cal webpage
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis-xyz committed Aug 29, 2024
1 parent 583f4fc commit 6fbef8b
Show file tree
Hide file tree
Showing 15 changed files with 819 additions and 43 deletions.
16 changes: 16 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ <h3 class="cardTitle">Inverter Inertia Emulation</h3>
</div>
</a>
</article>
<article>
<a href="./tse-calendar">
<div class="card">
<img
src="tse-calendar/web-screenshot.png"
alt="Screenshot of timetable web page"
class="cardImage"
width="1124"
height="559" >
<div class="cardBottom">
<h3 class="cardTitle">TSE Calendar Sync and Filter</h3>
<p class="cardDesc">A tool to synchronise personalised Toulouse School of Economics timetables to your calendar app</p>
</div>
</div>
</a>
</article>
</div>

<nav>
Expand Down
9 changes: 8 additions & 1 deletion docs/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Matthew Davis</title>
<link>https://dev.mdavis.xyz</link>
<description>A collection of projects, stories and thoughts about technology and politics</description>
<lastBuildDate>Wed, 01 May 2024 21:27:09 GMT</lastBuildDate>
<lastBuildDate>Mon, 27 May 2024 21:09:27 GMT</lastBuildDate>
<generator>PyRSS2Gen-1.1.0</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
Expand Down Expand Up @@ -98,5 +98,12 @@
<guid isPermaLink="true">https://dev.mdavis.xyz/thesis</guid>
<pubDate>Thu, 27 Oct 2016 00:00:00 GMT</pubDate>
</item>
<item>
<title>TSE Calendar Sync and Filter</title>
<link>https://dev.mdavis.xyz/tse-calendar</link>
<description>A tool to synchronise personalised Toulouse School of Economics timetables to your calendar app</description>
<guid isPermaLink="true">https://dev.mdavis.xyz/tse-calendar</guid>
<pubDate>Mon, 19 Feb 2024 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
Binary file added docs/tse-calendar/calendar-button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tse-calendar/combined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tse-calendar/combined.xcf
Binary file not shown.
466 changes: 466 additions & 0 deletions docs/tse-calendar/index.html

Large diffs are not rendered by default.

Binary file added docs/tse-calendar/phone-screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions docs/tse-calendar/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
ute_url_base = "https://ade-production.ut-capitole.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?data="
lambda_domain = "vvq4ws26xtuivxfdmznouhi7ge0dpqcq.lambda-url.eu-west-3.on.aws"
const alphanumericRegex = /^[a-zA-Z0-9]+$/;

function courseChanged() {
var courseDropdown = document.getElementById("courseDropdown");
var originalUrlField = document.getElementById("original-url");
var otherParent = document.getElementById("other-url-stuff");

if (courseDropdown.value === "other") {
otherParent.style.display = "block";
originalUrlField.value = "";
} else {
var selectedOption = courseDropdown.options[courseDropdown.selectedIndex];

otherParent.style.display = "none";
originalUrlField.value = selectedOption.getAttribute("data-url");
}

updateOutputUrl();
}
document.addEventListener('DOMContentLoaded', function() {
// after page refresh, hide/unhide the custom url field
courseChanged();
});
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("original-url").placeholder = ute_url_base + 'something';
});
document.addEventListener('DOMContentLoaded', function() {
document.getElementById("previous-url").placeholder = 'https://' + lambda_domain + '/...';
});

function updateOutputUrl() {
var courseDropdown = document.getElementById("courseDropdown");
var originalUrlField = document.getElementById("original-url");
var whitelistText = document.getElementById("whitelist").value;
var blacklistText = document.getElementById("blacklist").value;
var outputUrlField = document.getElementById("output-url");
var textToShow = "";
var urlId;

console.log("Updating output URL");

if (courseDropdown.value === "other") {
const originalUrl = originalUrlField.value;
if (! originalUrl.startsWith(ute_url_base)){
originalUrlField.classList.add("badInput");
outputUrlField.value = "Invalid URL";
}else{
urlId = originalUrl.replace(ute_url_base, '').trim();

// Test the input against the regular expression
if (!alphanumericRegex.test(urlId)){
originalUrlField.classList.add("badInput");
outputUrlField.value = "Invalid URL";
return;
}

originalUrlField.classList.remove("badInput");
console.log(`Found ${urlId} from original URL`);
}
}else{
// grab URL id from data tag
var selectedOption = courseDropdown.options[courseDropdown.selectedIndex];
urlId = selectedOption.getAttribute("data-url")
}

// Constructing the URL
const protocol = "https://";
const basepath = `/ics/v1/${urlId}`;

// add whitelist to parameters
const whitelistParams = whitelistText
.split('\n')
.map(line => line.trim())
.filter(keyword => keyword !== '')
.map(keyword => `wl=${encodeURIComponent(keyword)}`)
.join('&');

// add blacklist to parameters
const blacklistParams = blacklistText
.split('\n')
.map(line => line.trim())
.filter(keyword => keyword !== '')
.map(keyword => `bl=${encodeURIComponent(keyword)}`)
.join('&');

// Constructing the final URL
const finalUrl = `${protocol}${lambda_domain}${basepath}?${whitelistParams ? `&${whitelistParams}` : ''}${blacklistParams ? `&${blacklistParams}` : ''}`;

outputUrlField.value = finalUrl;

}

function copyToClipboard() {
// Get the textarea element
var textarea = document.getElementById("output-url");

// Select the text in the textarea
textarea.select();
textarea.setSelectionRange(0, 99999); // For mobile devices

// Copy the selected text to the clipboard
document.execCommand("copy");

// Deselect the textarea
textarea.setSelectionRange(0, 0);

console.log("Copied");
}

function showExplanations() {
// Hide all paragraphs inside the explanations container
var paragraphs = document.querySelectorAll('#explanations div');
paragraphs.forEach(function(paragraph) {
paragraph.style.display = 'none';
});

// Show the selected paragraph
var selectedOption = document.getElementById('installation-target').value;
if (selectedOption != ''){
var selectedParagraph = document.getElementById(selectedOption + "-explanation");
selectedParagraph.style.display = 'block';
}
}
document.addEventListener('DOMContentLoaded', function() {
// after page refresh, hide/unhide the custom url field
showExplanations();
});

function reverseUrl(){
var oldUrlField = document.getElementById("previous-url");
const oldUrl = new URL(oldUrlField.value.trim());

if (oldUrl.host != lambda_domain){
oldUrlField.classList.add("badInput");
console.log(`Received old URL, bad domain: ${oldUrl.host}`)
return ;
}else{
var urlId = oldUrl.pathname.split('/').pop();

if (!alphanumericRegex.test(urlId)){
oldUrlField.classList.add("badInput");
console.log("Received old URL, bad ID")
return;
}
console.log(`urlId is ${urlId}`);
// figure out if that's one of the known courseDropdowns
// if yes, select it
// if no, select other, and paste the URL into the custom URL field
var selectElement = document.getElementById("courseDropdown");
var correspondingCourse = selectElement.querySelector('option[data-url="' + urlId + '"]');
var otherUrlField = document.getElementById("original-url");
if (correspondingCourse) {
// Option found, select it
console.log(`course from URL is ${correspondingCourse.id}`);
correspondingCourse.selected = true;
otherUrlField.value = '';
} else {
console.log(`course from URL is unknown`);
document.getElementById('other-course').selected = true;
otherUrlField.value = oldUrlField.value;
}

var queryParams = new URLSearchParams(oldUrl.search);

document.getElementById("whitelist").value = queryParams.getAll("wl").join('\n');
document.getElementById("blacklist").value = queryParams.getAll("bl").join('\n');


oldUrlField.classList.remove("badInput");
updateOutputUrl();
}

}
33 changes: 33 additions & 0 deletions docs/tse-calendar/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
body {
font-family: Arial, sans-serif;
margin: 20px;
}

label {
display: block;
margin-top: 10px;
}

.badInput {
border-color: red;
}

.inline-image {
height: 2em; /* Adjust the height as needed */
vertical-align: middle;
margin-right: 0.2em; /* Optional: Adjust the spacing between image and text */
border-radius: 0.3em;
}

textarea {
width: 90%;
}

.warning {
color: red;
}

select {
font-size: 1.2em;
margin: 0.2em;
}
Binary file added docs/tse-calendar/sync-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tse-calendar/web-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions extraWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -763,3 +763,13 @@ I:MED
IO
EMABA12TD3
realise
<!--
I:ERNA
-->
I:EE
I:EEE
I:EGR
I:EEP
I:EMO
I:PPD
TPs/TDs
38 changes: 20 additions & 18 deletions pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,23 +332,25 @@
date: 27/10/2016


# - title: "TSE Calendar Sync and Filter"
# description: "A tool to synchronise personalised Toulouse School of Economics timetables to your calendar app"
# path: "tse-calendar"
# images:
# card:
# path: "web-screenshot.png"
# description: "Screenshot of timetable web page"
# width: 1124
# height: 559
# top:
# path: "combined.png"
# description: "Web page syncing to phone calendar app"
# width: 1004
# height: 3000
# template: "html"
# html: "content.html"
# date: 19/2/2024
- title: "TSE Calendar Sync and Filter"
description: "A tool to synchronise personalised Toulouse School of Economics timetables to your calendar app"
path: "tse-calendar"
images:
card:
path: "web-screenshot.png"
description: "Screenshot of timetable web page"
width: 1124
height: 559
top:
path: "combined.png"
description: "Web page syncing to phone calendar app"
width: 1004
height: 3000
template: "html"
exclude:
- 'estReadingTime'
html: "content.html"
date: 19/2/2024

# - title: "Test template"
# description: "Subtitle here"
Expand All @@ -366,4 +368,4 @@
# height: 725
# template: "html"
# html: "content.html"
# date: 19/2/2024
# date: 19/2/2024
Loading

0 comments on commit 6fbef8b

Please sign in to comment.