1
0
Fork 0

sched: interface.html, show timers & non-date alarms too

master
Rob Pilling 2023-05-29 13:32:25 +01:00
parent 855f196fd3
commit ed9d4d47c5
1 changed files with 60 additions and 14 deletions

View File

@ -93,24 +93,53 @@ function upload() {
}
function renderAlarm(alarm, exists) {
const localDate = dateFromAlarm(alarm);
const localDate = alarm.date ? dateFromAlarm(alarm) : null;
const tr = document.createElement('tr');
tr.classList.add('event-row');
tr.dataset.uid = alarm.id;
const tdTime = document.createElement('td');
tr.appendChild(tdTime);
const tdType = document.createElement('td');
tdType.type = "text";
tdType.classList.add('event-summary');
tr.appendChild(tdType);
const inputTime = document.createElement('input');
inputTime.type = "datetime-local";
if (localDate) {
tdType.textContent = "Alarm";
inputTime.type = "datetime-local";
inputTime.value = localDate.toISOString().slice(0,16);
inputTime.onchange = (e => {
const date = new Date(inputTime.value);
alarm.t = dateToMsSinceMidnight(date);
alarm.date = formatDate(date);
});
} else {
const [hours, mins, secs] = msToHMS(alarm.timer || alarm.t);
inputTime.type = "time";
inputTime.step = 1; // display seconds
inputTime.value = `${hours}:${mins}:${secs}`;
if (alarm.timer) {
tdType.textContent = "Timer";
inputTime.onchange = e => {
alarm.timer = hmsToMs(inputTime.value);
const now = new Date();
const currentTime = (now.getHours()*3600000)+(now.getMinutes()*60000)+(now.getSeconds()*1000);
alarm.t = currentTime + alarm.timer;
};
} else {
tdType.textContent = "Alarm";
inputTime.onchange = e => {
alarm.t = hmsToMs(inputTime.value);
};
}
}
if (!exists) tdType.textContent = "* " + tdType.textContent;
inputTime.classList.add('event-date');
inputTime.classList.add('form-input');
inputTime.dataset.uid = alarm.id;
inputTime.value = localDate.toISOString().slice(0,16);
inputTime.onchange = (e => {
const date = new Date(inputTime.value);
alarm.t = dateToMsSinceMidnight(date);
alarm.date = formatDate(date);
});
const tdTime = document.createElement('td');
tr.appendChild(tdTime);
tdTime.appendChild(inputTime);
const tdSummary = document.createElement('td');
@ -150,6 +179,24 @@ function renderAlarm(alarm, exists) {
document.getElementById('upload').disabled = false;
}
function msToHMS(ms) {
let secs = Math.floor(ms / 1000) % 60;
let mins = Math.floor(ms / 1000 / 60) % 60;
let hours = Math.floor(ms / 1000 / 60 / 60);
if (secs < 10) secs = "0" + secs;
if (mins < 10) mins = "0" + mins;
if (hours < 10) hours = "0" + hours;
return [hours, mins, secs];
}
function hmsToMs(hms) {
let [hours, mins, secs] = hms.split(":");
hours = Number(hours);
mins = Number(mins);
secs = Number(secs);
return ((hours * 60 + mins) * 60 + secs) * 1000;
}
function addAlarm() {
const alarm = getAlarmDefaults();
renderAlarm(alarm);
@ -165,9 +212,7 @@ function getData() {
schedSettings = JSON.parse(data || "{}") || {};
Util.hideModal();
alarms.forEach(alarm => {
if (alarm.date) {
renderAlarm(alarm, true);
}
renderAlarm(alarm, true);
});
});
});
@ -191,7 +236,8 @@ function onInit() {
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Date/Time</th>
<th>Summary</th>
<th></th>
</tr>