111 lines
3.8 KiB
JavaScript
111 lines
3.8 KiB
JavaScript
window.addEventListener('load', () => {
|
|
|
|
function parseBoolean(value) {
|
|
if(value === 'true') {
|
|
return true;
|
|
} else if (value === 'false') {
|
|
return false;
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
function generateQuery(query) {
|
|
initialQuery = `curl -H "accept: ${query['contentType']}" "https://holiday.bbr-dev.info/api/v1/holidays?country=${query['country']}`
|
|
|
|
delete query['contentType'];
|
|
delete query['country'];
|
|
|
|
for(const key in query) {
|
|
initialQuery += `&${key}=${query[key]}`
|
|
}
|
|
initialQuery+='"';
|
|
|
|
document.querySelector('#result-content').innerHTML = 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 dStartRangeRequired = document.querySelector("#dsr-start-range-required");
|
|
|
|
let dEndRange = document.querySelector("#dsr-end-range");
|
|
let dEndRangeRequired = document.querySelector("#dsr-end-range-required");
|
|
|
|
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);
|
|
}
|
|
switch(dateSelector.value) {
|
|
case 'year':
|
|
query['year'] = dYear.value;
|
|
break;
|
|
case 'date':
|
|
if(dDate.value) {
|
|
query['date'] = dDate.value;
|
|
}
|
|
break;
|
|
case 'range':
|
|
if(dStartRangeRequired.checked && dStartRange.value) {
|
|
query['startRange'] = dStartRange.value;
|
|
}
|
|
if(dEndRangeRequired.checked && dEndRange.value) {
|
|
query['endRange'] = dEndRange.value;
|
|
}
|
|
case 'all':
|
|
default:
|
|
}
|
|
|
|
generateQuery(query);
|
|
}
|
|
|
|
queryGenerator.addEventListener('change', event => {
|
|
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);
|
|
}
|
|
switch(dateSelector.value) {
|
|
case 'year':
|
|
query['year'] = dYear.value;
|
|
break;
|
|
case 'date':
|
|
if(dDate.value) {
|
|
query['date'] = dDate.value;
|
|
}
|
|
break;
|
|
case 'range':
|
|
if(dStartRangeRequired.checked && dStartRange.value) {
|
|
query['startRange'] = dStartRange.value;
|
|
}
|
|
if(dEndRangeRequired.checked && dEndRange.value) {
|
|
query['endRange'] = dEndRange.value;
|
|
}
|
|
case 'all':
|
|
default:
|
|
}
|
|
generateQuery(query);
|
|
})
|
|
})
|