-
-
Notifications
You must be signed in to change notification settings - Fork 512
Add visibility options for record view custom menu items #9415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3c1256d
8c5a31d
e7b7a08
d4bee61
9d6a960
bf9402d
a745e15
bd83337
55fd7b1
8001115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,12 @@ | |
| } | ||
| ]); | ||
|
|
||
| /** | ||
| * Render static page menu entries for a configured section. | ||
| * | ||
| * Accepts a page id, an array of page ids, or nested submenu config through | ||
| * `gn-static-page-menu`. | ||
| */ | ||
| module.directive("gnStaticPageMenu", [ | ||
| "gnStaticPagesService", | ||
| "gnGlobalSettings", | ||
|
|
@@ -140,6 +146,125 @@ | |
| // Set button style based on explicit parameter (defaults to false) | ||
| $scope.renderAsButton = $scope.renderAsButton === "true"; | ||
|
|
||
| /** | ||
| * Apply runtime visibility rules for a page. | ||
| * | ||
| * In `record_view_menu`, visibility depends on workflow state and | ||
| * metadata approval status from the current record context. | ||
| */ | ||
| function shouldShowPage(page) { | ||
| if (!page) return false; | ||
| if ( | ||
| $scope.section === "record_view_menu" && | ||
| $scope.context && | ||
| $scope.context.currentRecord | ||
| ) { | ||
| var currentRecord = $scope.context.currentRecord; | ||
| if (!currentRecord.isWorkflowEnabled()) | ||
| return page.showWhenWorkflowDisabled === true; | ||
| if (currentRecord.mdStatus === "2") return page.showOnApproved === true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other places comparing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in latest push |
||
| return page.showOnNonApproved === true; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Recursively build a display-ready menu from `pagesConfig`. | ||
| * | ||
| * `pagesConfig` may contain page ids (strings) and submenu descriptors. | ||
| * Unknown page ids are ignored and logged to help diagnose UI config issues. | ||
| */ | ||
| function buildMenu(pagesMenu, staticPages, pagesConfig) { | ||
| pagesConfig.forEach(function (menu) { | ||
| if (typeof menu === "string") { | ||
| if (staticPages[menu]) { | ||
| if (shouldShowPage(staticPages[menu])) { | ||
| pagesMenu.push(staticPages[menu]); | ||
| } | ||
| } else { | ||
| console.warn( | ||
| menu + | ||
| " not found in pages configuration." + | ||
| " Check your UI configuration." | ||
| ); | ||
| } | ||
| } else if (angular.isObject(menu)) { | ||
| var key = Object.keys(menu)[0]; | ||
| var value = menu[key]; | ||
|
|
||
| var submenu = { | ||
| label: key, | ||
| icon: undefined, | ||
| type: "submenu", | ||
| pages: [] | ||
| }; | ||
|
|
||
| var menuItems; | ||
|
|
||
| // If the submenu is using the legacy array format | ||
| if (angular.isArray(value)) { | ||
| menuItems = value; | ||
| // If the submenu is using the new object format with an items array and optional icon | ||
| } else if (angular.isObject(value)) { | ||
| if (angular.isArray(value.items)) { | ||
| menuItems = value.items; | ||
| } | ||
| if (angular.isDefined(value.icon)) { | ||
| submenu.icon = value.icon; | ||
| } | ||
| } else { | ||
| console.warn( | ||
| "Invalid menu configuration for " + | ||
| key + | ||
| ". Expected an array of page identifiers or an object with an items array." | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| buildMenu(submenu.pages, staticPages, menuItems); | ||
|
|
||
| if (submenu.pages.length > 0) { | ||
| pagesMenu.push(submenu); | ||
| } | ||
| } | ||
| }); | ||
| return pagesMenu; | ||
| } | ||
|
|
||
| /** | ||
| * Recompute rendered menu items from loaded pages and current config. | ||
| * | ||
| * When a single item is produced, expose it as `$scope.page` for | ||
| * simplified template handling; otherwise keep list rendering mode. | ||
| */ | ||
| function rebuildMenu() { | ||
| if (!$scope.pages) { | ||
| return; | ||
| } | ||
|
|
||
| $scope.pagesMenu = []; | ||
| buildMenu($scope.pagesMenu, $scope.pages, $scope.pagesConfig); | ||
|
|
||
| if ($scope.pagesMenu.length === 1) { | ||
| $scope.page = $scope.pagesMenu[0]; | ||
| $scope.isSubmenu = $scope.page.type === "submenu"; | ||
| $scope.isExternalLink = | ||
| $scope.page.format === "LINK" || | ||
| $scope.page.format === "EMAILLINK" || | ||
| $scope.page.format === "HTMLPAGE"; | ||
|
|
||
| if ( | ||
| $scope.page.format === "EMAILLINK" && | ||
| $scope.page.link && | ||
| !$scope.page.link.startsWith("mailto:") | ||
| ) { | ||
| $scope.page.link = "mailto:" + $scope.page.link; | ||
| } | ||
| } else { | ||
| $scope.page = null; | ||
| } | ||
| } | ||
|
|
||
| if ($scope.pagesConfig.length > 0) { | ||
| gnStaticPagesService.loadPages($scope.language, $scope.section).then( | ||
| function (response) { | ||
|
|
@@ -149,28 +274,21 @@ | |
| $scope.pages[page.pageId] = page; | ||
| }); | ||
|
|
||
| gnStaticPagesService.buildMenu( | ||
| $scope.pagesMenu, | ||
| $scope.pages, | ||
| $scope.pagesConfig | ||
| ); | ||
| if ($scope.pagesMenu.length === 1) { | ||
| $scope.page = $scope.pagesMenu[0]; | ||
| $scope.isSubmenu = $scope.page.type === "submenu"; | ||
| $scope.isExternalLink = | ||
| $scope.page.format === "LINK" || | ||
| $scope.page.format === "EMAILLINK" || | ||
| $scope.page.format === "HTMLPAGE"; | ||
|
|
||
| if ($scope.page.format === "EMAILLINK") { | ||
| $scope.page.link = "mailto:" + $scope.page.link; | ||
| } | ||
| } | ||
| rebuildMenu(); | ||
| }, | ||
| function (response) { | ||
| $scope.pagesList = null; | ||
| } | ||
| ); | ||
|
|
||
| // Rebuild visibility-dependent menu items when context or any nested value changes. | ||
| $scope.$watch( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deep $watch over the entire metadata record, which can be a large object, dirty-checks the whole graph on every digest and rebuilds the menu on any nested change. Not sure why context has been changed to include all the metadata, it should be more efficient to keep as previously adding the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in latest push |
||
| "context", | ||
| function () { | ||
| rebuildMenu(); | ||
| }, | ||
| true | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using
db.migration_onstartup=falsewhich setshibernate.hbm2ddl.auto=validate, the new columns will not be created, probably better to add the new columns in the migration scripts.On upgrade, Hibernate will find the entity declaring the new columns that don't exist in the DB and fail startup.
With the default
db.migration_onstartup=truethis problem will not happen.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in latest push