mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Sub page should override onPageInitialize() instead of onInitialize()
This commit is contained in:
parent
bde8789aec
commit
1edc128e69
@ -151,21 +151,23 @@ public class GitFilter implements Filter {
|
|||||||
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
HttpServletRequest httpRequest = (HttpServletRequest) request;
|
||||||
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
HttpServletResponse httpResponse = (HttpServletResponse) response;
|
||||||
|
|
||||||
if (gitop.isReady()) {
|
try {
|
||||||
try {
|
if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
|
||||||
if (GitSmartHttpTools.isInfoRefs(httpRequest)) {
|
if (gitop.isReady())
|
||||||
processRefs(httpRequest, httpResponse);
|
processRefs(httpRequest, httpResponse);
|
||||||
} else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) {
|
else
|
||||||
|
throw new GeneralException("Server is not ready");
|
||||||
|
} else if (GitSmartHttpTools.isReceivePack(httpRequest) || GitSmartHttpTools.isUploadPack(httpRequest)) {
|
||||||
|
if (gitop.isReady())
|
||||||
processPacks(httpRequest, httpResponse);
|
processPacks(httpRequest, httpResponse);
|
||||||
} else {
|
else
|
||||||
chain.doFilter(request, response);
|
throw new GeneralException("Server is not ready");
|
||||||
}
|
} else {
|
||||||
} catch (GeneralException e) {
|
chain.doFilter(request, response);
|
||||||
logger.error("Error serving git request", e);
|
|
||||||
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (GeneralException e) {
|
||||||
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server is not ready.");
|
logger.error("Error serving git request", e);
|
||||||
|
GitSmartHttpTools.sendError(httpRequest, httpResponse, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package com.pmease.gitop.web.page;
|
package com.pmease.gitop.web.page;
|
||||||
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.wicket.model.IModel;
|
|
||||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import com.pmease.gitop.core.model.User;
|
import com.pmease.gitop.core.model.User;
|
||||||
@ -10,21 +8,9 @@ import com.pmease.gitop.core.model.User;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class AbstractLayoutPage extends BasePage {
|
public abstract class AbstractLayoutPage extends BasePage {
|
||||||
|
|
||||||
public AbstractLayoutPage() {
|
@Override
|
||||||
commonInit();
|
protected void onPageInitialize() {
|
||||||
}
|
super.onPageInitialize();
|
||||||
|
|
||||||
public AbstractLayoutPage(PageParameters params) {
|
|
||||||
super(params);
|
|
||||||
commonInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AbstractLayoutPage(IModel<?> model) {
|
|
||||||
super(model);
|
|
||||||
commonInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void commonInit() {
|
|
||||||
add(new GlobalHeaderPanel("header"));
|
add(new GlobalHeaderPanel("header"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,8 @@ import com.pmease.gitop.web.page.init.ServerInitPage;
|
|||||||
public abstract class BasePage extends WebPage {
|
public abstract class BasePage extends WebPage {
|
||||||
|
|
||||||
private WebMarkupContainer body;
|
private WebMarkupContainer body;
|
||||||
|
|
||||||
|
private boolean shouldInitialize = true;
|
||||||
|
|
||||||
public BasePage() {
|
public BasePage() {
|
||||||
commonInit();
|
commonInit();
|
||||||
@ -47,23 +49,11 @@ public abstract class BasePage extends WebPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void commonInit() {
|
private void commonInit() {
|
||||||
body = new TransparentWebMarkupContainer("body");
|
if (!Gitop.getInstance().isReady() && getClass() != ServerInitPage.class) {
|
||||||
add(body);
|
redirect(ServerInitPage.class);
|
||||||
body.add(AttributeAppender.append("class",
|
|
||||||
new AbstractReadOnlyModel<String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getObject() {
|
|
||||||
String css = getPageCssClass();
|
|
||||||
return Strings.isNullOrEmpty(css) ? "" : css;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (!Gitop.getInstance().isReady()
|
|
||||||
&& getClass() != ServerInitPage.class) {
|
|
||||||
throw new RestartResponseAtInterceptPageException(
|
|
||||||
ServerInitPage.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldInitialize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -119,23 +109,47 @@ public abstract class BasePage extends WebPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void redirectWithIntercept(final Class<? extends Page> clazz) {
|
||||||
|
shouldInitialize = true;
|
||||||
|
throw new RestartResponseAtInterceptPageException(clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void redirectWithIntercept(final Class<? extends Page> clazz, final PageParameters pageParams) {
|
||||||
|
shouldInitialize = true;
|
||||||
|
throw new RestartResponseAtInterceptPageException(clazz, pageParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void redirectWithIntercept(final Page page) {
|
||||||
|
shouldInitialize = true;
|
||||||
|
throw new RestartResponseAtInterceptPageException(page);
|
||||||
|
}
|
||||||
|
|
||||||
public final void redirect(final Class<? extends Page> clazz) {
|
public final void redirect(final Class<? extends Page> clazz) {
|
||||||
|
shouldInitialize = false;
|
||||||
throw new RestartResponseException(clazz);
|
throw new RestartResponseException(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void redirect(final Class<? extends Page> clazz,
|
public final void redirect(final Class<? extends Page> clazz,
|
||||||
PageParameters parameters) {
|
PageParameters parameters) {
|
||||||
|
shouldInitialize = false;
|
||||||
throw new RestartResponseException(clazz, parameters);
|
throw new RestartResponseException(clazz, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void redirect(final Page page) {
|
public final void redirect(final Page page) {
|
||||||
|
shouldInitialize = false;
|
||||||
throw new RestartResponseException(page);
|
throw new RestartResponseException(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void redirect(String url) {
|
public final void redirect(String url) {
|
||||||
|
shouldInitialize = false;
|
||||||
throw new RedirectToUrlException(url);
|
throw new RedirectToUrlException(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void redirectToOriginal() {
|
||||||
|
shouldInitialize = false;
|
||||||
|
continueToOriginalDestination();
|
||||||
|
}
|
||||||
|
|
||||||
protected String getPageCssClass() {
|
protected String getPageCssClass() {
|
||||||
String name = getClass().getSimpleName();
|
String name = getClass().getSimpleName();
|
||||||
return StringUtils.camelCaseToLowerCaseWithHyphen(name);
|
return StringUtils.camelCaseToLowerCaseWithHyphen(name);
|
||||||
@ -144,10 +158,19 @@ public abstract class BasePage extends WebPage {
|
|||||||
protected boolean isPermitted() {
|
protected boolean isPermitted() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
body = new TransparentWebMarkupContainer("body");
|
||||||
|
add(body);
|
||||||
|
body.add(AttributeAppender.append("class",
|
||||||
|
new AbstractReadOnlyModel<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInitialize() {
|
public String getObject() {
|
||||||
super.onInitialize();
|
String css = getPageCssClass();
|
||||||
|
return Strings.isNullOrEmpty(css) ? "" : css;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
if (!isPermitted()) {
|
if (!isPermitted()) {
|
||||||
throw new AccessDeniedException();
|
throw new AccessDeniedException();
|
||||||
@ -179,8 +202,16 @@ public abstract class BasePage extends WebPage {
|
|||||||
* cause components with resources using global resources not working
|
* cause components with resources using global resources not working
|
||||||
* properly.
|
* properly.
|
||||||
*/
|
*/
|
||||||
add(new WebMarkupContainer("globalResourceBinder")
|
add(new WebMarkupContainer("globalResourceBinder").add(new BaseResourceBehavior()));
|
||||||
.add(new BaseResourceBehavior()));
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void onInitialize() {
|
||||||
|
super.onInitialize();
|
||||||
|
|
||||||
|
if (shouldInitialize) {
|
||||||
|
onPageInitialize();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getPageTitle();
|
protected abstract String getPageTitle();
|
||||||
|
|||||||
@ -36,6 +36,11 @@ public class AccountHomePage extends AbstractLayoutPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
add(new Label("accountName", getAccount().getName()));
|
add(new Label("accountName", getAccount().getName()));
|
||||||
|
|
||||||
|
|||||||
@ -41,9 +41,20 @@ public class RegisterPage extends AbstractLayoutPage {
|
|||||||
return "Gitop - Sign Up";
|
return "Gitop - Sign Up";
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegisterPage() {
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
final IModel<User> model = Model.<User>of(new User());
|
final IModel<User> model = Model.<User>of(new User());
|
||||||
Form<User> form = new Form<User>("form", model);
|
Form<User> form = new Form<User>("form", model) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInitialize() {
|
||||||
|
super.onInitialize();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
add(form);
|
add(form);
|
||||||
|
|
||||||
form.add(new FeedbackPanel("feedback", form));
|
form.add(new FeedbackPanel("feedback", form));
|
||||||
|
|||||||
@ -10,8 +10,6 @@ import org.apache.wicket.markup.html.link.Link;
|
|||||||
import org.apache.wicket.markup.html.list.ListItem;
|
import org.apache.wicket.markup.html.list.ListItem;
|
||||||
import org.apache.wicket.markup.html.list.ListView;
|
import org.apache.wicket.markup.html.list.ListView;
|
||||||
import org.apache.wicket.model.AbstractReadOnlyModel;
|
import org.apache.wicket.model.AbstractReadOnlyModel;
|
||||||
import org.apache.wicket.model.IModel;
|
|
||||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.pmease.gitop.core.model.User;
|
import com.pmease.gitop.core.model.User;
|
||||||
@ -50,21 +48,10 @@ public abstract class AccountSettingPage extends AbstractLayoutPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountSettingPage() {
|
@Override
|
||||||
commonInit();
|
protected void onPageInitialize() {
|
||||||
}
|
super.onPageInitialize();
|
||||||
|
|
||||||
public AccountSettingPage(PageParameters params) {
|
|
||||||
super(params);
|
|
||||||
commonInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountSettingPage(IModel<?> model) {
|
|
||||||
super(model);
|
|
||||||
commonInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void commonInit() {
|
|
||||||
add(new UserAvatarLink("userlink", new UserModel(getAccount())));
|
add(new UserAvatarLink("userlink", new UserModel(getAccount())));
|
||||||
|
|
||||||
add(new ListView<Category>("setting", ImmutableList.<Category>copyOf(Category.values())) {
|
add(new ListView<Category>("setting", ImmutableList.<Category>copyOf(Category.values())) {
|
||||||
|
|||||||
@ -34,7 +34,10 @@ public class AccountPasswordPage extends AccountSettingPage {
|
|||||||
return Category.PASSWORD;
|
return Category.PASSWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AccountPasswordPage() {
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
Form<User> form = new Form<User>("form", new UserModel(getAccount()));
|
Form<User> form = new Form<User>("form", new UserModel(getAccount()));
|
||||||
add(form);
|
add(form);
|
||||||
form.add(new PasswordFieldElement("oldPass", "Current Password",
|
form.add(new PasswordFieldElement("oldPass", "Current Password",
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package com.pmease.gitop.web.page.init;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.wicket.RestartResponseException;
|
|
||||||
import org.apache.wicket.markup.html.WebMarkupContainer;
|
import org.apache.wicket.markup.html.WebMarkupContainer;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
|
|
||||||
@ -22,9 +21,15 @@ public class ServerInitPage extends BasePage {
|
|||||||
public ServerInitPage() {
|
public ServerInitPage() {
|
||||||
initStage = Gitop.getInstance().getInitStage();
|
initStage = Gitop.getInstance().getInitStage();
|
||||||
if (initStage == null) {
|
if (initStage == null) {
|
||||||
continueToOriginalDestination();
|
redirectToOriginal();
|
||||||
throw new RestartResponseException(getApplication().getHomePage());
|
|
||||||
|
redirect(getApplication().getHomePage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
add(new Label("message", initStage.getMessage()));
|
add(new Label("message", initStage.getMessage()));
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.pmease.gitop.web.page.project;
|
package com.pmease.gitop.web.page.project;
|
||||||
|
|
||||||
|
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
import org.apache.wicket.model.IModel;
|
import org.apache.wicket.model.IModel;
|
||||||
import org.apache.wicket.model.LoadableDetachableModel;
|
import org.apache.wicket.model.LoadableDetachableModel;
|
||||||
@ -12,6 +13,7 @@ import com.pmease.gitop.core.model.Project;
|
|||||||
import com.pmease.gitop.web.page.AbstractLayoutPage;
|
import com.pmease.gitop.web.page.AbstractLayoutPage;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
|
@RequiresAuthentication
|
||||||
public class ProjectHomePage extends AbstractLayoutPage {
|
public class ProjectHomePage extends AbstractLayoutPage {
|
||||||
|
|
||||||
private final IModel<Project> projectModel;
|
private final IModel<Project> projectModel;
|
||||||
@ -43,6 +45,11 @@ public class ProjectHomePage extends AbstractLayoutPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
add(new Label("accountName", getProject().getOwner().getName()));
|
add(new Label("accountName", getProject().getOwner().getName()));
|
||||||
add(new Label("projectName", getProject().getName()));
|
add(new Label("projectName", getProject().getName()));
|
||||||
|
|||||||
@ -14,7 +14,10 @@ import com.pmease.gitop.web.page.BasePage;
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class TestPage extends BasePage {
|
public class TestPage extends BasePage {
|
||||||
|
|
||||||
public TestPage() {
|
@Override
|
||||||
|
protected void onPageInitialize() {
|
||||||
|
super.onPageInitialize();
|
||||||
|
|
||||||
final EditContext editContext = EditableUtils.getContext(new Project());
|
final EditContext editContext = EditableUtils.getContext(new Project());
|
||||||
|
|
||||||
Form<?> form = new Form<Void>("form") {
|
Form<?> form = new Form<Void>("form") {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user