mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
- Changed back to innerText on output - replaced global var report and extracted info for download from div - put another check on the download button to insure that the report can only be downloaded once data is available
122 lines
No EOL
3.5 KiB
HTML
122 lines
No EOL
3.5 KiB
HTML
<!--
|
|
~ Copyright 2017-2021 Koordinierungsstelle für IT-Standards (KoSIT)
|
|
~
|
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
~ you may not use this file except in compliance with the License.
|
|
~ You may obtain a copy of the License at
|
|
~
|
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
~
|
|
~ Unless required by applicable law or agreed to in writing, software
|
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
~ See the License for the specific language governing permissions and
|
|
~ limitations under the License.
|
|
-->
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Validator</title>
|
|
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
|
|
<meta content="width=device-width,initial-scale=1" name="viewport">
|
|
<link href="lib/vue.css" rel="stylesheet">
|
|
|
|
<style>
|
|
|
|
#result {
|
|
border: 1pt solid black;
|
|
margin-top: 20px
|
|
}
|
|
|
|
#result:empty {
|
|
display: none;
|
|
}
|
|
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script type="text/javascript">
|
|
|
|
var validate = function validate() {
|
|
const input = document.getElementById('file');
|
|
const output_bad_status = document.getElementById('bad_status');
|
|
const output_good_status = document.getElementById('good_status');
|
|
const output_result = document.getElementById('result');
|
|
const download = document.getElementById('dwn-btn');
|
|
|
|
// Reset all variables
|
|
output_bad_status.innerText = "";
|
|
output_good_status.innerText = "";
|
|
download.disabled = true;
|
|
output_result.innerText = "";
|
|
|
|
var headers = new Headers();
|
|
headers.append('Content-Type', 'application/xml');
|
|
|
|
var requestOptions = {
|
|
method: 'POST',
|
|
headers: headers,
|
|
body: input.files[0],
|
|
redirect: 'follow',
|
|
};
|
|
|
|
fetch('/', requestOptions)
|
|
.then(response => {
|
|
let status = response.status + " " + response.statusText;
|
|
if(response.status === 200) {
|
|
output_good_status.innerText = status;
|
|
} else {
|
|
output_bad_status.innerText = status;
|
|
}
|
|
response.text().then(result => {
|
|
output_result.innerText = result;
|
|
download.disabled = false;
|
|
})
|
|
response.text().catch(error => output_result.innerText = error);
|
|
})
|
|
return false;
|
|
};
|
|
|
|
let download = function download() {
|
|
const result = document.getElementById('result');
|
|
const filename = "report.html";
|
|
const element = document.createElement('a');
|
|
|
|
// Check if there is a report to download
|
|
if(result.innerText !== "") {
|
|
// Extraction of HTML Result from div-box "result"
|
|
let html_result = new DOMParser().parseFromString(result.innerText, "text/html");
|
|
// Eliminate the abundance
|
|
html_result = html_result.documentElement.innerHTML.replace(/<rep:report (.+)><rep:explanation>/, "");
|
|
|
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(html_result));
|
|
element.setAttribute('download', filename);
|
|
|
|
element.style.display = 'none';
|
|
document.body.appendChild(element);
|
|
|
|
element.click();
|
|
|
|
document.body.removeChild(element);
|
|
}
|
|
};
|
|
|
|
</script>
|
|
|
|
<div data-app id="app">Loading validator... </div>
|
|
<script>
|
|
window.$docsify = {
|
|
repo: "itplr-kosit/validator",
|
|
loadSidebar: false,
|
|
hideSidebar: true,
|
|
autoHeader: true,
|
|
}
|
|
</script>
|
|
<script src="lib/docsify.min.js"></script>
|
|
|
|
|
|
</body>
|
|
</html> |