Skip to content

Commit 0ac7a6b

Browse files
SteKoeulischulte
andauthored
feat: allow to opt-in toast notifications (#2177)
* feat: allow to opt-in toast notifications * Extended docs with configuration of opt-in toast notifications Co-authored-by: ulrichschulte <[email protected]>
1 parent 702c951 commit 0ac7a6b

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

spring-boot-admin-docs/src/main/asciidoc/server.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ In addition when the reverse proxy terminates the https connection, it may be ne
135135
| Polling duration in ms to fetch new threads data.
136136
| `2500`
137137

138+
| spring.boot.admin.ui.enable-toasts
139+
| Allows to enable toast notifications.
140+
| `false`
141+
138142
|===
139143

140144
include::server-discovery.adoc[]

spring-boot-admin-server-ui/src/main/frontend/utils/axios.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,39 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import sbaConfig from '@/sba-config'
16+
import sbaConfig from '@/sba-config';
1717
import axios from 'axios';
1818
import Vue from 'vue';
1919

2020
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
2121
axios.defaults.xsrfHeaderName = sbaConfig.csrf.headerName;
2222

23-
export const redirectOn401 = (predicate = () => true) => error => {
23+
export const redirectOn401 = (predicate = () => true) => (error) => {
2424
if (error.response && error.response.status === 401 && predicate(error)) {
25-
window.location.assign(`login?redirectTo=${encodeURIComponent(window.location.href)}`);
25+
window.location.assign(
26+
`login?redirectTo=${encodeURIComponent(window.location.href)}`
27+
);
2628
}
2729
return Promise.reject(error);
2830
};
2931

30-
const instance = axios.create({withCredentials: true, headers: {'Accept': 'application/json'}});
31-
instance.interceptors.response.use(response => response, redirectOn401());
32+
const instance = axios.create({
33+
withCredentials: true,
34+
headers: { Accept: 'application/json' },
35+
});
36+
instance.interceptors.response.use((response) => response, redirectOn401());
3237
instance.create = axios.create;
3338

3439
export default instance;
3540

3641
export const registerErrorToastInterceptor = (axios) => {
37-
axios.interceptors.response.use(
38-
response => response,
39-
error => {
40-
let data = error.request;
41-
Vue.$toast.error(`Request failed: ${data.status} - ${data.statusText}`);
42-
}
43-
)
44-
}
42+
if (sbaConfig.uiSettings.enableToasts === true) {
43+
axios.interceptors.response.use(
44+
(response) => response,
45+
(error) => {
46+
let data = error.request;
47+
Vue.$toast.error(`Request failed: ${data.status} - ${data.statusText}`);
48+
}
49+
);
50+
}
51+
};

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public UiController homeUiController(UiExtensions uiExtensions) throws IOExcepti
9090

9191
Settings uiSettings = Settings.builder().brand(this.adminUi.getBrand()).title(this.adminUi.getTitle())
9292
.loginIcon(this.adminUi.getLoginIcon()).favicon(this.adminUi.getFavicon())
93-
.faviconDanger(this.adminUi.getFaviconDanger())
93+
.faviconDanger(this.adminUi.getFaviconDanger()).enableToasts(this.adminUi.getEnableToasts())
9494
.notificationFilterEnabled(
9595
!this.applicationContext.getBeansOfType(NotificationFilterController.class).isEmpty())
9696
.routes(routes).rememberMeEnabled(this.adminUi.isRememberMeEnabled())

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public class AdminServerUiProperties {
126126
*/
127127
private List<String> additionalRouteExcludes = new ArrayList<>();
128128

129+
/**
130+
* Allows to enable toast notifications in SBA.
131+
*/
132+
private Boolean enableToasts = false;
133+
129134
@lombok.Data
130135
public static class PollTimer {
131136

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/web/UiController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ public static class Settings {
139139

140140
private final List<ViewSettings> viewSettings;
141141

142+
private final Boolean enableToasts;
143+
142144
}
143145

144146
@lombok.Data

0 commit comments

Comments
 (0)