Commit 08238d06 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 3dd9c853
/*global window, rJS, RSVP, Handlebars, URI */
/*global window, rJS, RSVP, Handlebars, Query */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, Handlebars, URI) {
(function (window, rJS, RSVP, Handlebars, Query) {
"use strict";
/////////////////////////////////////////////////////////////////
......@@ -20,6 +20,7 @@
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
/////////////////////////////////////////////////////////////////
......@@ -33,58 +34,43 @@
page_icon: 'clipboard'
})
.push(function () {
return gadget.jio_getAttachment(
'portal_workflow',
'links'
);
return gadget.getSetting("hateoas_url");
})
.push(function (result) {
.push(function (hateoas_url) {
return gadget.jio_getAttachment(
// result.data.rows[0].id,
'portal_workflow',
result._links.action_worklist.href
'support_request_module',
hateoas_url + 'support_request_module' +
'/SupportRequestModule_getWorklistAsJson'
);
})
.push(function (links) {
.push(function (result) {
/*jslint continue:true*/
var action_list = links.worklist,
query_string,
promise_list = [],
var promise_list = [],
display_options,
i;
for (i = 0; i < action_list.length; i += 1) {
query_string = new URI(action_list[i].href).query(true).query;
if (query_string.indexOf('portal_type:"Support Request"') === -1) {
for (i = 0; i < result.length; i += 1) {
if (result[i].action_count === 0) {
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([
gadget.getUrlFor({command: 'display', options: display_options}),
// Remove the counter from the title
action_list[i].name,
action_list[i].count
result[i].action_name,
result[i].action_count
]));
}
return RSVP.all(promise_list);
})
.push(function (result_list) {
var line_list = [],
i;
var line_list = [], i;
for (i = 0; i < result_list.length; i += 1) {
line_list.push({
link: result_list[i][0],
......@@ -97,5 +83,4 @@
});
});
});
}(window, rJS, RSVP, Handlebars, URI));
\ No newline at end of file
}(window, rJS, RSVP, Handlebars, Query));
\ 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