Skip to content

Commit

Permalink
Tweaks to the permalinking implementation
Browse files Browse the repository at this point in the history
Using Date.getDateString() didn't quite work for me: the dates returned
by the date picker never seemed to show up in the mapping. So use the
simpler YYYY-MM-DD date format and manually format the dates. The result
has been reliable for me.

Another tweak is to store the currentVersion, and once the commits are
loaded, identify the date for this version and update the header to
display a date (more user-friendly than a SHA).

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 committed May 24, 2024
1 parent 4b004aa commit b367512
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
var selectedConfigs = new Set();

var versionDateMapping = new Map();
var currentVersion = "";

function navigateToVersionFromDate(date) {
date = new Date(date).toDateString();
version = versionDateMapping.get(date);
if(!version) {
return // if no version present, do not navigate
Expand All @@ -97,16 +97,30 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
window.location.href = url;
}

function dateString(date) {
const yearStr = date.getUTCFullYear().toString().padStart(4, "0");
const monthStr = (date.getUTCMonth() + 1).toString().padStart(2, "0");
const dayStr = date.getUTCDate().toString().padStart(2, "0");
return `${yearStr}-${monthStr}-${dayStr}`;
}

function populateVersionOptions(data) {
data = JSON.parse(data)
let resp = Array.from(data);
let dates = new Set();
resp.forEach((res)=>{
versionDateMapping.set(new Date(res.commit.committer.date).toDateString(), res.sha)
let date = new Date(res.commit.committer.date);
dates.add(date);
versionDateMapping.set(dateString(date), res.sha)
// If we started with a SHA, replace it with the date string
// for a better user experience.
if (currentVersion == res.sha)
setHeading(currentVersion, dateString(date));
})
let datepicker = document.getElementById("versionDateTimePicker")
new tempusDominus.TempusDominus(datepicker, {
restrictions: {
enabledDates: Array.from(versionDateMapping.keys().map(ds => new Date(ds))),
enabledDates: Array.from(dates),
},
display: {
viewMode: 'calendar',
Expand All @@ -119,7 +133,7 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
},
},
localization: {
format: 'MM-dd-yyyy',
format: 'yyyy-MM-dd',
},
useCurrent: false,
})
Expand All @@ -131,9 +145,16 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
return `https://raw.githubusercontent.com/oracle/kconfigs/${version}/docs/summary.json`
}

function setHeading(version, date) {
let sp = document.getElementById("heading")
if (date)
sp.innerHTML = `Distribution Kernel Configs (date: ${date})`
else
sp.innerHTML = `Distribution Kernel Configs (version: ${version})`
}

function updateVersion(invalid=false) {
let params = new URLSearchParams(document.location.search);
let sp = document.getElementById("heading")
if(invalid) {
sp.innerHTML = `Distribution Kernel Configs`
alert("Invalid Version. Please add a valid version")
Expand All @@ -142,9 +163,13 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
window.location.href = url;
return
}
var version = params.get("version");
if(!version) return "gh-pages";
sp.innerHTML = `Distribution Kernel Configs (version: ${version})`
let version = params.get("version");
let date = "";
if(!version) {
version = "gh-pages";
date = "latest";
}
setHeading(version, date);
return version
}

Expand Down Expand Up @@ -268,7 +293,7 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
}
window.onpopstate = setState;
setState();
let version = updateVersion();
currentVersion = updateVersion();

let vor = new XMLHttpRequest()
vor.open("GET", "https://api.github.com/repos/oracle/kconfigs/commits?sha=gh-pages", true)
Expand All @@ -279,7 +304,7 @@ <h5 class="modal-title" id="versionModalLabel">Select Date of Snapshot</h5>
vor.send(null)

const xhr = new XMLHttpRequest();
xhr.open("GET", getSummaryURL(version), true);
xhr.open("GET", getSummaryURL(currentVersion), true);
xhr.onload = (event) => {
console.log("Loaded kernel config summary")
if(event.target.status === 200)
Expand Down

0 comments on commit b367512

Please sign in to comment.