diff options
| author | Shulhan <ms@kilabit.info> | 2022-06-12 12:57:58 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-06-12 14:26:21 +0700 |
| commit | 85418757eb06caa3ef30205249397cfb50e95f0f (patch) | |
| tree | 16b34d99bc97e79fb0ebf78b49f470958080a219 /_www/block.d/index.html | |
| parent | dbbf768254182ad12be3ecedf61685f8e18201a3 (diff) | |
| download | rescached-85418757eb06caa3ef30205249397cfb50e95f0f.tar.xz | |
_www: refactoring, various bug fixes and cleanups
On refactoring,
- standardize the method names on the rescached.js to match with the
Client, for example prefixing block.d operations with Blockd.
- use the GET /block.d, GET /hosts.d, GET /zone.d to fetch the
resources instead of using GET /environment for all.
On bug fixes,
- fix updating SOA record on zone.d due to refactoring
Diffstat (limited to '_www/block.d/index.html')
| -rw-r--r-- | _www/block.d/index.html | 76 |
1 files changed, 35 insertions, 41 deletions
diff --git a/_www/block.d/index.html b/_www/block.d/index.html index 27059c3..4471b69 100644 --- a/_www/block.d/index.html +++ b/_www/block.d/index.html @@ -82,7 +82,7 @@ <div id="HostBlockd" class="block_source"></div> <div> - <button onclick="blockdUpdate()">Save</button> + <button onclick="BlockdUpdate()">Save</button> </div> <script src="/index.js"></script> @@ -90,81 +90,75 @@ <script> let resc = null - function onLoad() { + async function onLoad() { resc = new Rescached("") - getEnvironment() - } - async function getEnvironment() { - const res = await resc.getEnvironment() + const res = await resc.Blockd() if (res.code != 200) { notifError(res.message) return } - - let env = res.data - renderHostBlockd(env.HostBlockd) + renderBlockd(resc.blockd) } function onCheckHostblock(key, val) { - resc.env.HostBlockd[key].IsEnabled = val + resc.blockd[key].IsEnabled = val } - async function blockdFetch(name) { + async function BlockdFetch(name) { const res = await resc.BlockdFetch(name) if (res.code != 200) { - notifError("blockdFetch: ", res.message) + notifError("BlockdFetch: ", res.message) return } - resc.env.HostBlockd[name] = res.data - - notifInfo("The hosts blocks has been updated.") + notifInfo(`The hosts for blockd.d ${name} has been fetched.`) - renderHostBlockd(resc.env.HostBlockd) + renderBlockd(resc.blockd) } - async function blockdUpdate() { - const res = await resc.BlockdUpdate(resc.env.HostBlockd) + async function BlockdUpdate() { + const res = await resc.BlockdUpdate(resc.blockd) if (res.code != 200) { - notifError("blockdUpdate: ", res.message) + notifError("BlockdUpdate: ", res.message) return } - renderHostBlockd(res.data) + renderBlockd(resc.blockd) notifInfo("The hosts blocks has been updated.") } - function renderHostBlockd(hostsBlockd) { + function renderBlockd(blockd) { let parent = document.getElementById("HostBlockd") parent.innerHTML = "" - for (var k in hostsBlockd) { - if (!hostsBlockd.hasOwnProperty(k)) { + for (var k in blockd) { + if (!blockd.hasOwnProperty(k)) { continue; } - let hostsBlock = hostsBlockd[k] + let hostsBlock = blockd[k] let item = document.createElement("div") item.classList.add("item") item.innerHTML = ` - <span class="is-enabled"> - <input - type="checkbox" - ${hostsBlock.IsEnabled ? "checked" : ""} - oninput="onCheckHostblock('${k}', this.checked)" - /> - </span> - <span class="info"> - <div> - ${hostsBlock.Name} - <button onclick="blockdFetch('${k}')"> - Update - </button> - </div> - <div> URL: <input value="${hostsBlock.URL}" disabled /> </div> - <div> Last updated at ${hostsBlock.LastUpdated} </div> - </span>` + <span class="is-enabled"> + <input + type="checkbox" + ${hostsBlock.IsEnabled ? "checked" : ""} + oninput="onCheckHostblock('${k}', this.checked)" + /> + </span> + <span class="info"> + <div> + ${hostsBlock.Name} + <button onclick="BlockdFetch('${k}')"> + Update + </button> + </div> + <div> URL: <input value="${hostsBlock.URL}" disabled /> </div> + <div> Last updated at ${hostsBlock.LastUpdated} </div> + </span> + ` parent.appendChild(item) } |
