holiday-api/assets/documentation.js

109 lines
3.7 KiB
JavaScript
Raw Permalink Normal View History

window.addEventListener('load', () => {
function parseBoolean(value) {
if(value === 'true') {
return true;
} else if (value === 'false') {
return false;
} else {
return undefined;
}
}
function generateQuery(query) {
2024-01-01 11:29:59 +00:00
initialQuery = `https://holiday.bbr-dev.info/api/v1/holidays?country=${query['country']}`
delete query['country'];
for(const key in query) {
initialQuery += `&${key}=${query[key]}`
}
2024-01-01 11:29:59 +00:00
document.querySelector('#query-link').href = initialQuery;
document.querySelector('#result-content').innerHTML = "curl \"" + initialQuery + "\"";
}
let country = document.querySelector("#country");
let contentType = document.querySelector("#content-type");
let stateHoliday = document.querySelector("#state-holiday");
let religiousHoliday = document.querySelector("#religious-holiday");
// select which date/year/range is used
let dateSelector = document.querySelector("#date-selector");
let dYear = document.querySelector("#dsy-year");
let dDate = document.querySelector("#dsd-date");
let dStartRange = document.querySelector("#dsr-start-range");
let dEndRange = document.querySelector("#dsr-end-range");
let queryGenerator = document.querySelector("#query-generator");
{
const query = {};
query['country'] = country.value;
query['contentType'] = contentType.value;
if(stateHoliday.value === 'true' || stateHoliday.value === 'false') {
query['stateHoliday'] = parseBoolean(stateHoliday.value);
}
if(religiousHoliday.value === 'true' || religiousHoliday.value === 'false') {
query['religiousHoliday'] = parseBoolean(religiousHoliday.value);
}
2024-01-01 11:29:59 +00:00
console.log(dateSelector.value, dStartRange.value, dEndRange.value);
switch(dateSelector.value) {
case 'year':
query['year'] = dYear.value;
break;
case 'date':
if(dDate.value) {
query['date'] = dDate.value;
}
break;
case 'range':
2024-01-01 11:29:59 +00:00
if(dStartRange.value) {
query['startRange'] = dStartRange.value;
}
2024-01-01 11:29:59 +00:00
if(dEndRange.value) {
query['endRange'] = dEndRange.value;
}
case 'all':
default:
}
generateQuery(query);
}
queryGenerator.addEventListener('change', event => {
const query = {};
query['country'] = country.value;
2024-01-01 11:29:59 +00:00
query['type'] = contentType.value;
if(stateHoliday.value === 'true' || stateHoliday.value === 'false') {
query['stateHoliday'] = parseBoolean(stateHoliday.value);
}
if(religiousHoliday.value === 'true' || religiousHoliday.value === 'false') {
query['religiousHoliday'] = parseBoolean(religiousHoliday.value);
}
2024-01-01 11:29:59 +00:00
console.log(dateSelector.value, dStartRange.value, dEndRange.value);
switch(dateSelector.value) {
case 'year':
query['year'] = dYear.value;
break;
case 'date':
if(dDate.value) {
query['date'] = dDate.value;
}
break;
case 'range':
2024-01-01 11:29:59 +00:00
if(dStartRange.value) {
query['startRange'] = dStartRange.value;
}
2024-01-01 11:29:59 +00:00
if(dEndRange.value) {
query['endRange'] = dEndRange.value;
}
case 'all':
default:
}
generateQuery(query);
})
})