From 2d4c74049b142a823e30521ffa1073f21865af10 Mon Sep 17 00:00:00 2001 From: nhthinh-axonivy Date: Thu, 28 Nov 2024 12:33:11 +0700 Subject: [PATCH] bug/IVYPORTAL-18051-Portal-Dashboard-shows-no-permission-screen-when-dashboards-is-empty _ adapt logic _ import default dashboard --- .../addon/portal/generic/menu/MenuView.java | 2 - .../bean/DashboardDetailModificationBean.java | 2 +- .../bean/DashboardModificationBean.java | 2 +- .../addon/portalkit/util/DashboardUtils.java | 10 +- .../portalkit/util/DefaultDashboardUtils.java | 336 ++++++++++++++++++ 5 files changed, 345 insertions(+), 7 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..bb808d0b6f6 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) { diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardDetailModificationBean.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardDetailModificationBean.java index 5727ffb6499..f49485ecb0f 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardDetailModificationBean.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardDetailModificationBean.java @@ -182,7 +182,7 @@ protected List collectDashboards() { } catch (PortalException e) { Ivy.log().error(e); } - DashboardUtils.addDefaultTaskCaseListDashboardsIfMissing(collectedDashboards); + DashboardUtils.addDefaultDashboardsIfMissing(collectedDashboards); return collectedDashboards.stream() .filter(dashboard -> dashboard.getId().equals(selectedDashboardId)).collect(Collectors.toList()); } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardModificationBean.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardModificationBean.java index c6c86eafd56..f4f8402d864 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardModificationBean.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portal/generic/bean/DashboardModificationBean.java @@ -72,7 +72,7 @@ protected void collectDashboardsForManagement() { String dashboardInUserProperty = readDashboardBySessionUser(); if (isPublicDashboard) { this.dashboards = DashboardUtils.getPublicDashboards(); - DashboardUtils.addDefaultTaskCaseListDashboardsIfMissing(this.dashboards); + DashboardUtils.addDefaultDashboardsIfMissing(this.dashboards); } else if (StringUtils.isNoneEmpty(dashboardInUserProperty)) { List myDashboards = getVisibleDashboards(dashboardInUserProperty); this.dashboards.addAll(myDashboards); diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DashboardUtils.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DashboardUtils.java index f42e63ec3d2..97cc6abd708 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DashboardUtils.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DashboardUtils.java @@ -134,12 +134,16 @@ public static List getVisiblePublicDashboards() { public static List getPublicDashboards() { String dashboardJson = Ivy.var().get(PortalVariable.DASHBOARD.key); List visibleDashboards = jsonToDashboards(dashboardJson); - addDefaultTaskCaseListDashboardsIfMissing(visibleDashboards); + addDefaultDashboardsIfMissing(visibleDashboards); setDashboardAsPublic(visibleDashboards); return visibleDashboards; } - public static void addDefaultTaskCaseListDashboardsIfMissing(List dashboards) { + public static void addDefaultDashboardsIfMissing(List dashboards) { + List dashboardsWithoutItem = dashboards.stream().filter(dashboard -> !dashboard.getIsTopMenu()).toList(); + if (dashboardsWithoutItem.size() == 0) { + dashboards.add(0,DefaultDashboardUtils.getDefaultDashboard()); + } if (!hasDashboardWithId(dashboards, DEFAULT_CASE_LIST_DASHBOARD)) { dashboards.add(0, DefaultDashboardUtils.getDefaultCaseListDashboard()); } @@ -198,7 +202,7 @@ public static List collectDashboards() { } } collectedDashboards.addAll(idToDashboard.values()); - addDefaultTaskCaseListDashboardsIfMissing(collectedDashboards); + addDefaultDashboardsIfMissing(collectedDashboards); return collectedDashboards; } diff --git a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DefaultDashboardUtils.java b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DefaultDashboardUtils.java index f092c03fb23..7e87c1d1856 100644 --- a/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DefaultDashboardUtils.java +++ b/AxonIvyPortal/portal/src/ch/ivy/addon/portalkit/util/DefaultDashboardUtils.java @@ -4,6 +4,339 @@ public class DefaultDashboardUtils { + private static String DEFAULT_DASHBOARD_JSON = """ + { + "id": "1", + "version": "12.0.0", + "templateId": "default-portal-dashboard-template", + "titles": [ + { + "locale": "en", + "value": "Dashboard" + }, + { + "locale": "fr", + "value": "Tableau de bord" + }, + { + "locale": "de", + "value": "Dashboard" + }, + { + "locale": "es", + "value": "Tablero de mandos" + } + ], + "icon": "si-pie-line-graph", + "widgets": [ + { + "type": "task", + "id": "task_1", + "names": [ + { + "locale": "en", + "value": "Your Tasks" + }, + { + "locale": "de", + "value": "Ihre Aufgaben" + }, + { + "locale": "fr", + "value": "Vos tâches" + }, + { + "locale": "es", + "value": "Sus tareas" + } + ], + "layout": { + "w": 8, + "h": 6, + "x": 0, + "y": 2 + }, + "enableQuickSearch": true, + "columns": [ + { + "field": "start", + "width": "65" + }, + { + "field": "priority", + "width": "65" + }, + { + "field": "id", + "visible": false + }, + { + "field": "name", + "width": "315" + }, + { + "field": "description", + "visible": false + }, + { + "field": "activator", + "width": "120" + }, + { + "field": "state", + "visible": false + }, + { + "field": "startTimestamp", + "visible": false + }, + { + "field": "expiryTimestamp" + }, + { + "field": "category", + "visible": false + }, + { + "field": "actions", + "width": "78" + } + ], + "sortDescending": true, + "sortField": "startTimestamp", + "canWorkOn": true, + "filters": [ + { + "field": "state", + "values": [ + "DONE", + "IN_PROGRESS", + "OPEN" + ], + "operator": "in", + "type": "standard" + } + ] + }, + { + "type": "case", + "id": "case_1", + "names": [ + { + "locale": "en", + "value": "Your Cases" + }, + { + "locale": "de", + "value": "Ihre Vorgänge" + }, + { + "locale": "fr", + "value": "Vos affaires" + }, + { + "locale": "es", + "value": "Sus casos" + } + ], + "layout": { + "w": 9, + "h": 6, + "x": 3, + "y": 8 + }, + "enableQuickSearch": true, + "columns": [ + { + "field": "id", + "width": "60" + }, + { + "field": "name", + "width": "320" + }, + { + "field": "description", + "visible": false + }, + { + "field": "state", + "width": "60" + }, + { + "field": "creator", + "width": "100" + }, + { + "field": "startTimestamp", + "width": "100" + }, + { + "field": "endTimestamp", + "visible": false + }, + { + "field": "category", + "visible": false + }, + { + "field": "actions", + "width": "60" + } + ], + "sortDescending": true, + "sortField": "startTimestamp", + "filters": [ + { + "field": "state", + "values": [ + "OPEN" + ], + "operator": "in", + "type": "standard" + } + ] + }, + { + "type": "compact-process", + "id": "process_1", + "names": [ + { + "locale": "en", + "value": "Your Processes" + }, + { + "locale": "de", + "value": "Ihre Prozesse" + }, + { + "locale": "fr", + "value": "Vos processus" + }, + { + "locale": "es", + "value": "Sus procesos" + } + ], + "layout": { + "w": 4, + "h": 4, + "x": 8, + "y": 4 + } + }, + { + "type": "welcome", + "id": "welcome_1", + "names": [ + { + "locale": "en", + "value": "Your Welcome Widget" + } + ], + "layout": { + "w": 12, + "h": 2, + "x": 0, + "y": 0 + }, + "welcomeTextPosition": "TOP_LEFT", + "welcomeTextSize": "HEADING_3", + "welcomeTextColor": "ffffff", + "welcomeTexts": [ + { + "locale": "en", + "value": ", welcome to the Axon Ivy Portal!" + }, + { + "locale": "fr", + "value": ", bienvenue sur le portail Axon Ivy!" + }, + { + "locale": "de", + "value": ", willkommen im Axon Ivy Portal!" + }, + { + "locale": "es", + "value": ", bienvenido al portal Axon Ivy!" + } + ], + "welcomeImageFit": "COVER", + "greeting": true + }, + { + "type": "client-statistic", + "id": "client_statistic_1", + "layout": { + "w": 2, + "h": 2, + "x": 8, + "y": 2 + }, + "chartId": "10" + }, + { + "type": "client-statistic", + "id": "client_statistic_2", + "layout": { + "w": 2, + "h": 2, + "x": 10, + "y": 2 + }, + "chartId": "11" + }, + { + "type": "client-statistic", + "id": "client_statistic_3", + "layout": { + "w": 3, + "h": 3, + "x": 0, + "y": 11 + }, + "chartId": "7" + }, + { + "type": "client-statistic", + "id": "client_statistic_4", + "layout": { + "w": 3, + "h": 3, + "x": 0, + "y": 8 + }, + "chartId": "3" + }, + { + "type": "client-statistic", + "id": "client_statistic_5", + "layout": { + "w": 3, + "h": 3, + "x": 0, + "y": 14 + }, + "chartId": "5" + }, + { + "type": "client-statistic", + "id": "client_statistic_6", + "layout": { + "w": 9, + "h": 3, + "x": 3, + "y": 14 + }, + "chartId": "4" + } + ], + "permissions": [ + "Everybody" + ] + } + """; + private static String DEFAULT_TASK_LIST_DASHBOARD_JSON = """ { "id": "default-task-list-dashboard", @@ -233,4 +566,7 @@ public static Dashboard getDefaultCaseListDashboard() { return DashboardUtils.jsonToDashboard(DEFAULT_CASE_LIST_DASHBOARD_JSON); } + public static Dashboard getDefaultDashboard() { + return DashboardUtils.jsonToDashboard(DEFAULT_DASHBOARD_JSON); + } }