mirror of
https://github.com/norohind/SquadsActivityMonitor.git
synced 2025-04-13 05:17:12 +03:00
Unifyin activity_table_html_template
This commit is contained in:
parent
cebe77cc09
commit
926609f29e
15
utils.py
15
utils.py
@ -173,34 +173,33 @@ def measure(function: callable):
|
||||
return decorated
|
||||
|
||||
|
||||
activity_table_html_template = """
|
||||
<!DOCTYPE HTML>
|
||||
activity_table_html_template = """<!DOCTYPE HTML>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<script src="/js/json2htmltable.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.onload = () => {
|
||||
window.addEventListener("load", () => {
|
||||
document.body.appendChild(buildHtmlTable({items})); // build table
|
||||
|
||||
var table = document.querySelector("body > table")
|
||||
var header = table.rows[0]
|
||||
|
||||
for (var i = 0, cell; cell = header.cells[i]; i++){
|
||||
if (cell.innerText.includes('ActionId')){
|
||||
var action_id_id = i;
|
||||
if (cell.innerText.includes('{target_column_name}')){
|
||||
var target_column_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (action_id_id == null) { // don't to anything if no action_id in the table
|
||||
if (target_column_id == null) { // don't to anything if no action_id in the table
|
||||
return;
|
||||
}
|
||||
|
||||
for (var i = 1, row; row = table.rows[i]; i++) { // append to action_id filed onclick action
|
||||
row.cells[action_id_id].setAttribute("onclick", "location.href='/diff/action_id'".replace('action_id', row.cells[action_id_id].innerText));
|
||||
row.cells[target_column_id].innerHTML = '<td><a href="{link}">{original_value}</a></td>'.replace('{link}', '{target_new_url}' + table.rows[i].cells[target_column_id].innerText).replace('{original_value}', table.rows[i].cells[target_column_id].innerText);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<link type="text/css" rel="stylesheet" href="/js/table_styles.css">
|
||||
</head>
|
||||
|
2
web.py
2
web.py
@ -61,7 +61,7 @@ class ActivityHtml:
|
||||
table_in_json: str = resp.text
|
||||
resp.content_type = falcon.MEDIA_HTML
|
||||
|
||||
resp.text = utils.activity_table_html_template.replace('{items}', table_in_json)
|
||||
resp.text = utils.activity_table_html_template.replace('{items}', table_in_json).replace('{target_column_name}', 'ActionId').replace('{target_new_url}', '/diff/')
|
||||
# what? f-strings? .format? never heard about them
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user