Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/test-plugin-utilities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test Plugin Utilities

on:
pull_request:
paths:
- 'tools/developer_tools/logr_plugins/**'
- '.github/workflows/test-plugin-utilities.yml'
workflow_dispatch:

jobs:
test:
name: Run Plugin Utility Tests
runs-on: ubuntu-latest

defaults:
run:
working-directory: tools/developer_tools/logr_plugins

strategy:
matrix:
python-version: ['3.11', '3.12']

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install pytest
run: python -m pip install --upgrade pip pytest

- name: Run tests
run: python -m pytest test/ -v
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ test-db:
test:
$(TOP)/sbin/cdb_test.sh

test-plugins:
cd $(TOP)/tools/developer_tools/logr_plugins && python -m pytest test/ -v

db:
$(TOP)/sbin/cdb_create_db.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public void loadInfoActionForPropertyValue(PropertyValue propertyValue) {
}
}

public List<Object> getAllMenuBarItems() {
List<Object> allItems = new ArrayList<>();
for (PluginManagerBase pluginManager : pluginManagerSet) {
List<?> items = pluginManager.getMenuBarItems();
if (items != null && !items.isEmpty()) {
allItems.addAll(items);
}
}
return allItems;
}

public PluginManagerBase getPluginManagerByName(String pluginName) {
for (PluginManagerBase pluginManager : pluginManagerSet) {
if (pluginManager.getPluginName().equals(pluginName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import gov.anl.aps.logr.portal.model.jsf.handlers.PropertyTypeHandlerInterface;
import gov.anl.aps.logr.portal.utilities.ConfigurationUtility;
import gov.anl.aps.logr.portal.utilities.SessionUtility;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

/**
Expand Down Expand Up @@ -97,8 +99,17 @@ public static Properties getDefaultPropertiesForPlugin(String pluginName) {
}

/**
* Override to display an extras tab for configuration on the multi edit screen.
*
* Override to provide menu bar items from a plugin.
*
* @return list of menu bar item objects, empty list by default
*/
public List<?> getMenuBarItems() {
return Collections.emptyList();
}

/**
* Override to display an extras tab for configuration on the multi edit screen.
*
* @return display the extra tab when true
*/
public boolean pluginHasCatalogMultiEditExtras() {
Expand Down
24 changes: 21 additions & 3 deletions src/java/LogrPortal/web/templates/portalViewMenubarTemplate.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ See LICENSE file.
</c:forEach>
</p:submenu>


<f:facet name="options">
<p:menubar styleClass="menuBarSupportingItems">

Expand All @@ -79,8 +78,27 @@ See LICENSE file.
value="Advanced Search"
update="@form"
styleClass="onlyIconMenuItem"
action="#{searchController.performInputBoxSearchAdvamced()}" />

action="#{searchController.performInputBoxSearchAdvamced()}" />

<c:forEach items="#{cdbPluginManager.allMenuBarItems}" var="pluginMenuItem">
<c:if test="#{!pluginMenuItem.hasChildren}">
<p:menuitem value="#{pluginMenuItem.text}"
icon="#{pluginMenuItem.icon}"
url="#{pluginMenuItem.href}"
target="_blank"/>
</c:if>
<c:if test="#{pluginMenuItem.hasChildren}">
<p:submenu label="#{pluginMenuItem.text}"
icon="#{pluginMenuItem.icon}">
<c:forEach items="#{pluginMenuItem.children}" var="childItem">
<p:menuitem value="#{childItem.text}"
icon="#{childItem.icon}"
url="#{childItem.href}"
target="_blank"/>
</c:forEach>
</p:submenu>
</c:if>
</c:forEach>

<ui:include src="portalViewSupplementalMenubar.xhtml"/>
<p:menuitem value="Login" id="loginButton" onclick="PF('loginDialogWidget').show()" rendered="#{!loginController.loggedIn}" icon="fa fa-sign-in"/>
Expand Down
4 changes: 2 additions & 2 deletions tools/developer_tools/logr_plugins/deploy_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) UChicago Argonne, LLC. All rights reserved.
See LICENSE file.
Expand All @@ -14,7 +14,7 @@
import sys

cdb_db_name = sys.argv[1]
if cdb_db_name == None:
if cdb_db_name is None:
cdb_db_name = 'bely'


Expand Down
2 changes: 1 addition & 1 deletion tools/developer_tools/logr_plugins/list_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) UChicago Argonne, LLC. All rights reserved.
See LICENSE file.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) UChicago Argonne, LLC. All rights reserved.
* See LICENSE file.
*/
package gov.anl.aps.logr.portal.plugins.support.menuBarLinks;

import java.util.List;

public class MenuBarItemObject {

private String icon;
private String text;
private String href;
private List<MenuBarItemObject> children;

public MenuBarItemObject() {
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getHref() {
return href;
}

public void setHref(String href) {
this.href = href;
}

public List<MenuBarItemObject> getChildren() {
return children;
}

public void setChildren(List<MenuBarItemObject> children) {
this.children = children;
}

public boolean getHasChildren() {
return children != null && !children.isEmpty();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) UChicago Argonne, LLC. All rights reserved.
* See LICENSE file.
*/
package gov.anl.aps.logr.portal.plugins.support.menuBarLinks;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import gov.anl.aps.logr.portal.plugins.PluginManagerBase;
import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;

public class MenuBarLinksPluginManager extends PluginManagerBase {

private static final Properties MENU_BAR_LINKS_PROPERTIES = getDefaultPropertiesForPlugin("menuBarLinks");

private static final String MENU_ITEMS_KEY = "menuItems";

private static List<MenuBarItemObject> MENU_BAR_ITEMS;

public String getMenuItemsJsonTextProperty() {
return MENU_BAR_LINKS_PROPERTIES.getProperty(MENU_ITEMS_KEY, "");
}

private void loadMenuBarItems() {
Type resultType = new TypeToken<LinkedList<MenuBarItemObject>>() {}.getType();
String json = getMenuItemsJsonTextProperty();

Gson gson = new GsonBuilder().create();
MENU_BAR_ITEMS = gson.fromJson(json, resultType);
}

@Override
public List<?> getMenuBarItems() {
if (MENU_BAR_ITEMS == null) {
loadMenuBarItems();
}
return MENU_BAR_ITEMS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# JSON array of menu bar items [{ icon, text, href, children (optional) }]
menuItems=[{"icon": "fa fa-external-link", "text": "Example App", "href": "https://example.com"}]
2 changes: 1 addition & 1 deletion tools/developer_tools/logr_plugins/remove_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) UChicago Argonne, LLC. All rights reserved.
See LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion tools/developer_tools/logr_plugins/save_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Copyright (c) UChicago Argonne, LLC. All rights reserved.
See LICENSE file.
Expand Down
Empty file.
42 changes: 42 additions & 0 deletions tools/developer_tools/logr_plugins/test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Copyright (c) UChicago Argonne, LLC. All rights reserved.
See LICENSE file.
"""

import os
import pytest

# Plugins that are excluded from compliance tests (deprecated)
EXCLUDED_PLUGINS = {"pdmLink"}

LOGR_PLUGINS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


@pytest.fixture
def plugins_dir():
"""Absolute path to logr_plugins/plugins/."""
return os.path.join(LOGR_PLUGINS_DIR, "plugins")


@pytest.fixture
def plugin_templates_dir():
"""Absolute path to logr_plugins/pluginTemplates/."""
return os.path.join(LOGR_PLUGINS_DIR, "pluginTemplates")


@pytest.fixture
def plugin_names(plugins_dir):
"""List of all non-excluded plugin directory names."""
names = sorted(
d
for d in os.listdir(plugins_dir)
if os.path.isdir(os.path.join(plugins_dir, d))
and d not in EXCLUDED_PLUGINS
)
return names


@pytest.fixture
def tmp_deploy_dir(tmp_path):
"""Temporary directory simulating deployment paths for parser tests."""
return tmp_path / "deploy"
Loading