Commit 9a84ef83 authored by Boxiang Sun's avatar Boxiang Sun Committed by Tristan Cavelier

erp5_officejs_support_request_ui: Speedup the Support Request worklist searching.

Use a custom ERP5 script instead global worklist searching.
parent 7783be22
/*global window, rJS, RSVP, Handlebars, URI */ /*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, URI) { (function (window, rJS, RSVP, Handlebars) {
"use strict"; "use strict";
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -33,58 +34,43 @@ ...@@ -33,58 +34,43 @@
page_icon: 'clipboard' page_icon: 'clipboard'
}) })
.push(function () { .push(function () {
return gadget.jio_getAttachment( return gadget.getSetting("hateoas_url");
'portal_workflow',
'links'
);
}) })
.push(function (result) { .push(function (hateoas_url) {
return gadget.jio_getAttachment( return gadget.jio_getAttachment(
// result.data.rows[0].id, 'support_request_module',
'portal_workflow', hateoas_url + 'support_request_module'
result._links.action_worklist.href + "/SupportRequestModule_getWorklistAsJson"
); );
}) })
.push(function (links) { .push(function (result) {
/*jslint continue:true*/ /*jslint continue:true*/
var action_list = links.worklist, var promise_list = [],
query_string,
promise_list = [],
display_options, display_options,
i; i;
for (i = 0; i < action_list.length; i += 1) {
query_string = new URI(action_list[i].href).query(true).query; for (i = 0; i < result.length; i += 1) {
if (query_string.indexOf('portal_type:"Support Request"') === -1) { if (result[i].action_count === 0) {
continue; continue;
} }
display_options = {extended_search: query_string}; display_options = {
jio_key: "support_request_module",
extended_search: result[i].query_string,
page: 'form',
view: 'view'
};
if (action_list[i].hasOwnProperty('module')) {
display_options = {
jio_key: new URI(action_list[i].module).segment(2),
extended_search: query_string,
page: 'form',
view: 'view'
};
} else {
display_options = {
extended_search: query_string,
page: 'search'
};
}
promise_list.push(RSVP.all([ promise_list.push(RSVP.all([
gadget.getUrlFor({command: 'display', options: display_options}), gadget.getUrlFor({command: 'display', options: display_options}),
// Remove the counter from the title // Remove the counter from the title
action_list[i].name, result[i].action_name,
action_list[i].count result[i].action_count
])); ]));
} }
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function (result_list) { .push(function (result_list) {
var line_list = [], var line_list = [], i;
i;
for (i = 0; i < result_list.length; i += 1) { for (i = 0; i < result_list.length; i += 1) {
line_list.push({ line_list.push({
link: result_list[i][0], link: result_list[i][0],
...@@ -97,5 +83,4 @@ ...@@ -97,5 +83,4 @@
}); });
}); });
}); });
}(window, rJS, RSVP, Handlebars));
}(window, rJS, RSVP, Handlebars, URI)); \ No newline at end of file
\ No newline at end of file
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.13948.13888.3242</string> </value> <value> <string>962.26499.5927.24507</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1506505200.17</float> <float>1506651141.01</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
import json
portal = context.getPortalObject()
count_list = []
state_dict = {
"submitted": "Support Request to Open",
"draft": "Support Request to Submit",
"validated": "Support Request to Close",
"suspended": "Suspended Support Requests"
}
# XXX hardcoded, these lines below reflect portal_workflow/ticket_workflow worklists
count_list.append({
'query_string': 'portal_type:"Support Request" AND simulation_state:"draft" AND local_roles:"Owner"',
'action_name': state_dict["draft"],
'action_count': portal.support_request_module.countFolder(portal_type="Support Request", simulation_state="draft", local_roles="Owner")[0][0]})
count_list.append({
'query_string': 'portal_type:"Support Request" AND simulation_state:"submitted" AND local_roles:"Assignor"',
'action_name': state_dict["submitted"],
'action_count': portal.support_request_module.countFolder(portal_type="Support Request", simulation_state="submitted", local_roles="Assignor")[0][0]})
count_list.append({
'query_string': 'portal_type:"Support Request" AND simulation_state:"validated" AND local_roles:("Assignee" OR "Assignor")',
'action_name': state_dict["validated"],
'action_count': portal.support_request_module.countFolder(portal_type="Support Request", simulation_state="validated", local_roles=("Assignee", "Assignor"))[0][0]})
count_list.append({
'query_string': 'portal_type:"Support Request" AND simulation_state:"suspended" AND local_roles:("Assignee" OR "Assignor")',
'action_name': state_dict["suspended"],
'action_count': portal.support_request_module.countFolder(portal_type="Support Request", simulation_state="suspended", local_roles=("Assignee", "Assignor"))[0][0]})
return json.dumps(count_list)
<?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>SupportRequestModule_getWorklistAsJson</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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