Skip to content

Commit e87e50f

Browse files
add a menu for selecting parent group to repo creation page
1 parent 6828d57 commit e87e50f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

templates/repo/create.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
<span class="help tw-hidden" data-help-for-repo-name=".profile">{{ctx.Locale.Tr "repo.repo_name_profile_public_hint"}}</span>
4444
<span class="help tw-hidden" data-help-for-repo-name=".profile-private">{{ctx.Locale.Tr "repo.repo_name_profile_private_hint"}}</span>
4545
</div>
46+
<div class="inline field">
47+
<label>{{ctx.Locale.Tr "repo.group"}}</label>
48+
<div id="group_selector" class="ui search dropdown">
49+
<span class="text truncated-item-container" title="{{ctx.Locale.Tr "group.parent.none_selected"}}"></span>
50+
<input type="hidden" id="gid" name="parent_group_id" value="0" required>
51+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
52+
<div class="menu">
53+
</div>
54+
</div>
55+
</div>
4656

4757
<div class="inline field">
4858
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>

web_src/js/features/repo-new.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) {
5858
onChangeOwner();
5959
}
6060

61+
function initRepoGroupSelector(form: HTMLFormElement) {
62+
const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('#uid');
63+
const elGroupDropdown = form.querySelector<HTMLInputElement>('#group_selector');
64+
const $dropdown = fomanticQuery(elGroupDropdown);
65+
const onChangeRepoOwner = function () {
66+
$dropdown.dropdown('setting', {
67+
apiSettings: {
68+
url: `${appSubUrl}/group/search?uid=${inputRepoOwnerUid.value}&recurse=true`,
69+
onResponse(response) {
70+
const results = [];
71+
results.push({name: '', value: ''}); // empty item means not using template
72+
const forEachFn = function({group, subgroups}, depth: number) {
73+
results.push({name: group.name, value: String(group.id)});
74+
for (const sg of subgroups) {
75+
forEachFn(sg, depth + 1);
76+
}
77+
};
78+
for (const g of response.data.subgroups) {
79+
forEachFn(g, 0);
80+
}
81+
return {results};
82+
},
83+
cache: false,
84+
},
85+
});
86+
};
87+
inputRepoOwnerUid.addEventListener('change', onChangeRepoOwner);
88+
onChangeRepoOwner();
89+
}
90+
6191
export function initRepoNew() {
6292
const pageContent = document.querySelector('.page-content.repository.new-repo');
6393
if (!pageContent) return;
@@ -96,4 +126,5 @@ export function initRepoNew() {
96126
updateUiRepoName();
97127

98128
initRepoNewTemplateSearch(form);
129+
initRepoGroupSelector(form);
99130
}

0 commit comments

Comments
 (0)