-
-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: dockge set/update agent friendly name #414
base: master
Are you sure you want to change the base?
feat: dockge set/update agent friendly name #414
Conversation
Add the option to set a friendly name to a dockge remote agent. If the field is not used the `agent.url` will be displayed
Hey @cyril59310, thanks for your feedback. The translation can be added - for sure. Currently trying to refactor the code a bit to enable renaming - which seems more difficult as expected .. |
In the file
please add |
adding `Friendly Name` to en.json
allow updates and removal of `friendly name`
@cyril59310 point 2 of your request is now also done. Only need to update codebase and remove all debug options |
6529f6d
to
96b5205
Compare
adding the `friendlyname` option to the running and paused container
96b5205
to
8f142af
Compare
when create a new stack via UI the friendly name should also be displayed
Thanks again @cyril59310 . This is now also implemented |
Merge branch 'feat/dockge-agents-friendly-name' into feat/dockge-agents-friendly-name-editable
add a query to update the friendlyname correctly
remove edit-pen for controller which cannot have a friendlyname for now
Finally I was able to get the @larswmh maybe need help this time with syntaxing/linting issues for sqlite statement. Or even a better solution than a "hardcoded" query |
fix linting issues
fix tsc check by updating var type
remove if condition and update to proper values to prevent duplicates
1e688f8
to
dcc48d3
Compare
I made some suggestions in order to add translation keys for our translators. |
@@ -7,6 +7,7 @@ export async function up(knex: Knex): Promise<void> { | |||
table.string("url", 255).notNullable().unique(); | |||
table.string("username", 255).notNullable(); | |||
table.string("password", 255).notNullable(); | |||
table.string("friendlyname", 255); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file cannot be modified. Have to create a new file.
Migration guide:
https://github.com/louislam/uptime-kuma/tree/master/db/knex_migrations
Also the naming convention, it should be friendly_name
.
Will come back later, as I would like to finish the next milestone of Uptime Kuma first.
backend/agent-manager.ts
Outdated
*/ | ||
async add(url : string, username : string, password : string) : Promise<Agent> { | ||
async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name Conventions
- Javascript/Typescript: camelCaseType
- SQLite: snake_case (Underscore)
- CSS/SCSS: kebab-case (Dash)
https://github.com/louislam/dockge/blob/master/CONTRIBUTING.md#name-conventions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all namings has been updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature!
Have some code feedback
backend/agent-manager.ts
Outdated
*/ | ||
|
||
async update(friendlyname : string, updatedFriendlyName : string) { | ||
await R.exec("UPDATE agent SET friendlyname = " + updatedFriendlyName + " WHERE friendlyname = " + friendlyname + ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SQL injection vuln here - if name has quotes this will break.
You can use parameter bindings to build queries safely:
await R.exec("UPDATE agent SET friendlyname = ? WHERE friendlyname = ?", [
updatedFriendlyName,
friendlyname
]);
https://github.com/louislam/redbean-node/blob/master/docs/Query.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a raw query, you could utilize the redbean ORM methods. See: https://github.com/louislam/redbean-node/blob/master/docs/Create-Update-Bean.md
Something like this if by ID (primary key):
const agent = await R.load('agent', id);
agent.friendlyName = friendlyName;
await R.store(agent);
Or by URL:
const agent = await R.findOne('agent', ' url = ? ', [url]);
agent.friendlyName = friendlyName;
await R.store(agent);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the input. Added this with update by url
and started a small "discussion"
#414 (comment)
backend/agent-manager.ts
Outdated
* @param updatedFriendlyName | ||
*/ | ||
|
||
async update(friendlyname : string, updatedFriendlyName : string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider accepting the agent's id
or the url
here for identifying the agent to update instead of friendly name.
ID is the primary key, so thats probably best to use for updating the agent. But URL is always set and has a unique constraint, so it will work too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with nathan, I would refactor to pass id around for the agent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure it should be the id
? it is currently not passed in the agentList and needs to be added. If a host will be added and deleted it will still increase and not release a taken number. The url
would be the "better" identifier ?
( just a small comment. I am not against refactoring this to id
but while updating this MR I was thinking about)
backend/models/agent.ts
Outdated
friendlyname: this.friendlyname, | ||
updatedFriendlyName: this.updatedFriendlyName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is updatedFriendlyName
also here on the model? Shouldn't just friendlyName
be sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to update this file while adding the other suggestions but it still worked with the correct variables. Where is this needed 🤔
Long time no see. Will have a look the next days on all your feedback. Many thanks 🙏🏻 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate this addition. Short of hacking the docker swarm mechanics to do node auto-discovery, I think is a fairly nice quality of life improvement.
Left some comments on some changes I'd make to make this prod-ready.
backend/agent-manager.ts
Outdated
* @param updatedFriendlyName | ||
*/ | ||
|
||
async update(friendlyname : string, updatedFriendlyName : string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with nathan, I would refactor to pass id around for the agent
backend/models/agent.ts
Outdated
@@ -23,6 +23,8 @@ export class Agent extends BeanModel { | |||
url: this.url, | |||
username: this.username, | |||
endpoint: this.endpoint, | |||
friendlyname: this.friendlyname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recommendation: you should consider just naming this field name
. There are no conflicts using the simpler version of the field name.
if (typeof(updatedFriendlyName) !== "string") { | ||
throw new Error("FriendlyName must be a string"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the more you know: since this is typescript, you shouldn't actually need to typecheck the input value for friendly name. We already know it's a string from before.
frontend/src/pages/DashboardHome.vue
Outdated
</template> | ||
|
||
<!-- Edit FriendlyName --> | ||
<font-awesome-icon v-if="agent.friendlyname !== '' && agent.friendlyname !== ''" icon="pen-to-square" @click="showEditAgentFriendlynameDialog[agent.friendlyname] = !showEditAgentFriendlynameDialog[agent.friendlyname]" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: I'm not sure why you're checking for blank string twice here, but if you switch to passing around agent.id
you will be able to edit a name no matter if the server was created with friendly name or not, so the v-if will be unnecessary.
frontend/src/pages/DashboardHome.vue
Outdated
<!-- 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: similar to nathan's comments up above, if you are finding agents by their ID, you can just set agent.name
here and use that to update the value. You also then don't have to show Current value:
in the label, because the input will have the current value. You may want to show agent.url
as part of the label, though, in case input name is blank.
frontend/src/pages/DashboardHome.vue
Outdated
<template v-if="$root.agentStatusList[endpoint]"> | ||
<span v-if="endpoint === '' && agent.friendlyname === ''" class="badge bg-secondary me-2">Controller</span> | ||
<span v-else-if="agent.friendlyname === ''" :href="agent.url">{{ endpoint }}</span> | ||
<span v-else :href="agent.url">{{ agent.friendlyname }}</span> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of suggestions here:
- We can use the fact that an empty string is falsy to shorten this chain.
- You probably don't want to be modifying things so drastically. If it's working, then a small change will do.
<template v-if="$root.agentStatusList[endpoint]"> | |
<span v-if="endpoint === '' && agent.friendlyname === ''" class="badge bg-secondary me-2">Controller</span> | |
<span v-else-if="agent.friendlyname === ''" :href="agent.url">{{ endpoint }}</span> | |
<span v-else :href="agent.url">{{ agent.friendlyname }}</span> | |
</template> | |
<span v-if="endpoint === ''" class="badge bg-secondary me-2">{{ $t("currentEndpoint") }}</span> | |
<a v-else :href="agent.url" target="_blank">{{ agent.name || endpoint }}</a> |
would love for this to be added! |
updating the merge request by adding the suggestions from reviewer
update agent.ts file by renaming the variables and added suggestion
Ready & happy about a second review :) && could need help with that one failing CI pipeline |
updated variables in language file
frontend/src/pages/DashboardHome.vue
Outdated
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span> | ||
<span v-else-if="agent.name === ''" :href="agent.url">{{ endpoint }}</span> | ||
<span v-else :href="agent.url">{{ agent.name }}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span> | |
<span v-else-if="agent.name === ''" :href="agent.url">{{ endpoint }}</span> | |
<span v-else :href="agent.url">{{ agent.name }}</span> | |
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span> | |
<span v-else-if="agent.name === ''" :href="agent.url" class="me-2">{{ endpoint }}</span> | |
<span v-else :href="agent.url" class="me-2">{{ agent.name }}</span> |
Add spacing from controller badge to edit icon for agent url and agent name display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. Updated in latest commit
backend/agent-manager.ts
Outdated
@@ -76,12 +76,15 @@ export class AgentManager { | |||
* @param url | |||
* @param username | |||
* @param password | |||
* @param name | |||
* @param updatedName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param updatedName |
Parameter updatedName is not used in this function, can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. Updated in latest commit
on which tag do i need to be to have this feature? |
It is planned to be included in the next release v1.5.0 . To use this feature you need to be on my branch and build the image on your own |
implement suggestions from review
add missing comma in en.json
https://github.com/louislam/dockge/blob/master/CONTRIBUTING.md
Tick the checkbox if you understand [x]:
Disclaimer
I am not a Software programmer and only have basic understandings on any Programming Languages used in the project, so please be patient and maybe assist me with further development of this feature
Description
Since
dockge agents
is still a beta feature and in the future maybe more and more remote instances will be added I wanted to enable the option for setting a friendly name for a remote instance. If the name is not set via the prompt. The defaultagent.url
will be displayedFixes #345
Type of change
New feature (non-breaking change which adds functionality)
My code follows the style guidelines of this project
I ran ESLint and other linters for modified files
I have performed a self-review of my own code and tested it
I have commented my code, particularly in hard-to-understand areas
(including JSDoc for methods)
My changes generate no new warnings
My code needed automated testing. I have added them (this is optional task)
Screenshots