From 4a8db15da6e25bc554b4be873cefcc1525e75d7b Mon Sep 17 00:00:00 2001 From: zeners Date: Sat, 9 Jan 2016 17:39:04 +0100 Subject: [PATCH] webui: searchdetails and searchlist splitted --- libresapi/src/webui-src/app/main.js | 2 +- libresapi/src/webui-src/app/menu.js | 3 +- libresapi/src/webui-src/app/menudef.js | 5 ++ libresapi/src/webui-src/app/retroshare.js | 2 +- libresapi/src/webui-src/app/search.js | 59 +++++++-------------- libresapi/src/webui-src/app/searchresult.js | 54 +++++++++++++++++++ 6 files changed, 83 insertions(+), 42 deletions(-) create mode 100644 libresapi/src/webui-src/app/searchresult.js diff --git a/libresapi/src/webui-src/app/main.js b/libresapi/src/webui-src/app/main.js index bccbfd616..a7f687ee3 100644 --- a/libresapi/src/webui-src/app/main.js +++ b/libresapi/src/webui-src/app/main.js @@ -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()), diff --git a/libresapi/src/webui-src/app/menu.js b/libresapi/src/webui-src/app/menu.js index 36a00e3f1..2faaa1205 100644 --- a/libresapi/src/webui-src/app/menu.js +++ b/libresapi/src/webui-src/app/menu.js @@ -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(){ diff --git a/libresapi/src/webui-src/app/menudef.js b/libresapi/src/webui-src/app/menudef.js index f1b937cd9..dba9208e0 100644 --- a/libresapi/src/webui-src/app/menudef.js +++ b/libresapi/src/webui-src/app/menudef.js @@ -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.*", diff --git a/libresapi/src/webui-src/app/retroshare.js b/libresapi/src/webui-src/app/retroshare.js index 1b27aaeac..e7e2521a3 100644 --- a/libresapi/src/webui-src/app/retroshare.js +++ b/libresapi/src/webui-src/app/retroshare.js @@ -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); diff --git a/libresapi/src/webui-src/app/search.js b/libresapi/src/webui-src/app/search.js index 0e7f24308..70bb3e9f5 100644 --- a/libresapi/src/webui-src/app/search.js +++ b/libresapi/src/webui-src/app/search.js @@ -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", { - onclick:function(){ - rs.request("transfers/control_download", { - action: "begin", - name: file.name, - size: file.size, - hash: file.hash, - }); - } - }, - "download") - ]), - ]) + 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(){ + m.route("/search/" + item.id); + } + }, item.search_string + " (" + res.length + ")"); }) ]) ]) diff --git a/libresapi/src/webui-src/app/searchresult.js b/libresapi/src/webui-src/app/searchresult.js new file mode 100644 index 000000000..67df7ef73 --- /dev/null +++ b/libresapi/src/webui-src/app/searchresult.js @@ -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 = ""; + 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") + ]), + ]) + }) + ]) + ]) + } +} +