Skip to content

Commit

Permalink
feature/IVYPORTAL-17461-Remove-Full-Task-List-and-Replace-it-with-the…
Browse files Browse the repository at this point in the history
…-Task-Widget-ver2
  • Loading branch information
nhthinh-axonivy committed Oct 18, 2024
1 parent b6f5626 commit d1a353e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public static Homepage findHomepage() {
private static void adjustHomepageStartLink(Homepage homepage) {
String relativeUrl = switch (homepage.getType()) {
case PROCESS -> findRelativeUrlByKeywork(PortalNavigator.PORTAL_PROCESS_START);
case TASK -> PortalNavigator.getDashboardPageUrl("386301385bfb469f833f80e6d14baf27");
case CASE -> findRelativeUrlByKeywork(PortalNavigator.PORTAL_CASE_START);
default -> "";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void init() {

if (CollectionUtils.isNotEmpty(DashboardUtils.getSubItemDashboards())) {
selectedDashboardId = readDashboardFromSession();
Ivy.log().error(selectedDashboardId);
currentDashboardIndex = findIndexOfDashboardById(selectedDashboardId);
selectedDashboard = dashboards.get(currentDashboardIndex);

Expand Down Expand Up @@ -415,16 +416,16 @@ protected void storeDashboardInSession(String id) {
}

private int findIndexOfDashboardById(String selectedDashboardId) {
if (DashboardUtils.DASHBOARD_TASK_TEMPLATE_ID.equalsIgnoreCase(selectedDashboardId)) {
return 0;
}


if (StringUtils.isNotBlank(selectedDashboardId)) {
return dashboards.stream().filter(dashboard -> dashboard.getId().contentEquals(selectedDashboardId)).findFirst()
.map(dashboards::indexOf).orElse(1);
.map(dashboards::indexOf).orElse(dashboards.stream().filter(dashboard -> !dashboard.getIsMenuItem())
.findFirst().map(dashboards::indexOf).orElse(0));
}

return 1;
return dashboards.stream().filter(dashboard -> !dashboard.getIsMenuItem()).findFirst().map(dashboards::indexOf)
.orElse(0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import ch.ivy.addon.portalkit.enums.MenuKind;
import ch.ivy.addon.portalkit.enums.SessionAttribute;
import ch.ivy.addon.portalkit.util.DashboardUtils;
import ch.ivy.addon.portalkit.util.RequestUtils;
import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.request.IHttpRequest;
Expand Down Expand Up @@ -119,7 +120,7 @@ public static void navigateToPortalCase() {

public static void navigateToPortalTask() {
Map<String, String> params = new HashMap<>();
params.put("dashboardId", "386301385bfb469f833f80e6d14baf27");
params.put("dashboardId", DashboardUtils.DASHBOARD_TASK_TEMPLATE_ID);
navigateByKeyword(PORTAL_DASHBOARD_PAGE_START, PORTAL_DASHBOARD_PAGE, params);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ch.ivy.addon.portalkit.enums;

public enum MenuKind {
DASHBOARD, PROCESS, TASK, CASE, CUSTOM, EXTERNAL_LINK, THIRD_PARTY, DASHBOARD_MENU_ITEM;
DASHBOARD, PROCESS, TASK, CASE, CUSTOM, EXTERNAL_LINK, THIRD_PARTY, DASHBOARD_MENU_ITEM, TASK_DASHBOARD_MENU_ITEM;

@Override
public String toString() {
Expand Down
73 changes: 52 additions & 21 deletions AxonIvyPortal/portal/webContent/resources/js/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ var MainMenu = {
urlToMenu: [
["PortalHome.xhtml", "DASHBOARD"],
["Processes.xhtml", "PROCESS"],
["PortalTasks.xhtml", "TASK"],
["TaskWidget.xhtml", "TASK"],
["PortalTaskDetails.xhtml", "TASK"],
["PortalTasks.xhtml", "TASK_DASHBOARD_MENU_ITEM"],
["TaskWidget.xhtml", "TASK_DASHBOARD_MENU_ITEM"],
["PortalTaskDetails.xhtml", "TASK_DASHBOARD_MENU_ITEM"],
["PortalCases.xhtml", "CASE"],
["CaseWidget.xhtml", "CASE"],
["PortalCaseDetails.xhtml", "CASE"],
Expand All @@ -183,11 +183,11 @@ var MainMenu = {
],

init: function (responsiveToolkit) {
this.highlightMenuItem();
this.responsiveToolkit = responsiveToolkit;
this.$mainMenuToggle = $(".sidebar-pin");
this.menulinks = $(".layout-sidebar .layout-menu a");
this.bindEvents();
this.restoreActiveMenuOnPageLoad(); // Restore active menu item on page load
},

bindEvents: function () {
Expand All @@ -202,33 +202,26 @@ var MainMenu = {
let activeMenuItemList = this.getActiveMenu();

if ($currentPageMenu.length > 0) {
var $dashboardGroup = $(".js-dashboard-group");
// Deactivate all other active menu items first
this.removeActiveMenu(activeMenuItemList);

// Check if it's a dashboard item that hasn't been converted to a menu item
// Check if the menu is a dashboard group
var $dashboardGroup = $(".js-dashboard-group");
if (
$currentPageMenu.hasClass("DASHBOARD") &&
!$currentPageMenu.hasClass("MENUITEM") &&
$dashboardGroup.length > 0
) {
// Only activate dashboard-related items
$.each(activeMenuItemList, function (i, menuItem) {
if (!menuItem.id.includes("-main-dashboard")) {
deactivateMenuItemOnLeftMenu(menuItem.id);
}
});
return;
} else {
// Add the active class to the current page menu
$currentPageMenu.parent().addClass("active-menuitem");
PF("main-menu").addMenuitem($currentPageMenu.parent().attr("id"));
}

// Prevent duplicate activation
if (
$currentPageMenu.parent().hasClass("active-menuitem") &&
activeMenuItemList.length === 1
) {
return;
}

this.removeActiveMenu(activeMenuItemList);
$currentPageMenu.parent().addClass("active-menuitem");
PF("main-menu").addMenuitem($currentPageMenu.parent().attr("id"));
}
},

Expand All @@ -249,7 +242,7 @@ var MainMenu = {

getMenuItemByCurrentPage: function () {
let currentPage = this.getCurentPageByPageUrl();
// Ensure not treating converted dashboard items as dashboards
// Ensure we're not treating converted dashboard items as dashboards
return $(".layout-menu").find(
'li[role="menuitem"] a.' + currentPage + ":not(.DASHBOARD)"
);
Expand All @@ -259,6 +252,11 @@ var MainMenu = {
return $(".layout-menu li.active-menuitem");
},

restoreActiveMenuOnPageLoad: function () {
// Try to highlight the current menu item on page load
this.highlightMenuItem();
},

isThirdPartyMenu: function (e) {
let menuClass = e.currentTarget.className;
if (
Expand Down Expand Up @@ -300,6 +298,39 @@ function deactivateMenuItemOnLeftMenu(menuId) {
}
}

// Ensure the script runs after the page is fully loaded
$(document).ready(function () {
MainMenu.init();
});

// Convert dashboard item to menu item
function convertDashboardToMenuItem(menuId) {
var $dashboardItem = $("#" + menuId);
// Remove the DASHBOARD class and add MENUITEM class
if ($dashboardItem.hasClass("DASHBOARD")) {
$dashboardItem.removeClass("DASHBOARD");
$dashboardItem.addClass("MENUITEM");
}
}

// Activate a menu item
function activeMenuItemOnLeftMenu(menuId) {
PF("main-menu").addMenuitem(menuId);
let $selectedMenu = $("[id$='" + menuId + "']");
if (!$selectedMenu.hasClass("active-menuitem")) {
$selectedMenu.addClass("active-menuitem");
}
}

// Deactivate a menu item
function deactivateMenuItemOnLeftMenu(menuId) {
PF("main-menu").removeMenuitem(menuId);
let $removedMenu = $("[id$='" + menuId + "']");
if ($removedMenu.hasClass("active-menuitem")) {
$removedMenu.removeClass("active-menuitem");
}
}


function handleError(xhr, renderDetail, isShowErrorLog){
//From PF 7.0 with new jQuery version, when we call ajax by remote command then navigate when remote command still executing, this request HTML status is abort
Expand Down

0 comments on commit d1a353e

Please sign in to comment.