Skip to content

Commit 6be0e99

Browse files
Copilotnhoening
andauthored
feat: initialize delete-data inputs to the graph's current start/end time range
Agent-Logs-Url: https://github.com/FlexMeasures/flexmeasures/sessions/88194780-0b56-4e59-8c91-0fd6d22a6c8d Co-authored-by: nhoening <1042336+nhoening@users.noreply.github.com>
1 parent b07ec8c commit 6be0e99

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

flexmeasures/ui/templates/includes/graphs.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@
446446
var queryStartDate = (startDate != null) ? (startDate.toISOString()) : (null);
447447
var queryEndDate = (endDate != null) ? (endDate.toISOString()) : (null);
448448

449+
// Notify the "Delete data" panel of the new graph date range so its inputs stay in sync.
450+
// detail: { startDate: Date, endDate: Date } – endDate has +1 day applied (exclusive end).
451+
document.dispatchEvent(new CustomEvent('graphDateRangeChanged', {
452+
detail: { startDate: startDate, endDate: endDate }
453+
}));
454+
449455
{% if active_page == "sensors" %}
450456
const toggleStats = document.getElementById('toggleStatsCheckbox');
451457
if (toggleStats.checked) {

flexmeasures/ui/templates/sensors/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,34 @@ <h5 id="statsHeader">Statistics</h5>
640640
const startInputEl = document.getElementById('deleteDataStart');
641641
const untilInputEl = document.getElementById('deleteDataUntil');
642642

643+
const _pad = n => String(n).padStart(2, '0');
644+
function toDatetimeLocalString(date) {
645+
if (!date || isNaN(date.getTime())) { return ''; }
646+
return `${date.getFullYear()}-${_pad(date.getMonth()+1)}-${_pad(date.getDate())}T${_pad(date.getHours())}:${_pad(date.getMinutes())}`;
647+
}
648+
649+
function syncDeleteInputsWithGraphRange(start, end) {
650+
if (start) { startInputEl.value = toDatetimeLocalString(start); }
651+
if (end) { untilInputEl.value = toDatetimeLocalString(end); }
652+
}
653+
654+
// Initialize delete data inputs with the time range currently shown in the graph.
655+
// event_starts_after/event_ends_before are set when URL params (start_time/end_time) are present.
656+
{% if event_starts_after %}
657+
(function () {
658+
try {
659+
var _start = new Date('{{ event_starts_after }}');
660+
var _end = {% if event_ends_before %}new Date('{{ event_ends_before }}'){% else %}null{% endif %};
661+
syncDeleteInputsWithGraphRange(_start, _end);
662+
} catch (e) { /* ignore invalid date strings */ }
663+
})();
664+
{% endif %}
665+
666+
// Keep delete data inputs in sync when the user changes the graph date picker
667+
document.addEventListener('graphDateRangeChanged', function(e) {
668+
syncDeleteInputsWithGraphRange(e.detail.startDate, e.detail.endDate);
669+
});
670+
643671
async function deleteData(sourceValue, startValue, untilValue) {
644672
const params = {};
645673
if (sourceValue) {

0 commit comments

Comments
 (0)