Commit eb39ffef authored by Sven Franck's avatar Sven Franck Committed by Romain Courteaud

[erp5_officejs_afs_directory] Fix slowness occuring when increasing the data size

parent 3c810f5b
/*global window, rJS, RSVP, Handlebars, URI, console, jIO, document */
/*global window, rJS, RSVP, Handlebars, URI, console, jIO, document, Boolean */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, URI, document) {
(function (window, rJS, RSVP, Handlebars, URI, document, Boolean) {
"use strict";
var gadget_klass = rJS(window),
......@@ -52,7 +52,8 @@
// get categories and flatten array of category arrays
categories = softwares
.map((obj) => obj.value.category_list)
.reduce((cur, prev) => cur.concat(prev)),
.reduce((cur, prev) => cur.concat(prev))
.filter(Boolean),
// remove duplicates (case sensitive!)
unique_categories = Array.from(new Set(categories)),
......@@ -99,4 +100,4 @@
masonry_container.innerHTML = content;
});
});
}(window, rJS, RSVP, Handlebars, URI, document));
}(window, rJS, RSVP, Handlebars, URI, document, Boolean));
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>959.46981.52420.64187</string> </value>
<value> <string>978.14093.21437.32017</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1496170069.03</float>
<float>1567678787.12</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -3,7 +3,12 @@
(function (window, RSVP, rJS, Handlebars, jIO) {
"use strict";
var gadget_klass = rJS(window),
var WIKI_URL = "https://en.wikipedia.org/api/rest_v1/page/summary/",
EMPTY = ["N/A", "", 0],
FALLBACK_SOFTWARE_LOGO_PATH = "gadget_erp5_afs_camera.png?format=png",
GET = "GET",
HEADERS_DICT = {"api-user-agent": "https://www.nexedi.com/contact"},
gadget_klass = rJS(window),
templater = gadget_klass.__template_element,
display_widget_table = Handlebars.compile(
templater.getElementById("display-template").innerHTML
......@@ -30,47 +35,45 @@
.declareMethod('render', function (options) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(options.jio_key);
})
return gadget.jio_get(options.jio_key)
.push(function (publisher) {
// https://en.wikipedia.org/api/rest_v1/
// only works in for english
var wikipedia_api_url =
'https://en.wikipedia.org/api/rest_v1/page/summary/',
wiki_list = [];
var wiki_list = [];
publisher.free_software_list.map(function (software) {
if (software.commercial_support === "N/A") {
if (EMPTY.includes(software.commercial_support)) {
delete software.commercial_support;
}
if (software.logo === "N/A" || software.logo === "") {
software.logo = 'gadget_erp5_afs_camera.png?format=png';
if (EMPTY.includes(software.logo)) {
software.logo = FALLBACK_SOFTWARE_LOGO_PATH;
}
if (software.success_case_list.length === 0 ||
software.success_case_list === "N/A" ||
software.success_case_list[0].title === "N/A" ||
software.success_case_list[0].title === "") {
if (EMPTY.includes(software.success_case_list) ||
EMPTY.includes(software.success_case_list.length)
) {
delete software.success_case_list;
} else {
software.success_case_list = software.success_case_list
.filter(function (entry) {
if (!!EMPTY.includes(entry.title)) {
return entry;
}
});
software.success_case_list = clean(software.success_case_list);
}
if (software.wikipedia_url === "N/A") {
if (EMPTY.includes(software.wikipedia_url)) {
delete software.wikipedia_url;
} else {
wiki_list.push(
new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
type: "GET",
headers: {"api-user-agent": "https://www.nexedi.com/contact"},
url: wikipedia_api_url + software.wikipedia_url.split("/").pop()
type: GET,
headers: HEADERS_DICT,
url: WIKI_URL + software.wikipedia_url.split("/").pop()
});
})
.push(function (my_content) {
var response = my_content.target.response || my_content.target.responseText;
return JSON.parse(response).extract;
return JSON.parse(
my_content.target.response || my_content.target.responseText
).extract;
}, function () {
return undefined;
})
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>959.45186.37882.22272</string> </value>
<value> <string>978.15194.20575.26129</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1496067089.61</float>
<float>1567678597.73</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,10 +9,10 @@
<thead>
<tr><td rowspan="1" colspan="3">Test RenderJS UI</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init"/>
<!-- Clean Up -->
<tr>
<!--tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
......@@ -21,7 +21,7 @@
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
</tr-->
<!-- Initialize -->
<tr>
......@@ -232,7 +232,7 @@
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//span[text()='1 Records']</td>
<td>//span[text()='2 Records']</td>
<td></td>
</tr>
<tr>
......
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