Commit 5104af10 authored by Alain Takoudjou's avatar Alain Takoudjou

Mynij Search: Fix error when there is no result from searx search.

parent 18460604
...@@ -169,6 +169,7 @@ ...@@ -169,6 +169,7 @@
.declareMethod("add_searx_results", function (key) { .declareMethod("add_searx_results", function (key) {
var gadget = this; var gadget = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return jIO.util.ajax({ return jIO.util.ajax({
...@@ -177,12 +178,9 @@ ...@@ -177,12 +178,9 @@
}); });
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
var error_html; return gadget.state.result_gadget.add_searx_no_result(
error_html = document.createElement("p"); "An error occured, please try again. " + error.message || ''
error_html.className = "no-result"; );
error_html.textContent = "An error occured, please try again. " +
error.message || '';
return gadget.state.result_gadget.show_searx_result(error_html);
}) })
.push(function (resultHTML) { .push(function (resultHTML) {
var i, var i,
...@@ -192,6 +190,10 @@ ...@@ -192,6 +190,10 @@
resultHTML.currentTarget.response, resultHTML.currentTarget.response,
"text/html"); "text/html");
elements = doc.body.querySelectorAll('div.result.result-default'); elements = doc.body.querySelectorAll('div.result.result-default');
if (elements.length === 0)
return gadget.state.result_gadget.add_searx_no_result(
"No result from your input, please update and try again."
);
for (i = 0; i < elements.length; i += 1) { for (i = 0; i < elements.length; i += 1) {
promise_list.push(gadget.state.result_gadget.show_searx_result( promise_list.push(gadget.state.result_gadget.show_searx_result(
elements[i], elements[i],
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.25983.38944.13892</string> </value> <value> <string>987.26215.20691.32768</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1603109825.17</float> <float>1603124167.5</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -95,6 +95,20 @@ ...@@ -95,6 +95,20 @@
}); });
}) })
.declareMethod("add_searx_no_result", function (msg) {
var error_html,
list_item = document.createElement("li"),
loader = document.getElementById("searx-loading"),
list = document.getElementById("searx-results");
loader.style.display = "none";
error_html = document.createElement("p");
error_html.className = "no-result";
error_html.textContent = msg;
list_item.appendChild(error_html);
list.appendChild(list_item);
})
.declareMethod("show_searx_result", function (item, key) { .declareMethod("show_searx_result", function (item, key) {
var list, var list,
list_item, list_item,
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.25959.50752.32221</string> </value> <value> <string>987.26221.22837.50619</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1603109745.73</float> <float>1603124223.76</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
display: none; display: none;
} }
.no-result {
font-size: 1.5em;
}
@media (max-width: 600px) { @media (max-width: 600px) {
#mynij-results > li, #searx-results > li { #mynij-results > li, #searx-results > li {
width: 100%; width: 100%;
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.26073.25277.8823</string> </value> <value> <string>987.26223.8725.60620</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1603115441.29</float> <float>1603124265.14</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment