wip on table view

pull/34/head
Zlatin Balevsky 2019-12-07 18:07:00 +00:00
parent 8bff987d30
commit 74dddc4da4
5 changed files with 85 additions and 10 deletions

View File

@ -62,6 +62,12 @@ public class FileManager {
fileTree.list(parent, callback);
}
List<SharedFile> getAllFiles() {
TraverseCallback cb = new TraverseCallback();
fileTree.traverse(cb);
return cb.found;
}
String getHashingFile() {
return hashingFile;
}

View File

@ -39,7 +39,7 @@ public class FilesServlet extends HttpServlet {
if (hashingFile != null)
sb.append("<Hashing>").append(Util.escapeHTMLinXML(hashingFile)).append("</Hashing>");
sb.append("</Status>");
} else if (section.equals("files")) {
} else if (section.equals("fileTree")) {
sb.append("<Files>");
sb.append("<Revision>").append(fileManager.getRevision()).append("</Revision>");
@ -63,7 +63,13 @@ public class FilesServlet extends HttpServlet {
}
fileManager.list(current, cb);
sb.append("</Files>");
} else if (section.equals("fileTable")) {
sb.append("<Files>");
sb.append("<Revision>").append(fileManager.getRevision()).append("</Revision>");
fileManager.getAllFiles().forEach(sf -> sharedFileToXML(sf, sb));
sb.append("</Files>");
}
resp.setContentType("text/xml");
resp.setCharacterEncoding("UTF-8");
resp.setDateHeader("Expires", 0);
@ -86,13 +92,7 @@ public class FilesServlet extends HttpServlet {
}
@Override
public void onFile(File f, SharedFile value) {
sb.append("<File>");
sb.append("<Name>").append(Util.escapeHTMLinXML(f.getName())).append("</Name>");
sb.append("<Size>").append(DataHelper.formatSize2Decimal(value.getCachedLength())).append("B").append("</Size>");
if (value.getComment() != null)
sb.append("<Comment>").append(Util.escapeHTMLinXML(value.getComment())).append("</Comment>");
// TODO: other stuff
sb.append("</File>");
sharedFileToXML(value, sb);
}
@Override
public void onDirectory(File f) {
@ -100,6 +100,17 @@ public class FilesServlet extends HttpServlet {
sb.append("<Directory>").append(Util.escapeHTMLinXML(name)).append("</Directory>");
}
}
private static void sharedFileToXML(SharedFile sf, StringBuilder sb) {
sb.append("<File>");
sb.append("<Name>").append(Util.escapeHTMLinXML(sf.getFile().getName())).append("</Name>");
sb.append("<Path>").append(Util.escapeHTMLinXML(sf.getCachedPath())).append("</Path>");
sb.append("<Size>").append(DataHelper.formatSize2Decimal(sf.getCachedLength())).append("B").append("</Size>");
if (sf.getComment() != null)
sb.append("<Comment>").append(Util.escapeHTMLinXML(sf.getComment())).append("</Comment>");
// TODO: other stuff
sb.append("</File>");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

View File

@ -275,7 +275,7 @@ function expand(nodeId) {
}
}
}
xmlhttp.open("GET", "/MuWire/Files?section=files&path="+encodedPath, true)
xmlhttp.open("GET", "/MuWire/Files?section=fileTree&path="+encodedPath, true)
xmlhttp.send()
}

View File

@ -0,0 +1,39 @@
function refreshStatus() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var xmlDoc = this.responseXML;
var count = xmlDoc.getElementsByTagName("Count")[0].childNodes[0].nodeValue
var countSpan = document.getElementById("count")
countSpan.innerHTML = count
var hashingSpan = document.getElementById("hashing")
var hashing = xmlDoc.getElementsByTagName("Hashing")
if (hashing != null && hashing.length == 1) {
hashingSpan.innerHTML = "Hashing "+hashing[0].childNodes[0].nodeValue
} else
hashingSpan.innerHTML = "";
var newRevision = xmlDoc.getElementsByTagName("Revision")[0].childNodes[0].nodeValue
if (newRevision > tableRevision) {
tableRevision = newRevision
// TODO: let the user know they can refresh the table
}
}
}
xmlhttp.open("GET", "/MuWire/Files?section=status", true)
xmlhttp.send();
}
var tableRevision = -1
function initFiles() {
setInterval(refreshStatus, 3000)
setTimeout(refreshStatus, 1)
nodesById.set("root",root)
}

View File

@ -2,12 +2,26 @@
pageEncoding="UTF-8"%>
<%@include file="initcode.jsi"%>
<% String pagetitle="Shared Files"; %>
<%
String pagetitle="Shared Files";
String viewAs = request.getParameter("viewAs");
if (viewAs == null)
viewAs = "tree";
%>
<html>
<head>
<%@ include file="css.jsi"%>
<% if (viewAs.equals("tree")) { %>
<script src="js/files.js"?<%=version%>" type="text/javascript"></script>
<% } else { %>
<script src="js/filesTable.js"?<%=version%> type="text/javascript"></script>
<% } %>
</head>
<body onload="initConnectionsCount(); initFiles();">
<%@ include file="header.jsi"%>
@ -20,6 +34,11 @@
<input type="hidden" name="action" value="share">
<input type="submit" value="Share">
</form>
<% if (viewAs.equals("tree")) { %>
<a class="menuitem" href="SharedFiles.jsp?viewAs=table">View As Table</a>
<% } else { %>
<a class="menuitem" href="SharedFiles.jsp?viewAs=tree">View As Tree</a>
<% } %>
</div>
<div class="menubox-divider"></div>
<%@include file="sidebar.jsi"%>