Skip to content

Commit bc94a55

Browse files
committed
prevent monitoring test if disabled
1 parent 4529648 commit bc94a55

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

src/ServicePulse.Host/vue/src/components/configuration/PlatformConnections.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ref } from "vue";
33
import LicenseExpired from "../LicenseExpired.vue";
44
import { licenseStatus } from "../../composables/serviceLicense.js";
5-
import { updateServiceControlUrls, serviceControlUrl as configuredServiceControlUrl, monitoringUrl as configuredMonitoringUrl } from "./../../composables/serviceServiceControlUrls.js";
5+
import { updateServiceControlUrls, serviceControlUrl as configuredServiceControlUrl, monitoringUrl as configuredMonitoringUrl, useIsMonitoringDisabled } from "./../../composables/serviceServiceControlUrls.js";
66
import { connectionState, monitoringConnectionState } from "../../composables/serviceServiceControl";
77
88
// This is needed because the ConfigurationView.vue routerView expects this event.
@@ -56,6 +56,10 @@ function testMonitoringUrl(event) {
5656
}
5757
}
5858
59+
function isMonitoringUrlSpecified() {
60+
return monitoringUrl.value && monitoringUrl.value !== "!";
61+
}
62+
5963
function saveConnections(event) {
6064
if (event) {
6165
updateServiceControlUrls(serviceControlUrl, monitoringUrl);
@@ -98,15 +102,15 @@ function saveConnections(event) {
98102
<label for="monitoringUrl"
99103
>CONNECTION URL
100104
<span class="auxilliary-label">(OPTIONAL)</span>
101-
<template v-if="monitoringConnectionState.unableToConnect">
105+
<template v-if="monitoringConnectionState.unableToConnect && !useIsMonitoringDisabled()">
102106
<span class="failed-validation"> <i class="fa fa-exclamation-triangle"></i> Unable to connect </span>
103107
</template>
104108
</label>
105109
<input type="text" id="monitoringUrl" name="monitoringUrl" v-model="monitoringUrl" class="form-control" required />
106110
</div>
107111

108112
<div class="col-5 no-side-padding">
109-
<button class="btn btn-default btn-secondary btn-connection-test" :class="{ disabled: !configuredMonitoringUrl }" type="button" @click="testMonitoringUrl">Test</button>
113+
<button class="btn btn-default btn-secondary btn-connection-test" :class="{ disabled: !isMonitoringUrlSpecified() }" type="button" @click="testMonitoringUrl" :disabled="!isMonitoringUrlSpecified()">Test</button>
110114
<span class="connection-test connection-testing" v-if="testingMonitoring"> <i class="glyphicon glyphicon-refresh rotate"></i>Testing </span>
111115
<span class="connection-test connection-successful" v-if="monitoringValid === true && !testingMonitoring"> <i class="fa fa-check"></i> Connection successful </span>
112116
<span class="connection-test connection-failed" v-if="monitoringValid === false && !testingMonitoring"> <i class="fa fa-exclamation-triangle"></i> Connection failed </span>

src/ServicePulse.Host/vue/src/composables/serviceServiceControl.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { reactive, onMounted, watch, computed } from "vue";
22
import { useIsSupported, useIsUpgradeAvailable } from "./serviceSemVer.js";
33
import { useServiceProductUrls } from "./serviceProductUrls.js";
4-
import { useFetchFromServiceControl, useFetchFromMonitoring, serviceControlUrl, monitoringUrl } from "./serviceServiceControlUrls";
4+
import { useFetchFromServiceControl, useFetchFromMonitoring, serviceControlUrl, monitoringUrl, useIsMonitoringDisabled } from "./serviceServiceControlUrls";
55
import { useShowToast } from "./toast.js";
66

77
export const stats = reactive({
@@ -101,16 +101,19 @@ export function useServiceControl() {
101101
}
102102
});
103103

104-
watch(monitoringConnectionFailure, async (newValue, oldValue) => {
105-
//NOTE to eliminate success msg showing everytime the screen is refreshed
106-
if (newValue != oldValue && !(oldValue === null && newValue === false)) {
107-
if (newValue) {
108-
useShowToast("error", "Error", "Could not connect to the ServiceControl Monitoring service at " + monitoringUrl.value + '. <a class="btn btn-default" href="/configuration#connections">View connection settings</a>');
109-
} else {
110-
useShowToast("success", "Success", "Connection to ServiceControl Monitoring service was successful at " + monitoringUrl.value + ".");
104+
// Only watch the state change if monitoring is enabled
105+
if (!useIsMonitoringDisabled()) {
106+
watch(monitoringConnectionFailure, async (newValue, oldValue) => {
107+
//NOTE to eliminate success msg showing everytime the screen is refreshed
108+
if (newValue != oldValue && !(oldValue === null && newValue === false)) {
109+
if (newValue) {
110+
useShowToast("error", "Error", "Could not connect to the ServiceControl Monitoring service at " + monitoringUrl.value + '. <a class="btn btn-default" href="/configuration#connections">View connection settings</a>');
111+
} else {
112+
useShowToast("success", "Success", "Connection to ServiceControl Monitoring service was successful at " + monitoringUrl.value + ".");
113+
}
111114
}
112-
}
113-
});
115+
});
116+
}
114117
}
115118

116119
export function useServiceControlStats() {

src/ServicePulse.Host/vue/src/composables/serviceServiceControlUrls.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import { ref } from "vue";
33
export const serviceControlUrl = ref(null);
44
export const monitoringUrl = ref(null);
55

6+
export function useIsMonitoringDisabled() {
7+
return monitoringUrl.value === null || monitoringUrl.value === "" || monitoringUrl.value === "!";
8+
}
9+
610
export function useFetchFromServiceControl(suffix) {
711
return fetch(serviceControlUrl.value + suffix);
812
}
913

1014
export function useFetchFromMonitoring(suffix) {
11-
if (monitoringUrl.value === null || monitoringUrl.value === "" || monitoringUrl.value === "!") {
15+
if (useIsMonitoringDisabled()) {
1216
return Promise.resolve(null);
1317
}
1418
return fetch(monitoringUrl.value + suffix);
@@ -99,7 +103,7 @@ export function updateServiceControlUrls(newServiceControlUrl, newMonitoringUrl)
99103

100104
if (!newMonitoringUrl.value) {
101105
newMonitoringUrl.value = "!"; //disabled
102-
} else if (!newMonitoringUrl.value.endsWith("/")) {
106+
} else if (!newMonitoringUrl.value.endsWith("/") && newMonitoringUrl.value !== "!") {
103107
newMonitoringUrl.value += "/";
104108
}
105109

0 commit comments

Comments
 (0)