Skip to content

Commit

Permalink
bug/IVYPORTAL-18051-Portal-Dashboard-shows-no-permission-screen-when-… (
Browse files Browse the repository at this point in the history
#1280)

* bug/IVYPORTAL-18051-Portal-Dashboard-shows-no-permission-screen-when-dashboards-is-empty
_ adapt logic
_ import default dashboard
  • Loading branch information
nhthinh-axonivy authored Dec 12, 2024
1 parent 8732522 commit e2e2645
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public void buildPortalLeftMenu(ITask workingTask, boolean isWorkingOnATask) {
mainMenuModel = new DefaultMenuModel();
mainMenuModel.getElements().add(buildDashboardItem()); // menuIndex = 0



List<SubMenuItem> subMenuItems = PortalMenuNavigator.callSubMenuItemsProcess();
int menuIndex = 1;
for (SubMenuItem subMenu : subMenuItems) {
Expand Down Expand Up @@ -152,13 +150,17 @@ private MenuElement buildDashboardItem() {
String mainMenuDisplayName = mainMenuEntryService.getNameInCurrentLocale();
String mainMenuIcon = mainMenuEntryService.getMenuIcon();

var subItemDashboards = getSubItemDashboards();
List<Dashboard> 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() {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<Dashboard> collectDashboards() {
return DashboardUtils.collectDashboards();
}
Expand Down

0 comments on commit e2e2645

Please sign in to comment.