Skip to content

Commit

Permalink
add vendor dropdown and put in seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
LDannijs committed Oct 4, 2023
1 parent 6eedb0e commit 326b957
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
26 changes: 2 additions & 24 deletions website/layouts/index.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
{{ define "main" }}
<main aria-role="main">
{{ partial "banner.html" (dict "title" "Device Repository for LoRaWAN®" "description" .Description) }}
<select id="tagDropdown">
<option value="" selected disabled>Select a Tag</option>
{{ $tags := slice }}
{{ range .Site.RegularPages }}
{{ $pageTags := .Params.tags }}
{{ range $pageTags }}
{{ if not (in $tags .) }}
{{ $tags = $tags | append . }}
{{ end }}
{{ end }}
{{ end }}
{{ $sortedTags := $tags | sort }}
{{ range $sortedTags }}
<option value="{{ . | urlize }}">{{ . }}</option>
{{ end }}
</select>
<script>
document.getElementById("tagDropdown").addEventListener("change", function() {
var selectedTag = this.value;
if (selectedTag) {
window.location.href = "{{ .Site.BaseURL }}tags/" + selectedTag + "/";
}
});
</script>
{{ partial "tagdropdown.html" . }}
{{ partial "vendordropdown.html" . }}
{{ partial "device-list.html" (dict "devices" ( where site.RegularPages "Section" "devices" ) ) }}
</main>
{{ end }}
24 changes: 24 additions & 0 deletions website/layouts/partials/tagdropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<select id="tagDropdown">
<option value="" selected disabled>Select a Tag</option>
{{ $tags := slice }}
{{ range .Site.RegularPages }}
{{ $pageTags := .Params.tags }}
{{ range $pageTags }}
{{ if not (in $tags .) }}
{{ $tags = $tags | append . }}
{{ end }}
{{ end }}
{{ end }}
{{ $sortedTags := $tags | sort }}
{{ range $sortedTags }}
<option value="{{ . | urlize }}">{{ . }}</option>
{{ end }}
</select>
<script>
document.getElementById("tagDropdown").addEventListener("change", function() {
var selectedTag = this.value;
if (selectedTag) {
window.location.href = "{{ .Site.BaseURL }}tags/" + selectedTag + "/";
}
});
</script>
30 changes: 30 additions & 0 deletions website/layouts/partials/vendordropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<select id="vendorDropdown">
<option value="" selected disabled>Select a Vendor</option>
{{ $uniqueVendors := dict }}
{{ $sortedVendors := slice }}
{{ range .Site.RegularPages }}
{{ with .Params.vendor }}
{{ $vendorID := .id | urlize }}
{{ $vendorName := .name }}
{{ with index $uniqueVendors $vendorID }}
{{/* Vendor already encountered, do nothing */}}
{{ else }}
{{ $uniqueVendors = $uniqueVendors | merge (dict $vendorID $vendorName) }}
{{ $sortedVendors = $sortedVendors | append $vendorID }}
{{ end }}
{{ end }}
{{ end }}
{{ $sortedVendors = sort $sortedVendors }}
{{ range $sortedVendors }}
<option value="{{ . }}">{{ index $uniqueVendors . }}</option>
{{ end }}
</select>
<script>
document.getElementById("vendorDropdown").addEventListener("change", function() {
var selectedVendor = this.value;
if (selectedVendor) {
// Redirect to the URL for the selected vendor
window.location.href = "{{ .Site.BaseURL }}devices/" + selectedVendor + "/";
}
});
</script>

0 comments on commit 326b957

Please sign in to comment.