Author: batosai
Date: 2008-08-10 19:25:49 +0000 (Sun, 10 Aug 2008)
New Revision: 21723
Modified:
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Added the interface to view scores and set trusts.
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-10 17:44:52 UTC
(rev 21722)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-10 19:25:49 UTC
(rev 21723)
@@ -12,6 +12,7 @@
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import com.db4o.foundation.TreeObject;
import freenet.client.HighLevelSimpleClient;
import freenet.clients.http.PageMaker;
@@ -162,9 +163,25 @@
}
private String makeKnownIdentitiesPage() {
+ return makeKnownIdentitiesPage("");
+ }
+
+ private String makeKnownIdentitiesPage(String owner) {
+
+ Identity treeOwner = null;
+ if(!owner.equals("")) {
+ try {
+ treeOwner = wot.getIdentityByURI(new
FreenetURI(owner));
+ if(treeOwner == null) return "Unknown URI";
+ } catch (MalformedURLException e) {
+ return e.getLocalizedMessage();
+ }
+ }
+
HTMLNode pageNode = getPageNode();
HTMLNode contentNode = pm.getContentNode(pageNode);
+ // Add an identity form
HTMLNode addBox = pm.getInfobox("Add an identity");
HTMLNode addBoxContent = pm.getContentNode(addBox);
@@ -173,18 +190,44 @@
createForm.addChild("input", new String[] {"type", "name",
"size"}, new String[] {"text", "identityURI", "70"});
createForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "add", "Add this identity !" });
+
+ // Known identities list
HTMLNode listBox = pm.getInfobox("Known Identities");
HTMLNode listBoxContent = pm.getContentNode(listBox);
- if(wot.getNbIdentities() == 0) {
+ // Form to select the tree owner (if selected, give the ability
to set trusts and display score)
+ HTMLNode selectForm = pr.addFormChild(listBoxContent, SELF_URI
+ "/viewTree", "selectForm");
+ HTMLNode selectBox = selectForm.addChild("select", "name",
"ownerURI");
+
+ ObjectSet<OwnIdentity> ownIdentities =
db.queryByExample(OwnIdentity.class);
+ while(ownIdentities.hasNext()) {
+ OwnIdentity ownIdentity = ownIdentities.next();
+ if(ownIdentity == treeOwner) {
+ selectBox.addChild("option", new String []
{"value", "selected"}, new String [] {ownIdentity.getRequestURI().toString(),
"selected"}, ownIdentity.getProp("nickName"));
+ }
+ else {
+ selectBox.addChild("option", "value",
ownIdentity.getRequestURI().toString(), ownIdentity.getProp("nickName"));
+ }
+ }
+ selectForm.addChild("input", new String[] { "type", "name",
"value" }, new String[] { "submit", "select", "View this identity" });
+
+ // Display the list of known identities
+ if(wot.getNbIdentities() == 0) { // Should never happen
listBoxContent.addChild("p", "You know no other
identites yet, we are fetching the seedfile that contains a first set of
identities (Freenet developpers).");
}
else {
- HTMLNode identitiesTable =
listBoxContent.addChild("table", "border", "0");
+ HTMLNode listForm = pr.addFormChild(listBoxContent,
SELF_URI + "/setTrust", "setTrustForm");
+
+ HTMLNode identitiesTable = listForm.addChild("table",
"border", "0");
HTMLNode row=identitiesTable.addChild("tr");
row.addChild("th", "NickName");
row.addChild("th", "Last update");
row.addChild("th", "Publish TrustList ?");
+ if(treeOwner != null) {
+ row.addChild("th", "Score (Rank)");
+ row.addChild("th", "Trust");
+ listForm.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "hidden", "owner",
treeOwner.getRequestURI().toString() });
+ }
ObjectSet<Identity> identities =
db.queryByExample(Identity.class);
while(identities.hasNext()) {
@@ -193,14 +236,34 @@
if(id instanceof OwnIdentity) continue;
row=identitiesTable.addChild("tr");
+
+ // NickName
row.addChild("td", new String[] {"title",
"style"}, new String[] {id.getRequestURI().toString(), "cursor: help;"},
id.getProp("nickName"));
+
+ // Last Change
row.addChild("td",
id.getLastChange().toString());
+ // Publish TrustList
boolean publishTrustList =
id.getProp("publishTrustList") != null &&
id.getProp("publishTrustList").equals("true");
row.addChild("td", publishTrustList ? "Yes" :
"No");
+
+ if(treeOwner != null) {
+ //Score
+ row.addChild("td",
String.valueOf(id.getScore((OwnIdentity)treeOwner, db).getScore())+"
("+id.getScore((OwnIdentity)treeOwner, db).getRank()+")");
+
+ // Trust
+ HTMLNode cell = row.addChild("td");
+ cell.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "text",
id.getRequestURI().toString(), "0" });
+ }
}
+ if(treeOwner != null) {
+ HTMLNode lastRow =
identitiesTable.addChild("tr");
+ HTMLNode lastCell = lastRow.addChild("td", new
String[] { "colspan", "align" }, new String[] { "5", "center" });
+ lastCell.addChild("input", new String[] {
"type", "name", "value" }, new String[] { "submit", "updateTrust", "Update
trust values !" });
+ }
}
+
contentNode.addChild(addBox);
contentNode.addChild(listBox);
return pageNode.generate();
@@ -251,9 +314,16 @@
else if(page.equals("/addIdentity")) {
return addIdentity(request);
}
+ else if(page.equals("/viewTree")) {
+ return
makeKnownIdentitiesPage(request.getPartAsString("ownerURI", 1024));
+ }
else if (page.equals("/insertIdentity")) {
return insertIdentity(request);
}
+ else if (page.equals("/setTrust")) {
+ // TODO Update all trust values
+ return null;
+ }
else {
return makeHomePage();
}