From e2e26450aeba0e8bd3169d38f1b0cedcaa159640 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen <117440893+nhthinh-axonivy@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:45:36 +0700 Subject: [PATCH] =?UTF-8?q?bug/IVYPORTAL-18051-Portal-Dashboard-shows-no-p?= =?UTF-8?q?ermission-screen-when-=E2=80=A6=20(#1280)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bug/IVYPORTAL-18051-Portal-Dashboard-shows-no-permission-screen-when-dashboards-is-empty _ adapt logic _ import default dashboard --- .../addon/portal/generic/menu/MenuView.java | 18 ++++--- .../portal/generic/bean/DashboardBean.java | 53 +++++++++++-------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/AxonIvyPortal/portal/src/ch/addon/portal/generic/menu/MenuView.java b/AxonIvyPortal/portal/src/ch/addon/portal/generic/menu/MenuView.java index 668df5c4364..25dc3cf939d 100644 --- a/AxonIvyPortal/portal/src/ch/addon/portal/generic/menu/MenuView.java +++ b/AxonIvyPortal/portal/src/ch/addon/portal/generic/menu/MenuView.java @@ -91,8 +91,6 @@ public void buildPortalLeftMenu(ITask workingTask, boolean isWorkingOnATask) { mainMenuModel = new DefaultMenuModel(); mainMenuModel.getElements().add(buildDashboardItem()); // menuIndex = 0 - - List subMenuItems = PortalMenuNavigator.callSubMenuItemsProcess(); int menuIndex = 1; for (SubMenuItem subMenu : subMenuItems) { @@ -152,13 +150,17 @@ private MenuElement buildDashboardItem() { String mainMenuDisplayName = mainMenuEntryService.getNameInCurrentLocale(); String mainMenuIcon = mainMenuEntryService.getMenuIcon(); - var subItemDashboards = getSubItemDashboards(); + List subItemDashboards = getSubItemDashboards(); if (subItemDashboards.size() > 1) { return buildDashboardGroupMenu(subItemDashboards, dashboardTitle, mainMenuDisplayName, mainMenuIcon, currentLanguage, dashboardLink); + } else if (subItemDashboards.size() == 1) { + Dashboard dashboard = subItemDashboards.getFirst(); + String localizedTitle = getLocalizedTitle(dashboard, currentLanguage, dashboardTitle); + return buildSingleDashboardMenu(localizedTitle, dashboardId, dashboardLink, dashboard.getIcon()); } - - return buildSingleDashboardMenu(dashboardTitle, dashboardId, dashboardLink); + + return buildSingleDashboardMenu(dashboardTitle, "", dashboardLink, ""); } private String determineDashboardLink() { @@ -240,9 +242,11 @@ private void setMenuExpansion(DefaultSubMenu dashboardGroupMenu) { } } - private MenuElement buildSingleDashboardMenu(String dashboardTitle, String dashboardId, String dashboardLink) { + private MenuElement buildSingleDashboardMenu(String dashboardTitle, String dashboardId, String dashboardLink, + String dashboardIcon) { var dashboardMenu = new PortalMenuBuilder(dashboardTitle, MenuKind.DASHBOARD, this.isWorkingOnATask) - .icon(PortalMenuItem.DEFAULT_DASHBOARD_ICON).url(dashboardLink).workingTaskId(this.workingTaskId).build(); + .icon(StringUtils.isNoneEmpty(dashboardIcon) ? dashboardIcon : PortalMenuItem.DEFAULT_DASHBOARD_ICON) + .url(dashboardLink).workingTaskId(this.workingTaskId).build(); if (StringUtils.isBlank(dashboardId)) { dashboardId = dashboardMenu.getId(); diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardBean.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardBean.java index b573ec9dde1..d4061a3be47 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardBean.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardBean.java @@ -91,33 +91,17 @@ public void init() { currentDashboardIndex = 0; dashboards = collectDashboards(); - if (isReadOnlyMode) { MenuView menuView = (MenuView) ManagedBeans.get("menuView"); menuView.updateDashboardCache(dashboards); } - if (CollectionUtils.isNotEmpty(DashboardUtils.getDashboardsWithoutMenuItem())) { + if (CollectionUtils.isNotEmpty(DashboardUtils.getDashboardsWithoutMenuItem()) + || isRequestPathForMainOrDetailModification()) { updateSelectedDashboardIdFromSessionAttribute(); - currentDashboardIndex = findIndexOfDashboardById(selectedDashboardId); - selectedDashboard = dashboards.get(currentDashboardIndex); - - String selectedDashboardName = selectedDashboard.getTitles().stream() - .filter(displayName -> displayName.getLocale().equals(Ivy.session().getContentLocale())) - .findFirst() - .orElseGet(() -> selectedDashboard.getTitles().get(0)).getValue(); - setSelectedDashboardName(selectedDashboardName); - initShareDashboardLink(selectedDashboard); - // can not find dashboard by dashboard id session in view mode - if (StringUtils.isBlank(selectedDashboardId) - || (!selectedDashboardId.equalsIgnoreCase(selectedDashboard.getId()) - && DashboardUtils.getDashboardsWithoutMenuItem().size() > 1)) { - DashboardUtils.storeDashboardInSession(selectedDashboard.getId()); - } - if (isReadOnlyMode) { - DashboardUtils.highlightDashboardMenuItem(selectedDashboard.getId()); - } - } + updateSelectedDashboard(); + storeAndHighlightDashboardIfRequired(); + } buildWidgetModels(selectedDashboard); isRunningTaskWhenClickingOnTaskInList = GlobalSettingService.getInstance() .findGlobalSettingValue(GlobalVariable.DEFAULT_BEHAVIOUR_WHEN_CLICKING_ON_LINE_IN_TASK_LIST) @@ -131,6 +115,33 @@ private void buildClientStatisticApiUri() { .getExternalContext().getRequestContextPath() + "/api/statistics/data"; } + private boolean isRequestPathForMainOrDetailModification() { + String requestPath = Ivy.request().getRequestPath(); + return requestPath.endsWith("/PortalMainDashboard.xhtml") + || requestPath.endsWith("/PortalDashboardDetailModification.xhtml"); + } + + private void updateSelectedDashboard() { + currentDashboardIndex = findIndexOfDashboardById(selectedDashboardId); + selectedDashboard = dashboards.get(currentDashboardIndex); + + String selectedDashboardName = selectedDashboard.getTitles().stream() + .filter(displayName -> displayName.getLocale().equals(Ivy.session().getContentLocale())).findFirst() + .orElseGet(() -> selectedDashboard.getTitles().get(0)).getValue(); + setSelectedDashboardName(selectedDashboardName); + initShareDashboardLink(selectedDashboard); + } + + private void storeAndHighlightDashboardIfRequired() { + if (StringUtils.isBlank(selectedDashboardId) || (!selectedDashboardId.equalsIgnoreCase(selectedDashboard.getId()) + && DashboardUtils.getDashboardsWithoutMenuItem().size() > 1)) { + DashboardUtils.storeDashboardInSession(selectedDashboard.getId()); + } + if (isReadOnlyMode) { + DashboardUtils.highlightDashboardMenuItem(selectedDashboard.getId()); + } + } + protected List collectDashboards() { return DashboardUtils.collectDashboards(); }