Commit a08a8750 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Major refactor on "News" API, update gadgets to use getNewsDict

Speed up the rendering and only do xhr to update if the user stays long enough on the page.

This change will significally drop the number of xhr on the site.
parent 68ba9666
......@@ -17,19 +17,23 @@
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, value, len = result.data.total_rows;
var i, value, news, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
if ((result.data.rows[i].value.hasOwnProperty("Computer_getNewsDict"))) {
value = result.data.rows[i].id;
result.data.rows[i].value.monitoring_status = {
news = result.data.rows[i].value.Computer_getNewsDict;
result.data.rows[i].value.Computer_getNewsDict = {
field_gadget_param : {
css_class: "",
description: "The Status",
hidden: 0,
"default": {jio_key: value},
"default": {jio_key: value,
result: news},
key: "status",
url: "gadget_slapos_computer_status.html",
title: "Status",
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
......@@ -74,7 +78,7 @@
['title', 'Title'],
['reference', 'Reference'],
['allocation_scope_title', 'Allocation Scope'],
['monitoring_status', 'Status']
['Computer_getNewsDict', 'Status']
];
return form_list.render({
erp5_document: {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.40849.41394.30003</string> </value>
<value> <string>972.38797.10404.27528</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1522772679.86</float>
<float>1545935797.99</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -27,14 +27,14 @@
.push(function (result) {
var i, value, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].value.monitoring_status)) {
value = result.data.rows[i].id;
result.data.rows[i].value.monitoring_status = {
if (1 || (result.data.rows[i].value.SoftwareInstallation_getNewsDict)) {
value = result.data.rows[i].value.SoftwareInstallation_getNewsDict;
result.data.rows[i].value.SoftwareInstallation_getNewsDict = {
field_gadget_param : {
css_class: "",
description: "The Status",
hidden: 0,
"default": {jio_key: value},
"default": {jio_key: value, result: value},
key: "status",
url: "gadget_slapos_installation_status.html",
title: "Status",
......@@ -108,7 +108,7 @@
column_list = [
['SoftwareInstallation_getSoftwareReleaseInformation', 'Software Release'],
['url_string', 'Url'],
['monitoring_status', 'Status']
['SoftwareInstallation_getNewsDict', 'Status']
],
ticket_column_list = [
['title', 'Title'],
......@@ -235,7 +235,8 @@
"my_monitoring_status": {
"description": "",
"title": "Monitoring Status",
"default": {jio_key: gadget.state.jio_key},
"default": {jio_key: gadget.state.jio_key,
result: gadget.state.doc.news},
"css_class": "",
"required": 1,
"editable": 0,
......
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>972.38674.1768.18517</string> </value>
<value> <string>972.38762.9625.45482</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -275,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1545925663.89</float>
<float>1545932477.94</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -16,19 +16,23 @@
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, value, len = result.data.total_rows;
var i, value, news, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
if (result.data.rows[i].value.hasOwnProperty("ComputerNetwork_getNewsDict")) {
value = result.data.rows[i].id;
result.data.rows[i].value.monitoring_status = {
news = result.data.rows[i].value.ComputerNetwork_getNewsDict;
result.data.rows[i].value.ComputerNetwork_getNewsDict = {
field_gadget_param : {
css_class: "",
description: "The Status",
hidden: 0,
"default": {jio_key: value},
"default": {jio_key: value,
result: news},
key: "status",
url: "gadget_slapos_network_status.html",
title: "Status",
type: "GadgetField"
}
};
result.data.rows[i].value["listbox_uid:list"] = {
key: "listbox_uid:list",
......@@ -66,7 +70,7 @@
var column_list = [
['title', 'Title'],
['reference', 'Reference'],
['monitoring_status', 'Status']
['ComputerNetwork_getNewsDict', 'Status']
];
return form_list.render({
erp5_document: {
......
......@@ -241,7 +241,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>966.41526.6603.40089</string> </value>
<value> <string>972.38848.17221.24388</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -259,7 +259,7 @@
</tuple>
<state>
<tuple>
<float>1523031808.56</float>
<float>1545936199.72</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -16,15 +16,17 @@
var gadget = this;
return gadget.jio_allDocs(param_list[0])
.push(function (result) {
var i, value, len = result.data.total_rows;
var i, value, news, len = result.data.total_rows;
for (i = 0; i < len; i += 1) {
if (1 || (result.data.rows[i].hasOwnProperty("id"))) {
if (1 || (result.data.rows[i].value.hasOwnProperty("Project_getNewsDict"))) {
value = result.data.rows[i].id;
result.data.rows[i].value.monitoring_status = {
news = result.data.rows[i].Project_getNewsDict;
result.data.rows[i].value.Project_getNewsDict = {
css_class: "",
description: "The Status",
hidden: 0,
"default": {jio_key: value},
"default": {jio_key: value,
result: news},
key: "status",
url: "gadget_slapos_project_status.html",
title: "Status",
......@@ -73,7 +75,7 @@
column_list = [
['title', 'Title'],
['reference', 'Reference'],
['monitoring_status', 'Status']
['Project_getNewsDict', 'Status']
];
destination_project_list = "%22NULL%22%2C";
for (i in result[1].assignment_destination_project_list) {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>965.32073.32542.58777</string> </value>
<value> <string>972.32024.53732.34406</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1522772741.41</float>
<float>1545936132.29</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -65,12 +65,7 @@
return partition_class;
}
function getStatus(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
function getStatus(gadget, result) {
var monitor_url,
status_class = 'ui-btn-no-data',
status_title = 'Computer',
......@@ -79,8 +74,8 @@
status_style = '',
right_style = '';
status_class = checkComputerStatus(result);
right_class = checkComputerPartitionStatus(result);
status_class = checkComputerStatus({news: result.news.computer});
right_class = checkComputerPartitionStatus({computer_partition_news: result.news.partition});
monitor_url = 'https://monitor.app.officejs.com/#/?page=ojsm_dispatch&query=portal_type%3A%22Software%20Instance%22%20AND%20aggregate_reference%3A%22' + result.reference + '%22';
if (status_class === 'ui-btn-no-data') {
......@@ -97,6 +92,15 @@
right_style: right_style
});
return gadget;
}
function getStatusLoop(gadget) {
return new RSVP.Queue()
.push(function () {
return gadget.jio_get(gadget.options.value.jio_key);
})
.push(function (result) {
return getStatus(gadget, result);
});
}
......@@ -116,19 +120,19 @@
return {};
})
.declareJob("getStatus", function () {
.declareJob("getStatus", function (result) {
var gadget = this;
return getStatus(gadget);
return getStatus(gadget, {news: result});
})
.onLoop(function () {
var gadget = this;
return getStatus(gadget);
return getStatusLoop(gadget);
}, 300000)
.declareMethod("render", function (options) {
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
return gadget.getStatus(options.value.result);
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.33041.14393.16810</string> </value>
<value> <string>972.38770.30010.49920</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1530119165.7</float>
<float>1545932459.6</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -63,9 +63,23 @@
.declareMethod("getContent", function () {
return {};
})
.declareJob("getStatus", function () {
var gadget = this;
return getStatus(gadget);
.declareJob("getStatus", function (result) {
var gadget = this,
status_class = 'ui-btn-no-data',
status_title = 'Installation',
status_style = "";
status_class = checkInstallationStatus({news: result});
if (status_class === 'ui-btn-no-data') {
status_style = "color: transparent !important;";
}
gadget.element.innerHTML = inline_status_template({
status_class: status_class,
status_title: status_title,
status_style: status_style
});
return gadget;
})
.onLoop(function () {
var gadget = this;
......@@ -76,7 +90,7 @@
var gadget = this;
gadget.options = options;
gadget.flag = options.value.jio_key;
return gadget.getStatus();
return gadget.getStatus(options.value.result);
});
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -257,7 +257,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.33049.60346.61764</string> </value>
<value> <string>972.38717.20279.51251</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -275,7 +275,7 @@
</tuple>
<state>
<tuple>
<float>1530119205.48</float>
<float>1545928626.78</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getHateoasNews</string> </value>
<value> <string>Base_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
computer_dict = {}
computer_partition_dict = {}
for computer in computer_list:
news_dict = computer.Computer_getNewsDict()
computer_dict[computer.getReference()] = news_dict["computer"]
computer_partition_dict[computer.getReference()] = news_dict["partition"]
return {"computer": computer_dict,
"partition": computer_partition_dict}
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>computer_list, REQUEST=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getNewsDictFromComputerList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if REQUEST is not None:
raise Unauthorized
computer_network_partition_dict = {}
for computer in context.getSubordinationRelatedValueList(portal_type="Computer"):
computer_network_partition_dict[computer.getReference()] = computer.Computer_getHateoasComputerPartitionNews()
return computer_network_partition_dict
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
return context.Base_getNewsDictFromComputerList(
context.getSubordinationRelatedValueList(portal_type="Computer"))
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Project_getHateoasComputerPartitionNews</string> </value>
<value> <string>ComputerNetwork_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
if REQUEST is not None:
raise Unauthorized
computer_partition_dict = { }
for computer_partition in context.objectValues(portal_type="Computer Partition"):
software_instance = computer_partition.getAggregateRelatedValue(portal_type="Software Instance")
if software_instance is not None:
computer_partition_dict[computer_partition.getTitle()] = context.Base_getHateoasNews(software_instance)
return computer_partition_dict
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
def get_computer_partition_dict(reference):
computer_dict = context.Base_getNewsDict(context)
computer_partition_dict = { }
for computer_partition in context.objectValues(portal_type="Computer Partition"):
software_instance = computer_partition.getAggregateRelatedValue(portal_type="Software Instance")
if software_instance is not None:
computer_partition_dict[computer_partition.getTitle()] = context.Base_getNewsDict(software_instance)
return {"computer": computer_dict,
"partition": computer_partition_dict}
# Use Cache here, at least transactional one.
return get_computer_partition_dict(context.getReference())
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_getHateoasComputerPartitionNews</string> </value>
<value> <string>Computer_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -100,7 +100,6 @@
<string>my_allocation_scope</string>
<string>my_subordination</string>
<string>my_news</string>
<string>my_computer_partition_news</string>
<string>my_source_title</string>
<string>my_source_project_title</string>
<string>my_monitor_scope</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>default</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_computer_partition_news</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>items</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Message Computer Partitions</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Computer_getHateoasComputerPartitionNews()</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -126,7 +126,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Base_getHateoasNews(here)</string> </value>
<value> <string>here/Computer_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
# This should be refactored
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
if REQUEST is None:
......
if REQUEST is not None:
raise Unauthorized
computer_network_partition_dict = {}
for computer in context.Organisation_getComputerTrackingList():
computer_network_partition_dict[computer.getReference()] = computer.Computer_getHateoasComputerPartitionNews()
return computer_network_partition_dict
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
return context.Base_getNewsDictFromComputerList(
context.Organisation_getComputerTrackingList())
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Organisation_getHateoasComputerPartitionNews</string> </value>
<value> <string>Organisation_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
if REQUEST is not None:
raise Unauthorized
computer_network_partition_dict = {}
for computer in context.Project_getComputerTrackingList():
computer_network_partition_dict[computer.getReference()] = computer.Computer_getHateoasComputerPartitionNews()
return computer_network_partition_dict
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
return context.Base_getNewsDictFromComputerList(
context.Project_getComputerTrackingList())
......@@ -62,7 +62,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerNetwork_getHateoasComputerPartitionNews</string> </value>
<value> <string>Project_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
return context.Base_getNewsDict(context)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstallation_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -126,7 +126,7 @@
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: here.Base_getHateoasNews(here)</string> </value>
<value> <string>here/SoftwareInstallation_getNewsDict</string> </value>
</item>
</dictionary>
</pickle>
......
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