Skip to content

Commit

Permalink
graphviewer: update URL and download links on form updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Jul 17, 2020
1 parent 5debc13 commit 4919ae9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/graphviewer/templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@

{% block d3script %}
<script type="application/javascript">

async function updateURLs(query) {
const searchString = '?' + new URLSearchParams(query).toString(),
location = new URL(window.location);

if (location.search !== searchString) {
location.search = searchString;
history.replaceState(null, '', location)

const downloadArea = document.getElementById('download-graph');
for (const a of downloadArea.getElementsByTagName("a")) {
a.search = searchString;
}
}
}

async function getDotStr() {
const form = document.getElementById('subgraph-form'),
formdata = new FormData(form);
console.log(new URLSearchParams(formdata).toString());
updateURLs(formdata);
const response = await fetch('subgraph/dot', {method: "POST", body: formdata});
if (response.status === 200)
return await response.text();
Expand Down Expand Up @@ -82,7 +98,7 @@ <h3>Kantenauswahl und -gestaltung:</h3>
{%- endblock -%}

{% block download_current %}
<div class="pure-u-1-3 pure-gap">
<div id="download-graph" class="pure-u-1-3 pure-gap">
<a>aktueller Graph</a>
<a href="subgraph/pdf?{{ query }}"><i class="fa fa-file-pdf"></i> als PDF</a>
<a href="subgraph/dot?{{ query }}"><i class="fa fa-doc-text"></i> als GraphViz .dot</a>
Expand Down

0 comments on commit 4919ae9

Please sign in to comment.