Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version dropdown to cookbook UI #68

Merged
merged 1 commit into from
Dec 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions internal/app/ui/templates/partials/cookbook/header.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
<div class="row">
<div>
<div class="row align-items-center">
<div class="col-auto">
<h1 class="cookbook-headline">
<a href="/ui/cookbooks/{{.cookbook.Metadata.Name}}/{{.cookbook.Metadata.Version}}">{{.cookbook.Metadata.Name}}</a>
</h1>
<p class="lead">{{.cookbook.Metadata.Description}}</p>
</div>
<div class="col-auto">
<select class="form-select form-select-sm" id="cookbook-versions-dropdown" onchange="if (this.value) window.location.href='/ui/cookbooks/{{.cookbook.Metadata.Name}}/' + this.value">
<option selected value="{{ .cookbook.Metadata.Version }}">{{ .cookbook.Metadata.Version }}</option>
</select>
</div>
</div>
<div class="row">
<p class="lead">{{ .cookbook.Metadata.Description }}</p>
</div>
<script>
async function fetchVersions() {
const response = await fetch('/api/cookbooks/{{.cookbook.Metadata.Name}}/versions');
const data = await response.json();
return data
}

let selectBox = document.getElementById("cookbook-versions-dropdown");
fetchVersions().then(
function(resp) {
resp.forEach(v => {
var opt = document.createElement("option");
opt.text = v
opt.value = v
if (v === "{{ .cookbook.Metadata.Version }}") {
opt.selected = true
}
selectBox.appendChild(opt)
});
selectBox.removeChild(selectBox.firstElementChild)
}
);
</script>
<div class="col">
<ul class="nav nav-tabs justify-content-end">
<li class="nav-item">
Expand Down