Search in sources :

Example 1 with Settings

use of org.jboss.hal.config.Settings in project console by hal.

the class HeaderView method updateRoles.

@Override
public void updateRoles(Environment environment, Settings settings, User user) {
    for (Iterator<HTMLElement> iterator = Elements.iterator(userDropdown); iterator.hasNext(); ) {
        HTMLElement element = iterator.next();
        if (element == logoutItem) {
            continue;
        }
        iterator.remove();
    }
    if (!user.getRoles().isEmpty()) {
        String csr = user.getRoles().stream().sorted(Roles.STANDARD_FIRST.thenComparing(Roles.BY_NAME)).map(Role::getName).collect(joining(", "));
        HTMLElement activeRoles = li().css(static_, CSS.activeRoles).textContent(resources.messages().activeRoles(csr)).title(resources.messages().activeRoles(csr)).element();
        userDropdown.insertBefore(activeRoles, logoutItem);
        userDropdown.insertBefore(divider(), logoutItem);
        if (user.isSuperuser() && environment.getAccessControlProvider() == RBAC) {
            Set<String> runAsRoleSetting = settings.get(RUN_AS).asSet();
            HTMLElement runAs = li().css(static_).textContent(resources.constants().runAs()).element();
            userDropdown.insertBefore(runAs, logoutItem);
            stream(environment.getRoles().spliterator(), false).sorted(Roles.STANDARD_FIRST.thenComparing(Roles.BY_NAME)).forEach(role -> {
                HTMLElement check, name;
                HTMLElement runAsRole = li().add(a().css(clickable).on(click, event -> presenter.runAs(role.getName())).add(check = span().css(fontAwesome("check"), marginRight5).element()).add(name = span().textContent(role.getName()).element())).element();
                if (!runAsRoleSetting.contains(role.getName())) {
                    // NON-NLS
                    check.style.visibility = "hidden";
                }
                if (role.isScoped()) {
                    name.title = role.getBaseRole().getName() + " / " + String.join(", ", role.getScope());
                }
                userDropdown.insertBefore(runAsRole, logoutItem);
            });
            if (runAsRoleSetting != null) {
                HTMLElement clearRunAs = li().add(a().css(clickable).on(click, event -> presenter.clearRunAs()).textContent(resources.constants().clearRunAs())).element();
                userDropdown.insertBefore(clearRunAs, logoutItem);
            }
            userDropdown.insertBefore(divider(), logoutItem);
        }
    }
}
Also used : Environment(org.jboss.hal.config.Environment) Endpoints(org.jboss.hal.config.Endpoints) LoggerFactory(org.slf4j.LoggerFactory) Tooltip(org.jboss.hal.ballroom.Tooltip) FinderSegment(org.jboss.hal.core.finder.FinderSegment) HtmlContentBuilder(org.jboss.gwt.elemento.core.builder.HtmlContentBuilder) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HalViewImpl(org.jboss.hal.core.mvp.HalViewImpl) User(org.jboss.hal.config.User) Elements.i(org.jboss.gwt.elemento.core.Elements.i) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) Settings(org.jboss.hal.config.Settings) Set(java.util.Set) CSS(org.jboss.hal.resources.CSS) EventType.click(org.jboss.gwt.elemento.core.EventType.click) FinderPath(org.jboss.hal.core.finder.FinderPath) MAX_BREADCRUMB_VALUE_LENGTH(org.jboss.hal.client.skeleton.HeaderPresenter.MAX_BREADCRUMB_VALUE_LENGTH) Collectors.joining(java.util.stream.Collectors.joining) Roles(org.jboss.hal.config.Roles) List(java.util.List) UIConstants(org.jboss.hal.resources.UIConstants) CSS.nav(org.jboss.hal.resources.CSS.nav) StreamSupport.stream(java.util.stream.StreamSupport.stream) Role(org.jboss.hal.config.Role) Segment(org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment) Element(elemental2.dom.Element) Strings.abbreviateMiddle(org.jboss.hal.resources.Strings.abbreviateMiddle) FontAwesomeSize.large(org.jboss.hal.resources.FontAwesomeSize.large) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) ModelBrowser(org.jboss.hal.core.modelbrowser.ModelBrowser) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) AccessControl(org.jboss.hal.core.accesscontrol.AccessControl) Logger(org.slf4j.Logger) RBAC(org.jboss.hal.config.AccessControlProvider.RBAC) Iterator(java.util.Iterator) Ids(org.jboss.hal.resources.Ids) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DropdownItem(org.jboss.hal.core.finder.FinderSegment.DropdownItem) ModelBrowserPath(org.jboss.hal.core.modelbrowser.ModelBrowserPath) FinderContext(org.jboss.hal.core.finder.FinderContext) HTMLLIElement(elemental2.dom.HTMLLIElement) Elements.nav(org.jboss.gwt.elemento.core.Elements.nav) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) EventType.bind(org.jboss.gwt.elemento.core.EventType.bind) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements(org.jboss.gwt.elemento.core.Elements) HTMLElement(elemental2.dom.HTMLElement)

Aggregations

Strings (com.google.common.base.Strings)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)1 PlaceRequest (com.gwtplatform.mvp.shared.proxy.PlaceRequest)1 Element (elemental2.dom.Element)1 HTMLElement (elemental2.dom.HTMLElement)1 HTMLLIElement (elemental2.dom.HTMLLIElement)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Inject (javax.inject.Inject)1 Elements (org.jboss.gwt.elemento.core.Elements)1 Elements.i (org.jboss.gwt.elemento.core.Elements.i)1 Elements.nav (org.jboss.gwt.elemento.core.Elements.nav)1