Skip to content

Commit

Permalink
api integration
Browse files Browse the repository at this point in the history
  • Loading branch information
PentaMine committed Feb 29, 2024
1 parent 71ff32e commit 58e27be
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"dependencies": {
"@encedeus/js-api": "^0.0.101",
"@repo/ui": "*",
"apexcharts": "^3.45.2"
},
Expand Down
79 changes: 71 additions & 8 deletions apps/console/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { Card, CardHeader, ServerIcon, BoxIcon, DriveIcon, CpuIcon, Button, ServerRunStatus } from "@repo/ui";
import {Card, CardHeader, ServerIcon, BoxIcon, DriveIcon, CpuIcon, Button, ServerRunStatus} from "@repo/ui";
import ApexCharts from "apexcharts";
import { onMount } from "svelte";
import {onMount} from "svelte";
import {api} from "./lib/services/api";
const urlParams = new URLSearchParams(window.location.search);
const serverId = urlParams.get("serverId");
Expand Down Expand Up @@ -112,6 +113,30 @@
}
};
let serverStatus = "loading";
let cpuUtilisation = 24.6;
let connectionError = "";
function setCup() {
cpuUtilisation += Number((cpuUtilisation * ((Math.random() - .5) * .02)).toFixed(2));
}
async function loadStatus() {
const resp = await api.serversService.getServerStatus(serverId!);
if (resp.error) {
serverStatus = "failed to check";
}
serverStatus = resp.response.status;
console.log(serverStatus);
}
async function loadData() {
loadStatus();
}
onMount(() => {
const memoryChart = new ApexCharts(document.querySelector("#memory-chart"), memoryOptions);
memoryChart.render();
Expand All @@ -120,7 +145,40 @@
cpuChart.render();
console.log("Server id: " + serverId);
loadData();
});
async function onClickStart() {
const resp = await api.serversService.startServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
}
connectionError = ""
}
async function onClickRestart() {
const resp = await api.serversService.restartServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
}
connectionError = ""
}
async function onClickStop() {
const resp = await api.serversService.stopServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
}
connectionError = ""
}
</script>

<main class="p-10 flex flex-col">
Expand All @@ -136,10 +194,10 @@
</span>
<div slot="content" class="py-8 px-11">
<div class="flex flex-col gap-5">
<ServerRunStatus status="running"/>
<ServerRunStatus status="{serverStatus}"/>
<div class="text-white flex flex-row items-center gap-2.5">
<CpuIcon width={32} height={32}/>
<span class="font-medium uppercase">211.19%</span>
<span class="font-medium uppercase">{cpuUtilisation}%</span>
</div>
<div class="text-white flex flex-row items-center gap-2.5">
<BoxIcon width={32} height={32}/>
Expand All @@ -150,9 +208,13 @@
<span class="font-medium uppercase">184.91 MB / 20 GB</span>
</div>
<div class="self-center mt-4 flex flex-row gap-2 items-center">
<Button size="sm" color="transparent">Start</Button>
<Button size="sm" color="transparent">Restart</Button>
<Button size="sm" color="red">Stop</Button>
<Button size="sm" color="transparent" on:click={onClickStart}>Start</Button>
<Button size="sm" color="transparent" on:click={onClickRestart}>Restart</Button>
<Button size="sm" color="red" on:click={onClickStop}>Stop</Button>
</div>

<div class="self-center text-red-500">
{connectionError}
</div>
</div>
</div>
Expand Down Expand Up @@ -181,7 +243,8 @@
</div>
<div class="bg-indigo-900 h-11 rounded-b-lg p-2.5 px-5 text-white flex gap-1.5 flex-shrink">
<span class="font-medium text-md">$</span>
<input type="text" placeholder="Type your command here" class="outline-indigo-500 opacity-85 focus:outline rounded-sm p-1 outline-2 bg-indigo-900 inline w-full">
<input type="text" placeholder="Type your command here"
class="outline-indigo-500 opacity-85 focus:outline rounded-sm p-1 outline-2 bg-indigo-900 inline w-full">
</div>
</section>
</div>
Expand Down
6 changes: 6 additions & 0 deletions apps/console/src/lib/services/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EncedeusAPI } from "@encedeus/js-api";

export const api = EncedeusAPI.getInstance("http://localhost:8080", {
withCredentials: true,

});
Loading

0 comments on commit 58e27be

Please sign in to comment.