diff options
author | Otto Richter <git@otto.splvs.net> | 2024-12-27 16:11:45 +0100 |
---|---|---|
committer | Otto Richter <git@otto.splvs.net> | 2024-12-29 13:05:30 +0100 |
commit | 8d32ca32c2d2b71de08a53208df66aa6aecfddc7 (patch) | |
tree | b0083f6ffbf1d51fcef91a2401c99cad13339bfc | |
parent | New repo: Rework advanced and template sections (diff) | |
download | forgejo-8d32ca32c2d2b71de08a53208df66aa6aecfddc7.tar.xz forgejo-8d32ca32c2d2b71de08a53208df66aa6aecfddc7.zip |
New repo: Rework initialization
- only show settings when ticked
- only offer README selection when there are multiple options
-rw-r--r-- | options/locale/locale_en-US.ini | 3 | ||||
-rw-r--r-- | templates/repo/create.tmpl | 64 | ||||
-rw-r--r-- | templates/repo/create_init.tmpl | 56 | ||||
-rw-r--r-- | tests/integration/repo_generate_test.go | 2 |
4 files changed, 67 insertions, 58 deletions
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 460f318292..3f9cad7051 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -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 diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 8212033242..7ee8587435 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -30,68 +30,20 @@ <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> diff --git a/templates/repo/create_init.tmpl b/templates/repo/create_init.tmpl new file mode 100644 index 0000000000..729b44c8e6 --- /dev/null +++ b/templates/repo/create_init.tmpl @@ -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> diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go index 4bd9f32119..bcee0df417 100644 --- a/tests/integration/repo_generate_test.go +++ b/tests/integration/repo_generate_test.go @@ -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) } } |