Skip to content

Commit dd338ed

Browse files
authored
Merge pull request #19 from AdvancedPhotonSource/menubar-link-plugin
Menubar Link Plugin
2 parents 530afe0 + f6493b5 commit dd338ed

27 files changed

Lines changed: 685 additions & 74 deletions
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test Plugin Utilities
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tools/developer_tools/logr_plugins/**'
7+
- '.github/workflows/test-plugin-utilities.yml'
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: Run Plugin Utility Tests
13+
runs-on: ubuntu-latest
14+
15+
defaults:
16+
run:
17+
working-directory: tools/developer_tools/logr_plugins
18+
19+
strategy:
20+
matrix:
21+
python-version: ['3.11', '3.12']
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
32+
- name: Install pytest
33+
run: python -m pip install --upgrade pip pytest
34+
35+
- name: Run tests
36+
run: python -m pytest test/ -v

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ test-db:
4343
test:
4444
$(TOP)/sbin/cdb_test.sh
4545

46+
test-plugins:
47+
cd $(TOP)/tools/developer_tools/logr_plugins && python -m pytest test/ -v
48+
4649
db:
4750
$(TOP)/sbin/cdb_create_db.sh
4851

src/java/LogrPortal/src/java/gov/anl/aps/logr/portal/plugins/CdbPluginManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ public void loadInfoActionForPropertyValue(PropertyValue propertyValue) {
110110
}
111111
}
112112

113+
public List<Object> getAllMenuBarItems() {
114+
List<Object> allItems = new ArrayList<>();
115+
for (PluginManagerBase pluginManager : pluginManagerSet) {
116+
List<?> items = pluginManager.getMenuBarItems();
117+
if (items != null && !items.isEmpty()) {
118+
allItems.addAll(items);
119+
}
120+
}
121+
return allItems;
122+
}
123+
113124
public PluginManagerBase getPluginManagerByName(String pluginName) {
114125
for (PluginManagerBase pluginManager : pluginManagerSet) {
115126
if (pluginManager.getPluginName().equals(pluginName)) {

src/java/LogrPortal/src/java/gov/anl/aps/logr/portal/plugins/PluginManagerBase.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import gov.anl.aps.logr.portal.model.jsf.handlers.PropertyTypeHandlerInterface;
99
import gov.anl.aps.logr.portal.utilities.ConfigurationUtility;
1010
import gov.anl.aps.logr.portal.utilities.SessionUtility;
11+
import java.util.Collections;
12+
import java.util.List;
1113
import java.util.Properties;
1214

1315
/**
@@ -97,8 +99,17 @@ public static Properties getDefaultPropertiesForPlugin(String pluginName) {
9799
}
98100

99101
/**
100-
* Override to display an extras tab for configuration on the multi edit screen.
101-
*
102+
* Override to provide menu bar items from a plugin.
103+
*
104+
* @return list of menu bar item objects, empty list by default
105+
*/
106+
public List<?> getMenuBarItems() {
107+
return Collections.emptyList();
108+
}
109+
110+
/**
111+
* Override to display an extras tab for configuration on the multi edit screen.
112+
*
102113
* @return display the extra tab when true
103114
*/
104115
public boolean pluginHasCatalogMultiEditExtras() {

src/java/LogrPortal/web/templates/portalViewMenubarTemplate.xhtml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ See LICENSE file.
5656
</c:forEach>
5757
</p:submenu>
5858

59-
6059
<f:facet name="options">
6160
<p:menubar styleClass="menuBarSupportingItems">
6261

@@ -79,8 +78,27 @@ See LICENSE file.
7978
value="Advanced Search"
8079
update="@form"
8180
styleClass="onlyIconMenuItem"
82-
action="#{searchController.performInputBoxSearchAdvamced()}" />
83-
81+
action="#{searchController.performInputBoxSearchAdvamced()}" />
82+
83+
<c:forEach items="#{cdbPluginManager.allMenuBarItems}" var="pluginMenuItem">
84+
<c:if test="#{!pluginMenuItem.hasChildren}">
85+
<p:menuitem value="#{pluginMenuItem.text}"
86+
icon="#{pluginMenuItem.icon}"
87+
url="#{pluginMenuItem.href}"
88+
target="_blank"/>
89+
</c:if>
90+
<c:if test="#{pluginMenuItem.hasChildren}">
91+
<p:submenu label="#{pluginMenuItem.text}"
92+
icon="#{pluginMenuItem.icon}">
93+
<c:forEach items="#{pluginMenuItem.children}" var="childItem">
94+
<p:menuitem value="#{childItem.text}"
95+
icon="#{childItem.icon}"
96+
url="#{childItem.href}"
97+
target="_blank"/>
98+
</c:forEach>
99+
</p:submenu>
100+
</c:if>
101+
</c:forEach>
84102

85103
<ui:include src="portalViewSupplementalMenubar.xhtml"/>
86104
<p:menuitem value="Login" id="loginButton" onclick="PF('loginDialogWidget').show()" rendered="#{!loginController.loggedIn}" icon="fa fa-sign-in"/>

tools/developer_tools/logr_plugins/deploy_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
Copyright (c) UChicago Argonne, LLC. All rights reserved.
44
See LICENSE file.
@@ -14,7 +14,7 @@
1414
import sys
1515

1616
cdb_db_name = sys.argv[1]
17-
if cdb_db_name == None:
17+
if cdb_db_name is None:
1818
cdb_db_name = 'bely'
1919

2020

tools/developer_tools/logr_plugins/list_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
Copyright (c) UChicago Argonne, LLC. All rights reserved.
44
See LICENSE file.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) UChicago Argonne, LLC. All rights reserved.
3+
* See LICENSE file.
4+
*/
5+
package gov.anl.aps.logr.portal.plugins.support.menuBarLinks;
6+
7+
import java.util.List;
8+
9+
public class MenuBarItemObject {
10+
11+
private String icon;
12+
private String text;
13+
private String href;
14+
private List<MenuBarItemObject> children;
15+
16+
public MenuBarItemObject() {
17+
}
18+
19+
public String getIcon() {
20+
return icon;
21+
}
22+
23+
public void setIcon(String icon) {
24+
this.icon = icon;
25+
}
26+
27+
public String getText() {
28+
return text;
29+
}
30+
31+
public void setText(String text) {
32+
this.text = text;
33+
}
34+
35+
public String getHref() {
36+
return href;
37+
}
38+
39+
public void setHref(String href) {
40+
this.href = href;
41+
}
42+
43+
public List<MenuBarItemObject> getChildren() {
44+
return children;
45+
}
46+
47+
public void setChildren(List<MenuBarItemObject> children) {
48+
this.children = children;
49+
}
50+
51+
public boolean getHasChildren() {
52+
return children != null && !children.isEmpty();
53+
}
54+
55+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) UChicago Argonne, LLC. All rights reserved.
3+
* See LICENSE file.
4+
*/
5+
package gov.anl.aps.logr.portal.plugins.support.menuBarLinks;
6+
7+
import com.google.gson.Gson;
8+
import com.google.gson.GsonBuilder;
9+
import com.google.gson.reflect.TypeToken;
10+
import gov.anl.aps.logr.portal.plugins.PluginManagerBase;
11+
import java.lang.reflect.Type;
12+
import java.util.LinkedList;
13+
import java.util.List;
14+
import java.util.Properties;
15+
16+
public class MenuBarLinksPluginManager extends PluginManagerBase {
17+
18+
private static final Properties MENU_BAR_LINKS_PROPERTIES = getDefaultPropertiesForPlugin("menuBarLinks");
19+
20+
private static final String MENU_ITEMS_KEY = "menuItems";
21+
22+
private static List<MenuBarItemObject> MENU_BAR_ITEMS;
23+
24+
public String getMenuItemsJsonTextProperty() {
25+
return MENU_BAR_LINKS_PROPERTIES.getProperty(MENU_ITEMS_KEY, "");
26+
}
27+
28+
private void loadMenuBarItems() {
29+
Type resultType = new TypeToken<LinkedList<MenuBarItemObject>>() {}.getType();
30+
String json = getMenuItemsJsonTextProperty();
31+
32+
Gson gson = new GsonBuilder().create();
33+
MENU_BAR_ITEMS = gson.fromJson(json, resultType);
34+
}
35+
36+
@Override
37+
public List<?> getMenuBarItems() {
38+
if (MENU_BAR_ITEMS == null) {
39+
loadMenuBarItems();
40+
}
41+
return MENU_BAR_ITEMS;
42+
}
43+
44+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# JSON array of menu bar items [{ icon, text, href, children (optional) }]
2+
menuItems=[{"icon": "fa fa-external-link", "text": "Example App", "href": "https://example.com"}]

0 commit comments

Comments
 (0)