diff --git a/hal-core/resource/resource/web/main_index.tmpl b/hal-core/resource/resource/web/main_index.tmpl index 5f2cd06f..14ffdf55 100644 --- a/hal-core/resource/resource/web/main_index.tmpl +++ b/hal-core/resource/resource/web/main_index.tmpl @@ -27,94 +27,21 @@ - - -
-
- {{#showSubNav}} - - - {{/showSubNav}} - - {{#showSubNav}}
{{/showSubNav}} - {{^showSubNav}}
{{/showSubNav}} - {{alerts}} - {{content}} -
- -
-
diff --git a/hal-core/resource/resource/web/main_nav.tmpl b/hal-core/resource/resource/web/main_nav.tmpl new file mode 100644 index 00000000..b8ddc259 --- /dev/null +++ b/hal-core/resource/resource/web/main_nav.tmpl @@ -0,0 +1,65 @@ + \ No newline at end of file diff --git a/hal-core/resource/resource/web/main_nav_side.tmpl b/hal-core/resource/resource/web/main_nav_side.tmpl new file mode 100644 index 00000000..346a658b --- /dev/null +++ b/hal-core/resource/resource/web/main_nav_side.tmpl @@ -0,0 +1,10 @@ + + diff --git a/hal-core/src/se/hal/intf/HalWebPage.java b/hal-core/src/se/hal/intf/HalWebPage.java index aa908907..1a14baac 100644 --- a/hal-core/src/se/hal/intf/HalWebPage.java +++ b/hal-core/src/se/hal/intf/HalWebPage.java @@ -12,22 +12,29 @@ import zutil.parser.Templator; import zutil.ui.Navigation; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; + public abstract class HalWebPage implements HttpPage{ - private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/main_index.tmpl"; + private static final String TEMPLATE_MAIN = HalContext.RESOURCE_WEB_ROOT + "/main_index.tmpl"; + private static final String TEMPLATE_NAVIGATION = HalContext.RESOURCE_WEB_ROOT + "/main_nav.tmpl"; + private static final String TEMPLATE_SIDE_NAVIGATION = HalContext.RESOURCE_WEB_ROOT + "/main_nav_side.tmpl"; + private static Navigation rootNav = Navigation.createRootNav(); private static Navigation userNav = Navigation.createRootNav(); private String pageId; private boolean showSubNav; + public HalWebPage(String id){ this.pageId = id; this.showSubNav = true; } + public String getId(){ return pageId; } @@ -41,19 +48,39 @@ public abstract class HalWebPage implements HttpPage{ try { DBConnection db = HalContext.getDB(); - Templator tmpl = new Templator(FileUtil.find(TEMPLATE)); - tmpl.set("user", User.getLocalUser(db)); - tmpl.set("showSubNav", showSubNav); - if (showSubNav) { - List breadcrumb = Navigation.getBreadcrumb(Navigation.getPagedNavigation(header)); - if (!breadcrumb.isEmpty()) - tmpl.set("subNav", breadcrumb.get(1).createPagedNavInstance(header).getSubNavs()); + // Prepare common template data + + Map data = new HashMap<>(); + data.put("page", Navigation.getPagedNavigation(header)); + data.put("user", User.getLocalUser(db)); + data.put("rootNav", rootNav.createPagedNavInstance(header).getSubNavs()); + data.put("userNav", userNav.createPagedNavInstance(header).getSubNavs()); + + List breadcrumb = Navigation.getBreadcrumb(Navigation.getPagedNavigation(header)); + if (!breadcrumb.isEmpty()) { + data.put("breadcrumb", breadcrumb); + data.put("subNav", breadcrumb.get(1).createPagedNavInstance(header).getSubNavs()); } - tmpl.set("rootNav", rootNav.createPagedNavInstance(header).getSubNavs()); - tmpl.set("userNav", userNav.createPagedNavInstance(header).getSubNavs()); - tmpl.set("content", httpRespond(session, cookie, request)); - tmpl.set("alerts", HalAlertManager.getInstance().generateAlerts()); // do last so we don't miss any alerts - out.print(tmpl.compile()); + + // Create templates + + Templator navigationTemplate = new Templator(FileUtil.find(TEMPLATE_NAVIGATION)); + navigationTemplate.setAll(data); + + Templator subNavigationTemplate = null; + if (showSubNav) { + subNavigationTemplate = new Templator(FileUtil.find(TEMPLATE_SIDE_NAVIGATION)); + subNavigationTemplate.setAll(data); + } + + Templator main = new Templator(FileUtil.find(TEMPLATE_MAIN)); + main.setAll(data); + main.set("navigation", navigationTemplate); + main.set("side_navigation", subNavigationTemplate); + main.set("content", httpRespond(session, cookie, request)); + main.set("alerts", HalAlertManager.getInstance().generateAlerts()); // do last so we don't miss any alerts + + out.print(main.compile()); } catch (Exception e) { throw new IOException(e); }