Commit a8242838 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Support worklists leading to multiple modules

ERP5JS will display the worklist on the search page in such case.
parent e52b6e1a
......@@ -1219,24 +1219,33 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
.asSearchTextExpression(sql_catalog)
query += ' AND %s' % role_query.replace('simulation_state', 'local_roles')
worklist_dict = {
'href': url_template_dict["jio_search_template"] % {
"query": make_query({"query": query})
},
'name': Base_translateString(re.sub(r' \(\d+\)$', '', action['name'])),
'count': action['count']
}
portal_type_list = action['query'].get('portal_type', None)
if (portal_type_list):
worklist_module_id = None
if same_type(portal_type_list, ''):
portal_type_list = [portal_type_list]
portal_type = action['query'].get('portal_type', None)
if (portal_type):
if not same_type(portal_type, ''):
portal_type = portal_type[0]
for portal_type in portal_type_list:
if (worklist_module_id is None):
worklist_module_id = portal.getDefaultModuleId(portal_type, default=None, only_visible=True)
elif (worklist_module_id != portal.getDefaultModuleId(portal_type, default=None, only_visible=True)):
worklist_module_id = None
if worklist_module_id is None:
break
worklist_module_id = portal.getDefaultModuleId(portal_type, default=None, only_visible=True)
if (worklist_module_id is not None):
work_list.append({
'href': url_template_dict["jio_search_template"] % {
"query": make_query({"query": query})
},
'name': Base_translateString(re.sub(r' \(\d+\)$', '', action['name'])),
'count': action['count'],
'module': default_document_uri_template % {
"relative_url": worklist_module_id
}
})
worklist_dict['module'] = default_document_uri_template % {
"relative_url": worklist_module_id
}
work_list.append(worklist_dict)
result_dict["worklist"] = work_list
......
......@@ -1080,7 +1080,7 @@ class TestERP5Document_getHateoas_mode_worklist(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(len(work_list), 1)
self.assertTrue(work_list[0]['count'] > 0)
self.assertEqual(work_list[0]['name'], 'Draft To Validate')
self.assertEqual(work_list[0]['module'], 'urn:jio:get:bar_module')
self.assertFalse('module' in work_list[0])
self.assertEqual(work_list[0]['href'], 'urn:jio:allDocs?query=portal_type%3A%28%22Bar%22%20OR%20%22Foo%22%29%20AND%20simulation_state%3A%22draft%22')
self.assertEqual(result_dict['_debug'], "worklist")
......@@ -1182,7 +1182,7 @@ return msg"
self.assertEqual(len(work_list), 1)
self.assertEqual(work_list[0]['name'], 'daiyanzhen')
self.assertTrue(work_list[0]['count'] > 0)
self.assertEqual(work_list[0]['module'], 'urn:jio:get:bar_module')
self.assertFalse('module' in work_list[0])
self.assertEqual(work_list[0]['href'], 'urn:jio:allDocs?query=portal_type%3A%28%22Bar%22%20OR%20%22Foo%22%29%20AND%20simulation_state%3A%22draft%22')
self.assertEqual(result_dict['_debug'], "worklist")
......
......@@ -48,18 +48,27 @@
var action_list = links.worklist,
query_string,
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;
display_options = {extended_search: query_string};
promise_list.push(RSVP.all([
gadget.getUrlFor({command: 'display', options: {
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
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.18006.50413.2645</string> </value>
<value> <string>955.63782.5969.52053</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1479305907.63</float>
<float>1481795737.46</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -32,7 +32,7 @@
<!-- Generate links to worklist on default module view -->
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-scope='m']//a[text()='Draft To Validate ' and contains(@href, '#!display') and contains(@href, 'n.jio_key=bar_module')]</td>
<td>//div[@data-gadget-scope='m']//a[text()='Draft To Validate ' and contains(@href, '#!display')]</td>
<td></td>
</tr>
......@@ -40,7 +40,7 @@
<!-- Header has a link to the previous history entry -->
<tr>
<td>click</td>
<td>//div[@data-gadget-scope='m']//a[text()='Draft To Validate ' and contains(@href, '#!display') and contains(@href, 'n.jio_key=bar_module')]</td>
<td>//div[@data-gadget-scope='m']//a[text()='Draft To Validate ' and contains(@href, '#!display')]</td>
<td></td>
</tr>
<tr>
......
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