()
| 99 | // --------------------------------------------------------------------------- |
| 100 | |
| 101 | function buildFilters() { |
| 102 | const bar = document.getElementById('filters'); |
| 103 | const presets = $(bar, 'presets'); |
| 104 | |
| 105 | for (const preset of RANGE_PRESETS) { |
| 106 | const button = el('button', 'range', preset.label); |
| 107 | button.type = 'button'; |
| 108 | button.dataset.days = String(preset.days); |
| 109 | button.addEventListener('click', () => { |
| 110 | state.preset = preset.days; |
| 111 | syncFilters(); |
| 112 | render(); |
| 113 | }); |
| 114 | presets.append(button); |
| 115 | } |
| 116 | |
| 117 | const from = $(bar, 'custom-from'); |
| 118 | const to = $(bar, 'custom-to'); |
| 119 | const apply = $(bar, 'custom-apply'); |
| 120 | apply.addEventListener('click', () => { |
| 121 | if (!isDay(from.value) || !isDay(to.value)) { |
| 122 | setRangeSummary('Enter both dates as YYYY-MM-DD.'); |
| 123 | return; |
| 124 | } |
| 125 | if (from.value > to.value) { |
| 126 | setRangeSummary('The start date must come before the end date.'); |
| 127 | return; |
| 128 | } |
| 129 | state.preset = 'custom'; |
| 130 | state.custom = { from: from.value, to: to.value }; |
| 131 | syncFilters(); |
| 132 | render(); |
| 133 | }); |
| 134 | |
| 135 | $(bar, 'refresh').addEventListener('click', () => { |
| 136 | refreshMeta().finally(render); |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | function syncFilters() { |
| 141 | const bar = document.getElementById('filters'); |
no test coverage detected