webui: searchdetails and searchlist splitted

This commit is contained in:
zeners 2016-01-09 17:39:04 +01:00
parent 4c66bb87bb
commit 4a8db15da6
6 changed files with 83 additions and 42 deletions

View File

@ -37,7 +37,7 @@ function Page(content, runst){
} else {
if ("waiting_init|waiting_startup".match(runstate.runstate)) {
return m("h2","server starting ...")
} else if("waiting_account_select|running_ok*") {
} else if("waiting_account_select|running_ok*".match(runstate.runstate)) {
if (runst === undefined || runst.match(runstate.runstate)) {
return m("div", [
m("div", menu.view()),

View File

@ -11,7 +11,8 @@ function goback(){
function buildmenu(menu, tagname, runstate, ignore){
if ((menu.runstate === undefined || runstate.match(menu.runstate))
&& (!ignore.match(menu.name))) {
&& (!ignore.match(menu.name))
&& (menu.path === undefined || !menu.path.contains(":"))) {
if (menu.action === undefined) {
return m(tagname , {
onclick: function(){

View File

@ -12,6 +12,11 @@ module.exports = { nodes: [
name: "peers",
runstate: "running_ok.*",
},
{
name:"searchresult",
path: "/search/:id",
runstate: "running_ok.*",
},
{
name: "search",
runstate: "running_ok.*",

View File

@ -170,7 +170,7 @@ function rs(path, args, callback, options){
allow: options.allow === undefined ? "ok" : options.allow,
then: function(response){
console.log(path + ": response: " + response.returncode);
if (!allow.match(response.returncode)) {
if (!this.allow.match(response.returncode)) {
requestFail(path, response, null);
} else if (callback != undefined && callback != null) {
callback(response.data, response.statetoken);

View File

@ -15,56 +15,37 @@ function dosearch(){
distant: true,
search_string: searchText
},
onCreateSearchResponse
);
function(resp){
m.route("/search/" + resp.search_id);
}
function onCreateSearchResponse(resp){
state={search_id: resp.search_id};
//tracking searchresults
rs("filesearch/"+state.search_id,{},null,{allow:"not_set|ok"});
//todo: route search/id, caching search-resultlists
);
}
module.exports = {
view: function(){
var results = [];
if (state.search_id != undefined){
var searchresult = rs("filesearch/"+state.search_id);
if (searchresult != undefined) {
results = searchresult;
}
}
var results = rs("filesearch");
if (results === undefined||results == null) {
results = [];
};
return m("div",[
m("h2","turtle file search"),
m("div", [
m("input[type=text]", {onchange:m.withAttr("value", updateText)}),
m("input[type=button][value=search]",{onclick:dosearch})
]),
m("table", [
m("tr" ,[
m("th","name"),
m("th","size"),
m("th",""),
]),
results.map(function(file){
return m("tr",[
m("th",file.name),
m("th",file.size),
m("th",[
m("span.btn", {
m("hr"),
m("h2","previous searches:"),
m("div", [
results.map(function(item){
var res = rs("filesearch/" + item.id,{},null,{allow:"not_set|ok"});
if (res === undefined) {
res =[];
};
return m("div.btn2",{
onclick:function(){
rs.request("transfers/control_download", {
action: "begin",
name: file.name,
size: file.size,
hash: file.hash,
});
m.route("/search/" + item.id);
}
},
"download")
]),
])
}, item.search_string + " (" + res.length + ")");
})
])
])

View File

@ -0,0 +1,54 @@
var m = require("mithril");
var rs = require("retroshare");
module.exports = {
view: function(){
var id=m.route.param("id");
console.log("search_id: " + id);
var results = rs("filesearch/" + id ,{},null,{allow:"not_set|ok"});
if (results === undefined || results.length == undefined) {
results = [];
}
var searches = rs("filesearch");
var searchdetail = "<unknown>";
if (!(searches === undefined) && !(searches.length === undefined)) {
searches.forEach(function(s){
if (s.id == id) {
searchdetail = s.search_string;
}
});
}
return m("div",[
m("h2","turtle file search results"),
m("h3", "searchtext: " + searchdetail + " (" + results.length + ")"),
m("hr"),
m("table", [
m("tr" ,[
m("th","name"),
m("th","size"),
m("th",""),
]),
results.map(function(file){
return m("tr",[
m("th",file.name),
m("th",file.size),
m("th",[
m("span.btn", {
onclick:function(){
rs.request("transfers/control_download", {
action: "begin",
name: file.name,
size: file.size,
hash: file.hash,
});
}
},
"download")
]),
])
})
])
])
}
}