Skip to content

Commit

Permalink
Merge 8c1cbe9 into 40eeb16
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Aug 16, 2020
2 parents 40eeb16 + 8c1cbe9 commit 7855e89
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 4 deletions.
9 changes: 9 additions & 0 deletions spring-boot-admin-docs/src/main/asciidoc/customizing.adoc
Expand Up @@ -145,3 +145,12 @@ It is possible to use a custom favicon, which is also used for desktop notificat
To filter languages to a subset of all supported languages:

- **spring.boot.admin.ui.available-languages**: Used as a filter of existing languages. (e.g `en,de` out of existing `de,en,fr,ko,pt-BR,ru,zh`)

=== Showing / Hiding views ===

You can very simply hide views in the navbar:

[source,yaml,indent=0]
----
include::{samples-dir}/spring-boot-admin-sample-servlet/src/main/resources/application.yml[tags=customization-view-settings]
----
Expand Up @@ -63,6 +63,18 @@ spring:
cache-templates: false
extension-resource-locations: file:@project.basedir@/../spring-boot-admin-sample-custom-ui/target/dist/

---

# tag::customization-view-settings[]
spring:
boot:
admin:
ui:
view-settings:
- name: "journal"
enabled: false
# end::customization-view-settings[]

---
spring:
profiles: insecure
Expand Down
3 changes: 2 additions & 1 deletion spring-boot-admin-server-ui/src/main/frontend/sba-config.js
Expand Up @@ -25,7 +25,8 @@ const DEFAULT_CONFIG = {
faviconDanger: 'assets/img/favicon-danger.png',
notificationFilterEnabled: false,
routes: [],
availableLanguages: []
availableLanguages: [],
viewSettings: []
},
user: null,
extensions: [],
Expand Down
12 changes: 12 additions & 0 deletions spring-boot-admin-server-ui/src/main/frontend/viewRegistry.js
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import sbaConfig from '@/sba-config'
import {VIEW_GROUP} from './views';

import remove from 'lodash/remove';
Expand Down Expand Up @@ -43,6 +44,10 @@ export default class ViewRegistry {
]
}

getViewByName(name) {
return this._views.find(v => v.name === name);
}

addView(...views) {
views.forEach(view => this._addView(view));
}
Expand All @@ -62,6 +67,13 @@ export default class ViewRegistry {
if (!view.group) {
view.group = VIEW_GROUP.NONE;
}

if (!view.isEnabled) {
view.isEnabled = () => {
let viewSettings = sbaConfig.uiSettings.viewSettings.find(vs => vs.name === view.name);
return (!viewSettings || viewSettings.enabled === true);
}
}
this._removeExistingView(view);
this._views.push(view);
}
Expand Down
30 changes: 28 additions & 2 deletions spring-boot-admin-server-ui/src/main/frontend/viewRegistry.spec.js
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import ViewRegistry from "./viewRegistry";
import sbaConfig from '@/sba-config'
import ViewRegistry from './viewRegistry';

describe('viewRegistry', () => {
describe('given view already in the registry', function () {
Expand All @@ -33,4 +33,30 @@ describe('viewRegistry', () => {
});

});

it('hide or show views depending on their settings', () => {
sbaConfig.uiSettings.viewSettings = [
{name: 'disabledView', enabled: false},
{name: 'explicitlyEnabledView', enabled: true}
];

const viewRegistry = new ViewRegistry();
viewRegistry.addView(...[
{name: 'disabledView', group: 'group'},
{name: 'explicitlyEnabledView', group: 'group'},
{name: 'implicitlyEnabledView', group: 'group'}
])

let disabledView = viewRegistry.getViewByName('disabledView');
expect(disabledView).toBeDefined();
expect(disabledView.isEnabled()).toBeFalsy();

let implicitlyEnabledView = viewRegistry.getViewByName('implicitlyEnabledView');
expect(implicitlyEnabledView).toBeDefined();
expect(implicitlyEnabledView.isEnabled()).toBeTruthy();

let explicitlyEnabledView = viewRegistry.getViewByName('explicitlyEnabledView');
expect(explicitlyEnabledView).toBeDefined();
expect(explicitlyEnabledView.isEnabled()).toBeTruthy();
});
});
Expand Up @@ -91,7 +91,7 @@ public UiController homeUiController(UiExtensions uiExtensions) throws IOExcepti
!this.applicationContext.getBeansOfType(NotificationFilterController.class).isEmpty())
.routes(routes).rememberMeEnabled(this.adminUi.isRememberMeEnabled())
.availableLanguages(this.adminUi.getAvailableLanguages()).externalViews(this.adminUi.getExternalViews())
.build();
.viewSettings(this.adminUi.getViewSettings()).build();

String publicUrl = (this.adminUi.getPublicUrl() != null) ? this.adminUi.getPublicUrl()
: this.adminServer.getContextPath();
Expand Down
Expand Up @@ -102,6 +102,11 @@ public class AdminServerUiProperties {
*/
private List<UiController.ExternalView> externalViews = new ArrayList<>();

/**
* External views shown in the navbar.
*/
private List<UiController.ViewSettings> viewSettings = new ArrayList<>();

/**
* Whether the option to remember a user should be available.
*/
Expand Down
Expand Up @@ -134,6 +134,8 @@ public static class Settings {

private final List<ExternalView> externalViews;

private final List<ViewSettings> viewSettings;

}

@lombok.Data
Expand Down Expand Up @@ -172,4 +174,27 @@ public ExternalView(String label, String url, Integer order, boolean iframe) {

}

@lombok.Data
@JsonInclude(Include.NON_EMPTY)
@ConstructorBinding
public static class ViewSettings {

/**
* Name of the view to address.
*/
private final String name;

/**
* Set view enabled.
*/
private boolean enabled = true;

public ViewSettings(String name, boolean enabled) {
Assert.hasText(name, "'name' must not be empty");
this.name = name;
this.enabled = enabled;
}

}

}

0 comments on commit 7855e89

Please sign in to comment.