Commit 29795b08 authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: Another approach for worklists

This reapplies parts of 9a84ef83 , but a
different server side approach:
 * use portal_workflow API to count worklists
 * introspect workflow to build queries
 * use translated state in the query, trying to be a bit more user
   friendly. We could do for portal_type as well.

This workarounds #20180907-24A654C a problem with queries generated by
gadget worklist does not seem to support complex queries with multiple
values ( local_roles: ['Assignor', 'Assignee'] ). This code generates
queries:

```
( ( local_roles:  "Assignee" OR local_roles:  "Assignor" ) AND portal_type:  "Support Request" AND translated_simulation_state_title:  "Opened" )
```

where the previous version generated queries like:

```
( portal_type:  "Support Request" AND simulation_state:  "validated" AND local_roles: (  "Assignee" OR  "Assignor" ) )
```

which did not match anything. Maybe because local_roles is handled
differently in catalog
parent 31ca17e8
Pipeline #5550 failed with stage
in 0 seconds
/*global window, rJS, RSVP, Handlebars, URI */ /*global window, rJS, RSVP, Handlebars, Query */
/*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, Query) {
"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: Query.objectToSearchText(result[i].query),
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, Query));
}(window, rJS, RSVP, Handlebars, URI)); \ No newline at end of file
\ No newline at end of file
"""Returns the worklists queries for ticket workflow, as a mapping where the key is the worklist ID and the value a JIO query.
This script has proxy role, as only manager can access workflow configuration.
"""
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
query_dict = {}
workflow = portal.portal_workflow.ticket_workflow
workflow_state_var = workflow.variables.getStateVar()
for worklist in workflow.worklists.objectValues():
query_list = [{
'type': 'complex',
'operator': 'OR',
'query_list': [
{'key': 'local_roles',
'type': 'simple',
'value': role, } for role in worklist.getGuard().getRolesText().split("; ")]
}]
for key in worklist.getVarMatchKeys():
value = worklist.getVarMatch(key)
if key == workflow_state_var:
# instead of having {'validation_state': 'draft'}, we want to have
# {'translated_validation_state_title': 'Brouillon'}
# so that it looks good in the module view.
key = 'translated_%s_title' % key
state_title = workflow['states'].restrictedTraverse(value).title_or_id()
value = unicode(translateString(
'%s [state in %s]' % (state_title, workflow.getId()),
default=unicode(translateString(state_title))))
query_list.append({
'key': key,
'value': value,
'type': 'simple',
})
query_dict[worklist.getId()] = {
'type': 'complex',
'query_list': query_list
}
return query_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></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>ERP5Site_getTicketWorkflowWorklistInfoDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# return worklists from ticket workflow in JSON format
from Products.ERP5Type.Message import translateString
import json
portal = context.getPortalObject()
worklist_query_dict = portal.ERP5Site_getTicketWorkflowWorklistInfoDict()
# Query portal actions to get the worklist count and
# extend this information with the query from our helper script.
worklist_action_list = [
{
'action_name': unicode(translateString(action['name'].rsplit(' (', 1)[0])), # Action name include the count, but we display it separatly.
'action_count': action['count'],
'query': worklist_query_dict[action['worklist_id']],
}
for action in portal.portal_actions.listFilteredActionsFor(context)['global']
if action['category'] == 'global' and action.get('workflow_id') == 'ticket_workflow'
]
return json.dumps(worklist_action_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