diff --git a/relay/frontend/static/api.js b/relay/frontend/static/api.js
index cbdb1c9..e4a1219 100644
--- a/relay/frontend/static/api.js
+++ b/relay/frontend/static/api.js
@@ -27,6 +27,24 @@ function get_date_string(date) {
}
+function append_table_row(table, row_name, row) {
+ var table_row = table.insertRow(-1);
+ table_row.id = row_name;
+
+ index = 0;
+
+ for (var prop in row) {
+ if (Object.prototype.hasOwnProperty.call(row, prop)) {
+ var cell = table_row.insertCell(index);
+ cell.className = prop;
+ cell.innerHTML = row[prop];
+
+ index += 1;
+ }
+ }
+}
+
+
class Client {
constructor() {
this.token = get_cookie("user-token");
diff --git a/relay/frontend/static/domain_ban.js b/relay/frontend/static/domain_ban.js
index ae92420..a86c7ba 100644
--- a/relay/frontend/static/domain_ban.js
+++ b/relay/frontend/static/domain_ban.js
@@ -40,20 +40,11 @@ async function ban() {
return
}
- var row = table.insertRow(-1);
- row.id = ban.domain;
-
- var new_domain = row.insertCell(0);
- var new_date = row.insertCell(1);
- var new_remove = row.insertCell(2);
-
- new_domain.className = "domain";
- new_date.className = "date";
- new_remove.className = "remove";
-
- new_domain.innerHTML = create_ban_object(ban.domain, ban.reason, ban.note);
- new_date.innerHTML = get_date_string(ban.created);
- new_remove.innerHTML = `✖`;
+ append_table_row(document.getElementById("instances"), ban.domain, {
+ domain: create_ban_object(ban.domain, ban.reason, ban.note),
+ date: get_date_string(ban.created),
+ remove: `✖`
+ });
elems.domain.value = null;
elems.reason.value = null;
diff --git a/relay/frontend/static/instance.js b/relay/frontend/static/instance.js
index 27351eb..e05d2bd 100644
--- a/relay/frontend/static/instance.js
+++ b/relay/frontend/static/instance.js
@@ -1,25 +1,3 @@
-function append_table_row(table, instance) {
- var row = table.insertRow(-1);
- row.id = instance.domain;
-
- var domain = row.insertCell(0);
- domain.className = "domain";
- domain.innerHTML = `${instance.domain}`;
-
- var software = row.insertCell(1);
- software.className = "software";
- software.innerHTML = instance.software
-
- var date = row.insertCell(2);
- date.className = "date";
- date.innerHTML = get_date_string(instance.created);
-
- var remove = row.insertCell(3);
- remove.className = "remove";
- remove.innerHTML = `✖`;
-}
-
-
async function add_instance() {
var elems = {
actor: document.getElementById("new-actor"),
@@ -48,7 +26,12 @@ async function add_instance() {
return
}
- append_table_row(document.getElementById("instances"), instance);
+ append_table_row(document.getElementById("instances"), instance.domain, {
+ domain: `${instance.domain}`,
+ software: instance.software,
+ date: get_date_string(instance.created),
+ remove: `✖`
+ });
elems.actor.value = null;
elems.inbox.value = null;
@@ -99,7 +82,12 @@ async function req_response(domain, accept) {
instances = await client.request("GET", `v1/instance`, null);
instances.forEach((instance) => {
if (instance.domain === domain) {
- append_table_row(document.getElementById("instances"), instance);
+ append_table_row(document.getElementById("instances"), instance.domain, {
+ domain: `${instance.domain}`,
+ software: instance.software,
+ date: get_date_string(instance.created),
+ remove: `✖`
+ });
}
});
}
diff --git a/relay/frontend/static/software_ban.js b/relay/frontend/static/software_ban.js
index 72e775d..2e0796d 100644
--- a/relay/frontend/static/software_ban.js
+++ b/relay/frontend/static/software_ban.js
@@ -42,18 +42,11 @@ async function ban() {
return
}
- row.id = ban.name;
- var new_name = row.insertCell(0);
- var new_date = row.insertCell(1);
- var new_remove = row.insertCell(2);
-
- new_name.className = "name";
- new_date.className = "date";
- new_remove.className = "remove";
-
- new_name.innerHTML = create_ban_object(ban.name, ban.reason, ban.note);
- new_date.innerHTML = get_date_string(ban.created);
- new_remove.innerHTML = `✖`;
+ append_table_row(document.getElementById("instances"), ban.name, {
+ name: create_ban_object(ban.name, ban.reason, ban.note),
+ date: get_date_string(ban.created),
+ remove: `✖`
+ });
elems.name.value = null;
elems.reason.value = null;
diff --git a/relay/frontend/static/whitelist.js b/relay/frontend/static/whitelist.js
index 86f02fb..bf6bf5d 100644
--- a/relay/frontend/static/whitelist.js
+++ b/relay/frontend/static/whitelist.js
@@ -15,21 +15,11 @@ async function add_whitelist() {
return
}
- var table = document.getElementById("whitelist");
- var row = table.insertRow(-1);
- row.id = item.domain;
-
- var domain = row.insertCell(0);
- domain.className = "domain";
- domain.innerHTML = item.domain;
-
- var date = row.insertCell(1);
- date.className = "date";
- date.innerHTML = get_date_string(item.created);
-
- var remove = row.insertCell(2);
- remove.className = "remove";
- remove.innerHTML = `✖`;
+ append_table_row(document.getElementById("instances"), item.domain, {
+ domain: item.domain,
+ date: get_date_string(ban.created),
+ remove: `✖`
+ });
domain_elem.value = null;
document.querySelector("details.section").open = false;