Skip to content

Commit 0b51e2f

Browse files
authored
Merge pull request #19 from wet-boew/18-add-support-for-custom-menu
Adding support for custom menu
2 parents b8b0f02 + ced9e3b commit 0b51e2f

7 files changed

Lines changed: 109 additions & 20 deletions

File tree

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/BannerLink.java renamed to gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/HeaderLink.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package goc.webtemplate;
22

3-
public class BannerLink extends Link{
3+
public class HeaderLink extends Link{
44
private static final long serialVersionUID = 1L;
55

66
private boolean newWindow;
77

8-
public BannerLink() {}
8+
public HeaderLink() {}
99

10-
public BannerLink(String href)
10+
public HeaderLink(String href)
1111
{
1212
this(href, "");
1313
}
1414

15-
public BannerLink(String href, String text)
15+
public HeaderLink(String href, String text)
1616
{
1717
this(href, text, false);
1818
}
1919

20-
public BannerLink(String href, String text, boolean newWindow)
20+
public HeaderLink(String href, String text, boolean newWindow)
2121
{
2222
super(href, text);
2323
this.newWindow = newWindow;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package goc.webtemplate;
2+
3+
import java.util.List;
4+
5+
public class HeaderMenu {
6+
7+
private String text;
8+
private List<HeaderLink> links;
9+
private Link logoutLink;
10+
11+
public HeaderMenu() {}
12+
13+
public HeaderMenu(String text, List<HeaderLink> links, Link logoutLink) {
14+
this.text = text;
15+
this.links = links;
16+
this.logoutLink = logoutLink;
17+
}
18+
19+
public String getText() {
20+
return text;
21+
}
22+
23+
public void setText(String text) {
24+
this.text = text;
25+
}
26+
27+
public List<HeaderLink> getLinks() {
28+
return links;
29+
}
30+
31+
public void setLinks(List<HeaderLink> links) {
32+
this.links = links;
33+
}
34+
35+
public Link getLogoutLink() {
36+
return logoutLink;
37+
}
38+
39+
public void setLogoutLink(Link logoutLink) {
40+
this.logoutLink = logoutLink;
41+
}
42+
}

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/InfoBanner.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
public class InfoBanner {
44
private String mainHTML;
5-
private BannerLink link;
6-
private BannerLink button;
5+
private HeaderLink link;
6+
private HeaderLink button;
77

88
public InfoBanner() {}
99

10-
public InfoBanner(String mainHTML, BannerLink link, BannerLink button)
10+
public InfoBanner(String mainHTML, HeaderLink link, HeaderLink button)
1111
{
1212
this.mainHTML = mainHTML;
1313
this.link = link;
@@ -22,19 +22,19 @@ public void setMainHTML(String mainHTML) {
2222
this.mainHTML = mainHTML;
2323
}
2424

25-
public BannerLink getLink() {
25+
public HeaderLink getLink() {
2626
return link;
2727
}
2828

29-
public void setLink(BannerLink link) {
29+
public void setLink(HeaderLink link) {
3030
this.link = link;
3131
}
3232

33-
public BannerLink getButton() {
33+
public HeaderLink getButton() {
3434
return button;
3535
}
3636

37-
public void setButton(BannerLink button) {
37+
public void setButton(HeaderLink button) {
3838
this.button = button;
3939
}
4040
}

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/component/AbstractCoreBean.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import goc.webtemplate.CustomSearch;
2121
import goc.webtemplate.FooterLink;
2222
import goc.webtemplate.FooterSection;
23+
import goc.webtemplate.HeaderMenu;
2324
import goc.webtemplate.IFooterSection;
2425
import goc.webtemplate.InfoBanner;
2526
import goc.webtemplate.IntranetTitle;
@@ -77,7 +78,7 @@ protected SimpleDateFormat initialValue() {
7778
return new SimpleDateFormat("yyyy-MM-dd");
7879
}
7980
};
80-
81+
8182
/**
8283
* Flag indicating whether the onWebTemplateInitialize has already been called.
8384
*/
@@ -147,6 +148,7 @@ private enum Themes { GCWEB, GCINTRANET }
147148
private ContextualFooter contextualFooter = null;
148149
private boolean hideMainFooter = false;
149150
private boolean hideCorporateFooter = false;
151+
private HeaderMenu headerMenu = null;
150152
//-------------------------------------------------------
151153

152154
//-------------------------------------------------------
@@ -1543,6 +1545,25 @@ public boolean getHideCorporateFooter() {
15431545
public void setHideCorporateFooter(boolean value) {
15441546
this.hideCorporateFooter = value;
15451547
}
1548+
1549+
/**
1550+
* Returns whether to display a header menu on top of the page
1551+
*
1552+
* can be overriden programatically.
1553+
*/
1554+
public HeaderMenu getHeaderMenu() {
1555+
this.initializeOnce();
1556+
return this.headerMenu;
1557+
}
1558+
1559+
/**
1560+
* Sets whether to display a header menu on top of the page
1561+
*
1562+
* can be overriden programatically.
1563+
*/
1564+
public void setHeaderMenu(HeaderMenu value) {
1565+
this.headerMenu = value;
1566+
}
15461567

15471568
/**
15481569
* Returns a copy of the breadcrumb list, ready for JSON serialization
@@ -1952,7 +1973,8 @@ public String getRenderAppTop() {
19521973
this.showPreContent,
19531974
this.customSearch != null? Arrays.asList(this.customSearch): null,
19541975
this.getHasLeftMenuSections(), //topSecMenu, true if there is at least one left menu section defined
1955-
this.infoBanner
1976+
this.infoBanner,
1977+
this.headerMenu
19561978
);
19571979
} else {
19581980
appTop = new AppTop.AppTopGCIntranet(

gocwebtemplate-core/gocwebtemplate-core-base/src/main/java/goc/webtemplate/component/jsonentities/AppTop.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import goc.webtemplate.Breadcrumb;
1010
import goc.webtemplate.CustomSearch;
11+
import goc.webtemplate.HeaderMenu;
1112
import goc.webtemplate.InfoBanner;
1213
import goc.webtemplate.IntranetTitle;
1314
import goc.webtemplate.LanguageLink;
@@ -34,6 +35,7 @@ public class AppTop implements Serializable {
3435
private List<SecMenuItem> menuLinks;
3536
private List<LanguageLink> lngLinks;
3637
private InfoBanner infoBanner;
38+
private HeaderMenu headerMenu;
3739

3840
/**
3941
* This is a List but should only have one item in it.
@@ -62,7 +64,7 @@ public AppTop()
6264

6365
public AppTop(String cdnEnv, String subTheme, String localPath, List<Link> appName, String menuPath,
6466
List<SecMenuItem> menuLinks, List<LanguageLink> lngLinks, List<Link> signIn, List<Link> signOut, List<Link> appSettings,
65-
boolean search, List<Breadcrumb> breadcrumbs, boolean showPreContent, List<CustomSearch> customSearch, boolean topSecMenu, InfoBanner infoBanner) {
67+
boolean search, List<Breadcrumb> breadcrumbs, boolean showPreContent, List<CustomSearch> customSearch, boolean topSecMenu, InfoBanner infoBanner, HeaderMenu headerMenu) {
6668
this.cdnEnv = cdnEnv;
6769
this.subTheme = subTheme;
6870
this.localPath = localPath;
@@ -79,6 +81,7 @@ public AppTop(String cdnEnv, String subTheme, String localPath, List<Link> appNa
7981
this.customSearch = customSearch;
8082
this.topSecMenu = topSecMenu;
8183
this.infoBanner = infoBanner;
84+
this.headerMenu = headerMenu;
8285
}
8386

8487
public String getCdnEnv() {
@@ -209,6 +212,14 @@ public void setInfoBanner(InfoBanner infoBanner) {
209212
this.infoBanner = infoBanner;
210213
}
211214

215+
public HeaderMenu getHeaderMenu() {
216+
return headerMenu;
217+
}
218+
219+
public void setHeaderMenu(HeaderMenu headerMenu) {
220+
this.headerMenu = headerMenu;
221+
}
222+
212223

213224
/**
214225
* For v4.0.27+ we have to render AppTop differently depending on the theme,
@@ -236,7 +247,7 @@ public AppTopGCIntranet(String cdnEnv, String subTheme, String localPath, List<L
236247

237248
super(cdnEnv, subTheme, localPath, appName, menuPath,
238249
menuLinks, lngLinks, signIn, signOut, appSettings,
239-
search, breadcrumbs, showPreContent, customSearch, topSecMenu, null);
250+
search, breadcrumbs, showPreContent, customSearch, topSecMenu, null, null);
240251

241252
this.intranetTitle = intranetTitle;
242253
this.gcToolsModal = gcToolsModal;

gocwebtemplate-core/gocwebtemplate-core-base/src/test/java/goc/webtemplate/component/abstractcorebeantest/RenderAppTopTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import static org.junit.jupiter.api.Assertions.assertTrue;
44

55
import java.util.ArrayList;
6+
import java.util.List;
67

78
import org.junit.jupiter.api.Test;
89

9-
import goc.webtemplate.BannerLink;
10+
import goc.webtemplate.HeaderLink;
11+
import goc.webtemplate.HeaderMenu;
1012
import goc.webtemplate.InfoBanner;
1113
import goc.webtemplate.Link;
1214
import goc.webtemplate.MenuItem;
@@ -33,11 +35,25 @@ public void testCustomMenuItem() {
3335
public void testInfoBanner() {
3436
AbstractCoreBeanImpl sut = new AbstractCoreBeanImpl();
3537

36-
InfoBanner banner = new InfoBanner("Main Text", new BannerLink("google", "Link"), new BannerLink("yahoo", "Button"));
38+
InfoBanner banner = new InfoBanner("Main Text", new HeaderLink("google", "Link"), new HeaderLink("yahoo", "Button"));
3739
sut.setInfoBanner(banner);
3840

3941
assertTrue(sut.getRenderAppTop().contains("\"infoBanner\":{\"mainHTML\":\"Main Text\",\"link\":{\"newWindow\":false,\"href\":\"google\",\"text\":\"Link\"},\"button\":{\"newWindow\":false,\"href\":\"yahoo\",\"text\":\"Button\"}"),
4042
"\"RenderTop: InfoBanner not rendered as expected.\"");
4143
}
4244

45+
@Test
46+
public void testHeaderMenu() {
47+
AbstractCoreBeanImpl sut = new AbstractCoreBeanImpl();
48+
49+
List<HeaderLink> list = new ArrayList<HeaderLink>();
50+
list.add(new HeaderLink("google", "Link 1"));
51+
list.add(new HeaderLink("google", "Link 2", true));
52+
53+
HeaderMenu menu = new HeaderMenu("Main Text", list, new Link("google", "Logout Now"));
54+
sut.setHeaderMenu(menu);
55+
String x = sut.getRenderAppTop();
56+
assertTrue(sut.getRenderAppTop().contains("\"headerMenu\":{\"text\":\"Main Text\",\"links\":[{\"newWindow\":false,\"href\":\"google\",\"text\":\"Link 1\"},{\"newWindow\":true,\"href\":\"google\",\"text\":\"Link 2\"}],\"logoutLink\":{\"href\":\"google\",\"text\":\"Logout Now\"}}"),
57+
"\"RenderTop: HeaderMenu not rendered as expected.\"");
58+
}
4359
}

gocwebtemplate-core/gocwebtemplate-core-base/src/test/java/goc/webtemplate/component/abstractcorebeantest/RenderFooterTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
import org.junit.jupiter.api.Test;
99

10-
import goc.webtemplate.BannerLink;
1110
import goc.webtemplate.ContextualFooter;
1211
import goc.webtemplate.FooterLink;
13-
import goc.webtemplate.Link;
1412

1513
public class RenderFooterTest {
1614

0 commit comments

Comments
 (0)