wip on web ui for advanced sharing
This commit is contained in:
@ -327,6 +327,9 @@ See also .menu-icon
|
||||
.menuitem.settings .menu-icon:before {
|
||||
content: url("images/ConfigurationPage.png");
|
||||
}
|
||||
.menuitem.advancedSharing .menu-icon:before {
|
||||
content: url("images/AdvancedSharing.png");
|
||||
}
|
||||
.menuitem.downloads .menu-icon:before {
|
||||
content: url("images/Downloads.png");
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.muwire.webui;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.muwire.core.Core;
|
||||
import com.muwire.core.files.DirectoryUnsharedEvent;
|
||||
import com.muwire.core.files.DirectoryWatchedEvent;
|
||||
import com.muwire.core.files.directories.UISyncDirectoryEvent;
|
||||
import com.muwire.core.files.directories.WatchedDirectoryConfigurationEvent;
|
||||
|
||||
public class AdvancedSharingManager {
|
||||
|
||||
private final Core core;
|
||||
private volatile long revision;
|
||||
|
||||
public AdvancedSharingManager(Core core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
public long getRevision() {
|
||||
return revision;
|
||||
}
|
||||
|
||||
public void onDirectoryWatchedEvent(DirectoryWatchedEvent e) {
|
||||
revision++;
|
||||
}
|
||||
|
||||
public void onDirectoryUnsharedEvent(DirectoryUnsharedEvent e) {
|
||||
revision++;
|
||||
}
|
||||
|
||||
|
||||
void sync(File dir) {
|
||||
revision++;
|
||||
UISyncDirectoryEvent event = new UISyncDirectoryEvent();
|
||||
event.setDirectory(dir);
|
||||
core.getEventBus().publish(event);
|
||||
}
|
||||
|
||||
void configure(File dir, boolean autoWatch, int syncInterval) {
|
||||
revision++;
|
||||
WatchedDirectoryConfigurationEvent event = new WatchedDirectoryConfigurationEvent();
|
||||
event.setAutoWatch(autoWatch);
|
||||
event.setDirectory(dir);
|
||||
event.setSyncInterval(syncInterval);
|
||||
core.getEventBus().publish(event);
|
||||
}
|
||||
}
|
142
webui/src/main/java/com/muwire/webui/AdvancedSharingServlet.java
Normal file
142
webui/src/main/java/com/muwire/webui/AdvancedSharingServlet.java
Normal file
@ -0,0 +1,142 @@
|
||||
package com.muwire.webui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.Collator;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muwire.core.Core;
|
||||
import com.muwire.core.files.directories.WatchedDirectory;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
public class AdvancedSharingServlet extends HttpServlet {
|
||||
|
||||
private Core core;
|
||||
private AdvancedSharingManager advancedSharingManager;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String section = req.getParameter("section");
|
||||
if (section == null) {
|
||||
resp.sendError(403, "Bad section param");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<?xml version='1.0' encoding='UTF-8'?>");
|
||||
|
||||
if (section.equals("revision")) {
|
||||
sb.append("<Revision>").append(advancedSharingManager.getRevision()).append("</Revision>");
|
||||
} else if (section.equals("dirs")) {
|
||||
List<WrappedDir> dirs = core.getWatchedDirectoryManager().getWatchedDirs().
|
||||
map(WrappedDir::new).
|
||||
collect(Collectors.toList());
|
||||
DIR_COMPARATORS.sort(dirs, req);
|
||||
|
||||
sb.append("<WatchedDirs>");
|
||||
dirs.forEach(d -> d.toXML(sb));
|
||||
sb.append("</WatchedDirs>");
|
||||
} else {
|
||||
resp.sendError(403, "Bad section param");
|
||||
return;
|
||||
}
|
||||
|
||||
resp.setContentType("text/xml");
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setDateHeader("Expires", 0);
|
||||
resp.setHeader("Pragma", "no-cache");
|
||||
resp.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
|
||||
byte[] out = sb.toString().getBytes("UTF-8");
|
||||
resp.setContentLength(out.length);
|
||||
resp.getOutputStream().write(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String action = req.getParameter("action");
|
||||
if (action == null) {
|
||||
resp.sendError(403,"Bad param");
|
||||
return;
|
||||
}
|
||||
String path = req.getParameter("path");
|
||||
if (path == null) {
|
||||
resp.sendError(403, "Bad param");
|
||||
return;
|
||||
}
|
||||
|
||||
File dir = Util.getFromPathElements(path);
|
||||
|
||||
if (action.equals("sync")) {
|
||||
advancedSharingManager.sync(dir);
|
||||
Util.pause();
|
||||
} else if (action.equals("configure")) {
|
||||
boolean autoWatch = Boolean.parseBoolean(req.getParameter("autoWatch"));
|
||||
int syncInterval = Integer.parseInt(req.getParameter("syncInterval"));
|
||||
advancedSharingManager.configure(dir, autoWatch, syncInterval);
|
||||
Util.pause();
|
||||
resp.sendRedirect("/MuWire/AdvancedSharing");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
core = (Core) config.getServletContext().getAttribute("core");
|
||||
advancedSharingManager = (AdvancedSharingManager) config.getServletContext().getAttribute("advancedSharingManager");
|
||||
}
|
||||
|
||||
private static class WrappedDir {
|
||||
private final String directory;
|
||||
private final boolean autoWatch;
|
||||
private final long lastSync;
|
||||
private final int syncInterval;
|
||||
|
||||
WrappedDir(WatchedDirectory wd) {
|
||||
this.directory = wd.getDirectory().getAbsolutePath();
|
||||
this.autoWatch = wd.getAutoWatch();
|
||||
this.lastSync = wd.getLastSync();
|
||||
this.syncInterval = wd.getSyncInterval();
|
||||
}
|
||||
|
||||
void toXML(StringBuilder sb) {
|
||||
sb.append("<WatchedDir>");
|
||||
sb.append("<Directory>").append(Util.escapeHTMLinXML(directory)).append("</Directory>");
|
||||
sb.append("<AutoWatch>").append(autoWatch).append("</AutoWatch>");
|
||||
sb.append("<LastSync>").append(DataHelper.formatTime(lastSync)).append("</LastSync>");
|
||||
sb.append("<SyncInterval>").append(syncInterval).append("</SyncInterval>");
|
||||
sb.append("</WatchedDir>");
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<WrappedDir> BY_DIRECTORY = (l, r) -> {
|
||||
return Collator.getInstance().compare(l.directory, r.directory);
|
||||
};
|
||||
|
||||
private static final Comparator<WrappedDir> BY_AUTOWATCH = (l, r) -> {
|
||||
return Boolean.compare(l.autoWatch, r.autoWatch);
|
||||
};
|
||||
|
||||
private static final Comparator<WrappedDir> BY_LAST_SYNC = (l, r) -> {
|
||||
return Long.compare(l.lastSync, r.lastSync);
|
||||
};
|
||||
|
||||
private static final Comparator<WrappedDir> BY_SYNC_INTERVAL = (l, r) -> {
|
||||
return Integer.compare(l.syncInterval, r.syncInterval);
|
||||
};
|
||||
|
||||
private static final ColumnComparators<WrappedDir> DIR_COMPARATORS = new ColumnComparators<>();
|
||||
static {
|
||||
DIR_COMPARATORS.add("Directory", BY_DIRECTORY);
|
||||
DIR_COMPARATORS.add("Auto Watch", BY_AUTOWATCH);
|
||||
DIR_COMPARATORS.add("Last Sync", BY_LAST_SYNC);
|
||||
DIR_COMPARATORS.add("Sync Interval", BY_SYNC_INTERVAL);
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ import com.muwire.core.filefeeds.FeedLoadedEvent;
|
||||
import com.muwire.core.filefeeds.UIFeedConfigurationEvent;
|
||||
import com.muwire.core.files.AllFilesLoadedEvent;
|
||||
import com.muwire.core.files.DirectoryUnsharedEvent;
|
||||
import com.muwire.core.files.DirectoryWatchedEvent;
|
||||
import com.muwire.core.files.FileDownloadedEvent;
|
||||
import com.muwire.core.files.FileHashedEvent;
|
||||
import com.muwire.core.files.FileHashingEvent;
|
||||
@ -177,6 +178,10 @@ public class MuWireClient {
|
||||
core.getEventBus().register(FeedFetchEvent.class, feedManager);
|
||||
core.getEventBus().register(FeedItemFetchedEvent.class, feedManager);
|
||||
|
||||
AdvancedSharingManager advancedSharingManager = new AdvancedSharingManager(core);
|
||||
core.getEventBus().register(DirectoryWatchedEvent.class, advancedSharingManager);
|
||||
core.getEventBus().register(DirectoryUnsharedEvent.class, advancedSharingManager);
|
||||
|
||||
servletContext.setAttribute("searchManager", searchManager);
|
||||
servletContext.setAttribute("downloadManager", downloadManager);
|
||||
servletContext.setAttribute("connectionCounter", connectionCounter);
|
||||
@ -186,6 +191,7 @@ public class MuWireClient {
|
||||
servletContext.setAttribute("certificateManager", certificateManager);
|
||||
servletContext.setAttribute("uploadManager", uploadManager);
|
||||
servletContext.setAttribute("feedManager", feedManager);
|
||||
servletContext.setAttribute("advancedSharingManager", advancedSharingManager);
|
||||
}
|
||||
|
||||
public String getHome() {
|
||||
|
3
webui/src/main/js/advancedSharing.js
Normal file
3
webui/src/main/js/advancedSharing.js
Normal file
@ -0,0 +1,3 @@
|
||||
function initAdvancedSharing() {
|
||||
|
||||
}
|
35
webui/src/main/webapp/AdvancedSharing.jsp
Normal file
35
webui/src/main/webapp/AdvancedSharing.jsp
Normal file
@ -0,0 +1,35 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@ page import="com.muwire.webui.*" %>
|
||||
<%@include file="initcode.jsi"%>
|
||||
|
||||
<%
|
||||
|
||||
String pagetitle=Util._t("Advanced Sharing");
|
||||
|
||||
%>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<%@ include file="css.jsi"%>
|
||||
<script src="js/util.js?<%=version%>" type="text/javascript"></script>
|
||||
<script src="js/tables.js?<%=version%> type="text/javascript"></script>
|
||||
<script src="js/advancedSharing.js?<%=version%>" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
<body onload="initTranslate(jsTranslations); initConnectionsCount(); initAdvancedSharing();">
|
||||
<%@ include file="header.jsi"%>
|
||||
<aside>
|
||||
<div class="menubox-divider"></div>
|
||||
<%@include file="sidebar.jsi"%>
|
||||
</aside>
|
||||
<section class="main foldermain">
|
||||
<div id="table-wrapper">
|
||||
<div class="paddedTable" id="table-scroll">
|
||||
<div id="dirsTable"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="dirConfig"></div>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
@ -76,6 +76,10 @@
|
||||
<div class="menu-icon"></div>
|
||||
<div class="menu-text"><%=Util._t("Settings")%></div>
|
||||
</a>
|
||||
<a class="menuitem advancedSharing" href="AdvancedSharing">
|
||||
<div class="menu-icon"></div>
|
||||
<div class="menu-text"><%=Util._t("Advanced Sharing")%></div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menubox-divider"></div>
|
||||
|
@ -85,6 +85,11 @@
|
||||
<servlet-class>com.muwire.webui.FileInfoServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>com.muwire.webui.AdvancedSharingServlet</servlet-name>
|
||||
<servlet-class>com.muwire.webui.AdvancedSharingServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>com.muwire.webui.MuWireServlet</servlet-name>
|
||||
<url-pattern>/index.jsp</url-pattern>
|
||||
@ -155,6 +160,11 @@
|
||||
<url-pattern>/FileInfo</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>com.muwire.webui.AdvancedSharingServlet</servlet-name>
|
||||
<url-pattern>/AdvancedShare</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
__JASPER__
|
||||
|
||||
<!--
|
||||
@ -237,4 +247,9 @@ Mappings without the .jsp suffix
|
||||
<url-pattern>/FileDetails</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>com.muwire.webui.AdvancedSharing_jsp</servlet-name>
|
||||
<url-pattern>/AdvancedSharing</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
Reference in New Issue
Block a user