Search in sources :

Example 1 with BooleanChoiceOption

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);
}
Also used : RepositoryNamePanel(com.gitblit.wicket.panels.RepositoryNamePanel) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) Form(org.apache.wicket.markup.html.form.Form) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) RepositoryModel(com.gitblit.models.RepositoryModel) BooleanChoiceOption(com.gitblit.wicket.panels.BooleanChoiceOption) Button(org.apache.wicket.markup.html.form.Button) AccessRestrictionType(com.gitblit.Constants.AccessRestrictionType) AuthorizationControl(com.gitblit.Constants.AuthorizationControl) File(java.io.File) AccessPolicyPanel(com.gitblit.wicket.panels.AccessPolicyPanel) BooleanOption(com.gitblit.wicket.panels.BooleanOption)

Aggregations

AccessRestrictionType (com.gitblit.Constants.AccessRestrictionType)1 AuthorizationControl (com.gitblit.Constants.AuthorizationControl)1 GitBlitException (com.gitblit.GitBlitException)1 RepositoryModel (com.gitblit.models.RepositoryModel)1 AccessPolicyPanel (com.gitblit.wicket.panels.AccessPolicyPanel)1 BooleanChoiceOption (com.gitblit.wicket.panels.BooleanChoiceOption)1 BooleanOption (com.gitblit.wicket.panels.BooleanOption)1 RepositoryNamePanel (com.gitblit.wicket.panels.RepositoryNamePanel)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 SimpleAttributeModifier (org.apache.wicket.behavior.SimpleAttributeModifier)1 Button (org.apache.wicket.markup.html.form.Button)1 Form (org.apache.wicket.markup.html.form.Form)1 CompoundPropertyModel (org.apache.wicket.model.CompoundPropertyModel)1