From 0e7cff2621a2b08f95ccebb0cd1b1a49dcd478df Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Mon, 27 Oct 2025 07:57:59 -0400 Subject: [PATCH] Initial commit --- api.js | 38 +++++++++++ app.js | 27 ++++++++ app_state.js | 19 ++++++ index.html | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui.js | 33 ++++++++++ 5 files changed, 292 insertions(+) create mode 100644 api.js create mode 100644 app.js create mode 100644 app_state.js create mode 100644 index.html create mode 100644 ui.js diff --git a/api.js b/api.js new file mode 100644 index 0000000..efb891c --- /dev/null +++ b/api.js @@ -0,0 +1,38 @@ +var api = { + init: function (base_url) { + this.endpoint = base_url; + // console.log("API Init with base_url = " + base_url); + }, + load_workers: function () { + console.log("load workers"); + this.load_from_api("/1/workers", function (data, textStatus, jqXHR) { + console.log("Workers"); + console.log(data); + }); + }, + load_status: function () { + console.log("load status"); + this.load_from_api("/api.json", function (data, textStatus, jqXHR) { + console.log("Status"); + console.log(data); + }); + }, + load_from_api: function (endpoint, callback) { + var headers = {}; + headers.Authorization = "Bearer " + app_state.api_token; + const url = this.endpoint + endpoint; + $.ajax({ + method: "get", + url: url, + headers: headers, + }) + .done(function (data, textStatus, jqXHR) { + console.log("Endpoint " + endpoint + " result " + jqXHR.status); + callback(data, textStatus, jqXHR); + }) + .fail(function (jqXHR, textStatus) { + console.log("Failed -> " + jqXHR.status + "/" + textStatus); + }); + }, + endpoint: null, +}; diff --git a/app.js b/app.js new file mode 100644 index 0000000..683a363 --- /dev/null +++ b/app.js @@ -0,0 +1,27 @@ +var app = { + init: function () { + console.log("Init App"); + app_state.init(); + ui.init(); + api.init(app_state.api_endpoint); + this.refresh(); + }, + refresh: function () { + console.log("refresh " + Date.now()); + api.load_status(); + this.poll_timer = setInterval(this.refresh, 5000); + }, + poll_toggle: function () { + console.log("POLL TIMER = " + this.poll_timer); + if (this.poll_timer == null) { + console.log("poll_toggle triggered " + Date.now()); + this.poll_timer = setInterval(this.refresh, 5000); + app_state.should_poll = true; + } else { + console.log("disabling timer"); + this.poll_timer = null; + app_state.should_poll = false; + } + }, + poll_timer: null, +}; diff --git a/app_state.js b/app_state.js new file mode 100644 index 0000000..724650e --- /dev/null +++ b/app_state.js @@ -0,0 +1,19 @@ +var app_state = { + api_endpoint: "http://198.46.176.136:44444", + api_token: "thisisthetoken", + should_poll: false, + show_config_form: false, + init: function () { + this.load_state(); + }, + load_state: function () { + console.log("Loading state"); + this.api_endpoint = localStorage.getItem("endpoint"); + this.api_token = localStorage.getItem("token"); + }, + save_state: function () { + console.log("Saving state"); + localStorage.setItem("endpoint", this.api_endpoint); + localStorage.setItem("token", this.api_token); + }, +}; diff --git a/index.html b/index.html new file mode 100644 index 0000000..0aefa7a --- /dev/null +++ b/index.html @@ -0,0 +1,175 @@ + + + + + + + + + + + + + +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+
+ + +
+
+ + +
+ + +
+ | + | + | + | + | +
+ + +
+ + + + + + + + + + + +
NameCXSharesHash Rate
+
+
+ + + diff --git a/ui.js b/ui.js new file mode 100644 index 0000000..d642b60 --- /dev/null +++ b/ui.js @@ -0,0 +1,33 @@ +var ui = { + init: function () { + console.log("Init UI"); + $("#api_endpoint_field").val(app_state.api_endpoint); + $("#api_token_field").val(app_state.api_token); + }, + address_changed_handler: function () { + app_state.api_endpoint = $("#api_endpoint_field").val(); + app_state.save_state(); + console.log("Address changed -> " + app_state.api_endpoint); + }, + token_changed_handler: function () { + app_state.api_token = $("#api_token_field").val(); + app_state.save_state(); + console.log("Token Changed -> " + app_state.api_token); + }, + poll_changed_handler: function () { + console.log("toggle of poll changed." + Date.now()); + app.poll_toggle(); + }, + toggle_configuration_form: function () { + if (app_state.show_config_form) { + console.log("hide the form"); + app_state.show_config_form = false; + $("#configuration_form").css('display", "none'); + } else { + console.log("display the form"); + app_state.show_config_form = true; + $("#configuration_form").css("display", "inline"); + } + console.log("toggle configuration form" + app_state.show_config_form); + }, +};