This repository has been archived on 2021-05-23. You can view files and clone it, but cannot push or open issues or pull requests.
simpledash/resources/templates/cards/api.html

36 lines
1.2 KiB
HTML

{{- $format := splitList "\n" (trim .Data.format) -}}
{{- $randID := randAlphaNum 10 -}}
<div class="card-header">
<a class="card-header-title" href="{{.URL}}">
{{if ne .Icon ""}}
{{template "icon" .Icon}}&nbsp;
{{end}}
{{.Title}}
</a>
</div>
<div class="card-content">
<progress class="progress is-light" id="APILoading_{{$randID}}"></progress>
{{range $index, $fmtStr := $format}}
<div id="{{printf `APIElement%d_%s` $index $randID}}"></div>
{{end}}
</div>
{{if .Data.footer}}
<div class="card-footer">
<p class="card-footer-item">{{.Data.footer}}</p>
</div>
{{end}}
<script>
var request = new XMLHttpRequest()
request.open('GET', "{{proxy .URL}}", true)
request.onload = function () {
const data = JSON.parse(this.response)
document.getElementById("APILoading_{{$randID}}").classList.add("is-hidden")
{{range $index, $fmtStr := $format}}
document.getElementById("{{printf `APIElement%d_%s` $index $randID}}").innerHTML = `{{unescJS (trim $fmtStr)}}`
{{end}}
}
{{range $key, $value := .Data.headers}}
request.setRequestHeader("{{$key}}", "{{$value}}")
{{end}}
request.send()
</script>