Commit c0f2d88f authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Get proxy server URLs from configuration file

Also fix configuration file to be json compatible.
parent 9de5842a
......@@ -152,11 +152,12 @@
console.log(error);
return undefined;
})
.push(function (rconfig) {
.push(function (response) {
var rtc_config;
if (!rconfig)
if (!response)
return default_rtcconfig;
return rconfig.rtcConfig;
rtc_config = JSON.parse(response.target.responseText);
return rtc_config.rtcConfig;
});
})
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.12631.48739.25105</string> </value>
<value> <string>990.12632.20339.25224</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1614018738.61</float>
<float>1630505542.2</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, document*/
(function (window, document, rJS, RSVP) {
var gadget,
proxies = [
"https://softinst116265.host.vifib.net/erp5/ERP5Site_getHTTPResource",
"https://softinst116446.host.vifib.net/erp5/ERP5Site_getHTTPResource"
];
var gadget;
rJS(window)
.setState({
model_gadget : null,
......@@ -30,10 +26,20 @@
.push(function () {
return gadget.getDeclaredGadget("result");
})
.push(function (result) {
result_gadget = result;
return model_gadget.getConfig()
.push(function (config) {
if (!config)
return ["https://proxy1.mynij.com/proxy"];
return config.proxies.urls;
});
})
.push(function (result) {
return gadget.changeState({
model_gadget : model_gadget,
result_gadget : result
result_gadget : result_gadget,
proxies: result
});
});
})
......@@ -63,6 +69,8 @@
return gadget.getSetting('index_list', []);
})
.push(function (results) {
var add_item = document.createElement("option"),
empty_item;
index_list = results;
while (drop_list.firstChild) {
......@@ -74,6 +82,15 @@
option_item.appendChild(document.createTextNode(item));
drop_list.appendChild(option_item);
});
if (results.length === 0) {
empty_item = document.createElement("option");
empty_item.style.display = "none";
drop_list.appendChild(empty_item);
}
add_item.value = "ADD";
add_item.classList.add('add-source');
add_item.appendChild(document.createTextNode("Add Source..."));
drop_list.appendChild(add_item);
})
.push(function () {
......@@ -179,8 +196,9 @@
return new RSVP.Queue()
.push(function () {
var rng = Math.floor(Math.random() * Math.floor(proxies.length)),
proxy = proxies[rng],
var count = gadget.state.proxies.length,
rng = Math.floor(Math.random() * Math.floor(count)),
proxy = gadget.state.proxies[rng],
query = encodeURI(key);
return jIO.util.ajax({
url : proxy + "?url=https%3A%2F%2Fsoftinst141674.host.vifib.net%2Fsearch%3Fq%3D" +
......@@ -218,6 +236,19 @@
});
})
.declareService(function () {
var gadget = this,
select = this.element.querySelector(".index-select");
select.onchange = function (e) {
e.preventDefault();
if (e.target.value === "ADD") {
return gadget.redirect({"command": "display", "options": {
page: "ojs_local_controller"
}});
}
};
})
.onEvent("submit", function (event) {
var gadget = this,
search_key = document.getElementById("search_input").value,
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.12602.3691.30958</string> </value>
<value> <string>994.32554.11757.37154</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1614017833.95</float>
<float>1630510763.68</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -218,5 +218,26 @@
.push(undefined, function (my_error) {
console.log(my_error);
});
});
})
.declareMethod("getConfig", function () {
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url : "mynij-config.json"
});
})
.push(undefined, function (error) {
//no rtcconfig file found, use the default
console.log(error);
return undefined;
})
.push(function (response) {
var config_json;
if (!response)
return undefined;
config_json = JSON.parse(response.target.responseText);
return config_json;
});
});
}(window, document, RSVP, rJS, jIO));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.7469.5007.51797</string> </value>
<value> <string>989.8620.48638.3003</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1609845884.52</float>
<float>1630509683.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -6,10 +6,6 @@
var gadget_klass = rJS(window),
template_element = gadget_klass.__template_element,
concurrent_requests = 3,
proxies = [
"https://softinst116265.host.vifib.net/erp5/ERP5Site_getHTTPResource",
"https://softinst116446.host.vifib.net/erp5/ERP5Site_getHTTPResource"
],
build_template_progress = Handlebars.compile(template_element
.getElementById("build-template-progress")
.innerHTML);
......@@ -89,6 +85,7 @@
function build() {
var status;
return gadget.getIndexToBuild()
.push(function (entry) {
var link_list,
......@@ -162,7 +159,18 @@
});
}
return build();
return gadget.state.model_gadget.getConfig()
.push(function (config) {
if (!config)
config = {"proxies":
{"urls": ["https://proxy1.mynij.com/proxy"]}};
return gadget.changeState({
proxies: config.proxies.urls
});
})
.push(function () {
return build();
});
})
.onLoop(function () {
......@@ -235,8 +243,8 @@
proxy;
return new RSVP.Queue()
.push(function () {
rng = Math.floor(Math.random() * Math.floor(proxies.length));
proxy = proxies[rng];
rng = Math.floor(Math.random() * Math.floor(gadget.state.proxies.length));
proxy = gadget.state.proxies[rng];
return jIO.util.ajax({url : proxy + "?url=" + link});
})
.push(function (page) {
......@@ -350,8 +358,8 @@
return new RSVP.Queue()
.push(function () {
var rng = Math.floor(Math.random() * Math.floor(proxies.length)),
proxy = proxies[rng];
var rng = Math.floor(Math.random() * Math.floor(gadget.state.proxies.length)),
proxy = gadget.state.proxies[rng];
return jIO.util.ajax({url : proxy + "?url=" + link});
})
.push(function (page) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.3475.54016.22254</string> </value>
<value> <string>994.32596.8054.51882</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1613470010.32</float>
<float>1630513271.74</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>987.20399.12095.58538</string> </value>
<value> <string>991.47441.48178.21742</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1602776317.22</float>
<float>1619781040.08</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -153,7 +153,8 @@
link,
link_par,
body,
loader = document.getElementById("searx-loading");
loader = document.getElementById(
"searx-loading");
loader.style.display = "none";
list = document.getElementById("searx-results");
......@@ -268,6 +269,10 @@
}
return short_url;
})
.declareMethod("setSearxMoreLink", function (query) {
var link = this.querySelector('searx-morelink');
link.href = "https://searx.info/search?q=" + query + "&category_general=on";
});
}(window, RSVP, rJS, document, DOMParser, URL));
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>990.3487.35664.34628</string> </value>
<value> <string>990.5192.14888.10222</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1613572333.62</float>
<float>1619793226.18</float>
<string>UTC</string>
</tuple>
</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