Match table - extract back to json
This commit is contained in:
parent
e4752fd039
commit
71f84cd0a9
109
jsdev/index.html
109
jsdev/index.html
@ -64,44 +64,80 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
var matches_table
|
"use strict"
|
||||||
var match_row_template
|
// Globals
|
||||||
function main() {
|
let matches_table
|
||||||
matches_table = document.getElementById("web-cfg-matches")
|
let match_row_template
|
||||||
match_row_template = document.getElementById("web-cfg-matches-row")
|
let config
|
||||||
const config = JSON.parse(document.getElementById('m41config').text);
|
function populate_match_table(matches_config) {
|
||||||
matches_table = document.getElementById("web-cfg-matches")
|
for (let match_config of matches_config) {
|
||||||
for (match of config["matches"]) {
|
|
||||||
let vals = []
|
|
||||||
let matchType = ""
|
|
||||||
const {
|
const {
|
||||||
"name": match_name,
|
"name": match_name,
|
||||||
"addrs" : addrs,
|
"addrs" : addrs,
|
||||||
"addr_rexs" : addr_rexs,
|
"addr_rexs" : addr_rexs,
|
||||||
} = match
|
} = match_config
|
||||||
|
|
||||||
|
const [match_type, match_values] = (() => {
|
||||||
|
if (addrs != undefined) {
|
||||||
|
return ["addrs", addrs]
|
||||||
|
} else {
|
||||||
|
return ["addr_rexs", addr_rexs]
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
if (addrs != undefined) {
|
|
||||||
vals = addrs
|
|
||||||
matchType = "addrs"
|
|
||||||
} else {
|
|
||||||
vals = addr_rexs
|
|
||||||
matchType = "addr_rexs"
|
|
||||||
}
|
|
||||||
|
|
||||||
addMatchRow()
|
addMatchRow()
|
||||||
const rows = matches_table.tBodies[0].rows
|
const rows = matches_table.tBodies[0].rows
|
||||||
const lrow = rows.item(rows.length -1 )
|
const last_row = rows.item(rows.length -1 )
|
||||||
const [ nameCell, typeCell, valCell ] = lrow.cells
|
const [ name_cell, type_cell, value_cell ] = last_row.cells
|
||||||
nameCell.innerText = match_name
|
|
||||||
typeCell.firstElementChild.value = matchType
|
name_cell.innerText = match_name
|
||||||
valCell.firstElementChild.value = vals.join("\n")
|
type_cell.firstElementChild.value = match_type
|
||||||
|
value_cell.firstElementChild.value = match_values.join("\n")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function addMatchRow() {
|
|
||||||
row_copy = match_row_template.content.cloneNode(true)
|
function extract_match_table() {
|
||||||
tb = matches_table.tBodies[0]
|
let matches = []
|
||||||
tb.appendChild(row_copy)
|
for (let row of matches_table.tBodies[0].rows) {
|
||||||
|
const [ name_cell, type_cell, value_cell ] = row.cells
|
||||||
|
let m = {"name" : name_cell.innerText}
|
||||||
|
switch (type_cell.firstElementChild.value) {
|
||||||
|
case "addrs": {
|
||||||
|
m["addrs"] = value_cell.firstElementChild.value.split("\n")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "addr_rexs": {
|
||||||
|
m["addr_rexs"] = value_cell.firstElementChild.value.split("\n")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matches.push(m)
|
||||||
|
}
|
||||||
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
matches_table = document.getElementById("web-cfg-matches")
|
||||||
|
match_row_template = document.getElementById("web-cfg-matches-row")
|
||||||
|
config = JSON.parse(document.getElementById('m41config').text);
|
||||||
|
populate_match_table(config["matches"])
|
||||||
|
save()
|
||||||
|
document.getElementById("before").value = JSON.stringify(config["matches"])
|
||||||
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
const matches = extract_match_table()
|
||||||
|
document.getElementById("after").value = JSON.stringify(matches)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addMatchRow() {
|
||||||
|
let row_clone = match_row_template.content.cloneNode(true)
|
||||||
|
matches_table.tBodies[0].appendChild(row_clone)
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="main()">
|
<body onload="main()">
|
||||||
@ -122,15 +158,24 @@
|
|||||||
<h1>Mail4one Web config</h1>
|
<h1>Mail4one Web config</h1>
|
||||||
<table id="web-cfg-matches">
|
<table id="web-cfg-matches">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
<th>Values</th>
|
<th>Values</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<button onClick="addMatchRow()">Add Match</button>
|
<button onClick="addMatchRow()">Add Match</button>
|
||||||
|
<button onClick="save()">Save</button>
|
||||||
|
<div>
|
||||||
|
<label for="cfg_before">Before</label>
|
||||||
|
<textarea id="before" name="cfg_before" style="width=100%"></textarea>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="cfg_after">After</label>
|
||||||
|
<textarea id="after" name="cfg_after"></textarea>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user