Skip to content

Commit

Permalink
Dynamic Workflow Menu (#2137)
Browse files Browse the repository at this point in the history
* Added menu provider

* Implemented WF Menu Updater

* Production JS

* Changelog updated

* Handle no workflow menu views, e.g. multi_results

* Production JS

* Log warning instead of throwing an error

* Production JS

* Do not repace WF menu if the server responded exceptionally

* Production JS

* Fetch the current url from the attribute dataset

* Comment updated
  • Loading branch information
ramonski committed Sep 23, 2022
1 parent 36ece05 commit 5c04635
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
2.3.0 (unreleased)
------------------

- #2137 Dynamic Workflow Menu
- #2139 Fix LabClerk cannot create partitions from received samples
- #2130 Catalog mapping for Samples and Analyses
- #2131 Allow to edit the analysis service sort keys in the services listing
Expand Down
10 changes: 10 additions & 0 deletions src/senaite/core/browser/contentmenu/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
xmlns:five="http://namespaces.zope.org/five"
i18n_domain="plone">

<!-- Menu Provider -->
<browser:page
for="*"
name="menu"
class=".menu_provider.MenuProviderView"
permission="zope2.View"
allowed_attributes="workflow_menu"
layer="senaite.core.interfaces.ISenaiteCore"
/>

<!-- A content provider showing the menu -->

<adapter
Expand Down
8 changes: 8 additions & 0 deletions src/senaite/core/browser/contentmenu/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

from zope.interface import Interface


class IMenuProvider(Interface):
"""View to render a menu/submenu
"""
34 changes: 34 additions & 0 deletions src/senaite/core/browser/contentmenu/menu_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

from Products.Five import BrowserView
from zope.component import getMultiAdapter
from zope.interface import implementer
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

from .interfaces import IMenuProvider


@implementer(IMenuProvider)
class MenuProviderView(BrowserView):
"""View to render a menu/submenu
"""
template = ViewPageTemplateFile('templates/contentmenu.pt')

def __init__(self, context, request):
super(BrowserView, self).__init__(context, request)
self.menu = []

@property
def contentmenu(self):
return getMultiAdapter(
(self.context, self.request, self), name="plone.contentmenu")

def available(self):
return self.contentmenu.available()

def workflow_menu(self):
menu_id = "content_status_history"
menu = self.contentmenu.menu()
self.menu = filter(
lambda m: m.get("action").endswith(menu_id), menu)
return self.template()
2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/senaite/core/browser/static/bundles/main.js.map

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions webpack/app/senaite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,39 @@ document.addEventListener("DOMContentLoaded", () => {
let controller = ReactDOM.render(<AddressWidgetController root_el={widget} />, widget);
window.widgets[id] = controller;
}

// Workflow Menu Update for Ajax Transitions
// https://github.com/senaite/senaite.app.listing/pull/87
document.body.addEventListener("listing:submit", (event) => {
let menu = document.getElementById("plone-contentmenu-workflow");
// return immediately if no workflow menu is present
if (menu === null ) {
return false;
}
// get the base url from the `data-base-url` attribute
let base_url = document.body.dataset.baseUrl;
if (base_url === undefined) {
// fallback to the current location URL
base_url = location.href.split("#")[0].split("?")[0];
}
const request = new Request(base_url + "/menu/workflow_menu");
fetch(request)
.then((response) => {
// we might get a 404 when the current page URL ends with a view, e.g.
// `WS-ID/manage_results` or `CLIENT-ID/multi_results` etc.
if (response.ok) {
return response.text();
}
})
.then((html) => {
if (!html) {
return;
}
let parser = new DOMParser();
let doc = parser.parseFromString(html, "text/html");
let el = doc.body.firstChild;
menu.replaceWith(el);
})
});

});

0 comments on commit 5c04635

Please sign in to comment.