DRAFT: feat(friendlyName): make friendlyname configurable

allow updates and removal of `friendly name`
This commit is contained in:
stroskler 2024-02-01 18:54:52 +00:00
parent 11f5fff65d
commit 54e158f75a
No known key found for this signature in database
GPG key ID: BFC1D7C45DD50847
5 changed files with 81 additions and 3 deletions

View file

@ -77,6 +77,7 @@ export class AgentManager {
* @param username * @param username
* @param password * @param password
* @param friendlyname * @param friendlyname
* @param updatedFriendlyName
*/ */
async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> { async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> {
let bean = R.dispense("agent") as 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) { connect(url : string, username : string, password : string) {
let obj = new URL(url); let obj = new URL(url);
let endpoint = obj.host; let endpoint = obj.host;
@ -279,6 +298,7 @@ export class AgentManager {
username: "", username: "",
endpoint: "", endpoint: "",
friendlyname: "", friendlyname: "",
updatedFriendlyName: "",
}; };
for (let endpoint in list) { for (let endpoint in list) {

View file

@ -23,7 +23,8 @@ export class Agent extends BeanModel {
url: this.url, url: this.url,
username: this.username, username: this.username,
endpoint: this.endpoint, endpoint: this.endpoint,
friendlyname: this.friendlyname friendlyname: this.friendlyname,
updatedFriendlyName: this.updatedFriendlyName
}; };
} }

View file

@ -66,5 +66,31 @@ export class ManageAgentSocketHandler extends SocketHandler {
callbackError(e, callback); 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);
}
});
} }
} }

View file

@ -11,8 +11,11 @@ declare module 'vue' {
Appearance: typeof import('./src/components/settings/Appearance.vue')['default'] Appearance: typeof import('./src/components/settings/Appearance.vue')['default']
ArrayInput: typeof import('./src/components/ArrayInput.vue')['default'] ArrayInput: typeof import('./src/components/ArrayInput.vue')['default']
ArraySelect: typeof import('./src/components/ArraySelect.vue')['default'] ArraySelect: typeof import('./src/components/ArraySelect.vue')['default']
BButton: typeof import('bootstrap-vue-next')['BButton']
BDropdown: typeof import('bootstrap-vue-next')['BDropdown'] BDropdown: typeof import('bootstrap-vue-next')['BDropdown']
BDropdownItem: typeof import('bootstrap-vue-next')['BDropdownItem'] 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'] BModal: typeof import('bootstrap-vue-next')['BModal']
Confirm: typeof import('./src/components/Confirm.vue')['default'] Confirm: typeof import('./src/components/Confirm.vue')['default']
Container: typeof import('./src/components/Container.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'] TwoFADialog: typeof import('./src/components/TwoFADialog.vue')['default']
Uptime: typeof import('./src/components/Uptime.vue')['default'] Uptime: typeof import('./src/components/Uptime.vue')['default']
} }
export interface ComponentCustomProperties {
vBModal: typeof import('bootstrap-vue-next')['vBModal']
}
} }

View file

@ -55,10 +55,19 @@
<span v-else :href="agent.url">{{ agent.friendlyname }}</span> <span v-else :href="agent.url">{{ agent.friendlyname }}</span>
</template> </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 --> <!-- Remove Button -->
<font-awesome-icon v-if="endpoint !== ''" class="ms-2 remove-agent" icon="trash" @click="showRemoveAgentDialog[agent.url] = !showRemoveAgentDialog[agent.url]" /> <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)"> <BModal v-model="showRemoveAgentDialog[agent.url]" :okTitle="$t('removeAgent')" okVariant="danger" @ok="removeAgent(agent.url)">
<p>{{ agent.url }}</p> <p>{{ agent.url }}</p>
{{ $t("removeAgentMsg") }} {{ $t("removeAgentMsg") }}
@ -129,12 +138,14 @@ export default {
dockerRunCommand: "", dockerRunCommand: "",
showAgentForm: false, showAgentForm: false,
showRemoveAgentDialog: {}, showRemoveAgentDialog: {},
showEditAgentFriendlynameDialog: {},
connectingAgent: false, connectingAgent: false,
agent: { agent: {
url: "http://", url: "http://",
username: "", username: "",
password: "", password: "",
friendlyname: "", 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) { getStatusNum(statusName) {
let num = 0; let num = 0;
@ -295,7 +320,7 @@ export default {
} }
}, },
}, }
}; };
</script> </script>