diff options
Diffstat (limited to 'src/marlin.web/Views/Jobs/Spawn.cshtml')
| -rw-r--r-- | src/marlin.web/Views/Jobs/Spawn.cshtml | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/marlin.web/Views/Jobs/Spawn.cshtml b/src/marlin.web/Views/Jobs/Spawn.cshtml new file mode 100644 index 0000000..8f7ee43 --- /dev/null +++ b/src/marlin.web/Views/Jobs/Spawn.cshtml @@ -0,0 +1,56 @@ +@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 { name = b.Name, commit = b.Commit.Hash }) + })); +} + +<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.Ref)"></select><br/> + Commit: <input type="text" id="commit" name="@nameof(JobsController.JobSpawnRequest.Commit)" readonly/><br/> + Recipe: <input type="text" name="@nameof(JobsController.JobSpawnRequest.Recipe)" value="@Model.Recipe"/><br/> + <button type="submit">Save</button> +</form> + +<script> + const sources = @Html.Raw(sourcesJson); + const vcsSelect = document.getElementById('vcs'); + const refSelect = document.getElementById('ref'); + const commitInput = document.getElementById('commit'); + + for (const s of sources) { + vcsSelect.add(new Option(s.label, s.id)); + } + + function currentSource() { + return sources.find(s => s.id === vcsSelect.value); + } + + function populateRefs() { + refSelect.innerHTML = ''; + for (const b of currentSource()?.branches ?? []) { + refSelect.add(new Option(b.name, b.name)); + } + refSelect.value = currentSource()?.mainBranch ?? ''; + populateCommit(); + } + + function populateCommit() { + const branch = currentSource()?.branches.find(b => b.name === refSelect.value); + commitInput.value = branch?.commit ?? ''; + } + + vcsSelect.addEventListener('change', populateRefs); + refSelect.addEventListener('change', populateCommit); + + populateRefs(); +</script> |
