Skip to content

Commit 9185818

Browse files
authored
openequella#637,openequella#624,openequella#619 Add icon and newWindow field, ensure externals urls come through (openequella#645)
1 parent 65057f8 commit 9185818

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

Source/Plugins/Core/com.equella.core/js/src/MainUI/Template.purs

+17-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ import OEQ.Utils.Interop (nullAny)
6464
import Partial.Unsafe (unsafePartial)
6565
import React (Children, ReactClass, ReactElement, ReactThis, childrenToArray, createElement)
6666
import React as R
67-
import React.DOM (div', footer, span', text)
67+
import React.DOM (div', footer, img, span', text)
6868
import React.DOM as D
69+
import React.DOM.Props (src)
6970
import React.DOM.Props as DP
7071
import Web.DOM.DOMTokenList as DOMTokens
7172
import Web.DOM.Document (documentElement)
@@ -78,7 +79,13 @@ import Web.HTML.HTMLElement as HTML
7879
import Web.HTML.Window (document, toEventTarget)
7980

8081
newtype ExternalHref = ExternalHref String
81-
newtype MenuItem = MenuItem {route::Either ExternalHref String, title::String, systemIcon::Maybe String}
82+
newtype MenuItem = MenuItem {
83+
route::Either ExternalHref String,
84+
title::String,
85+
systemIcon::Maybe String,
86+
iconUrl :: Maybe String,
87+
newWindow :: Boolean
88+
}
8289

8390
data Command = Init | AttemptRoute Route | NavAway Boolean
8491
| ToggleMenu | UserMenuAnchor (Maybe HTMLElement) | MenuClick Route | GoBack | CloseError
@@ -330,15 +337,17 @@ templateClass = withStyles ourStyles $ R.component "Template" $ \this -> do
330337
where
331338
logoSrc = logoPath
332339
group items = [list {component: "nav"} (navItem <$> items)]
333-
navItem (MenuItem {title,systemIcon,route}) = linkProps
340+
navItem (MenuItem {title,systemIcon,route,iconUrl,newWindow}) = linkProps
334341
[
335-
listItemIcon_ $ icon {color: inherit} [ D.text $ fromMaybe "folder" $ systemIcon ],
342+
listItemIcon_ $ case iconUrl of
343+
Just url -> img [src url]
344+
Nothing -> icon {color: inherit} [ D.text $ fromMaybe "folder" $ systemIcon ],
336345
listItemText' {disableTypography: true, primary: typography {variant: subheading, component: "div"} [text title] }
337346
]
338347
where
339348
linkProps = case route of
340349
Right r | Just m <- routeHref <$> matchRoute r -> RMUI.listItem { component: "a", href: m.href, onClick: m.onClick }
341-
Left (ExternalHref href) -> RMUI.listItem { component: "a", href }
350+
Left (ExternalHref href) -> RMUI.listItem { component: "a", href, target: if newWindow then "_blank" else "" }
342351
Right r -> RMUI.listItem {component: "a", href: show r}
343352

344353
htmlElement :: Effect HTMLElement
@@ -561,7 +570,9 @@ instance decodeMI :: DecodeJson MenuItem where
561570
_ -> Right "home.do"
562571
title <- o .? "title"
563572
systemIcon <- o .?? "systemIcon"
564-
pure $ MenuItem {title, route, systemIcon}
573+
iconUrl <- o .?? "iconUrl"
574+
newWindow <- o .? "newWindow"
575+
pure $ MenuItem {title, route, systemIcon, iconUrl, newWindow}
565576

566577
decodeCounts :: Json -> Either String Counts
567578
decodeCounts v = do

Source/Plugins/Core/com.equella.core/scalasrc/com/tle/web/api/LegacyContentApi.scala

+13-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ case class InternalRedirect(route: String, userUpdated: Boolean)
6666

6767
case class ExternalRedirect(href: String)
6868

69-
case class MenuItem(title: String, href: Option[String], systemIcon: Option[String], route: Option[String])
69+
case class MenuItem(title: String, href: Option[String], systemIcon: Option[String], route: Option[String],
70+
iconUrl: Option[String], newWindow: Boolean)
7071

7172
case class LegacyContent
7273
(html: Map[String, String],
@@ -94,15 +95,15 @@ object LegacyContentController extends AbstractSectionsController with SectionFi
9495

9596
import LegacyGuice.urlService
9697

97-
def relativeURI(uri: String): Option[String] = {
98+
def relativeURI(uri: String): Option[RelativeUrl] = {
9899
val baseUrl = AbsoluteUrl.parse(urlService.getBaseInstitutionURI.toString)
99100
val Host = baseUrl.host
100101
val Port = baseUrl.port
101102
val basePaths = baseUrl.path.parts.filter(_.length > 0)
102103
Url.parse(uri) match {
103-
case RelativeUrl(RootlessPath(_), _, _) => Some(uri)
104+
case r: RelativeUrl => Some(r)
104105
case AbsoluteUrl(_, Authority(_, Host, Port), path, q, f) if path.parts.startsWith(basePaths) =>
105-
Some(RelativeUrl(RootlessPath(path.parts.drop(basePaths.length)), q, f).toString())
106+
Some(RelativeUrl(RootlessPath(path.parts.drop(basePaths.length)), q, f))
106107
case _ => None
107108
}
108109
}
@@ -260,12 +261,16 @@ class LegacyContentApi {
260261
val menuLink = mc.getLink
261262
val href = Option(menuLink.getBookmark).getOrElse(
262263
new BookmarkAndModify(context, menuLink.getHandlerMap.getHandler("click").getModifier)).getHref
263-
val relativized = LegacyContentController.relativeURI(href)
264-
264+
val relativized = LegacyContentController.relativeURI(href).filter(_.path.parts.last.endsWith(".do"))
265+
val route = Option(mc.getRoute)
266+
val iconUrl = if (mc.isCustomImage) Some(mc.getBackgroundImagePath) else None
265267
MenuItem(menuLink.getLabelText,
266-
None,
268+
if (relativized.isEmpty && route.isEmpty) Some(href) else None,
267269
Option(mc.getSystemIcon),
268-
Option(mc.getRoute).orElse(relativized))
270+
route.orElse(relativized.map(_.toString)),
271+
iconUrl,
272+
"_blank" == menuLink.getTarget
273+
)
269274
}
270275
}
271276
}

Source/Plugins/Core/com.equella.core/src/com/tle/web/customlinks/menu/CustomLinksMenuContributor.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ private MenuContribution newLink(String name, String url, int order, boolean new
110110
link.setLabel(new TextLabel(name));
111111
link.setTarget(target);
112112

113-
return new MenuContribution(link, iconUrl, 20, order);
113+
MenuContribution mc = new MenuContribution(link, iconUrl, 20, order);
114+
mc.setCustomImage(true);
115+
return mc;
114116
}
115117

116118
@Override

Source/Plugins/Core/com.equella.core/src/com/tle/web/template/section/MenuContributor.java

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MenuContribution
3535
private final int linkPriority;
3636
private final String systemIcon;
3737
private final String route;
38+
private boolean customImage;
3839

3940
public MenuContribution(HtmlLinkState link, String backgroundImage, int groupPriority, int linkPriority, String systemIcon,
4041
String route)
@@ -72,6 +73,16 @@ public String getBackgroundImagePath()
7273
return backgroundImagePath;
7374
}
7475

76+
public boolean isCustomImage()
77+
{
78+
return customImage;
79+
}
80+
81+
public void setCustomImage(boolean customImage)
82+
{
83+
this.customImage = customImage;
84+
}
85+
7586
public int getGroupPriority()
7687
{
7788
return groupPriority;

0 commit comments

Comments
 (0)