mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Remove old web interface
This commit is contained in:
1 parent
bca949f7be
commit
fbf2843f5b
56 files changed
+1
-1424
No files matched your search
@@ -30,19 +30,6 @@ const masterInventoryGauge = new prometheus.Gauge(
|
||||
class MasterPlugin extends plugin.BaseMasterPlugin {
|
||||
async init() {
|
||||
|
||||
let externalAddress = this.master.config.get("master.external_address");
|
||||
let root = externalAddress ? new URL(externalAddress).pathname : "/";
|
||||
this.ui = {
|
||||
sidebar: [
|
||||
{
|
||||
getHtml: () => `
|
||||
<div class="nav-item mr-1">
|
||||
<a class="nav-link align-middle" href="${root}subspace_storage/storage">Storage</a>
|
||||
</div>`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
this.items = await loadDatabase(this.master.config);
|
||||
this.itemsLastUpdate = new Map(this.items._items.entries());
|
||||
this.autosaveId = setInterval(() => {
|
||||
@@ -61,7 +48,6 @@ class MasterPlugin extends plugin.BaseMasterPlugin {
|
||||
}, 1000);
|
||||
|
||||
routes.addApiRoutes(this.master.app, this.items, this.metrics.endpointHitCounter);
|
||||
routes.addWebRoutes(this.master.app);
|
||||
}
|
||||
|
||||
updateStorage() {
|
||||
|
||||
@@ -5,11 +5,6 @@ const path = require("path");
|
||||
const prometheus = require("@clusterio/lib/prometheus");
|
||||
|
||||
|
||||
function addWebRoutes(app) {
|
||||
app.use("/subspace_storage", express.static(path.join(__dirname, "static")));
|
||||
app.get("/subspace_storage/storage", (req, res) => { res.render("subspace_storage/views/storage"); });
|
||||
}
|
||||
|
||||
function addApiRoutes(app, items, endpointHitCounter) {
|
||||
|
||||
/**
|
||||
@@ -52,6 +47,5 @@ function addApiRoutes(app, items, endpointHitCounter) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addWebRoutes,
|
||||
addApiRoutes,
|
||||
};
|
||||
@@ -1,99 +0,0 @@
|
||||
// function to draw data we recieve from ajax requests
|
||||
"use strict";
|
||||
var _lastData = [];
|
||||
function drawcontents(data) {
|
||||
data = data || _lastData; //Cache data so we can drawcontents without waiting for the server, for the search box.
|
||||
_lastData = data;
|
||||
|
||||
// allow searching for multiple criteria separated by space
|
||||
var searchArgs = document.querySelector("#search").value;
|
||||
searchArgs = searchArgs.trim();
|
||||
searchArgs = "(" + searchArgs.replace(/ +/g,")|(") + ")";
|
||||
const search = new RegExp(searchArgs, "i");
|
||||
data = data.filter(function(item) {
|
||||
return search.test(item.name);
|
||||
});
|
||||
|
||||
sortByKey(data, "count");
|
||||
|
||||
const table = document.querySelector("#contents tbody"); //tables have tbody inserted automatically
|
||||
const rows = table.children;
|
||||
|
||||
//update existing rows or create new ones
|
||||
data.forEach(function(item, i) {
|
||||
// format count to have .s in it for large number readability (1,000,000)
|
||||
item.count = item.count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
|
||||
let row = rows[i];
|
||||
if(!row) {
|
||||
row = document.createElement("tr");
|
||||
row.innerHTML = "<td><div></div></td><td class=name></td><td class=count></td>";
|
||||
table.appendChild(row);
|
||||
}
|
||||
|
||||
const itemIcon = row.querySelector("div");
|
||||
const iconClass = getItemIconClass(item.name);
|
||||
if (itemIcon.getAttribute("class") !== iconClass) {
|
||||
itemIcon.setAttribute("class", iconClass);
|
||||
}
|
||||
|
||||
let localeName = item.name;
|
||||
let meta = factorioItemMetadata.get(item.name);
|
||||
if (meta && meta.localised_name) {
|
||||
// TODO implement the locale to name conversion.
|
||||
localeName = factorioLocale.get(meta.localised_name[0]);
|
||||
} else {
|
||||
for (let section of ["item-name", "entity-name", "fluid-name", "equipment-name"]) {
|
||||
let name = factorioLocale.get(`${section}.${item.name}`);
|
||||
if (name) {
|
||||
localeName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const name = row.querySelector(".name");
|
||||
if(name.textContent !== localeName) {
|
||||
name.textContent = localeName;
|
||||
}
|
||||
|
||||
const count = row.querySelector(".count");
|
||||
if(count.textContent !== String(item.count)) {
|
||||
count.textContent = item.count;
|
||||
}
|
||||
});
|
||||
|
||||
//remove excess rows, for example, after filtering
|
||||
while (data.length < rows.length) {
|
||||
table.removeChild(rows[data.length]);
|
||||
}
|
||||
}
|
||||
|
||||
// get cluster inventory from master
|
||||
function updateInventory() {
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
let data = JSON.parse(xmlhttp.responseText);
|
||||
drawcontents(data);
|
||||
}
|
||||
};
|
||||
xmlhttp.open("GET", `${root}api/inventory`, true);
|
||||
xmlhttp.send();
|
||||
}
|
||||
if(JSON.parse(localStorage.settings)["Periodically update storage screen"]) {
|
||||
setInterval(updateInventory, 500);
|
||||
} else {
|
||||
updateInventory();
|
||||
}
|
||||
|
||||
// function to sort arrays of objects after a keys value
|
||||
function sortByKey(array, key) {
|
||||
array.sort(function(a, b) {
|
||||
return b[key] - a[key];
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelector("#search").addEventListener("input", function() {
|
||||
drawcontents();
|
||||
});
|
||||
@@ -1,41 +0,0 @@
|
||||
<!doctype HTML>
|
||||
<head>
|
||||
<%- include("head") %>
|
||||
<script defer src="<%= locals.root %>subspace_storage/storage.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%- include("nav") %>
|
||||
<div id="body" class="container">
|
||||
<div id="storage">
|
||||
<div class="page-header mt-2 row" id="banner">
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-md-7 col-sm-6">
|
||||
<h2>Storage</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mt-3 mb-3 row">
|
||||
<input type="text" class="form-control" id="search" placeholder="search">
|
||||
</div>
|
||||
<div id="contents" class="row w-100">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th scope="col">Icon</th>
|
||||
<th scope="col">Resource</th>
|
||||
<th scope="col">Quantity</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><!-- populated by js --></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
|
||||
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
|
||||
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
|
||||
crossorigin="anonymous"></script>
|
||||
</body>
|
||||
Reference in new issue
Block a user