mirror of
https://github.com/louislam/dockge.git
synced 2025-02-22 11:35:56 +00:00
DRAFT: feat(friendlyName): make friendlyname configurable
allow updates and removal of `friendly name`
This commit is contained in:
parent
11f5fff65d
commit
54e158f75a
5 changed files with 81 additions and 3 deletions
|
@ -77,6 +77,7 @@ export class AgentManager {
|
|||
* @param username
|
||||
* @param password
|
||||
* @param friendlyname
|
||||
* @param updatedFriendlyName
|
||||
*/
|
||||
async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> {
|
||||
let bean = R.dispense("agent") as Agent;
|
||||
|
@ -106,6 +107,24 @@ export class AgentManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param friendlyname
|
||||
* @param updatedFriendlyName
|
||||
*/
|
||||
|
||||
async update(friendlyname : string, updatedFriendlyName : string) {
|
||||
let bean = await R.findOne("agent", " friendlyname = ? ", [
|
||||
friendlyname,
|
||||
]);
|
||||
|
||||
if (bean) {
|
||||
bean.friendlyname = updatedFriendlyName;
|
||||
} else {
|
||||
throw new Error("Friendly name could not be updated ");
|
||||
}
|
||||
}
|
||||
|
||||
connect(url : string, username : string, password : string) {
|
||||
let obj = new URL(url);
|
||||
let endpoint = obj.host;
|
||||
|
@ -279,6 +298,7 @@ export class AgentManager {
|
|||
username: "",
|
||||
endpoint: "",
|
||||
friendlyname: "",
|
||||
updatedFriendlyName: "",
|
||||
};
|
||||
|
||||
for (let endpoint in list) {
|
||||
|
|
|
@ -23,7 +23,8 @@ export class Agent extends BeanModel {
|
|||
url: this.url,
|
||||
username: this.username,
|
||||
endpoint: this.endpoint,
|
||||
friendlyname: this.friendlyname
|
||||
friendlyname: this.friendlyname,
|
||||
updatedFriendlyName: this.updatedFriendlyName
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -66,5 +66,31 @@ export class ManageAgentSocketHandler extends SocketHandler {
|
|||
callbackError(e, callback);
|
||||
}
|
||||
});
|
||||
|
||||
// updateAgent
|
||||
socket.on("updateAgent", async (friendlyname : unknown, updatedFriendlyName : unknown, callback : unknown) => {
|
||||
try {
|
||||
log.debug("manage-agent-socket-handler", "updateAgent");
|
||||
checkLogin(socket);
|
||||
|
||||
if (typeof(updatedFriendlyName) !== "string") {
|
||||
throw new Error("FriendlyName must be a string");
|
||||
}
|
||||
|
||||
let manager = socket.instanceManager;
|
||||
await manager.update(friendlyname, updatedFriendlyName);
|
||||
|
||||
server.disconnectAllSocketClients(undefined, socket.id);
|
||||
manager.sendAgentList();
|
||||
|
||||
callbackResult({
|
||||
ok: true,
|
||||
msg: "agentUpdatedSuccessfully",
|
||||
msgi18n: true,
|
||||
}, callback);
|
||||
} catch (e) {
|
||||
callbackError(e, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
6
frontend/components.d.ts
vendored
6
frontend/components.d.ts
vendored
|
@ -11,8 +11,11 @@ declare module 'vue' {
|
|||
Appearance: typeof import('./src/components/settings/Appearance.vue')['default']
|
||||
ArrayInput: typeof import('./src/components/ArrayInput.vue')['default']
|
||||
ArraySelect: typeof import('./src/components/ArraySelect.vue')['default']
|
||||
BButton: typeof import('bootstrap-vue-next')['BButton']
|
||||
BDropdown: typeof import('bootstrap-vue-next')['BDropdown']
|
||||
BDropdownItem: typeof import('bootstrap-vue-next')['BDropdownItem']
|
||||
BFormGroup: typeof import('bootstrap-vue-next')['BFormGroup']
|
||||
BFormInput: typeof import('bootstrap-vue-next')['BFormInput']
|
||||
BModal: typeof import('bootstrap-vue-next')['BModal']
|
||||
Confirm: typeof import('./src/components/Confirm.vue')['default']
|
||||
Container: typeof import('./src/components/Container.vue')['default']
|
||||
|
@ -29,4 +32,7 @@ declare module 'vue' {
|
|||
TwoFADialog: typeof import('./src/components/TwoFADialog.vue')['default']
|
||||
Uptime: typeof import('./src/components/Uptime.vue')['default']
|
||||
}
|
||||
export interface ComponentCustomProperties {
|
||||
vBModal: typeof import('bootstrap-vue-next')['vBModal']
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,19 @@
|
|||
<span v-else :href="agent.url">{{ agent.friendlyname }}</span>
|
||||
</template>
|
||||
|
||||
<!-- Edit FriendlyName -->
|
||||
<font-awesome-icon class="ms-2" icon="pen-to-square" @click="showEditAgentFriendlynameDialog[agent.friendlyname] = !showEditAgentFriendlynameDialog[agent.friendlyname]" />
|
||||
|
||||
<!-- 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)">
|
||||
<label for="Update Friendlyname" class="form-label">Current value: {{ $t(agent.friendlyname) }}</label>
|
||||
<input id="updatedFriendlyName" v-model="agent.updatedFriendlyName" type="text" class="form-control" optional>
|
||||
</BModal>
|
||||
|
||||
<!-- Remove Button -->
|
||||
<font-awesome-icon v-if="endpoint !== ''" class="ms-2 remove-agent" icon="trash" @click="showRemoveAgentDialog[agent.url] = !showRemoveAgentDialog[agent.url]" />
|
||||
|
||||
<!-- Remoe Agent Dialog -->
|
||||
<!-- Remove Agent Dialog -->
|
||||
<BModal v-model="showRemoveAgentDialog[agent.url]" :okTitle="$t('removeAgent')" okVariant="danger" @ok="removeAgent(agent.url)">
|
||||
<p>{{ agent.url }}</p>
|
||||
{{ $t("removeAgentMsg") }}
|
||||
|
@ -129,12 +138,14 @@ export default {
|
|||
dockerRunCommand: "",
|
||||
showAgentForm: false,
|
||||
showRemoveAgentDialog: {},
|
||||
showEditAgentFriendlynameDialog: {},
|
||||
connectingAgent: false,
|
||||
agent: {
|
||||
url: "http://",
|
||||
username: "",
|
||||
password: "",
|
||||
friendlyname: "",
|
||||
updatedFriendlyName: "",
|
||||
}
|
||||
};
|
||||
},
|
||||
|
@ -208,6 +219,20 @@ export default {
|
|||
});
|
||||
},
|
||||
|
||||
updateFriendlyname(friendlyname, updatedFriendlyName) {
|
||||
//console.log(this.showEditAgentFriendlynameDialog.inputNewFriendlyName);
|
||||
this.$root.getSocket().emit("updateAgent", friendlyname, updatedFriendlyName, (res) => {
|
||||
this.$root.toastRes(res);
|
||||
|
||||
if (res.ok) {
|
||||
this.showAgentForm = false;
|
||||
this.agent = {
|
||||
updatedFriendlyName: "",
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getStatusNum(statusName) {
|
||||
let num = 0;
|
||||
|
||||
|
@ -295,7 +320,7 @@ export default {
|
|||
}
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue