mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-05-24 23:52:35 +02:00
feat: Set default friendly name using hostname or the URL host
- Default name based on hostname/URL host if available - Fallback default is 'My monitor'
This commit is contained in:
parent
999132aca8
commit
5a8e194b94
1 changed files with 23 additions and 1 deletions
|
@ -109,7 +109,7 @@
|
||||||
<!-- Friendly Name -->
|
<!-- Friendly Name -->
|
||||||
<div class="my-3">
|
<div class="my-3">
|
||||||
<label for="name" class="form-label">{{ $t("Friendly Name") }}</label>
|
<label for="name" class="form-label">{{ $t("Friendly Name") }}</label>
|
||||||
<input id="name" v-model="monitor.name" type="text" class="form-control" required data-testid="friendly-name-input">
|
<input id="name" v-model="monitor.name" type="text" class="form-control" data-testid="friendly-name-input" :placeholder="defaultFriendlyName">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- URL -->
|
<!-- URL -->
|
||||||
|
@ -1157,6 +1157,23 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
defaultFriendlyName() {
|
||||||
|
if (this.monitor.hostname) {
|
||||||
|
return this.monitor.hostname;
|
||||||
|
}
|
||||||
|
if (this.monitor.url) {
|
||||||
|
try {
|
||||||
|
const url = new URL(this.monitor.url);
|
||||||
|
return url.hostname;
|
||||||
|
} catch (e) {
|
||||||
|
// Handle invalid URL, maybe return a generic placeholder or empty string
|
||||||
|
return this.$t("My Monitor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Default placeholder if neither hostname nor URL is available
|
||||||
|
return this.$t("My Monitor");
|
||||||
|
},
|
||||||
|
|
||||||
ipRegex() {
|
ipRegex() {
|
||||||
|
|
||||||
// Allow to test with simple dns server with port (127.0.0.1:5300)
|
// Allow to test with simple dns server with port (127.0.0.1:5300)
|
||||||
|
@ -1700,6 +1717,11 @@ message HealthCheckResponse {
|
||||||
|
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
|
|
||||||
|
// Use defaultFriendlyName if Friendly Name is empty
|
||||||
|
if (!this.monitor.name) {
|
||||||
|
this.monitor.name = this.defaultFriendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.isInputValid()) {
|
if (!this.isInputValid()) {
|
||||||
this.processing = false;
|
this.processing = false;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue