feat: separate status page into clusters

This commit is contained in:
spiral 2022-03-09 21:29:51 -05:00
parent 1cfeb1234c
commit 67c4c64847
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E

View File

@ -9,6 +9,7 @@
let message = "Loading..."; let message = "Loading...";
let shards = []; let shards = [];
let clusters = {};
let pingAverage = ""; let pingAverage = "";
let currentCommitMsg = ""; let currentCommitMsg = "";
@ -27,20 +28,32 @@
const get = async () => { const get = async () => {
const pkdata = await api().private.meta.get(); const pkdata = await api().private.meta.get();
shards = pkdata.shards.sort((x, y) => (x.id > y.id) ? 1 : -1); let data = pkdata.shards.sort((x, y) => (x.id > y.id) ? 1 : -1);
let pings = 0; let pings = 0;
shards = shards.map(shard => { data = data.map(shard => {
pings += shard.ping; pings += shard.ping;
shard.last_connection = new Date(Number(shard.last_connection) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift() shard.last_connection = new Date(Number(shard.last_connection) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift()
shard.last_heartbeat = new Date(Number(shard.last_heartbeat) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift() shard.last_heartbeat = new Date(Number(shard.last_heartbeat) * 1000).toUTCString().match(/([0-9][0-9]:[0-9][0-9]:[0-9][0-9])/)?.shift()
return shard; return shard;
});
console.log(data[0].cluster_id);
pingAverage = Math.trunc(pings / shards.length).toString();
currentCommitMsg = `Current Git commit: <a href="https://github.com/xSke/PluralKit/commit/${pkdata.version}">${pkdata.version.slice(0,7)}</a>`;
if (data[0].cluster_id === 0) {
let clusterData = {};
data.forEach(shard => {
if (clusterData[shard.cluster_id] === undefined) clusterData[shard.cluster_id] = [];
clusterData[shard.cluster_id].push(shard);
}); });
clusters = clusterData;
pingAverage = Math.trunc(pings / shards.length).toString(); } else {
shards = data;
currentCommitMsg = `Current Git commit: <a href="https://github.com/xSke/PluralKit/commit/${pkdata.version}">${pkdata.version.slice(0,7)}</a>`; }
message = ""; message = "";
}; };
get(); get();
@ -129,16 +142,35 @@
</Card> </Card>
</Col> </Col>
</Row> </Row>
<Row> {#if shards.length > 0}
<Col class="mx-auto" xs={12} lg={11} xl={10}> <Row>
<Card class="mb-4"> <Col class="mx-auto" xs={12} lg={11} xl={10}>
<CardBody> <Card class="mb-4">
<span>{ message }</span> <CardBody>
{#each shards as shard} <span>{ message }</span>
<ShardItem shard={shard} bind:hover={hover} /> {#each shards as shard}
{/each} <ShardItem shard={shard} bind:hover={hover} />
</CardBody> {/each}
</Card> </CardBody>
</Col> </Card>
</Row> </Col>
</Row>
{/if}
{#each Object.keys(clusters) as key}
<Row>
<Col class="mx-auto" xs={12} lg={11} xl={10}>
<Card class="mb-4">
<CardBody>
<CardTitle style="margin-top: 8px; outline: none;">
Cluster {key}
</CardTitle>
<br>
{#each clusters[key] as shard}
<ShardItem shard={shard} bind:hover={hover} />
{/each}
</CardBody>
</Card>
</Col>
</Row>
{/each}
</Container> </Container>