Add download button for pathbuilders
This commit is contained in:
parent
8b3218ad00
commit
9f5ca27f55
4 changed files with 87 additions and 30 deletions
|
|
@ -13,15 +13,16 @@
|
||||||
<b>URL:</b> <a href="{{ .Info.URL }}" target="_blank" rel="noopener noreferrer">{{ .Info.URL }}</a> <br />
|
<b>URL:</b> <a href="{{ .Info.URL }}" target="_blank" rel="noopener noreferrer">{{ .Info.URL }}</a> <br />
|
||||||
<hr />
|
<hr />
|
||||||
<b>Running:</b> <code>{{ .Info.Running }}</code> <br />
|
<b>Running:</b> <code>{{ .Info.Running }}</code> <br />
|
||||||
<b>Last Rebuild:</b> <code>{{ .Info.LastRebuild }}</code> <br />
|
<!-- <b>OwnerEmail:</b> <code>{{ .Instance.OwnerEmail }}</code> <br /> -->
|
||||||
<hr />
|
<hr />
|
||||||
<b>Created:</b> <code>{{ .Instance.Created }}</code> <br />
|
<b>Created:</b> <code class="date">{{ .Instance.Created.Format "2006-01-02T15:04:05Z07:00" }}</code> <br />
|
||||||
<b>OwnerEmail:</b> <code>{{ .Instance.OwnerEmail }}</code> <br />
|
<b>Last Rebuild:</b> <code class="date">{{ .Info.LastRebuild.Format "2006-01-02T15:04:05Z07:00" }}</code> <br />
|
||||||
<hr />
|
<hr />
|
||||||
<b>FilesystemBase:</b> <code>{{ .Instance.FilesystemBase }}</code> <br />
|
<b>FilesystemBase:</b> <code>{{ .Instance.FilesystemBase }}</code> <br />
|
||||||
<b>AutoBlindUpdateEnabled:</b> <code>{{ .Instance.AutoBlindUpdateEnabled }}</code> <br />
|
<b>AutoBlindUpdateEnabled:</b> <code>{{ .Instance.AutoBlindUpdateEnabled }}</code> <br />
|
||||||
<hr />
|
<hr />
|
||||||
<b>Pathbuilders:</b> <code>{{ .Info.Pathbuilders }}</code> <br />
|
<b>Pathbuilders:</b> <code class="pathbuilders">{{ .Info.Pathbuilders }}</code><br />
|
||||||
|
<script>window.pathbuilders={{ .Info.Pathbuilders }};</script>
|
||||||
<hr />
|
<hr />
|
||||||
<b>SqlDatabase:</b> <code>{{ .Instance.SqlDatabase }}</code> <br />
|
<b>SqlDatabase:</b> <code>{{ .Instance.SqlDatabase }}</code> <br />
|
||||||
<b>SqlUsername:</b> <code>{{ .Instance.SqlUsername }}</code> <br />
|
<b>SqlUsername:</b> <code>{{ .Instance.SqlUsername }}</code> <br />
|
||||||
|
|
@ -35,3 +36,4 @@
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script src="/dis/static/autolink.js"></script>
|
<script src="/dis/static/autolink.js"></script>
|
||||||
|
<script src="/dis/static/instance.js"></script>
|
||||||
|
|
@ -1,24 +1,19 @@
|
||||||
/** adding links to each item, see http://blog.parkermoore.de/2014/08/01/header-anchor-links-in-vanilla-javascript-for-github-pages-and-jekyll/ */
|
/** Adapted from http://blog.parkermoore.de/2014/08/01/header-anchor-links-in-vanilla-javascript-for-github-pages-and-jekyll/ */
|
||||||
var anchorForId = function (id) {
|
const anchorForId = (id) => {
|
||||||
var anchor = document.createElement("a");
|
const anchor = document.createElement("a")
|
||||||
anchor.className = "header-link";
|
anchor.className = "header-link"
|
||||||
anchor.href = "#" + id;
|
anchor.href = "#" + id
|
||||||
anchor.innerHTML = "#";
|
anchor.innerHTML = "#"
|
||||||
return anchor;
|
return anchor
|
||||||
};
|
|
||||||
|
|
||||||
var linkifyAnchors = function (level) {
|
|
||||||
var headers = document.getElementsByTagName("h" + level);
|
|
||||||
for (var h = 0; h < headers.length; h++) {
|
|
||||||
var header = headers[h];
|
|
||||||
|
|
||||||
if (typeof header.id !== "undefined" && header.id !== "") {
|
|
||||||
header.appendChild(anchorForId(header.id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
for (var level = 1; level <= 6; level++) {
|
|
||||||
linkifyAnchors(level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const linkifyAnchors = (level) => {
|
||||||
|
const headers = document.getElementsByTagName("h" + level);
|
||||||
|
Array.from(headers).forEach((header) => {
|
||||||
|
if (typeof header.id === "undefined" || header.id === "") return
|
||||||
|
header.appendChild(anchorForId(header.id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// linkify all the anchors from 1 ... 6
|
||||||
|
Array(6).forEach((_, i) => linkifyAnchors(i + 1))
|
||||||
60
internal/component/control/html/static/instance.js
Normal file
60
internal/component/control/html/static/instance.js
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
const types = {
|
||||||
|
"date": (element) => {
|
||||||
|
return (new Date(element.innerText)).toString()
|
||||||
|
},
|
||||||
|
"pathbuilders": (element) => {
|
||||||
|
const pathbuilders = window.pathbuilders; // read from context!
|
||||||
|
const wrapper = document.createElement("span");
|
||||||
|
|
||||||
|
let found_one = false
|
||||||
|
Object.keys(pathbuilders).forEach(name => {
|
||||||
|
found_one = true
|
||||||
|
|
||||||
|
const filename = name + ".xml"
|
||||||
|
const data = pathbuilders[name]
|
||||||
|
const mime = "application/xml"
|
||||||
|
wrapper.append(make_download_link(filename, name, data, mime))
|
||||||
|
wrapper.append(document.createTextNode(" "))
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!found_one) return '(none)';
|
||||||
|
|
||||||
|
const small = document.createElement('small')
|
||||||
|
small.append(document.createTextNode("(click to download)"))
|
||||||
|
wrapper.append(small)
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const make_download_link = (filename, title, content, type) => {
|
||||||
|
const blob = new Blob(
|
||||||
|
[content],
|
||||||
|
{
|
||||||
|
type: type ?? "text/plain"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const link = document.createElement("a")
|
||||||
|
link.target = "_blank"
|
||||||
|
link.download = filename
|
||||||
|
link.href = URL.createObjectURL(blob)
|
||||||
|
link.append(document.createTextNode(title))
|
||||||
|
|
||||||
|
return link
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(types).forEach(key => {
|
||||||
|
const f = types[key];
|
||||||
|
const elements = document.querySelectorAll("code." + key)
|
||||||
|
elements.forEach(element => {
|
||||||
|
const newElement = f(element)
|
||||||
|
if (typeof newElement === 'string') {
|
||||||
|
element.innerHTML = ""
|
||||||
|
element.appendChild(document.createTextNode(newElement))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
element.parentNode.replaceChild(newElement, element)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -15,8 +15,8 @@ type Info struct {
|
||||||
|
|
||||||
LastRebuild time.Time
|
LastRebuild time.Time
|
||||||
|
|
||||||
Running bool // is the instance running?
|
Running bool // is the instance running?
|
||||||
Pathbuilders []string // list of pathbuilders
|
Pathbuilders map[string]string // list of pathbuilders
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info returns information about this WissKI instance.
|
// Info returns information about this WissKI instance.
|
||||||
|
|
@ -39,7 +39,7 @@ func (wisski *WissKI) Info(quick bool) (info Info, err error) {
|
||||||
// these might execute php code or require additional database queries.
|
// these might execute php code or require additional database queries.
|
||||||
if !quick {
|
if !quick {
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
info.Pathbuilders, _ = wisski.Pathbuilders()
|
info.Pathbuilders, _ = wisski.AllPathbuilders()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
group.Go(func() (err error) {
|
group.Go(func() (err error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue