Commit e94b2719 authored by Anne Blankert's avatar Anne Blankert

layerinfo in sortable table

parent c3d17c03
...@@ -6,17 +6,85 @@ ...@@ -6,17 +6,85 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Info</title> <title>Info</title>
<script> <script>
let layerInfo = null;
let prevFieldname = '';
function sortBy(name) {
let fieldname;
switch(name) {
case 'schema':
fieldname = 'f_table_schema';
break;
case 'name':
fieldname = 'f_table_name';
break;
case 'geom_column':
fieldname = 'f_geometry_column';
break;
case 'geom_type':
fieldname = 'type';
break;
case 'dim':
fieldname = 'coord_dimension';
break;
case 'count':
fieldname = 'estimated_rows'
break;
default:
fieldname = name;
}
updateLayerInfo(fieldname, fieldname != prevFieldname);
if (prevFieldname != fieldname) {
prevFieldname = fieldname;
} else {
prevFieldname = '';
}
}
function updateLayerInfo(field, ascending) {
const table = document.querySelector('#layerinfo');
switch (field) {
case 'f_table_schema':
layerInfo.sort((item1, item2) => ('' + item1.f_table_schema + item1.f_table_name).localeCompare(item2.f_table_schema + item2.f_table_name))
break;
case 'f_table_name':
layerInfo.sort((item1, item2) => ('' + item1[field]).localeCompare(item2[field]));
break;
case 'f_geometry_column':
case 'type':
case 'coord_dimension':
layerInfo.sort((item1, item2) => ('' + item1[field] + '.' + item1.f_table_schema + '.' + item1.f_table_name).localeCompare(item2[field] + '.' + item2.f_table_schema + '.' + item2.f_table_name));
break;
case 'srid':
layerInfo.sort((item1, item2)=>item1.srid-item2.srid?item1.srid-item2.srid:('' + item1.f_table_schema + item1.f_table_name).localeCompare(item2.f_table_schema + item2.f_table_name));
break;
case 'estimated_rows':
layerInfo.sort((item1, item2)=>item1.estimated_rows-item2.estimated_rows);
}
if (!ascending) {
layerInfo.reverse();
}
table.innerHTML = '<tr><th>schema</th><th>name</th><th>geom_column</th><th>srid</th><th>geom_type</th><th>dim</th><th>count</th></tr>' +
layerInfo.map(item=>`<tr>
<td>${item.f_table_schema}</td>
<td><a href="tableinfo.html?table=${item.f_table_schema}.${item.f_table_name}&geom_column=${item.f_geometry_column}&srid=${item.srid}&geom_type=${item.type}&dimensions=${item.coord_dimension}&estimated_rows=${item.estimated_rows}">${item.f_table_name}</a></td>
<td>${item.f_geometry_column}</td>
<td>${item.srid}</td>
<td>${item.type}</td>
<td>${item.coord_dimension}D</td>
<td>${item.estimated_rows}</td></tr>`).join('\n');
const tableHeaders = document.querySelectorAll('tr > th');
for (let i = 0; i < tableHeaders.length; i++) {
tableHeaders[i].innerHTML = `<a href="#" onclick="sortBy('${tableHeaders[i].textContent}')">${tableHeaders[i].textContent}</a>`
}
}
function init() { function init() {
fetch('data/list_layers').then(response=>{ fetch('data/list_layers').then(response=>{
if (response.ok) { if (response.ok) {
response.json().then(json=> { response.json().then(json=> {
const list = document.querySelector('#layerlist'); layerInfo = json;
for (item of json) { sortBy('schema');
const li = document.createElement('li');
li.innerHTML = `<a href="tableinfo.html?table=${item.f_table_schema}.${item.f_table_name}&geom_column=${item.f_geometry_column}&srid=${item.srid}&geom_type=${item.type}&dimensions=${item.coord_dimension}">${item.f_table_schema}.${item.f_table_name}</a> geom: ${item.f_geometry_column}, srid:${item.srid}, geom_type:${item.type}, ${item.coord_dimension}D, count: ${item.estimated_rows}`
list.appendChild(li);
}
}) })
} }
}) })
...@@ -25,6 +93,6 @@ ...@@ -25,6 +93,6 @@
</head> </head>
<body onload="init()"> <body onload="init()">
<h1>Vector layers in database</h1> <h1>Vector layers in database</h1>
<ul id="layerlist"></ul> <table id="layerinfo"></table>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment