forked from I2P_Developers/i2p.i2p
Wizard: Improve ajax
Drop unused test wrapper Enable first run detection Spelling fix
This commit is contained in:
@ -25,14 +25,10 @@ import java.io.IOException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import com.vuze.plugins.mlab.tools.ndt.swingemu.Tcpbw100UIWrapper;
|
|
||||||
import com.vuze.plugins.mlab.tools.ndt.swingemu.Tcpbw100UIWrapperListener;
|
|
||||||
|
|
||||||
import edu.internet2.ndt.Tcpbw100;
|
import edu.internet2.ndt.Tcpbw100;
|
||||||
|
|
||||||
import net.minidev.json.JSONObject;
|
import net.minidev.json.JSONObject;
|
||||||
@ -102,41 +98,6 @@ public class MLabRunner {
|
|||||||
try{
|
try{
|
||||||
_log.warn("Starting NDT Test");
|
_log.warn("Starting NDT Test");
|
||||||
|
|
||||||
new Tcpbw100UIWrapper(
|
|
||||||
new Tcpbw100UIWrapperListener()
|
|
||||||
{
|
|
||||||
private LinkedList<String> history = new LinkedList<String>();
|
|
||||||
|
|
||||||
public void reportSummary(String str) {
|
|
||||||
str = str.trim();
|
|
||||||
log(str);
|
|
||||||
if (listener != null){
|
|
||||||
if (!str.startsWith("Click")) {
|
|
||||||
listener.reportSummary(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reportDetail(String str) {
|
|
||||||
str = str.trim();
|
|
||||||
log(str);
|
|
||||||
if (listener != null) {
|
|
||||||
listener.reportDetail(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void log(String str) {
|
|
||||||
synchronized( history ){
|
|
||||||
if (history.size() > 0 && history.getLast().equals(str)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
history.add(str);
|
|
||||||
}
|
|
||||||
_log.warn(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// String host = "ndt.iupui.donar.measurement-lab.org";
|
// String host = "ndt.iupui.donar.measurement-lab.org";
|
||||||
// String host = "jlab4.jlab.org";
|
// String host = "jlab4.jlab.org";
|
||||||
|
|
||||||
@ -208,6 +169,10 @@ public class MLabRunner {
|
|||||||
public void cancelled() {
|
public void cancelled() {
|
||||||
test.killIt();
|
test.killIt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return test.getStatus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test.runIt();
|
test.runIt();
|
||||||
@ -253,7 +218,7 @@ public class MLabRunner {
|
|||||||
results.put("server_city", server_city);
|
results.put("server_city", server_city);
|
||||||
if (server_country != null)
|
if (server_country != null)
|
||||||
results.put("server_country", server_country);
|
results.put("server_country", server_country);
|
||||||
listener.complete( results );
|
listener.complete(results);
|
||||||
}
|
}
|
||||||
if (_log.shouldWarn()) {
|
if (_log.shouldWarn()) {
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
@ -293,6 +258,7 @@ public class MLabRunner {
|
|||||||
public interface ToolRun {
|
public interface ToolRun {
|
||||||
public void cancel();
|
public void cancel();
|
||||||
public void addListener(ToolRunListener l);
|
public void addListener(ToolRunListener l);
|
||||||
|
public String getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,11 +297,18 @@ public class MLabRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
synchronized(this) {
|
||||||
|
return listeners.isEmpty() ? "" : listeners.get(0).getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The listener for ToolRun */
|
/** The listener for ToolRun */
|
||||||
public interface ToolRunListener {
|
public interface ToolRunListener {
|
||||||
public void cancelled();
|
public void cancelled();
|
||||||
|
public String getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The parameter for runNDT() */
|
/** The parameter for runNDT() */
|
||||||
|
@ -42,17 +42,6 @@ JTextArea
|
|||||||
append(
|
append(
|
||||||
String str )
|
String str )
|
||||||
{
|
{
|
||||||
Tcpbw100UIWrapperListener listener = Tcpbw100UIWrapper.current_adapter;
|
|
||||||
|
|
||||||
if ( listener != null ){
|
|
||||||
|
|
||||||
listener.reportDetail( str );
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//System.out.println( "text: " + str );
|
|
||||||
}
|
|
||||||
|
|
||||||
text += str;
|
text += str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,17 +42,6 @@ StyledDocument
|
|||||||
|
|
||||||
throws BadLocationException
|
throws BadLocationException
|
||||||
{
|
{
|
||||||
Tcpbw100UIWrapperListener listener = Tcpbw100UIWrapper.current_adapter;
|
|
||||||
|
|
||||||
if ( listener != null ){
|
|
||||||
|
|
||||||
listener.reportSummary( s );
|
|
||||||
|
|
||||||
}else{
|
|
||||||
|
|
||||||
//System.out.println( "doc: " + s );
|
|
||||||
}
|
|
||||||
|
|
||||||
str += s;
|
str += s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created on May 20, 2010
|
|
||||||
* Created by Paul Gardner
|
|
||||||
*
|
|
||||||
* Copyright 2010 Vuze, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details ( see the LICENSE file ).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package com.vuze.plugins.mlab.tools.ndt.swingemu;
|
|
||||||
|
|
||||||
public class
|
|
||||||
Tcpbw100UIWrapper
|
|
||||||
{
|
|
||||||
public static Tcpbw100UIWrapperListener current_adapter;
|
|
||||||
|
|
||||||
public
|
|
||||||
Tcpbw100UIWrapper(
|
|
||||||
Tcpbw100UIWrapperListener adapter )
|
|
||||||
{
|
|
||||||
current_adapter = adapter;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created on May 20, 2010
|
|
||||||
* Created by Paul Gardner
|
|
||||||
*
|
|
||||||
* Copyright 2010 Vuze, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details ( see the LICENSE file ).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package com.vuze.plugins.mlab.tools.ndt.swingemu;
|
|
||||||
|
|
||||||
public interface
|
|
||||||
Tcpbw100UIWrapperListener
|
|
||||||
{
|
|
||||||
public void
|
|
||||||
reportSummary(
|
|
||||||
String str );
|
|
||||||
|
|
||||||
public void
|
|
||||||
reportDetail(
|
|
||||||
String str );
|
|
||||||
}
|
|
@ -293,6 +293,7 @@ public class Tcpbw100 extends JApplet implements ActionListener {
|
|||||||
private boolean retry = false;
|
private boolean retry = false;
|
||||||
|
|
||||||
// I2P
|
// I2P
|
||||||
|
private String _displayStatus = "";
|
||||||
private final Log _log = new Log(Tcpbw100.class);
|
private final Log _log = new Log(Tcpbw100.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1279,7 +1280,18 @@ public class Tcpbw100 extends JApplet implements ActionListener {
|
|||||||
* @param msg String value of status
|
* @param msg String value of status
|
||||||
* */
|
* */
|
||||||
public void showStatus(String msg) {
|
public void showStatus(String msg) {
|
||||||
_log.warn(msg);
|
synchronized(this) {
|
||||||
|
_displayStatus = msg;
|
||||||
|
}
|
||||||
|
_log.warn("NDT STATUS: " + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* I2P
|
||||||
|
* Translated status, not HTML escaped.
|
||||||
|
*/
|
||||||
|
public synchronized String getStatus() {
|
||||||
|
return _displayStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +136,7 @@ public class WizardHandler extends FormHandler {
|
|||||||
if (_helper == null) {
|
if (_helper == null) {
|
||||||
addFormError("Bad state for test");
|
addFormError("Bad state for test");
|
||||||
} else if (_helper.cancelNDT()) {
|
} else if (_helper.cancelNDT()) {
|
||||||
addFormNotice(_t("Candelled bandwidth test"));
|
addFormNotice(_t("Cancelled bandwidth test"));
|
||||||
} else {
|
} else {
|
||||||
addFormError(_t("Bandwidth test was not running"));
|
addFormError(_t("Bandwidth test was not running"));
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,19 @@ public class WizardHelper extends HelperBase {
|
|||||||
return _listener != null && !_listener.isComplete();
|
return _listener != null && !_listener.isComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return HTML-escaped status string or ""
|
||||||
|
*/
|
||||||
|
public synchronized String getTestStatus() {
|
||||||
|
String rv = "";
|
||||||
|
if (_runner != null) {
|
||||||
|
String s = _runner.getStatus();
|
||||||
|
if (s != null)
|
||||||
|
rv = DataHelper.escapeHTML(s);
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return HTML-escaped status string or ""
|
* @return HTML-escaped status string or ""
|
||||||
*/
|
*/
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
boolean wizRun = ctx.getBooleanProperty(net.i2p.router.web.helpers.WizardHelper.PROP_COMPLETE);
|
boolean wizRun = ctx.getBooleanProperty(net.i2p.router.web.helpers.WizardHelper.PROP_COMPLETE);
|
||||||
String firstVersion = ctx.getProperty("router.firstVersion");
|
String firstVersion = ctx.getProperty("router.firstVersion");
|
||||||
String tgt;
|
String tgt;
|
||||||
final boolean ENABLE_WIZARD_ON_FIRST_RUN = false;
|
final boolean ENABLE_WIZARD_ON_FIRST_RUN = true;
|
||||||
if (oldHome) {
|
if (oldHome) {
|
||||||
tgt = "console";
|
tgt = "console";
|
||||||
} else if (!ENABLE_WIZARD_ON_FIRST_RUN || wizRun || firstVersion == null) {
|
} else if (!ENABLE_WIZARD_ON_FIRST_RUN || wizRun || firstVersion == null) {
|
||||||
|
59
apps/routerconsole/jsp/js/welcomeajax.js
Normal file
59
apps/routerconsole/jsp/js/welcomeajax.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
var fails = 0;
|
||||||
|
|
||||||
|
function ajax(url, target, refresh) {
|
||||||
|
// native XMLHttpRequest object
|
||||||
|
if (window.XMLHttpRequest) {
|
||||||
|
req = new XMLHttpRequest();
|
||||||
|
req.onreadystatechange = function() {ajaxDone(url, target, refresh);};
|
||||||
|
req.open("GET", url, true);
|
||||||
|
req.send(null);
|
||||||
|
// IE/Windows ActiveX version
|
||||||
|
} else if (window.ActiveXObject) {
|
||||||
|
req = new ActiveXObject("Microsoft.XMLDOM");
|
||||||
|
if (req) {
|
||||||
|
req.onreadystatechange = function() {ajaxDone(target);};
|
||||||
|
req.open("GET", url, true);
|
||||||
|
req.send(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ajaxDone(url, target, refresh) {
|
||||||
|
// only if req is "loaded"
|
||||||
|
if (req.readyState == 4) {
|
||||||
|
var fail = false;
|
||||||
|
var running = true;
|
||||||
|
var done = false;
|
||||||
|
// only if "OK"
|
||||||
|
if (req.status == 200) {
|
||||||
|
// output 1 for complete, 0 + status string for in progress
|
||||||
|
fails = 0;
|
||||||
|
var status;
|
||||||
|
if (req.responseText.startsWith("1")) {
|
||||||
|
results = doneMessage;
|
||||||
|
running = false;
|
||||||
|
done = true;
|
||||||
|
status = "";
|
||||||
|
} else {
|
||||||
|
results = progressMessage;
|
||||||
|
status = req.responseText.substring("1")
|
||||||
|
}
|
||||||
|
document.getElementById("xhr2").innerHTML = status;
|
||||||
|
document.getElementById(target).innerHTML = results;
|
||||||
|
} else if (fails == 0) {
|
||||||
|
// avoid spurious message if cancelled by user action
|
||||||
|
fails++;
|
||||||
|
} else {
|
||||||
|
document.getElementById(target).innerHTML = failMessage;
|
||||||
|
running = false;
|
||||||
|
fail = true;
|
||||||
|
}
|
||||||
|
var form = document.forms[0];
|
||||||
|
form.prev.disabled = fail || !done;
|
||||||
|
form.skip.disabled = !done;
|
||||||
|
form.cancelbw.disabled = !running;
|
||||||
|
form.next.disabled = fail || !done;
|
||||||
|
|
||||||
|
setTimeout(function() {ajax(url, target, refresh);}, refresh);
|
||||||
|
}
|
||||||
|
}
|
@ -66,11 +66,16 @@
|
|||||||
wizhelper.setContextId(i2pcontextId);
|
wizhelper.setContextId(i2pcontextId);
|
||||||
if (ipg == 4) {
|
if (ipg == 4) {
|
||||||
%>
|
%>
|
||||||
<script src="/js/ajax.js" type="text/javascript"></script>
|
<script src="/js/welcomeajax.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var failMessage = "<hr><b><%=intl._t("Router is down")%><\/b>";
|
var failMessage = "<b><%=intl._t("Router is down")%><\/b>";
|
||||||
|
var progressMessage = "<b><%=intl._t("Bandwidth test in progress...")%><\/b>";
|
||||||
|
var doneMessage = "<b><%=intl._t("Bandwidth test is complete, click Next")%><\/b>";
|
||||||
function requestAjax1() { ajax("/welcomexhr1.jsp", "xhr", "1000"); }
|
function requestAjax1() { ajax("/welcomexhr1.jsp", "xhr", "1000"); }
|
||||||
function initAjax() { setTimeout(requestAjax1, "1000"); }
|
function initAjax() {
|
||||||
|
document.getElementById("xhr").innerHTML = progressMessage;
|
||||||
|
setTimeout(requestAjax1, "1000");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<%
|
<%
|
||||||
}
|
}
|
||||||
@ -148,6 +153,8 @@
|
|||||||
<!-- for non-script -->
|
<!-- for non-script -->
|
||||||
<%=intl._t("Javascript is disabled - wait 60 seconds for the bandwidth test to complete and then click Next")%>
|
<%=intl._t("Javascript is disabled - wait 60 seconds for the bandwidth test to complete and then click Next")%>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="xhr2">
|
||||||
|
</div>
|
||||||
<%
|
<%
|
||||||
|
|
||||||
} else if (ipg == 5) {
|
} else if (ipg == 5) {
|
||||||
|
@ -8,9 +8,10 @@
|
|||||||
}
|
}
|
||||||
} catch (IllegalStateException ise) {}
|
} catch (IllegalStateException ise) {}
|
||||||
wizhelper.setContextId(i2pcontextId);
|
wizhelper.setContextId(i2pcontextId);
|
||||||
|
// output 1 for complete, 0 + status string for in progress
|
||||||
if (wizhelper.isNDTComplete()) {
|
if (wizhelper.isNDTComplete()) {
|
||||||
%><%=wizhelper._t("Bandwidth test is complete, click Next")%><%
|
%>1<%
|
||||||
} else {
|
} else {
|
||||||
%><%=wizhelper._t("Bandwidth test in progress...")%><%
|
%>0<%=wizhelper.getTestStatus()%><%
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
|
Reference in New Issue
Block a user