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