Commit dd4aeeb2 authored by Roque's avatar Roque

erp5_web_project_ui: use sql script to get project info

parent 9e0abdc6
import json
# TODO remove hardcoded fields and values, use script parameters
query = """SELECT DISTINCT COUNT(*) AS `#number` ,`related_source_project__relative_url_1_catalog`.`relative_url` AS `source_project__relative_url`,
`catalog`.`portal_type` AS `portal_type`, `catalog`.`modification_date` AS `modification_date`
FROM (catalog AS `catalog`
LEFT JOIN ( category AS `related_source_project__relative_url_category`
INNER JOIN catalog AS `related_source_project__relative_url_1_catalog`
ON related_source_project__relative_url_category.base_category_uid = 282 AND related_source_project__relative_url_1_catalog.uid = related_source_project__relative_url_category.category_uid)
ON related_source_project__relative_url_category.uid = catalog.uid)
WHERE
1 = 1
AND (`catalog`.`modification_date` >= "2019-02-19 10:02:00")
AND `catalog`.`simulation_state` IN ('planned', 'ordered', 'confirmed', 'delivered', 'ready')
AND ( `catalog`.`portal_type` IN ('Task', 'Bug', 'Task Report'))
AND ( `related_source_project__relative_url_1_catalog`.`relative_url` IS NOT NULL)
GROUP BY
`related_source_project__relative_url_1_catalog`.`relative_url`, `catalog`.`portal_type`"""
project_dict = {'someproperty': 0, 'anotherproperty': 'value'}
project_dict = {}
def getProjectId(id):
segments = id.split("/");
if (len(segments) == 2):
return id
return "/".join(segments[0:-1])
for row in context.cmf_activity_sql_connection.manage_test(query):
key = getProjectId(row['source_project__relative_url'])
if key in project_dict:
project_dict[key][row['portal_type']] = row["#number"]
else:
project_dict[key] = {row['portal_type'] : row["#number"]}
# TODO set number of outdated docs!!
# one query by "opened" state (total) and the same but filtering by modification date (outdated)
return json.dumps(project_dict, indent=2)
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getProjectInfo</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -150,7 +150,9 @@
</item>
<item>
<key> <string>renderjs_extra</string> </key>
<value> <string></string> </value>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
......@@ -243,4 +245,17 @@
</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: {"project_info_dict": here.Base_getProjectInfo()}</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -39,12 +39,9 @@
getComplexQuery({"portal_type" : "Test Result",
"source_project__validation_state" : "validated"},
"AND")),
document_query,
aux_complex_query,
aux_query_list = [],
query_list = [],
portal_type_list = ["Task", "Bug", "Task Report"],
valid_state_list = ["planned", "ordered", "confirmed", "delivered", "ready"],
//document_query,
//portal_type_list = ["Task", "Bug", "Task Report"],
//valid_state_list = ["planned", "ordered", "confirmed", "delivered", "ready"],
test_state_list = ["failed", "stopped"],
date_query,
one_year_old_date = new Date();
......@@ -62,7 +59,7 @@
value: one_year_old_date
});
document_query = Query.objectToSearchText(new SimpleQuery({
/*document_query = Query.objectToSearchText(new SimpleQuery({
key: "source_project__validation_state",
operator: "=",
type: "simple",
......@@ -71,7 +68,7 @@
// done with string queries directly because there is no way to do "key IN <list-of-values>" with Query
// unless appending simple queries with AND by iterating on list but it's inefficient
document_query += ' AND portal_type: ("' + portal_type_list.join('", "') + '")';
document_query += ' AND simulation_state: ("' + valid_state_list.join('", "') + '")';
document_query += ' AND simulation_state: ("' + valid_state_list.join('", "') + '")';*/
return new RSVP.Queue()
.push(function () {
......@@ -90,12 +87,6 @@
select_list: select_list,
sort_on: [["modification_date", "descending"]]
}));
promise_list.push(gadget.jio_allDocs({
query: document_query,
limit: limit,
select_list: select_list,
sort_on: [["modification_date", "descending"]]
}));
promise_list.push(gadget.jio_allDocs({
query: test_result_query,
limit: limit,
......@@ -103,14 +94,20 @@
group_by: ['source_project__relative_url'],
sort_on: [["modification_date", "descending"]]
}));
/*promise_list.push(gadget.jio_allDocs({
query: document_query,
limit: limit,
select_list: select_list,
sort_on: [["modification_date", "descending"]]
}));*/
return RSVP.all(promise_list);
})
.push(function (result_list) {
return [result_list[0].data.rows, result_list[1].data.rows, result_list[2].data.rows, result_list[3].data.rows];
return [result_list[0].data.rows, result_list[1].data.rows, result_list[2].data.rows/*, result_list[3].data.rows*/];
});
}
function renderProjectList(project_list, milestone_list, document_list, test_result_list) {
function renderProjectList(project_info_dict, project_list, milestone_list, test_result_list) {
var i, j,
item,
project_html,
......@@ -194,14 +191,17 @@
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('render', function (options) {
if (options.project_info_dict) {
options.project_info_dict = JSON.parse(options.project_info_dict);
}
return this.changeState(options);
})
.onStateChange(function () {
.onStateChange(function (modification_dict) {
var gadget = this;
return getProjectElementList(gadget)
.push(function (element_list) {
renderProjectList(element_list[0], element_list[1]);
renderProjectList(modification_dict.project_info_dict, element_list[0], element_list[1], element_list[2]);
});
})
......
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