mirror of
https://github.com/louislam/dockge.git
synced 2025-03-11 20:04:46 +00:00
fix: pull-request suggestions
updating the merge request by adding the suggestions from reviewer
This commit is contained in:
parent
dcc48d3240
commit
825b72761b
6 changed files with 42 additions and 40 deletions
|
@ -76,15 +76,15 @@ export class AgentManager {
|
||||||
* @param url
|
* @param url
|
||||||
* @param username
|
* @param username
|
||||||
* @param password
|
* @param password
|
||||||
* @param friendlyname
|
* @param name
|
||||||
* @param updatedFriendlyName
|
* @param updatedName
|
||||||
*/
|
*/
|
||||||
async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> {
|
async add(url: string, username: string, password: string, name: string): Promise<Agent> {
|
||||||
let bean = R.dispense("agent") as Agent;
|
let bean = R.dispense("agent") as Agent;
|
||||||
bean.url = url;
|
bean.url = url;
|
||||||
bean.username = username;
|
bean.username = username;
|
||||||
bean.password = password;
|
bean.password = password;
|
||||||
bean.friendlyname = friendlyname;
|
bean.name = name;
|
||||||
await R.store(bean);
|
await R.store(bean);
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
@ -109,12 +109,19 @@ export class AgentManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param friendlyname
|
* @param url
|
||||||
* @param updatedFriendlyName
|
* @param updatedName
|
||||||
*/
|
*/
|
||||||
|
async update(url: string, updatedName: string) {
|
||||||
async update(friendlyname : string, updatedFriendlyName : string) {
|
const agent = await R.findOne("agent", " url = ? ", [
|
||||||
await R.exec("UPDATE agent SET friendlyname = " + updatedFriendlyName + " WHERE friendlyname = " + friendlyname + "");
|
url,
|
||||||
|
]);
|
||||||
|
if (agent) {
|
||||||
|
agent.name = updatedName;
|
||||||
|
await R.store(agent);
|
||||||
|
} else {
|
||||||
|
throw new Error("Agent not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(url : string, username : string, password : string) {
|
connect(url : string, username : string, password : string) {
|
||||||
|
@ -289,8 +296,8 @@ export class AgentManager {
|
||||||
url: "",
|
url: "",
|
||||||
username: "",
|
username: "",
|
||||||
endpoint: "",
|
endpoint: "",
|
||||||
friendlyname: "",
|
name: "",
|
||||||
updatedFriendlyName: "",
|
updatedName: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let endpoint in list) {
|
for (let endpoint in list) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ export async function up(knex: Knex): Promise<void> {
|
||||||
table.string("url", 255).notNullable().unique();
|
table.string("url", 255).notNullable().unique();
|
||||||
table.string("username", 255).notNullable();
|
table.string("username", 255).notNullable();
|
||||||
table.string("password", 255).notNullable();
|
table.string("password", 255).notNullable();
|
||||||
table.string("friendlyname", 255);
|
table.string("name", 255);
|
||||||
table.boolean("active").notNullable().defaultTo(true);
|
table.boolean("active").notNullable().defaultTo(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export class ManageAgentSocketHandler extends SocketHandler {
|
||||||
let data = requestData as LooseObject;
|
let data = requestData as LooseObject;
|
||||||
let manager = socket.instanceManager;
|
let manager = socket.instanceManager;
|
||||||
await manager.test(data.url, data.username, data.password);
|
await manager.test(data.url, data.username, data.password);
|
||||||
await manager.add(data.url, data.username, data.password, data.friendlyname);
|
await manager.add(data.url, data.username, data.password, data.name);
|
||||||
|
|
||||||
// connect to the agent
|
// connect to the agent
|
||||||
manager.connect(data.url, data.username, data.password);
|
manager.connect(data.url, data.username, data.password);
|
||||||
|
@ -68,17 +68,13 @@ export class ManageAgentSocketHandler extends SocketHandler {
|
||||||
});
|
});
|
||||||
|
|
||||||
// updateAgent
|
// updateAgent
|
||||||
socket.on("updateAgent", async (friendlyname : string, updatedFriendlyName : string, callback : unknown) => {
|
socket.on("updateAgent", async (name : string, updatedName : string, callback : unknown) => {
|
||||||
try {
|
try {
|
||||||
log.debug("manage-agent-socket-handler", "updateAgent");
|
log.debug("manage-agent-socket-handler", "updateAgent");
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
|
|
||||||
if (typeof(updatedFriendlyName) !== "string") {
|
|
||||||
throw new Error("FriendlyName must be a string");
|
|
||||||
}
|
|
||||||
|
|
||||||
let manager = socket.instanceManager;
|
let manager = socket.instanceManager;
|
||||||
await manager.update(friendlyname, updatedFriendlyName);
|
await manager.update(name, updatedName);
|
||||||
|
|
||||||
server.disconnectAllSocketClients(undefined, socket.id);
|
server.disconnectAllSocketClients(undefined, socket.id);
|
||||||
manager.sendAgentList();
|
manager.sendAgentList();
|
||||||
|
|
|
@ -133,10 +133,10 @@ export default defineComponent({
|
||||||
endpointDisplayFunction(endpoint : string) {
|
endpointDisplayFunction(endpoint : string) {
|
||||||
for (const [k, v] of Object.entries(this.$data.agentList)) {
|
for (const [k, v] of Object.entries(this.$data.agentList)) {
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
if (endpoint === v["endpoint"] && v["friendlyname"] !== "") {
|
if (endpoint === v["endpoint"] && v["name"] !== "") {
|
||||||
return v["friendlyname"];
|
return v["name"];
|
||||||
}
|
}
|
||||||
if (endpoint === v["endpoint"] && v["friendlyname"] === "" ) {
|
if (endpoint === v["endpoint"] && v["name"] === "" ) {
|
||||||
return endpoint;
|
return endpoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
<label for="name" class="form-label">{{ $t("dockgeAgent") }}</label>
|
<label for="name" class="form-label">{{ $t("dockgeAgent") }}</label>
|
||||||
<select v-model="stack.endpoint" class="form-select">
|
<select v-model="stack.endpoint" class="form-select">
|
||||||
<option v-for="(agent, endpoint) in $root.agentList" :key="endpoint" :value="endpoint" :disabled="$root.agentStatusList[endpoint] != 'online'">
|
<option v-for="(agent, endpoint) in $root.agentList" :key="endpoint" :value="endpoint" :disabled="$root.agentStatusList[endpoint] != 'online'">
|
||||||
({{ $root.agentStatusList[endpoint] }}) {{ (agent.friendlyname !== '') ? agent.friendlyname : agent.url || $t("Controller") }}
|
({{ $root.agentStatusList[endpoint] }}) {{ (agent.name !== '') ? agent.name : agent.url || $t("Controller") }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -50,18 +50,18 @@
|
||||||
|
|
||||||
<!-- Agent Display Name -->
|
<!-- Agent Display Name -->
|
||||||
<template v-if="$root.agentStatusList[endpoint]">
|
<template v-if="$root.agentStatusList[endpoint]">
|
||||||
<span v-if="endpoint === '' && agent.friendlyname === ''" class="badge bg-secondary me-2">Controller</span>
|
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span>
|
||||||
<span v-else-if="agent.friendlyname === ''" :href="agent.url">{{ endpoint }}</span>
|
<span v-else-if="agent.name === ''" :href="agent.url">{{ endpoint }}</span>
|
||||||
<span v-else :href="agent.url">{{ agent.friendlyname }}</span>
|
<span v-else :href="agent.url">{{ agent.name }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<!-- Edit FriendlyName -->
|
<!-- Edit Name -->
|
||||||
<font-awesome-icon v-if="agent.friendlyname !== '' && agent.friendlyname !== ''" icon="pen-to-square" @click="showEditAgentFriendlynameDialog[agent.friendlyname] = !showEditAgentFriendlynameDialog[agent.friendlyname]" />
|
<font-awesome-icon icon="pen-to-square" @click="showEditAgentNameDialog[agent.name] = !showEditAgentNameDialog[agent.Name]" />
|
||||||
|
|
||||||
<!-- Edit Dialog -->
|
<!-- Edit Dialog -->
|
||||||
<BModal v-model="showEditAgentFriendlynameDialog[agent.friendlyname]" :no-close-on-backdrop="true" :close-on-esc="true" :okTitle="$t('Update Friendlyname')" okVariant="info" @ok="updateFriendlyname(agent.friendlyname, agent.updatedFriendlyName)">
|
<BModal v-model="showEditAgentNameDialog[agent.name]" :no-close-on-backdrop="true" :close-on-esc="true" :okTitle="$t('Update Name')" okVariant="info" @ok="updateName(agent.url, agent.updatedName)">
|
||||||
<label for="Update Friendlyname" class="form-label">Current value: {{ $t(agent.friendlyname) }}</label>
|
<label for="Update Name" class="form-label">Current value: {{ $t(agent.name) }}</label>
|
||||||
<input id="updatedFriendlyName" v-model="agent.updatedFriendlyName" type="text" class="form-control" optional>
|
<input id="updatedName" v-model="agent.updatedName" type="text" class="form-control" optional>
|
||||||
</BModal>
|
</BModal>
|
||||||
|
|
||||||
<!-- Remove Button -->
|
<!-- Remove Button -->
|
||||||
|
@ -94,8 +94,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="friendlyname" class="form-label">{{ $t("Friendly Name") }}</label>
|
<label for="name" class="form-label">{{ $t("Friendly Name") }}</label>
|
||||||
<input id="friendlyname" v-model="agent.friendlyname" type="text" class="form-control" optional>
|
<input id="name" v-model="agent.name" type="text" class="form-control" optional>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary" :disabled="connectingAgent">
|
<button type="submit" class="btn btn-primary" :disabled="connectingAgent">
|
||||||
|
@ -138,14 +138,14 @@ export default {
|
||||||
dockerRunCommand: "",
|
dockerRunCommand: "",
|
||||||
showAgentForm: false,
|
showAgentForm: false,
|
||||||
showRemoveAgentDialog: {},
|
showRemoveAgentDialog: {},
|
||||||
showEditAgentFriendlynameDialog: {},
|
showEditAgentNameDialog: {},
|
||||||
connectingAgent: false,
|
connectingAgent: false,
|
||||||
agent: {
|
agent: {
|
||||||
url: "http://",
|
url: "http://",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
friendlyname: "",
|
name: "",
|
||||||
updatedFriendlyName: "",
|
updatedName: "",
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -219,15 +219,14 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
updateFriendlyname(friendlyname, updatedFriendlyName) {
|
updateName(url, updatedName) {
|
||||||
//console.log(this.showEditAgentFriendlynameDialog.inputNewFriendlyName);
|
this.$root.getSocket().emit("updateAgent", url, updatedName, (res) => {
|
||||||
this.$root.getSocket().emit("updateAgent", friendlyname, updatedFriendlyName, (res) => {
|
|
||||||
this.$root.toastRes(res);
|
this.$root.toastRes(res);
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
this.showAgentForm = false;
|
this.showAgentForm = false;
|
||||||
this.agent = {
|
this.agent = {
|
||||||
updatedFriendlyName: "",
|
updatedName: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue