feat: Add js to dashboard to pull data after page load
All checks were successful
Build Docker / Build Image (push) Successful in 41s
All checks were successful
Build Docker / Build Image (push) Successful in 41s
This commit is contained in:
parent
7a4300066f
commit
71e59a9a95
Binary file not shown.
63
main.py
63
main.py
@ -38,48 +38,6 @@ def index():
|
|||||||
if not account:
|
if not account:
|
||||||
return redirect("/logout")
|
return redirect("/logout")
|
||||||
|
|
||||||
domains = account_module.getDomains(account)
|
|
||||||
|
|
||||||
# Sort
|
|
||||||
sort = request.args.get("sort")
|
|
||||||
if sort == None:
|
|
||||||
sort = "domain"
|
|
||||||
sort = sort.lower()
|
|
||||||
sort_price = ""
|
|
||||||
sort_price_next = "⬇"
|
|
||||||
sort_expiry = ""
|
|
||||||
sort_expiry_next = "⬇"
|
|
||||||
sort_domain = ""
|
|
||||||
sort_domain_next = "⬇"
|
|
||||||
reverse = False
|
|
||||||
|
|
||||||
direction = request.args.get("direction")
|
|
||||||
if direction == None:
|
|
||||||
direction = "⬇"
|
|
||||||
|
|
||||||
if direction == "⬆":
|
|
||||||
reverse = True
|
|
||||||
|
|
||||||
if sort == "expiry":
|
|
||||||
# Sort by next expiry
|
|
||||||
domains = sorted(domains, key=lambda k: k['renewal'],reverse=reverse)
|
|
||||||
sort_expiry = direction
|
|
||||||
sort_expiry_next = reverseDirection(direction)
|
|
||||||
|
|
||||||
|
|
||||||
elif sort == "price":
|
|
||||||
# Sort by price
|
|
||||||
domains = sorted(domains, key=lambda k: k['value'],reverse=reverse)
|
|
||||||
sort_price = direction
|
|
||||||
sort_price_next = reverseDirection(direction)
|
|
||||||
else:
|
|
||||||
# Sort by domain
|
|
||||||
domains = sorted(domains, key=lambda k: k['name'],reverse=reverse)
|
|
||||||
sort_domain = direction
|
|
||||||
sort_domain_next = reverseDirection(direction)
|
|
||||||
|
|
||||||
domainsMobile = render.domains(domains,True)
|
|
||||||
domains = render.domains(domains)
|
|
||||||
|
|
||||||
plugins = ""
|
plugins = ""
|
||||||
dashFunctions = plugins_module.getDashboardFunctions()
|
dashFunctions = plugins_module.getDashboardFunctions()
|
||||||
@ -87,11 +45,7 @@ def index():
|
|||||||
functionOutput = plugins_module.runPluginFunction(function["plugin"],function["function"],{},request.cookies.get("account"))
|
functionOutput = plugins_module.runPluginFunction(function["plugin"],function["function"],{},request.cookies.get("account"))
|
||||||
plugins += render.plugin_output_dash(functionOutput,plugins_module.getPluginFunctionReturns(function["plugin"],function["function"]))
|
plugins += render.plugin_output_dash(functionOutput,plugins_module.getPluginFunctionReturns(function["plugin"],function["function"]))
|
||||||
|
|
||||||
return render_template("index.html", account=account,domains=domains,
|
return render_template("index.html", account=account, plugins=plugins)
|
||||||
domainsMobile=domainsMobile, plugins=plugins,
|
|
||||||
sort_price=sort_price,sort_expiry=sort_expiry,
|
|
||||||
sort_domain=sort_domain,sort_price_next=sort_price_next,
|
|
||||||
sort_expiry_next=sort_expiry_next,sort_domain_next=sort_domain_next)
|
|
||||||
|
|
||||||
def reverseDirection(direction: str):
|
def reverseDirection(direction: str):
|
||||||
if direction == "⬆":
|
if direction == "⬆":
|
||||||
@ -875,9 +829,9 @@ def auction(domain):
|
|||||||
error=error)
|
error=error)
|
||||||
|
|
||||||
if domainInfo['info'] is None:
|
if domainInfo['info'] is None:
|
||||||
if domainInfo['registered'] == False and domainInfo['expired'] == False:
|
if 'registered' in domainInfo and domainInfo['registered'] == False and 'expired' in domainInfo and domainInfo['expired'] == False:
|
||||||
# Needs to be registered
|
# Needs to be registered
|
||||||
next_action = f'ERROR GETTING NEXT STATE'
|
next_action = f'ERROR GETTING NEXT STATE'
|
||||||
else:
|
else:
|
||||||
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
|
next_action = f'<a href="/auction/{domain}/open">Open Auction</a>'
|
||||||
return render_template("auction.html", account=account,
|
return render_template("auction.html", account=account,
|
||||||
@ -1519,6 +1473,17 @@ def api_wallet(function):
|
|||||||
return jsonify({"result": len(account_module.getPendingRedeems(account,password))})
|
return jsonify({"result": len(account_module.getPendingRedeems(account,password))})
|
||||||
|
|
||||||
|
|
||||||
|
if function == "domains":
|
||||||
|
domains = account_module.getDomains(account)
|
||||||
|
if 'error' in domains:
|
||||||
|
return jsonify({"result": [], "error": domains['error']})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify({"result": domains})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400
|
return jsonify({"error": "Invalid function", "result": "Invalid function"}), 400
|
||||||
|
|
||||||
|
|
||||||
|
2
templates/assets/js/script.min.js
vendored
2
templates/assets/js/script.min.js
vendored
@ -1 +1 @@
|
|||||||
async function request(e){try{const t=await fetch(`/api/v1/${e}`);if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);const o=await t.json();return void 0!==o.error?`Error: ${o.error}`:o.result}catch(e){return console.error("Request failed:",e),"Error"}}window.addEventListener("load",(async()=>{const e=["hsd-sync","hsd-version","hsd-height","wallet-sync","wallet-available","wallet-total","wallet-locked","wallet-pending","wallet-domainCount","wallet-bidCount","wallet-pendingReveal","wallet-pendingRegister","wallet-pendingRedeem"],t=["wallet-available","wallet-total","wallet-locked"];for(const o of e){const e=document.getElementById(o);if(e){const l=o.replace(/-/g,"/");let n=await request(l);t.includes(o)&&(n=Number(n).toFixed(2),n=n.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")),e.innerHTML=n}}})),function(){"use strict";var e=document.querySelector(".sidebar"),t=document.querySelectorAll("#sidebarToggle, #sidebarToggleTop");if(e){e.querySelector(".collapse");var o=[].slice.call(document.querySelectorAll(".sidebar .collapse")).map((function(e){return new bootstrap.Collapse(e,{toggle:!1})}));for(var l of t)l.addEventListener("click",(function(t){if(document.body.classList.toggle("sidebar-toggled"),e.classList.toggle("toggled"),e.classList.contains("toggled"))for(var l of o)l.hide()}));window.addEventListener("resize",(function(){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)<768)for(var e of o)e.hide()}))}var n=document.querySelector("body.fixed-nav .sidebar");n&&n.on("mousewheel DOMMouseScroll wheel",(function(e){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)>768){var t=e.originalEvent,o=t.wheelDelta||-t.detail;this.scrollTop+=30*(o<0?1:-1),e.preventDefault()}}));var r=document.querySelector(".scroll-to-top");r&&window.addEventListener("scroll",(function(){var e=window.pageYOffset;r.style.display=e>100?"block":"none"}))}();
|
async function request(e){try{const t=await fetch(`/api/v1/${e}`);if(!t.ok)throw new Error(`HTTP error! Status: ${t.status}`);const n=await t.json();return void 0!==n.error?`Error: ${n.error}`:n.result}catch(e){return console.error("Request failed:",e),"Error"}}function sortTable(e,t=!1){const n=document.getElementById("data-table"),a=n.querySelector("tbody"),o=Array.from(a.querySelectorAll("tr")),r=n.querySelectorAll("th");let l=n.getAttribute("data-sort-order")||"asc",c=n.getAttribute("data-sort-column")||"-1";l=t||c!=e?"asc":"asc"===l?"desc":"asc",n.setAttribute("data-sort-order",l),n.setAttribute("data-sort-column",e),o.sort(((t,n)=>{let a=t.cells[e].innerText.trim(),o=n.cells[e].innerText.trim();return isNaN(a)||isNaN(o)?Date.parse(a)&&Date.parse(o)?"asc"===l?new Date(a)-new Date(o):new Date(o)-new Date(a):"asc"===l?a.localeCompare(o):o.localeCompare(a):"asc"===l?a-o:o-a})),a.innerHTML="",o.forEach((e=>a.appendChild(e))),updateSortIndicators(r,e,l)}function updateSortIndicators(e,t,n){e.forEach(((e,a)=>{let o=e.querySelector(".sort-indicator");o.innerHTML=a===t?"asc"===n?" ▲":" ▼":""}))}window.addEventListener("load",(async()=>{const e=["hsd-sync","hsd-version","hsd-height","wallet-sync","wallet-available","wallet-total","wallet-locked","wallet-pending","wallet-domainCount","wallet-bidCount","wallet-pendingReveal","wallet-pendingRegister","wallet-pendingRedeem"],t=["wallet-available","wallet-total","wallet-locked"];for(const n of e){const e=document.getElementById(n);if(e){const a=n.replace(/-/g,"/");let o=await request(a);t.includes(n)&&(o=Number(o).toFixed(2)),o=o.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),e.innerHTML=o}}})),document.addEventListener("DOMContentLoaded",(function(){fetch("/api/v1/wallet/domains").then((e=>e.json())).then((e=>{const t=document.querySelector("#data-table tbody");t.innerHTML="",e.result.forEach((e=>{const n=document.createElement("tr"),a=document.createElement("td");a.textContent=e.name,n.appendChild(a);var o="Unknown";"stats"in e&&"daysUntilExpire"in e.stats&&(o=e.stats.daysUntilExpire);const r=document.createElement("td");r.textContent=`${o} days`,n.appendChild(r);const l=document.createElement("td");l.textContent=`${(e.value/1e6).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g,",")} HNS`,n.appendChild(l);const c=document.createElement("td");c.innerHTML=e.registered?"<a href='/manage/"+e.name+"'>Manage</a>":"<a href='/auction/"+e.name+"/register'>Register</a>",n.appendChild(c),t.appendChild(n)})),sortTable(0,!0)})).catch((e=>console.error("Error fetching data:",e)))})),setInterval((async function(){const e=["hsd-sync","hsd-height","wallet-sync","wallet-pending","wallet-available","wallet-total"];for(const t of e){const e=document.getElementById(t);if(e){const n=t.replace(/-/g,"/");let a=await request(n);["wallet-available","wallet-total"].includes(t)&&(a=Number(a).toFixed(2)),a=a.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),e.innerHTML=a}}}),2e4),function(){"use strict";var e=document.querySelector(".sidebar"),t=document.querySelectorAll("#sidebarToggle, #sidebarToggleTop");if(e){e.querySelector(".collapse");var n=[].slice.call(document.querySelectorAll(".sidebar .collapse")).map((function(e){return new bootstrap.Collapse(e,{toggle:!1})}));for(var a of t)a.addEventListener("click",(function(t){if(document.body.classList.toggle("sidebar-toggled"),e.classList.toggle("toggled"),e.classList.contains("toggled"))for(var a of n)a.hide()}));window.addEventListener("resize",(function(){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)<768)for(var e of n)e.hide()}))}var o=document.querySelector("body.fixed-nav .sidebar");o&&o.on("mousewheel DOMMouseScroll wheel",(function(e){if(Math.max(document.documentElement.clientWidth||0,window.innerWidth||0)>768){var t=e.originalEvent,n=t.wheelDelta||-t.detail;this.scrollTop+=30*(n<0?1:-1),e.preventDefault()}}));var r=document.querySelector(".scroll-to-top");r&&window.addEventListener("scroll",(function(){var e=window.pageYOffset;r.style.display=e>100?"block":"none"}))}();
|
@ -137,6 +137,23 @@
|
|||||||
<h6 class="text-primary fw-bold m-0">Domains</h6>
|
<h6 class="text-primary fw-bold m-0">Domains</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body"><div class="table-responsive">
|
<div class="card-body"><div class="table-responsive">
|
||||||
|
<table class="table" id="data-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th onclick="sortTable(0)">Domain <span class="sort-indicator"></span></th>
|
||||||
|
<th onclick="sortTable(1)">Expires <span class="sort-indicator"></span></th>
|
||||||
|
<th onclick="sortTable(2)">Price Paid <span class="sort-indicator"></span></th>
|
||||||
|
<th><span class="sort-indicator"></span></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<!-- {{domains | safe}} -->
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -150,7 +167,7 @@
|
|||||||
{{domains | safe}}
|
{{domains | safe}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div></div>
|
</div> --></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user