Skip to content

Commit

Permalink
Version switching in the webui
Browse files Browse the repository at this point in the history
  • Loading branch information
angelini committed Dec 21, 2021
1 parent 918eef7 commit 0c9a880
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
20 changes: 19 additions & 1 deletion assets/templates/version.html.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{{ template "header.html.tmpl" "DL project" }}

<h1>Project: {{ .Project }}</h1>
<h3>Version: {{ .Version }}</h3>
<div>
<label for="version">Version: </label>
<select id="version" autocomplete="off">
{{ range $v := .Versions }}
<option value="{{ $v }}" {{ if eq $v $.Version }}selected{{ end }}>{{ $v }}</option>
{{ end }}
</select>
</div>
<ul>
{{ range .Objects }}
<li>
Expand All @@ -17,4 +24,15 @@
{{ end }}
</ul>

<script>
const action = "/projects/{{ .Project }}/versions/";
const select = document.getElementById("version");

select.addEventListener("change", (option) => {
console.log(window.location.host + action + option.target.value);
window.location.href = window.location.origin + action + option.target.value;
return false;
});
</script>

{{ template "footer.html.tmpl" }}
28 changes: 20 additions & 8 deletions pkg/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,22 @@ type Object struct {
}

type VersionData struct {
Project int64
Version int64
Objects []Object
Project int64
Version int64
Versions []int64
Objects []Object
}

func fetchVersionData(ctx context.Context, dlc *client.Client, project, version int64) (*VersionData, error) {
vrange := client.VersionRange{From: nil, To: &version}
resp, err := dlc.Get(ctx, project, "", vrange)
get, err := dlc.Get(ctx, project, "", vrange)
if err != nil {
return nil, err
}

var objects []Object

for _, object := range resp {
for _, object := range get {
mode := fs.FileMode(object.Mode)
truncated := len(object.Content) > 2000

Expand All @@ -172,10 +173,21 @@ func fetchVersionData(ctx context.Context, dlc *client.Client, project, version
})
}

inspect, err := dlc.Inspect(ctx, project)
if err != nil {
return nil, err
}

versions := make([]int64, inspect.LatestVersion)
for i := int64(1); i <= inspect.LatestVersion; i++ {
versions[i-1] = i
}

return &VersionData{
Project: project,
Version: version,
Objects: objects,
Project: project,
Version: version,
Versions: versions,
Objects: objects,
}, nil
}

Expand Down

0 comments on commit 0c9a880

Please sign in to comment.