All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ikasan.dashboard.ui.layout.IkasanAppLayout Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package org.ikasan.dashboard.ui.layout;


import com.github.appreciated.app.layout.component.appbar.AppBarBuilder;
import com.github.appreciated.app.layout.component.appbar.IconButton;
import com.github.appreciated.app.layout.component.applayout.LeftLayouts;
import com.github.appreciated.app.layout.component.builder.AppLayoutBuilder;
import com.github.appreciated.app.layout.component.menu.left.LeftMenuComponentWrapper;
import com.github.appreciated.app.layout.component.menu.left.LeftSubmenu;
import com.github.appreciated.app.layout.component.menu.left.builder.LeftAppMenuBuilder;
import com.github.appreciated.app.layout.component.menu.left.builder.LeftSubMenuBuilder;
import com.github.appreciated.app.layout.component.menu.left.items.LeftNavigationItem;
import com.github.appreciated.app.layout.component.router.AppLayoutRouterLayout;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.page.Push;
import com.vaadin.flow.component.page.Viewport;
import com.vaadin.flow.server.InitialPageSettings;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.server.PageConfigurator;
import com.vaadin.flow.server.VaadinSession;
import com.vaadin.flow.theme.Theme;
import com.vaadin.flow.theme.material.Material;
import org.ikasan.dashboard.ui.administration.view.*;
import org.ikasan.dashboard.ui.dashboard.view.DashboardView;
import org.ikasan.dashboard.ui.general.component.AboutIkasanDialog;
import org.ikasan.dashboard.ui.scheduler.view.SchedulerView;
import org.ikasan.dashboard.ui.search.view.SearchView;
import org.ikasan.dashboard.ui.util.ComponentSecurityVisibility;
import org.ikasan.dashboard.ui.util.SecurityConstants;
import org.ikasan.dashboard.ui.util.SystemEventConstants;
import org.ikasan.dashboard.ui.util.SystemEventLogger;
import org.ikasan.dashboard.ui.visualisation.view.BusinessStreamDesignerView;
import org.ikasan.dashboard.ui.visualisation.view.GraphView;
import org.ikasan.security.service.authentication.IkasanAuthentication;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;

import javax.annotation.Resource;
import java.util.HashMap;


@Push
@JsModule("./styles/shared-styles.js")
@CssImport("./styles/shared-styles.css")
@CssImport(value = "./styles/dialog-overlay.css", themeFor = "vaadin-dialog-overlay")
@Viewport("width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes")
@Theme(Material.class)
@PWA(name = "Ikasan Visualisation Dashboard",
    shortName = "Ikasan",
    enableInstallPrompt = false)
public class IkasanAppLayout extends AppLayoutRouterLayout implements PageConfigurator
{
    @Resource
    private SystemEventLogger systemEventLogger;

    @Value("${banner.text.message:}")
    private String bannerTextMessage;

    @Value("${banner.text.color:}")
    private String bannerTextColor;

    @Value("${is.ikasan.enterprise.scheduler.instance:true}")
    private boolean isIkasanEnterpriseSchedulerInstance;

    private LeftMenuComponentWrapper leftAppMenu;
    private LeftSubmenu leftSubmenu;
    private LeftNavigationItem dashboardMenuItem;
    private LeftNavigationItem searchMenuItem;
    private LeftNavigationItem visualisationMenuItem;
    private LeftNavigationItem schedulerMenuItem;
    private LeftNavigationItem systemEventMenuItem;
    private LeftNavigationItem userManagementMenuItem;
    private LeftNavigationItem groupManagementMenuItem;
    private LeftNavigationItem roleManagementMenuItem;
    private LeftNavigationItem policyManagementMenuItem;
    private LeftNavigationItem userDirectoryManagementMenuItem;
    private LeftNavigationItem businessStreamDesignerMenuItem;
    private LeftNavigationItem quartzSchedulerMenuItem;

    private IconButton swaggerUI;

    public IkasanAppLayout()
    {
        Image ikasan = new Image("frontend/images/ikasan-titling-transparent.png", "");
        ikasan.setHeight("30px");

        IconButton logout = new IconButton(VaadinIcon.SIGN_OUT.create());
        logout.getElement().setProperty("title", "Log Out");
        logout.setId("logoutButton");

        logout.addClickListener((ComponentEventListener>) divClickEvent ->
        {
            IkasanAuthentication authentication = (IkasanAuthentication) SecurityContextHolder.getContext()
                .getAuthentication();
            this.systemEventLogger.logEvent(SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS
                , SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS, authentication.getName());
            SecurityContextHolder.getContext().setAuthentication(null);
            UI.getCurrent().navigate("");
            VaadinSession.getCurrent().getSession().invalidate();
            UI.getCurrent().getPage().executeJs("window.location.href=''");
            UI.getCurrent().getSession().close();
        });

        this.swaggerUI = new IconButton(VaadinIcon.CODE.create());
        this.swaggerUI.getElement().setProperty("title", "Swagger UI");
        this.swaggerUI.addClickListener(event -> UI.getCurrent().getPage().open("/swagger-ui.html", "_blank"));

        IconButton aboutButton = new IconButton(VaadinIcon.INFO_CIRCLE_O.create());
        aboutButton.setId("aboutButton");
        aboutButton.addClickListener((ComponentEventListener>) buttonClickEvent -> {
            AboutIkasanDialog aboutIkasanDialog = new AboutIkasanDialog();
            aboutIkasanDialog.open();
        });

        AppLayoutBuilder appLayoutBuilder = AppLayoutBuilder
            .get(LeftLayouts.LeftHybridSmall.class)
            .withIconComponent(ikasan)
            .withAppBar(AppBarBuilder.get()
                .add(aboutButton)
                .add(swaggerUI)
                .add(logout)
                .build());

        LeftAppMenuBuilder leftAppMenuBuilder = LeftAppMenuBuilder.get();

        this.dashboardMenuItem = new LeftNavigationItem("Dashboard", VaadinIcon.DASHBOARD.create(), DashboardView.class);
        this.dashboardMenuItem.setId("dashboardMenuItem");
        this.dashboardMenuItem.getElement().getStyle().remove("padding");
        leftAppMenuBuilder = leftAppMenuBuilder.add(dashboardMenuItem);

        this.searchMenuItem = new LeftNavigationItem(getTranslation("menu-item.search", UI.getCurrent().getLocale(), null), VaadinIcon.SEARCH.create(), SearchView.class);
        this.searchMenuItem.setId("searchMenuItem");
        leftAppMenuBuilder = leftAppMenuBuilder.add(searchMenuItem);


        this.visualisationMenuItem = new LeftNavigationItem(getTranslation("menu-item.visualisation", UI.getCurrent().getLocale(), null), VaadinIcon.CLUSTER.create(), GraphView.class);
        this.visualisationMenuItem.setId("visualisationMenuItem");

        leftAppMenuBuilder = leftAppMenuBuilder.add(this.visualisationMenuItem);

        this.schedulerMenuItem = new LeftNavigationItem("Scheduler", VaadinIcon.CLOCK.create(), SchedulerView.class);
        this.schedulerMenuItem.setId("schedulerMenuItem");

        leftAppMenuBuilder = leftAppMenuBuilder.add(this.schedulerMenuItem);

        LeftSubMenuBuilder leftSubMenuBuilder = LeftSubMenuBuilder
            .get(getTranslation("menu-item.administration", UI.getCurrent().getLocale(), null), VaadinIcon.TOOLS.create());

        this.systemEventMenuItem = new LeftNavigationItem(getTranslation("menu-item.administration-events", UI.getCurrent().getLocale(), null), VaadinIcon.CROSSHAIRS.create(), AdministrationSearchView.class);
        this.systemEventMenuItem.setId("systemEventMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.systemEventMenuItem);

        this.userManagementMenuItem = new LeftNavigationItem(getTranslation("menu-item.users",
            UI.getCurrent().getLocale(), null), VaadinIcon.USERS.create(), UserManagementView.class);
        this.userManagementMenuItem.setId("userManagementMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.userManagementMenuItem);

        this.groupManagementMenuItem = new LeftNavigationItem(getTranslation("menu-item.groups",
            UI.getCurrent().getLocale(), null), VaadinIcon.GROUP.create(), GroupManagementView.class);
        this.groupManagementMenuItem.setId("groupManagementMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.groupManagementMenuItem);

        this.roleManagementMenuItem = new LeftNavigationItem(getTranslation("menu-item.roles",
            UI.getCurrent().getLocale(), null), VaadinIcon.DOCTOR.create(), RoleManagementView.class);
        this.roleManagementMenuItem.setId("roleManagementMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.roleManagementMenuItem);

        this.policyManagementMenuItem = new LeftNavigationItem(getTranslation("menu-item.policies",
            UI.getCurrent().getLocale(), null), VaadinIcon.SAFE.create(), PolicyManagementView.class);
        this.policyManagementMenuItem.setId("policyManagementMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.policyManagementMenuItem);

        this.userDirectoryManagementMenuItem = new LeftNavigationItem(getTranslation("menu-item.user-directories",
            UI.getCurrent().getLocale(), null), VaadinIcon.COG.create(), UserDirectoriesView.class);
        this.userDirectoryManagementMenuItem.setId("userDirectoryManagementMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.userDirectoryManagementMenuItem);

        this.quartzSchedulerMenuItem = new LeftNavigationItem(getTranslation("menu-item.quartz-scheduler",
            UI.getCurrent().getLocale(), null), VaadinIcon.CALENDAR_CLOCK.create(), QuartzSchedulerView.class);
        this.quartzSchedulerMenuItem.setId("quartzSchedulerViewMenuItem");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.quartzSchedulerMenuItem);

        this.businessStreamDesignerMenuItem = new LeftNavigationItem("Designer", VaadinIcon.PALETE.create(), BusinessStreamDesignerView.class);
        this.businessStreamDesignerMenuItem.setId("businessStreamDesignerMenuItem");
        this.businessStreamDesignerMenuItem.getElement().getThemeList().remove("spacing-s");
        leftSubMenuBuilder = leftSubMenuBuilder.add(this.businessStreamDesignerMenuItem);

        if(leftSubMenuBuilder != null)
        {
            this.leftSubmenu = leftSubMenuBuilder.build();
            this.leftSubmenu.getSubmenuContainer().getThemeList().remove("spacing-s");
            leftAppMenuBuilder.add(this.leftSubmenu);
        }

        this.leftAppMenu = (LeftMenuComponentWrapper) leftAppMenuBuilder.build();
        this.leftAppMenu.getMenu().getThemeList().remove("spacing-s");

        init((LeftLayouts.LeftHybridSmall)appLayoutBuilder.withAppMenu(leftAppMenu).build());
    }

    @Override
    public void onAttach(AttachEvent attachEvent)
    {
        if(this.bannerTextMessage != null && !this.bannerTextMessage.isEmpty()) {
            Span bannerText = new Span(bannerTextMessage);
            bannerText.getElement().getStyle().set("font-size", "30pt");
            bannerText.getElement().getStyle().set("color", bannerTextColor);

            HorizontalLayout bannerLayout = new HorizontalLayout(bannerText);
            bannerLayout.getElement().getStyle().set("position", "absolute");
            bannerLayout.getElement().getStyle().set("left", "50%");
            bannerLayout.getElement().getStyle().set("transform", "translate(-50%)");
            super.getAppLayout().setTitleComponent(bannerLayout);
        }

        super.onAttach(attachEvent);
        this.dashboardMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.DASHBOARD_READ, SecurityConstants.DASHBOARD_WRITE,
            SecurityConstants.DASHBOARD_ADMIN));

        this.searchMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.SEARCH_ADMIN, SecurityConstants.SEARCH_READ, SecurityConstants.SEARCH_WRITE,
            SecurityConstants.ALL_AUTHORITY));

        this.schedulerMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY
            , SecurityConstants.SCHEDULER_ADMIN, SecurityConstants.SCHEDULER_READ, SecurityConstants.SCHEDULER_WRITE
            , SecurityConstants.SCHEDULER_ALL_READ, SecurityConstants.SCHEDULER_ALL_WRITE, SecurityConstants.SCHEDULER_ALL_ADMIN)
            && isIkasanEnterpriseSchedulerInstance);

        this.visualisationMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY));

        this.leftSubmenu.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.USER_ADMINISTRATION_ADMIN, SecurityConstants.USER_ADMINISTRATION_WRITE,
            SecurityConstants.USER_ADMINISTRATION_READ, SecurityConstants.USER_DIRECTORY_ADMIN, SecurityConstants.USER_DIRECTORY_WRITE, SecurityConstants.USER_DIRECTORY_READ,
            SecurityConstants.GROUP_ADMINISTRATION_ADMIN, SecurityConstants.GROUP_ADMINISTRATION_WRITE, SecurityConstants.GROUP_ADMINISTRATION_READ,
            SecurityConstants.POLICY_ADMINISTRATION_ADMIN, SecurityConstants.POLICY_ADMINISTRATION_READ, SecurityConstants.POLICY_ADMINISTRATION_WRITE,
            SecurityConstants.ROLE_ADMINISTRATION_ADMIN, SecurityConstants.ROLE_ADMINISTRATION_READ, SecurityConstants.ROLE_ADMINISTRATION_WRITE,SecurityConstants.ALL_AUTHORITY,
            SecurityConstants.SYSTEM_EVENT_ADMIN, SecurityConstants.SYSTEM_EVENT_READ, SecurityConstants.SYSTEM_EVENT_WRITE));

        this.systemEventMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.SYSTEM_EVENT_ADMIN, SecurityConstants.SYSTEM_EVENT_READ,
            SecurityConstants.SYSTEM_EVENT_WRITE));

        this.userManagementMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.USER_ADMINISTRATION_ADMIN, SecurityConstants.USER_ADMINISTRATION_WRITE,
            SecurityConstants.USER_ADMINISTRATION_READ));

        this.groupManagementMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.GROUP_ADMINISTRATION_ADMIN, SecurityConstants.GROUP_ADMINISTRATION_WRITE,
            SecurityConstants.GROUP_ADMINISTRATION_READ));

        this.roleManagementMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.ROLE_ADMINISTRATION_ADMIN, SecurityConstants.ROLE_ADMINISTRATION_READ,
            SecurityConstants.ROLE_ADMINISTRATION_WRITE));

        this.policyManagementMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY, SecurityConstants.POLICY_ADMINISTRATION_ADMIN, SecurityConstants.POLICY_ADMINISTRATION_READ,
            SecurityConstants.POLICY_ADMINISTRATION_WRITE));

        this.userDirectoryManagementMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY
            , SecurityConstants.USER_DIRECTORY_ADMIN, SecurityConstants.USER_DIRECTORY_WRITE, SecurityConstants.USER_DIRECTORY_READ));

        this.swaggerUI.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY));

        this.businessStreamDesignerMenuItem.setVisible(ComponentSecurityVisibility.hasAuthorisation(SecurityConstants.ALL_AUTHORITY
            , SecurityConstants.BUSINESS_STREAM_ADMIN));
    }

    @Override
    public void configurePage(InitialPageSettings settings) {
        HashMap attributes = new HashMap<>();
        attributes.put("rel", "shortcut icon");
        attributes.put("type", "image/png");
        settings.addLink("icons/icon.png", attributes);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy