This commit is contained in:
Louis Lam 2023-12-21 20:47:47 +08:00
parent 5056df2644
commit 37f261480a
8 changed files with 57 additions and 14 deletions

View File

@ -139,10 +139,19 @@ export class AgentManager {
async sendAgentList() { async sendAgentList() {
let list = await Agent.getAgentList(); let list = await Agent.getAgentList();
let result : Record<string, LooseObject> = {}; let result : Record<string, LooseObject> = {};
// Myself
result[""] = {
url: "",
username: "",
endpoint: "",
};
for (let endpoint in list) { for (let endpoint in list) {
let agent = list[endpoint]; let agent = list[endpoint];
result[endpoint] = agent.toJSON(); result[endpoint] = agent.toJSON();
} }
this.socket.emit("agentList", { this.socket.emit("agentList", {
ok: true, ok: true,
agentList: result, agentList: result,

View File

@ -36,6 +36,7 @@ import { AgentProxySocketHandler } from "./socket-handlers/agent-proxy-socket-ha
import { AgentSocketHandler } from "./agent-socket-handler"; import { AgentSocketHandler } from "./agent-socket-handler";
import { AgentSocket } from "../common/agent-socket"; import { AgentSocket } from "../common/agent-socket";
import { ManageAgentSocketHandler } from "./socket-handlers/manage-agent-socket-handler"; import { ManageAgentSocketHandler } from "./socket-handlers/manage-agent-socket-handler";
import { Terminal } from "./terminal";
export class DockgeServer { export class DockgeServer {
app : Express; app : Express;

View File

@ -1,7 +1,6 @@
import { BeanModel } from "redbean-node/dist/bean-model"; import { BeanModel } from "redbean-node/dist/bean-model";
import { R } from "redbean-node"; import { R } from "redbean-node";
import { LooseObject } from "../../common/util-common"; import { LooseObject } from "../../common/util-common";
import User from "./user";
export class Agent extends BeanModel { export class Agent extends BeanModel {
@ -23,7 +22,6 @@ export class Agent extends BeanModel {
return { return {
url: this.url, url: this.url,
username: this.username, username: this.username,
password: this.password,
endpoint: this.endpoint, endpoint: this.endpoint,
}; };
} }

View File

@ -43,7 +43,7 @@
</div> </div>
</div> </div>
<div ref="stackList" class="stack-list" :class="{ scrollbar: scrollbar }" :style="stackListStyle"> <div ref="stackList" class="stack-list" :class="{ scrollbar: scrollbar }" :style="stackListStyle">
<div v-if="Object.keys($root.stackList).length === 0" class="text-center mt-3"> <div v-if="Object.keys(sortedStackList).length === 0" class="text-center mt-3">
<router-link to="/compose">{{ $t("addFirstStackMsg") }}</router-link> <router-link to="/compose">{{ $t("addFirstStackMsg") }}</router-link>
</div> </div>

View File

@ -57,7 +57,7 @@ export default {
if (this.stack.endpoint) { if (this.stack.endpoint) {
return this.stack.endpoint; return this.stack.endpoint;
} else { } else {
return "Current"; return this.$t("currentEndpoint");
} }
}, },
url() { url() {

View File

@ -105,5 +105,7 @@
"dockgeURL": "Dockge URL (e.g. http://127.0.0.1:5001)", "dockgeURL": "Dockge URL (e.g. http://127.0.0.1:5001)",
"agentOnline": "Online", "agentOnline": "Online",
"agentOffline": "Offline", "agentOffline": "Offline",
"agentConnecting": "Connecting" "connecting": "Connecting",
"connect": "Connect",
"addAgent": "Add Agent"
} }

View File

@ -8,6 +8,7 @@
<div class="row first-row"> <div class="row first-row">
<!-- Left --> <!-- Left -->
<div class="col-md-7"> <div class="col-md-7">
<!-- Stats -->
<div class="shadow-box big-padding text-center mb-4"> <div class="shadow-box big-padding text-center mb-4">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
@ -25,6 +26,7 @@
</div> </div>
</div> </div>
<!-- Docker Run -->
<h2 class="mb-3">{{ $t("Docker Run") }}</h2> <h2 class="mb-3">{{ $t("Docker Run") }}</h2>
<div class="mb-3"> <div class="mb-3">
<textarea id="name" v-model="dockerRunCommand" type="text" class="form-control docker-run" required placeholder="docker run ..."></textarea> <textarea id="name" v-model="dockerRunCommand" type="text" class="form-control docker-run" required placeholder="docker run ..."></textarea>
@ -34,20 +36,32 @@
</div> </div>
<!-- Right --> <!-- Right -->
<div class="col-md-5"> <div class="col-md-5">
<!-- Agent List -->
<div class="shadow-box big-padding"> <div class="shadow-box big-padding">
<h4 class="mb-3">{{ $tc("dockgeAgent", 2) }} <span class="badge bg-warning" style="font-size: 12px;">beta</span></h4> <h4 class="mb-3">{{ $tc("dockgeAgent", 2) }} <span class="badge bg-warning" style="font-size: 12px;">beta</span></h4>
<div class="mb-3"> <div v-for="(agent, endpoint) in $root.agentList" :key="endpoint" class="mb-3">
Current <!-- Agent Status -->
<template v-if="$root.agentStatusList[endpoint]">
<span v-if="$root.agentStatusList[endpoint] === 'online'" class="badge bg-primary me-2">{{ $t("agentOnline") }}</span>
<span v-else-if="$root.agentStatusList[endpoint] === 'offline'" class="badge bg-danger me-2">{{ $t("agentOffline") }}</span>
<span v-else class="badge bg-secondary me-2">{{ $t($root.agentStatusList[endpoint]) }}</span>
</template>
<!-- Agent Display Name -->
<span v-if="endpoint === ''">{{ $t("currentEndpoint") }}</span>
<span v-else>{{ endpoint }}</span>
<font-awesome-icon v-if="endpoint !== ''" class="ms-2 remove-agent" icon="trash" @click="removeAgent(agent.url)" />
</div> </div>
<button v-if="!showAgentForm" class="btn btn-normal" @click="showAgentForm = !showAgentForm">Add Agent</button> <button v-if="!showAgentForm" class="btn btn-normal" @click="showAgentForm = !showAgentForm">{{ $t("addAgent") }}</button>
<!-- Add Agent Form --> <!-- Add Agent Form -->
<form v-if="showAgentForm" @submit.prevent="addAgent"> <form v-if="showAgentForm" @submit.prevent="addAgent">
<div class="mb-3"> <div class="mb-3">
<label for="url" class="form-label">{{ $t("dockgeURL") }}</label> <label for="url" class="form-label">{{ $t("dockgeURL") }}</label>
<input id="url" v-model="agent.url" type="text" class="form-control" required> <input id="url" v-model="agent.url" type="url" class="form-control" required placeholder="http://">
</div> </div>
<div class="mb-3"> <div class="mb-3">
@ -60,7 +74,7 @@
<input id="password" v-model="agent.password" type="password" class="form-control" required autocomplete="new-password"> <input id="password" v-model="agent.password" type="password" class="form-control" required autocomplete="new-password">
</div> </div>
<button type="submit" class="btn btn-normal">Add Agent</button> <button type="submit" class="btn btn-normal">{{ $t("connect") }}</button>
</form> </form>
</div> </div>
</div> </div>
@ -142,16 +156,29 @@ export default {
methods: { methods: {
addAgent() { addAgent() {
alert(123); this.$root.getSocket().emit("addAgent", this.agent, (res) => {
if (res.ok) {
this.$root.toastRes(res);
this.showAgentForm = false;
}
});
this.showAgentForm = false; this.showAgentForm = false;
}, },
removeAgent(url) {
this.$root.getSocket().emit("removeAgent", url, (res) => {
if (res.ok) {
this.$root.toastRes(res);
}
});
},
getStatusNum(statusName) { getStatusNum(statusName) {
let num = 0; let num = 0;
for (let stackName in this.$root.stackList) { for (let stackName in this.$root.completeStackList) {
const stack = this.$root.stackList[stackName]; const stack = this.$root.completeStackList[stackName];
if (statusNameShort(stack.status) === statusName) { if (statusNameShort(stack.status) === statusName) {
num += 1; num += 1;
} }
@ -284,4 +311,9 @@ table {
} }
.remove-agent {
cursor: pointer;
color: rgba(255, 255, 255, 0.3);
}
</style> </style>

View File

@ -7,6 +7,7 @@
"skipLibCheck": true "skipLibCheck": true
}, },
"include": [ "include": [
"backend/**/*" "backend/**/*",
"common/**/*"
] ]
} }