Added #1206. Friendly name is no longer required

When adding or updating a monitor, if a friendly name is not specified,
the URL or hostname will be used instead. Note: the hostname has
priority over the URL so if both are set (possible in instances where
monitor type has been changed), the friendly name will be set to the
hostname.

Signed-off-by: Computroniks <mnickson@sidingsmedia.com>
This commit is contained in:
Computroniks 2022-01-29 18:38:21 +00:00
parent 9827e709d2
commit e049a0c98e
No known key found for this signature in database
GPG Key ID: AB524D88499439A1
1 changed files with 34 additions and 2 deletions

View File

@ -38,7 +38,7 @@
<!-- Friendly Name -->
<div class="my-3">
<label for="name" class="form-label">{{ $t("Friendly Name") }}</label>
<input id="name" v-model="monitor.name" type="text" class="form-control" required>
<input id="name" v-model="monitor.name" type="text" class="form-control" :required="friendlyNameRequired()">
</div>
<!-- URL -->
@ -317,6 +317,7 @@ export default {
},
acceptedStatusCodeOptions: [],
dnsresolvetypeOptions: [],
friendlyNameRequiredOptions: [],
// Source: https://digitalfortress.tech/tips/top-15-commonly-used-regex/
ipRegexPattern: "((^\\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\\s*$)|(^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$))",
@ -413,12 +414,17 @@ export default {
"TXT",
];
let friendlyNameRequiredOptions = [
"push",
];
for (let i = 100; i <= 999; i++) {
acceptedStatusCodeOptions.push(i.toString());
}
this.acceptedStatusCodeOptions = acceptedStatusCodeOptions;
this.dnsresolvetypeOptions = dnsresolvetypeOptions;
this.friendlyNameRequiredOptions = friendlyNameRequiredOptions;
},
methods: {
init() {
@ -450,7 +456,10 @@ export default {
this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => {
if (res.ok) {
this.monitor = res.monitor;
// Handling for when friendly name isn't set
if (this.monitor.name === this.monitor.url || this.monitor.name === this.monitor.hostname) {
this.monitor.name = "";
}
// Handling for monitors that are created before 1.7.0
if (this.monitor.retryInterval === 0) {
this.monitor.retryInterval = this.monitor.interval;
@ -486,6 +495,16 @@ export default {
async submit() {
this.processing = true;
// Check if friendly name has been supplied. If not, use URL
// or hostname
if (this.monitor.name === "") {
if (this.monitor.hostname === null || this.monitor.hostname === "") {
this.monitor.name = this.monitor.url;
} else {
this.monitor.name = this.monitor.hostname;
}
}
if (!this.isInputValid()) {
this.processing = false;
return;
@ -532,6 +551,19 @@ export default {
addedNotification(id) {
this.monitor.notificationIDList[id] = true;
},
/**
* Is the friendly name required for the selected option.
* Returns true if it is else null
* @returns {null|true}
*/
friendlyNameRequired() {
if (this.friendlyNameRequiredOptions.includes(this.monitor.type)) {
return true;
} else {
return null;
}
}
},
};
</script>