blob: 848cae4b73779455cb95e5b06167d3627d183c0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
@using System.Linq
@using System.Text.Json
@using marlin.web.Controllers
@model marlin.web.Controllers.JobsController.JobSpawnDetails
@{
var sourcesJson = JsonSerializer.Serialize(Model.Sources.Select(s => new
{
id = s.Id,
label = s.UpstreamUrl,
mainBranch = s.MainBranch,
branches = s.Branches.Select(b => new
{
id = b.Id,
name = b.Name,
commit = b.Commit.Hash,
recipes = b.Commit.WorkflowSnapshot?.Workflow.Recipes.Values.Select(r => new { id = r.Id, name = r.Name })
?? Enumerable.Empty<object>()
})
}));
}
<form method="post" asp-action="Spawn">
VCS: <select id="vcs" name="@nameof(JobsController.JobSpawnRequest.Vcs)"></select><br/>
Ref: <select id="ref" name="@nameof(JobsController.JobSpawnRequest.Branch)"></select><br/>
Recipe: <select id="recipe" name="@nameof(JobsController.JobSpawnRequest.Recipe)"></select><br/>
<button type="submit">Save</button>
</form>
<script>
const sources = @Html.Raw(sourcesJson);
const vcsSelect = document.getElementById('vcs');
const refSelect = document.getElementById('ref');
const recipeSelect = document.getElementById('recipe');
for (const s of sources) {
vcsSelect.add(new Option(s.label, s.id));
}
function currentSource() {
return sources.find(s => s.id === vcsSelect.value);
}
function currentBranch() {
return currentSource()?.branches.find(b => b.id === refSelect.value);
}
function populateRefs() {
refSelect.innerHTML = '';
for (const b of currentSource()?.branches ?? []) {
refSelect.add(new Option(b.name, b.id));
}
const mainBranch = currentSource()?.branches.find(b => b.name === currentSource()?.mainBranch);
refSelect.value = mainBranch?.id ?? '';
populateRecipes();
}
function populateRecipes() {
recipeSelect.innerHTML = '';
for (const r of currentBranch()?.recipes ?? []) {
recipeSelect.add(new Option(r.name, r.id));
}
}
vcsSelect.addEventListener('change', populateRefs);
refSelect.addEventListener('change', populateRecipes);
populateRefs();
</script>
|