use of com.gitblit.wicket.panels.BooleanChoiceOption in project gitblit by gitblit.
the class NewRepositoryPage method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
CompoundPropertyModel<RepositoryModel> rModel = new CompoundPropertyModel<>(repositoryModel);
Form<RepositoryModel> form = new Form<RepositoryModel>("editForm", rModel) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit() {
try {
if (!namePanel.updateModel(repositoryModel)) {
return;
}
accessPolicyPanel.updateModel(repositoryModel);
repositoryModel.owners = new ArrayList<String>();
repositoryModel.owners.add(GitBlitWebSession.get().getUsername());
// setup branch defaults
boolean useGitFlow = addGitflowModel.getObject();
repositoryModel.HEAD = Constants.R_MASTER;
repositoryModel.mergeTo = Constants.MASTER;
if (useGitFlow) {
// tickets normally merge to develop unless they are hotfixes
repositoryModel.mergeTo = Constants.DEVELOP;
}
repositoryModel.allowForks = app().settings().getBoolean(Keys.web.allowForking, true);
// optionally generate an initial commit
boolean addReadme = addReadmeModel.getObject();
String gitignore = null;
boolean addGitignore = addGitignoreModel.getObject();
if (addGitignore) {
gitignore = gitignoreModel.getObject();
if (StringUtils.isEmpty(gitignore)) {
throw new GitBlitException(getString("gb.pleaseSelectGitIgnore"));
}
}
// init the repository
app().gitblit().updateRepositoryModel(repositoryModel.name, repositoryModel, true);
// optionally create an initial commit
initialCommit(repositoryModel, addReadme, gitignore, useGitFlow);
} catch (GitBlitException e) {
error(e.getMessage());
return;
}
setRedirect(true);
setResponsePage(SummaryPage.class, WicketUtils.newRepositoryParameter(repositoryModel.name));
}
};
// do not let the browser pre-populate these fields
form.add(new SimpleAttributeModifier("autocomplete", "off"));
namePanel = new RepositoryNamePanel("namePanel", repositoryModel);
form.add(namePanel);
// prepare the default access controls
AccessRestrictionType defaultRestriction = AccessRestrictionType.fromName(app().settings().getString(Keys.git.defaultAccessRestriction, AccessRestrictionType.PUSH.name()));
if (AccessRestrictionType.NONE == defaultRestriction) {
defaultRestriction = AccessRestrictionType.PUSH;
}
AuthorizationControl defaultControl = AuthorizationControl.fromName(app().settings().getString(Keys.git.defaultAuthorizationControl, AuthorizationControl.NAMED.name()));
if (AuthorizationControl.AUTHENTICATED == defaultControl) {
defaultRestriction = AccessRestrictionType.PUSH;
}
repositoryModel.authorizationControl = defaultControl;
repositoryModel.accessRestriction = defaultRestriction;
accessPolicyPanel = new AccessPolicyPanel("accessPolicyPanel", repositoryModel);
form.add(accessPolicyPanel);
//
// initial commit options
//
// add README
addReadmeModel = Model.of(false);
form.add(new BooleanOption("addReadme", getString("gb.initWithReadme"), getString("gb.initWithReadmeDescription"), addReadmeModel));
// add .gitignore
File gitignoreDir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
File[] files = gitignoreDir.listFiles();
if (files == null) {
files = new File[0];
}
List<String> gitignores = new ArrayList<String>();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".gitignore")) {
gitignores.add(StringUtils.stripFileExtension(file.getName()));
}
}
Collections.sort(gitignores);
gitignoreModel = Model.of("");
addGitignoreModel = Model.of(false);
form.add(new BooleanChoiceOption<String>("addGitIgnore", getString("gb.initWithGitignore"), getString("gb.initWithGitignoreDescription"), addGitignoreModel, gitignoreModel, gitignores).setVisible(gitignores.size() > 0));
// TODO consider gitflow at creation (ticket-55)
addGitflowModel = Model.of(false);
form.add(new BooleanOption("addGitFlow", "Include a .gitflow file", "This will generate a config file which guides Git clients in setting up Gitflow branches.", addGitflowModel).setVisible(false));
form.add(new Button("create"));
add(form);
}
Aggregations