New repo: Rework initialization

- only show settings when ticked
- only offer README selection when there are multiple options
This commit is contained in:
Otto Richter 2024-12-27 16:11:45 +01:00
parent 4cde56906e
commit 8d32ca32c2
4 changed files with 67 additions and 58 deletions

View file

@ -1103,7 +1103,8 @@ object_format_helper = Object format of the repository. Cannot be changed later.
readme = README
readme_helper = Select a README file template
readme_helper_desc = This is the place where you can write a complete description for your project.
auto_init = Initialize repository (Adds .gitignore, License and README)
auto_init = Initialize repository
auto_init_description = Start the Git history with a README and optionally add License and .gitignore files.
create_repo = Create repository
default_branch = Default branch
default_branch_label = default

View file

@ -29,69 +29,21 @@
</fieldset>
<div id="non_template">
<fieldset>
<legend>{{ctx.Locale.Tr "repo.auto_init"}}</legend>
{{template "repo/create_init" .}}
</fieldset>
<fieldset>
<legend>{{ctx.Locale.Tr "repo.new_advanced"}}</legend>
<details><summary>{{ctx.Locale.Tr "repo.new_advanced_expand"}}</summary>
{{template "repo/create_advanced" .}}
</details>
</fieldset>
<div class="inline field">
<label>.gitignore</label>
<div class="ui multiple search selection dropdown">
<input type="hidden" name="gitignores" value="{{.gitignores}}">
<div class="default text">{{ctx.Locale.Tr "repo.repo_gitignore_helper"}}</div>
<div class="menu">
{{range .Gitignores}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.repo_gitignore_helper_desc"}}</span>
</div>
<div class="inline field">
<label>{{ctx.Locale.Tr "repo.license"}}</label>
<div class="ui search selection dropdown">
<input type="hidden" name="license" value="{{.license}}">
<div class="default text">{{ctx.Locale.Tr "repo.license_helper"}}</div>
<div class="menu">
<div class="item" data-value="">{{ctx.Locale.Tr "repo.license_helper"}}</div>
{{range .Licenses}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.license_helper_desc" "https://choosealicense.com/"}}</span>
</div>
<div class="inline field">
<label>{{ctx.Locale.Tr "repo.readme"}}</label>
<div class="ui selection dropdown">
<input type="hidden" name="readme" value="{{.readme}}">
<div class="default text">{{ctx.Locale.Tr "repo.readme_helper"}}</div>
<div class="menu">
{{range .Readmes}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.readme_helper_desc"}}</span>
</div>
<div class="inline field">
<div class="ui checkbox" id="auto-init">
<input name="auto_init" type="checkbox" {{if .auto_init}}checked{{end}}>
<label>{{ctx.Locale.Tr "repo.auto_init"}}</label>
</div>
</div>
</div>
<br>
<div class="inline field">
<label></label>
<button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
{{ctx.Locale.Tr "repo.create_repo"}}
</button>
</div>
<button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
{{ctx.Locale.Tr "repo.create_repo"}}
</button>
</div>
</form>
</div>

View file

@ -0,0 +1,56 @@
<label>
<input name="auto_init" type="checkbox" {{if .auto_init}}checked{{end}}>
{{ctx.Locale.Tr "repo.auto_init"}}
<span class="help">{{ctx.Locale.Tr "repo.auto_init_description"}}</span>
</label>
<div class="hide-unless-checked">
<label>
.gitignore
<div class="ui multiple search selection dropdown">
<input type="hidden" name="gitignores" value="{{.gitignores}}">
<div class="default text">{{ctx.Locale.Tr "repo.repo_gitignore_helper"}}</div>
<div class="menu">
{{range .Gitignores}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.repo_gitignore_helper_desc"}}</span>
</label>
<label>
{{ctx.Locale.Tr "repo.license"}}
<div class="ui search selection dropdown">
<input type="hidden" name="license" value="{{.license}}">
<div class="default text">{{ctx.Locale.Tr "repo.license_helper"}}</div>
<div class="menu">
<div class="item" data-value="">{{ctx.Locale.Tr "repo.license_helper"}}</div>
{{range .Licenses}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.license_helper_desc" "https://choosealicense.com/"}}</span>
</label>
{{$supportedReadmesLength := len .Readmes}}
{{/* Only offer README selection if there is an actual choice */}}
{{if ge $supportedReadmesLength 2}}
<label>
{{ctx.Locale.Tr "repo.readme"}}
<div class="ui selection dropdown">
<input type="hidden" name="readme" value="{{.readme}}">
<div class="default text">{{ctx.Locale.Tr "repo.readme_helper"}}</div>
<div class="menu">
{{range .Readmes}}
<div class="item" data-value="{{.}}">{{.}}</div>
{{end}}
</div>
</div>
<span class="help">{{ctx.Locale.Tr "repo.readme_helper_desc"}}</span>
</label>
{{else}}
<input type="hidden" name="readme" value="Default">
{{end}}
</div>

View file

@ -43,7 +43,7 @@ func assertRepoCreateForm(t *testing.T, htmlDoc *HTMLDoc, owner *user_model.User
// the template menu is loaded client-side, so don't assert the option exists
assert.Equal(t, templateID, htmlDoc.GetInputValueByName("repo_template"), "Unexpected repo_template selection")
for _, name := range []string{"issue_labels", "gitignores", "license", "readme", "object_format_name"} {
for _, name := range []string{"issue_labels", "gitignores", "license", "object_format_name"} {
htmlDoc.AssertDropdownHasOptions(t, name)
}
}