-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(ui): Add Reporting page web UI (#43)
* feature(ui): Add Reporting page web UI Signed-off-by: hayk96 <hayko5999@gmail.com> * fix(api): Fix exception handling of /export API Signed-off-by: hayk96 <hayko5999@gmail.com> --------- Signed-off-by: hayk96 <hayko5999@gmail.com>
- Loading branch information
Showing
8 changed files
with
506 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const modal = document.getElementById("exportModal"); | ||
const btn = document.getElementById("openModalBtn"); | ||
const span = document.getElementsByClassName("close")[0]; | ||
|
||
|
||
modal.style.display = "none"; | ||
|
||
btn.onclick = function() { | ||
modal.style.display = "flex"; | ||
} | ||
|
||
span.onclick = function() { | ||
modal.style.display = "none"; | ||
} | ||
|
||
document.getElementById('exportForm').addEventListener('submit', async function(event) { | ||
event.preventDefault(); | ||
|
||
const expr = document.getElementById('expr').value; | ||
const start = document.getElementById('start').value ? new Date(document.getElementById('start').value).toISOString() : null; | ||
const end = document.getElementById('end').value ? new Date(document.getElementById('end').value).toISOString() : null; | ||
const step = document.getElementById('step').value; | ||
const timestamp_format = document.getElementById('timestamp_format').value; | ||
const format = document.getElementById('format').value; | ||
|
||
const replaceFields = {}; | ||
document.querySelectorAll('.replace-field').forEach(field => { | ||
const key = field.querySelector('.replace-key').value; | ||
const value = field.querySelector('.replace-value').value; | ||
if (key && value) { | ||
replaceFields[key] = value; | ||
} | ||
}); | ||
|
||
const data = { | ||
expr: expr, | ||
start: start, | ||
end: end, | ||
step: step, | ||
timestamp_format: timestamp_format, | ||
replace_fields: replaceFields | ||
}; | ||
|
||
try { | ||
const response = await fetch('/api/v1/export?format=' + format, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Error: ${response.statusText}`); | ||
} | ||
|
||
const blob = await response.blob(); | ||
const url = window.URL.createObjectURL(blob); | ||
const a = document.createElement('a'); | ||
a.style.display = 'none'; | ||
a.href = url; | ||
a.download = `data.${format}`; | ||
document.body.appendChild(a); | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
document.body.removeChild(a); | ||
} catch (error) { | ||
document.getElementById('results').innerHTML = `<p style="color: red;">${error.message}</p>`; | ||
} | ||
}); | ||
|
||
document.getElementById('addReplaceField').addEventListener('click', function() { | ||
const container = document.getElementById('replaceFieldsContainer'); | ||
const newField = document.createElement('div'); | ||
newField.className = 'replace-field'; | ||
newField.innerHTML = ` | ||
<input type="text" class="replace-key" placeholder="Source field"> | ||
<input type="text" class="replace-value" placeholder="Target field"> | ||
<button type="button" class="remove-field">‒</button> | ||
`; | ||
container.appendChild(newField); | ||
}); | ||
|
||
document.getElementById('replaceFieldsContainer').addEventListener('click', function(event) { | ||
if (event.target.classList.contains('remove-field')) { | ||
event.target.parentElement.remove(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.