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
…dashboards-is-empty
  • Loading branch information
nhthinh-axonivy committed Dec 6, 2024
1 parent cfc06d8 commit 04b3205
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 66 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,49 +92,35 @@ public void init() {
dashboards = collectDashboards();

if (isReadOnlyMode) {
updateDashboardCache();
MenuView menuView = (MenuView) ManagedBeans.get("menuView");
menuView.updateDashboardCache(dashboards);
}

if (CollectionUtils.isNotEmpty(DashboardUtils.getDashboardsWithoutMenuItem())) {
handleDashboardsWithoutMenuItem();
} else if (isRequestPathForMainOrDetailModification()) {
handleRequestPathSpecificDashboard();
}

buildWidgetModels(selectedDashboard);
initializeTaskBehavior();
buildClientStatisticApiUri();
if (CollectionUtils.isNotEmpty(DashboardUtils.getDashboardsWithoutMenuItem())
|| isRequestPathForMainOrDetailModification()) {
updateSelectedDashboardIdFromSessionAttribute();
updateSelectedDashboard();
storeAndHighlightDashboardIfRequired();
}
buildWidgetModels(selectedDashboard);
isRunningTaskWhenClickingOnTaskInList = GlobalSettingService.getInstance()
.findGlobalSettingValue(GlobalVariable.DEFAULT_BEHAVIOUR_WHEN_CLICKING_ON_LINE_IN_TASK_LIST)
.equals(BehaviourWhenClickingOnLineInTaskList.RUN_TASK.name());

/**
* Updates the dashboard cache in read-only mode.
*/
private void updateDashboardCache() {
MenuView menuView = (MenuView) ManagedBeans.get("menuView");
menuView.updateDashboardCache(dashboards);
buildClientStatisticApiUri();
}

/**
* Handles the scenario where dashboards do not have menu items.
*/
private void handleDashboardsWithoutMenuItem() {
updateSelectedDashboardIdFromSessionAttribute();
updateSelectedDashboard();
storeAndHighlightDashboardIfRequired();
private void buildClientStatisticApiUri() {
this.clientStatisticApiUri = FacesContext.getCurrentInstance()
.getExternalContext().getRequestContextPath() + "/api/statistics/data";
}

/**
* Handles scenarios for specific request paths.
*/
private void handleRequestPathSpecificDashboard() {
updateSelectedDashboardIdFromSessionAttribute();
updateSelectedDashboard();
storeAndHighlightDashboardIfRequired();
private boolean isRequestPathForMainOrDetailModification() {
String requestPath = Ivy.request().getRequestPath();
return requestPath.endsWith("/PortalMainDashboard.xhtml")
|| requestPath.endsWith("/PortalDashboardDetailModification.xhtml");
}

/**
* Updates the selected dashboard based on the session attribute and index.
*/
private void updateSelectedDashboard() {
currentDashboardIndex = findIndexOfDashboardById(selectedDashboardId);
selectedDashboard = dashboards.get(currentDashboardIndex);
Expand All @@ -146,45 +132,16 @@ private void updateSelectedDashboard() {
initShareDashboardLink(selectedDashboard);
}

/**
* Stores the dashboard ID in the session and highlights it if required.
*/
private void storeAndHighlightDashboardIfRequired() {
if (StringUtils.isBlank(selectedDashboardId) || (!selectedDashboardId.equalsIgnoreCase(selectedDashboard.getId())
&& DashboardUtils.getDashboardsWithoutMenuItem().size() > 1)) {
DashboardUtils.storeDashboardInSession(selectedDashboard.getId());
DashboardUtils.storeDashboardInSession(selectedDashboard.getId());
}
if (isReadOnlyMode) {
DashboardUtils.highlightDashboardMenuItem(selectedDashboard.getId());
DashboardUtils.highlightDashboardMenuItem(selectedDashboard.getId());
}
}

/**
* Checks if the current request path matches the main or detail modification views.
*
* @return true if the request path matches, false otherwise
*/
private boolean isRequestPathForMainOrDetailModification() {
String requestPath = Ivy.request().getRequestPath();
return requestPath.endsWith("/PortalMainDashboard.xhtml")
|| requestPath.endsWith("/PortalDashboardDetailModification.xhtml");
}

/**
* Initializes the behavior for task clicks.
*/
private void initializeTaskBehavior() {
isRunningTaskWhenClickingOnTaskInList = GlobalSettingService.getInstance()
.findGlobalSettingValue(GlobalVariable.DEFAULT_BEHAVIOUR_WHEN_CLICKING_ON_LINE_IN_TASK_LIST)
.equals(BehaviourWhenClickingOnLineInTaskList.RUN_TASK.name());
}


private void buildClientStatisticApiUri() {
this.clientStatisticApiUri = FacesContext.getCurrentInstance()
.getExternalContext().getRequestContextPath() + "/api/statistics/data";
}

protected List<Dashboard> collectDashboards() {
return DashboardUtils.collectDashboards();
}
Expand Down

0 comments on commit 04b3205

Please sign in to comment.