mirror of
https://github.com/arcan1s/ffxivbis.git
synced 2025-04-25 09:47:18 +00:00
small static cleanup
This commit is contained in:
parent
c11103a5ba
commit
e86f3ee092
@ -12,11 +12,21 @@ from aiohttp.web import HTTPNotFound, Response, View
|
|||||||
|
|
||||||
class StaticHtmlView(View):
|
class StaticHtmlView(View):
|
||||||
|
|
||||||
|
def __get_content_type(self, filename: str) -> str:
|
||||||
|
_, ext = os.path.splitext(filename)
|
||||||
|
print(ext)
|
||||||
|
if ext == '.css':
|
||||||
|
return 'text/css'
|
||||||
|
elif ext == '.js':
|
||||||
|
return 'text/javascript'
|
||||||
|
return 'text/plain'
|
||||||
|
|
||||||
async def get(self) -> Response:
|
async def get(self) -> Response:
|
||||||
resource_name = self.request.match_info['resource_id']
|
resource_name = self.request.match_info['resource_id']
|
||||||
resource_path = os.path.join(self.request.app['templates_root'], 'static', resource_name)
|
resource_path = os.path.join(self.request.app['templates_root'], 'static', resource_name)
|
||||||
if not os.path.exists(resource_path) or os.path.isdir(resource_path):
|
if not os.path.exists(resource_path) or os.path.isdir(resource_path):
|
||||||
return HTTPNotFound()
|
return HTTPNotFound()
|
||||||
|
content_type = self.__get_content_type(resource_name)
|
||||||
|
|
||||||
with open(resource_path) as resource_file:
|
with open(resource_path) as resource_file:
|
||||||
return Response(text=resource_file.read(), content_type='text/css')
|
return Response(text=resource_file.read(), content_type=content_type)
|
@ -4,6 +4,7 @@
|
|||||||
<title>Best in slot</title>
|
<title>Best in slot</title>
|
||||||
|
|
||||||
<link href="{{ static('styles.css') }}" rel="stylesheet" type="text/css">
|
<link href="{{ static('styles.css') }}" rel="stylesheet" type="text/css">
|
||||||
|
<link href=""
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>best in slot</h2>
|
<h2>best in slot</h2>
|
||||||
@ -67,6 +68,6 @@
|
|||||||
|
|
||||||
{% include "export_to_csv.jinja2" %}
|
{% include "export_to_csv.jinja2" %}
|
||||||
{% include "root.jinja2" %}
|
{% include "root.jinja2" %}
|
||||||
{% include "search.jinja2" %}
|
<script src="/static/table_search.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,35 +1,2 @@
|
|||||||
<button onclick="exportTableToCsv('result.csv')">Export to csv</button>
|
<button onclick="exportTableToCsv('result.csv')">Export to csv</button>
|
||||||
|
<script src="/static/table_export.js" type="text/javascript"></script>
|
||||||
<script type="application/javascript">
|
|
||||||
function downloadCsv(csv, filename) {
|
|
||||||
var csvFile = new Blob([csv], {"type": "text/csv"});
|
|
||||||
|
|
||||||
var downloadLink = document.createElement("a");
|
|
||||||
downloadLink.download = filename;
|
|
||||||
downloadLink.href = window.URL.createObjectURL(csvFile);
|
|
||||||
downloadLink.style.display = "none";
|
|
||||||
|
|
||||||
document.body.appendChild(downloadLink);
|
|
||||||
downloadLink.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
function exportTableToCsv(filename) {
|
|
||||||
var table = document.getElementById("result");
|
|
||||||
var rows = table.getElementsByTagName("tr");
|
|
||||||
|
|
||||||
var csv = [];
|
|
||||||
for (var i = 0; i < rows.length; i++) {
|
|
||||||
if (rows[i].style.display === "none")
|
|
||||||
continue
|
|
||||||
var cols = rows[i].querySelectorAll("td, th");
|
|
||||||
|
|
||||||
var row = [];
|
|
||||||
for (var j = 0; j < cols.length; j++)
|
|
||||||
row.push(cols[j].innerText);
|
|
||||||
|
|
||||||
csv.push(row.join(","));
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadCsv(csv.join("\n"), filename);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
@ -55,6 +55,6 @@
|
|||||||
|
|
||||||
{% include "export_to_csv.jinja2" %}
|
{% include "export_to_csv.jinja2" %}
|
||||||
{% include "root.jinja2" %}
|
{% include "root.jinja2" %}
|
||||||
{% include "search.jinja2" %}
|
<script src="/static/table_search.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
|
|
||||||
{% include "export_to_csv.jinja2" %}
|
{% include "export_to_csv.jinja2" %}
|
||||||
{% include "root.jinja2" %}
|
{% include "root.jinja2" %}
|
||||||
{% include "search.jinja2" %}
|
<script src="/static/table_search.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -55,6 +55,6 @@
|
|||||||
|
|
||||||
{% include "export_to_csv.jinja2" %}
|
{% include "export_to_csv.jinja2" %}
|
||||||
{% include "root.jinja2" %}
|
{% include "root.jinja2" %}
|
||||||
{% include "search.jinja2" %}
|
<script src="/static/table_search.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
<script type="text/javascript">
|
|
||||||
function searchTable() {
|
|
||||||
var input = document.getElementById("search");
|
|
||||||
var filter = input.value.toLowerCase();
|
|
||||||
var table = document.getElementById("result");
|
|
||||||
var tr = table.getElementsByTagName("tr");
|
|
||||||
|
|
||||||
// from 1 coz of header
|
|
||||||
for (var i = 1; i < tr.length; i++) {
|
|
||||||
var td = tr[i].getElementsByClassName("include_search");
|
|
||||||
var display = "none";
|
|
||||||
for (var j = 0; j < td.length; j++) {
|
|
||||||
if (td[j].tagName.toLowerCase() === "td") {
|
|
||||||
if (td[j].innerHTML.toLowerCase().indexOf(filter) > -1) {
|
|
||||||
display = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tr[i].style.display = display;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
31
templates/static/table_export.js
Normal file
31
templates/static/table_export.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
function downloadCsv(csv, filename) {
|
||||||
|
var csvFile = new Blob([csv], {"type": "text/csv"});
|
||||||
|
|
||||||
|
var downloadLink = document.createElement("a");
|
||||||
|
downloadLink.download = filename;
|
||||||
|
downloadLink.href = window.URL.createObjectURL(csvFile);
|
||||||
|
downloadLink.style.display = "none";
|
||||||
|
|
||||||
|
document.body.appendChild(downloadLink);
|
||||||
|
downloadLink.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportTableToCsv(filename) {
|
||||||
|
var table = document.getElementById("result");
|
||||||
|
var rows = table.getElementsByTagName("tr");
|
||||||
|
|
||||||
|
var csv = [];
|
||||||
|
for (var i = 0; i < rows.length; i++) {
|
||||||
|
if (rows[i].style.display === "none")
|
||||||
|
continue
|
||||||
|
var cols = rows[i].querySelectorAll("td, th");
|
||||||
|
|
||||||
|
var row = [];
|
||||||
|
for (var j = 0; j < cols.length; j++)
|
||||||
|
row.push(cols[j].innerText);
|
||||||
|
|
||||||
|
csv.push(row.join(","));
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadCsv(csv.join("\n"), filename);
|
||||||
|
}
|
21
templates/static/table_search.js
Normal file
21
templates/static/table_search.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function searchTable() {
|
||||||
|
var input = document.getElementById("search");
|
||||||
|
var filter = input.value.toLowerCase();
|
||||||
|
var table = document.getElementById("result");
|
||||||
|
var tr = table.getElementsByTagName("tr");
|
||||||
|
|
||||||
|
// from 1 coz of header
|
||||||
|
for (var i = 1; i < tr.length; i++) {
|
||||||
|
var td = tr[i].getElementsByClassName("include_search");
|
||||||
|
var display = "none";
|
||||||
|
for (var j = 0; j < td.length; j++) {
|
||||||
|
if (td[j].tagName.toLowerCase() === "td") {
|
||||||
|
if (td[j].innerHTML.toLowerCase().indexOf(filter) > -1) {
|
||||||
|
display = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tr[i].style.display = display;
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,6 @@
|
|||||||
|
|
||||||
{% include "export_to_csv.jinja2" %}
|
{% include "export_to_csv.jinja2" %}
|
||||||
{% include "root.jinja2" %}
|
{% include "root.jinja2" %}
|
||||||
{% include "search.jinja2" %}
|
<script src="/static/table_search.js" type="text/javascript"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user