From 48bddd435df8f2e2ef3f05d4ecf8b6cdb09ae3a7 Mon Sep 17 00:00:00 2001 From: Martin Spielmann Date: Sun, 31 Jul 2016 17:34:17 +0200 Subject: [PATCH] Fix bootstrap and angular resources --- .classpath | 2 +- .../com/gitblit/wicket/ng/NgController.java | 16 ++++++++++-- .../com/gitblit/wicket/pages/BasePage.html | 2 +- .../com/gitblit/wicket/pages/BasePage.java | 8 ++++-- .../wicket/resources/bootstrap/Bootstrap.java | 26 +++++++++++++++++-- 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.classpath b/.classpath index 3b008223..d531303b 100644 --- a/.classpath +++ b/.classpath @@ -112,7 +112,7 @@ - + diff --git a/src/main/java/com/gitblit/wicket/ng/NgController.java b/src/main/java/com/gitblit/wicket/ng/NgController.java index 648a12d9..65ba78cd 100644 --- a/src/main/java/com/gitblit/wicket/ng/NgController.java +++ b/src/main/java/com/gitblit/wicket/ng/NgController.java @@ -17,13 +17,16 @@ package com.gitblit.wicket.ng; import java.text.MessageFormat; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.wicket.Component; import org.apache.wicket.behavior.Behavior; +import org.apache.wicket.markup.head.HeaderItem; import org.apache.wicket.markup.head.IHeaderResponse; import org.apache.wicket.markup.head.JavaScriptHeaderItem; import org.apache.wicket.request.resource.PackageResourceReference; +import org.apache.wicket.resource.JQueryResourceReference; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -56,7 +59,16 @@ public class NgController extends Behavior { @Override public void renderHead(Component component, IHeaderResponse response) { // add Google AngularJS reference - response.render(JavaScriptHeaderItem.forReference(new PackageResourceReference(NgController.class, "angular.js"))); + response.render(JavaScriptHeaderItem.forReference(new PackageResourceReference(NgController.class, "angular.js"){ + private static final long serialVersionUID = 1L; + + @Override + public List getDependencies() { + List deps = super.getDependencies(); + deps.add(JavaScriptHeaderItem.forReference(JQueryResourceReference.get())); + return deps; + } + })); Gson gson = new GsonBuilder().create(); @@ -71,7 +83,7 @@ public class NgController extends Behavior { } line(sb, "}"); - response.render(JavaScriptHeaderItem.forScript(sb.toString(), "angularController")); + response.render(JavaScriptHeaderItem.forScript(sb.toString(), "angularController-"+name)); } private void line(StringBuilder sb, String line) { diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.html b/src/main/java/com/gitblit/wicket/pages/BasePage.html index fe9cc481..9b026982 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.html +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.html @@ -10,6 +10,7 @@ [page title] + @@ -48,7 +49,6 @@ - diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index 0c35bb4b..51e671c8 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -40,8 +40,10 @@ import org.apache.wicket.request.http.handler.RedirectRequestHandler; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.request.resource.ContextRelativeResourceReference; import org.apache.wicket.request.resource.JavaScriptResourceReference; +import org.apache.wicket.resource.JQueryResourceReference; import org.apache.wicket.markup.head.CssHeaderItem; import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.JavaScriptHeaderItem; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.link.ExternalLink; import org.apache.wicket.markup.html.panel.FeedbackPanel; @@ -67,6 +69,7 @@ import com.gitblit.wicket.CacheControl; import com.gitblit.wicket.GitBlitWebApp; import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.WicketUtils; +import com.gitblit.wicket.resources.bootstrap.Bootstrap; public abstract class BasePage extends SessionPage { @@ -96,9 +99,10 @@ public abstract class BasePage extends SessionPage { @Override public void renderHead(IHeaderResponse response) { super.renderHead(response); + response.render(JavaScriptHeaderItem.forReference(JQueryResourceReference.get())); + if (app().settings().getBoolean(Keys.web.useResponsiveLayout, true)) { - response.render(CssHeaderItem.forReference( - new ContextRelativeResourceReference("/bootstrap/css/bootstrap-responsive.css", false))); + response.render(CssHeaderItem.forReference(Application.get().getSharedResources().get(Bootstrap.BOOTSTRAP_RESPONSIVE_CSS_RESOURCE))); } if (app().settings().getBoolean(Keys.web.hideHeader, false)) { response.render(CssHeaderItem.forReference(new ContextRelativeResourceReference("/hideheader.css", false))); diff --git a/src/main/java/com/gitblit/wicket/resources/bootstrap/Bootstrap.java b/src/main/java/com/gitblit/wicket/resources/bootstrap/Bootstrap.java index f675af66..0d0778d2 100644 --- a/src/main/java/com/gitblit/wicket/resources/bootstrap/Bootstrap.java +++ b/src/main/java/com/gitblit/wicket/resources/bootstrap/Bootstrap.java @@ -1,14 +1,27 @@ package com.gitblit.wicket.resources.bootstrap; +import java.util.List; + +import org.apache.wicket.markup.head.HeaderItem; +import org.apache.wicket.markup.head.JavaScriptHeaderItem; import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.request.resource.CssPackageResource; +import org.apache.wicket.request.resource.IResource; import org.apache.wicket.request.resource.PackageResourceReference; +import org.apache.wicket.request.resource.SharedResourceReference; +import org.apache.wicket.resource.JQueryResourceReference; public class Bootstrap { + + public static final String BOOTSTRAP_RESPONSIVE_CSS_RESOURCE = "bootstrap:responsiveCss"; public static void install(WebApplication app) { app.mountResource("/bootstrap/css/bootstrap.css", new PackageResourceReference(Bootstrap.class, "css/bootstrap.css")); - app.mountResource("/bootstrap/css/bootstrap-responsive.css", new PackageResourceReference(Bootstrap.class, "css/bootstrap-responsive.css")); + + app.getSharedResources().add(BOOTSTRAP_RESPONSIVE_CSS_RESOURCE, new CssPackageResource(Bootstrap.class, "css/bootstrap-responsive.css", null, null, null)); + app.mountResource("/bootstrap/css/bootstrap-responsive.css", app.getSharedResources().get(BOOTSTRAP_RESPONSIVE_CSS_RESOURCE)); + app.mountResource("/bootstrap/css/iconic.css", new PackageResourceReference(Bootstrap.class, "css/iconic.css")); app.mountResource("/bootstrap/font/iconic_fill.afm", new PackageResourceReference(Bootstrap.class, "font/iconic_fill.afm")); @@ -30,7 +43,16 @@ public class Bootstrap { app.mountResource("/bootstrap/img/glyphicons-halflings-white.png", new PackageResourceReference(Bootstrap.class, "img/glyphicons-halflings-white.png")); app.mountResource("/bootstrap/img/glyphicons-halflings.png", new PackageResourceReference(Bootstrap.class, "img/glyphicons-halflings.png")); - app.mountResource("/bootstrap/js/bootstrap.js", new PackageResourceReference(Bootstrap.class, "js/bootstrap.js")); + app.mountResource("/bootstrap/js/bootstrap.js", new PackageResourceReference(Bootstrap.class, "js/bootstrap.js"){ + private static final long serialVersionUID = 1L; + + @Override + public List getDependencies() { + List deps = super.getDependencies(); + deps.add(JavaScriptHeaderItem.forReference(JQueryResourceReference.get())); + return deps; + } + }); } } -- 2.39.5