Skip to content

Commit

Permalink
WEB-3957 : Add new "Please help!" menu in Plone toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
boulch committed Aug 17, 2023
1 parent 1511b0b commit 9ad5ca4
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
1.1.20 (unreleased)
-------------------

- WEB-3957 : Add new "Please help!" menu in Plone toolbar
[boulch]

- WEB-3972 : Add "elloha" plugin in external content section
[boulch]

Expand Down
4 changes: 3 additions & 1 deletion src/imio/smartweb/core/browser/static/src/edit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './edit.less'
jQuery(document).ready(function ($) {

// Hide / show editor's tools & messages when clicking on "Preview" in Plone toolbar
$("#contentview-preview a").click(function(e){
$(".hide-in-preview, #section-byline, #global_statusmessage").toggle("fast");
Expand All @@ -11,5 +10,8 @@ jQuery(document).ready(function ($) {
var auth_sources = $("#plone-authentic-sources-menu").wrap("<ul class='plonetoolbar-authentic-sources-menu'>").parent();
$(".personaltools-wrapper").prepend(auth_sources);

// Move smartweb help menu just before user/personaltools-menulink in Plone toolbar
var smartweb_help = $("#plone-smartweb-help-menu").wrap("<ul class='plonetoolbar-smartweb-help-menu'>").parent();
$(".personaltools-wrapper").prepend(smartweb_help);
});

5 changes: 5 additions & 0 deletions src/imio/smartweb/core/browser/static/src/edit.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ ul.plonetoolbar-authentic-sources-menu {
padding-inline-start: 0;
width: 100%;
}

ul.plonetoolbar-smartweb-help-menu {
padding-inline-start: 0;
width: 100%;
}
16 changes: 14 additions & 2 deletions src/imio/smartweb/core/viewlets/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@
/>

<browser:menu
id="authentic-sources-menu"
title=""
id="plone_authentic_sources_menu"
title="Authentic sources menu"
class=".toolbar.AuthenticSourcesMenu"
/>

Expand All @@ -340,4 +340,16 @@
factory=".toolbar.AuthenticSourcesMenuItem"
provides="plone.app.contentmenu.interfaces.IContentMenuItem" />

<browser:menu
id="plone_smartweb_help_menu"
title="Smartweb help menu"
class=".toolbar.SmartwebHelpMenu"
/>

<adapter
for="* *"
name="smartweb.menu.smartweb_help"
factory=".toolbar.SmartwebHelpMenuItem"
provides="plone.app.contentmenu.interfaces.IContentMenuItem" />

</configure>
20 changes: 20 additions & 0 deletions src/imio/smartweb/core/viewlets/interfaces.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from zope.browsermenu.interfaces import IBrowserMenu
from zope.browsermenu.interfaces import IBrowserSubMenuItem


class IAuthenticSourcesMenu(IBrowserMenu):
"""The authentic sources menu."""


class ISmartwebHelpMenu(IBrowserMenu):
"""The smartweb help menu."""


class IAuthenticSourcesSubMenuItem(IBrowserSubMenuItem):
"""The authentic sources submenu item."""


class ISmartwebHelpSubMenuItem(IBrowserSubMenuItem):
"""The smartweb help submenu item."""
117 changes: 108 additions & 9 deletions src/imio/smartweb/core/viewlets/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

from imio.smartweb.core import config
from imio.smartweb.core.utils import get_json
from imio.smartweb.core.viewlets.interfaces import IAuthenticSourcesMenu
from imio.smartweb.core.viewlets.interfaces import IAuthenticSourcesSubMenuItem
from imio.smartweb.core.viewlets.interfaces import ISmartwebHelpMenu
from imio.smartweb.core.viewlets.interfaces import ISmartwebHelpSubMenuItem
from imio.smartweb.locales import SmartwebMessageFactory as _
from plone import api
from plone.app.contentmenu.menu import BrowserMenu
from plone.app.contentmenu.menu import BrowserSubMenuItem
from plone.memoize import ram
from time import time
from zope.browsermenu.interfaces import IBrowserMenu
from zope.interface import implementer

import os
import re


@implementer(IBrowserMenu)
def _cache_key(func, obj, context, request):
return (obj.id, time() // (5 * 60))


@implementer(IAuthenticSourcesSubMenuItem)
class AuthenticSourcesMenuItem(BrowserSubMenuItem):
title = _("Authentic sources")
submenuId = "authentic-sources-menu"
submenuId = "plone_authentic_sources_menu"
icon = "boxes"
extra = {
"id": "plone-authentic-sources-menu",
Expand Down Expand Up @@ -49,9 +57,9 @@ def selected(self):
return False


@implementer(IBrowserMenu)
@implementer(IAuthenticSourcesMenu)
class AuthenticSourcesMenu(BrowserMenu):
@ram.cache(lambda *args: time() // (60 * 60))
@ram.cache(_cache_key)
def getMenuItems(self, context, request):
news_entity_url = self.get_entity_from_authentic_source(
config.NEWS_URL, "smartweb.news_entity_uid"
Expand All @@ -62,9 +70,13 @@ def getMenuItems(self, context, request):
directory_entity_url = self.get_entity_from_authentic_source(
config.DIRECTORY_URL, "smartweb.directory_entity_uid"
)
news = {"url": news_entity_url, "icon": "newspaper"}
events = {"url": events_entity_url, "icon": "calendar-event"}
directory = {"url": directory_entity_url, "icon": "file-person"}
news = {"url": news_entity_url, "icon": "newspaper", "id": "news"}
events = {"url": events_entity_url, "icon": "calendar-event", "id": "events"}
directory = {
"url": directory_entity_url,
"icon": "file-person",
"id": "directory",
}
authentic_sources = [news, events, directory]

menu_items = []
Expand All @@ -79,7 +91,11 @@ def getMenuItems(self, context, request):
"action": source["url"],
"selected": False,
"icon": source["icon"],
"extra": {"id": "some-id", "separator": None, "class": ""},
"extra": {
"id": f'plone-authentic-sources-menu{source["id"]}',
"separator": None,
"class": "",
},
"submenu": None,
}
menu_items.append(menu_item)
Expand All @@ -93,3 +109,86 @@ def get_entity_from_authentic_source(self, authentic_sources_url, registry_key):
if not result or not result.get("items"):
return None
return result.get("items")[0].get("@id")


@implementer(ISmartwebHelpSubMenuItem)
class SmartwebHelpMenuItem(BrowserSubMenuItem):
title = _("Please help!")
submenuId = "plone_smartweb_help_menu"
icon = "info-circle"
extra = {
"id": "plone-smartweb-help-menu",
"li_class": "plonetoolbar-smartweb-help-menu",
}

order = 50

@property
def action(self):
return "#"

def available(self):
permission = "Modify portal content"
if api.user.has_permission(permission, obj=self.context) is False:
return False
return True


@implementer(ISmartwebHelpMenu)
class SmartwebHelpMenu(BrowserMenu):
@ram.cache(_cache_key)
def getMenuItems(self, context, request):
rtfm_action = os.environ.get(
"help_menu_rtfm", "https://docs.imio.be/iasmartweb/smartweb_v6"
)
support_action = os.environ.get("help_menu_support", "https://support.imio.be")
workshop_action = os.environ.get(
"help_menu_workshop",
"https://my-formulaires.imio.be/ateliers-imio/ateliers-iasmartweb-1"
)

# Read The Funny Manual... (no?)
rtfm = {
"title": _("Read documentation"),
"description": "",
"action": rtfm_action,
"selected": False,
"icon": "eye-fill",
"extra": {
"id": "plone-smartweb-help-menu-rtfm",
"separator": None,
"class": "",
},
"submenu": None,
}

support = {
"title": _("Ask a question"),
"description": "",
"action": support_action,
"selected": False,
"icon": "chat-square-heart-fill",
"extra": {
"id": "plone-smartweb-help-menu-support",
"separator": None,
"class": "",
},
"submenu": None,
}

workshop = {
"title": _("Take part of workshop"),
"description": "",
"action": workshop_action,
"selected": False,
"icon": "rocket-takeoff-fill",
"extra": {
"id": "plone-smartweb-help-menu-workshop",
"separator": None,
"class": "",
},
"submenu": None,
}

menu_items = [rtfm, support, workshop]
return menu_items

0 comments on commit 9ad5ca4

Please sign in to comment.