Commit 4267ba77 authored by Ayush Tiwari's avatar Ayush Tiwari

[hal_json + web_renderjs_ui]: Generate URLs using URL columns for renderJS UI

Also, change the JSON format and update tests according to these changes
parent 69013fa0
...@@ -24,5 +24,6 @@ return context.ERP5Document_getHateoas( ...@@ -24,5 +24,6 @@ return context.ERP5Document_getHateoas(
sort_on=sort_on, sort_on=sort_on,
local_roles=local_roles, local_roles=local_roles,
selection_domain=selection_domain, selection_domain=selection_domain,
extra_param_json=extra_param_json,
restricted=1 restricted=1
) )
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None, extra_param_json=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, local_roles=None, form=None, relative_url=None, restricted=0, list_method=None, default_param_json=None, form_relative_url=None, bulk_list="[]", sort_on=None, selection_domain=None, extra_param_json=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -1182,8 +1182,8 @@ return context.getPortalObject().foo_module.contentValues() ...@@ -1182,8 +1182,8 @@ return context.getPortalObject().foo_module.contentValues()
) )
result_dict = json.loads(result) result_dict = json.loads(result)
#editalble creation date is defined at proxy form #editalble creation date is defined at proxy form
self.assertEqual(result_dict['_embedded']['contents'][0]['creation_date']['type'], 'DateTimeField') self.assertEqual(result_dict['_embedded']['contents'][0]['creation_date']['field_gadget_param']['type'], 'DateTimeField')
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['type'], 'DateTimeField') self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param']['type'], 'DateTimeField')
# There is a count method on this listbox # There is a count method on this listbox
self.assertEqual(result_dict['_embedded']['count'], 0) self.assertEqual(result_dict['_embedded']['count'], 0)
...@@ -1241,12 +1241,12 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id ...@@ -1241,12 +1241,12 @@ return context.getPortalObject().portal_catalog(portal_type='Foo', sort_on=[('id
) )
result_dict = json.loads(result) result_dict = json.loads(result)
self.assertEqual(2, len(result_dict['_embedded']['contents'])) self.assertEqual(2, len(result_dict['_embedded']['contents']))
self.assertIn("field_listbox", result_dict['_embedded']['contents'][0]['id']['key']) self.assertIn("field_listbox", result_dict['_embedded']['contents'][0]['id']['field_gadget_param']['key'])
self.assertEqual("StringField", result_dict['_embedded']['contents'][0]['id']['type']) self.assertEqual("StringField", result_dict['_embedded']['contents'][0]['id']['field_gadget_param']['type'])
self.assertEqual(document_list[0].getId(), result_dict['_embedded']['contents'][0]['id']['default']) self.assertEqual(document_list[0].getId(), result_dict['_embedded']['contents'][0]['id']['field_gadget_param']['default'])
self.assertIn("field_listbox", result_dict['_embedded']['contents'][1]['id']['key']) self.assertIn("field_listbox", result_dict['_embedded']['contents'][1]['id']['field_gadget_param']['key'])
self.assertEqual("StringField", result_dict['_embedded']['contents'][1]['id']['type']) self.assertEqual("StringField", result_dict['_embedded']['contents'][1]['id']['field_gadget_param']['type'])
self.assertEqual(document_list[1].getId(), result_dict['_embedded']['contents'][1]['id']['default']) self.assertEqual(document_list[1].getId(), result_dict['_embedded']['contents'][1]['id']['field_gadget_param']['default'])
# There is a count method on the listbox # There is a count method on the listbox
self.assertEqual(result_dict['_embedded']['count'], 0) self.assertEqual(result_dict['_embedded']['count'], 0)
......
...@@ -77,12 +77,20 @@ ...@@ -77,12 +77,20 @@
{{#if editable}} {{#if editable}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> <div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
{{else}} {{else}}
<a href="{{href}}" class="ui-link"> {{#if href}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> <a href="{{href}}" class="ui-link">
</a> <div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
</a>
{{else}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
{{/if}}
{{/if}} {{/if}}
{{else}} {{else}}
<a href="{{href}}" class="ui-link">{{default}}</a> {{#if href}}
<a href="{{href}}" class="ui-link">{{default}}</a>
{{else}}
<p>{{default}}</p>
{{/if}}
{{/if}} {{/if}}
</td> </td>
{{/each}} {{/each}}
...@@ -117,12 +125,20 @@ ...@@ -117,12 +125,20 @@
{{#if editable}} {{#if editable}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> <div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
{{else}} {{else}}
<a href="{{href}}" class="ui-link"> {{#if href}}
<a href="{{href}}" class="ui-link">
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
</a>
{{else}}
<div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div> <div class="editable_div" data-column="{{column}}" data-line="{{line}}"></div>
</a> {{/if}}
{{/if}} {{/if}}
{{else}} {{else}}
<a href="{{href}}" class="ui-link">{{default}}</a> {{#if href}}
<a href="{{href}}" class="ui-link">{{default}}</a>
{{else}}
<p>{{default}}</p>
{{/if}}
{{/if}} {{/if}}
</td> </td>
{{/each}} {{/each}}
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.63630.22597.59392</string> </value> <value> <string>966.44073.11272.27409</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1520243676.37</float> <float>1523002868.97</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -468,9 +468,11 @@ ...@@ -468,9 +468,11 @@
.push(function () { .push(function () {
var lines = gadget.state.lines, var lines = gadget.state.lines,
promise_list = [], promise_list = [],
url_promise_list = [],
allDocs_result = gadget.state.allDocs_result, allDocs_result = gadget.state.allDocs_result,
counter, counter,
pagination_message = ''; pagination_message = '',
content_value;
column_list = JSON.parse(gadget.state.column_list_json); column_list = JSON.parse(gadget.state.column_list_json);
// for actual allDocs_result structure see ref:gadget_erp5_jio.js // for actual allDocs_result structure see ref:gadget_erp5_jio.js
...@@ -496,17 +498,35 @@ ...@@ -496,17 +498,35 @@
} }
}) })
); );
for (j = 0; j < column_list.length; j += 1) {
content_value = allDocs_result.data.rows[i].value[column_list[j][0]] || "";
if (content_value.url_value) {
if (content_value.url_value.command) {
url_promise_list.push(
gadget.getUrlFor(content_value.url_value)
);
} else {
url_promise_list.push(false);
}
}
}
} }
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all(promise_list); return RSVP.all([
RSVP.all(promise_list),
RSVP.all(url_promise_list)
]);
}) })
.push(function (result_list) {
.push(function (line_link_list) {
var row_list = [], var row_list = [],
value, value,
cell_list, cell_list,
url_value,
index = 0,
listbox_tbody_template, listbox_tbody_template,
line_link_list = result_list[0],
url_column_list = result_list[1],
setNonEditable = function (cell) {cell.editable = false; }; setNonEditable = function (cell) {cell.editable = false; };
// reset list of UIDs of editable sub-documents // reset list of UIDs of editable sub-documents
gadget.props.listbox_uid_dict = { gadget.props.listbox_uid_dict = {
...@@ -520,15 +540,35 @@ ...@@ -520,15 +540,35 @@
cell_list = []; cell_list = [];
for (j = 0; j < column_list.length; j += 1) { for (j = 0; j < column_list.length; j += 1) {
value = allDocs_result.data.rows[i].value[column_list[j][0]] || ""; value = allDocs_result.data.rows[i].value[column_list[j][0]] || "";
// value can be simply just a value in case of non-editable field //url column
// thus we construct "field_json" manually and insert the value in "default" // get url value
if (value.constructor !== Object) { if (value.url_value) {
url_value = url_column_list[index];
index += 1;
} else {
url_value = line_link_list[i];
}
// We need to check for field_gadget_param and then update
// value accordingly. value can be simply just a value in
// case of non-editable field thus we construct "field_json"
// manually and insert the value in "default"
if (value.constructor === Object) {
if (value.field_gadget_param) {
value = value.field_gadget_param;
} else {
value = {
'editable': 0,
'default': value.default
};
}
} else {
value = { value = {
'editable': 0, 'editable': 0,
'default': value 'default': value
}; };
} }
value.href = line_link_list[i]; value.href = url_value;
value.editable = value.editable && gadget.state.editable; value.editable = value.editable && gadget.state.editable;
value.line = i; value.line = i;
value.column = j; value.column = j;
......
...@@ -236,7 +236,7 @@ ...@@ -236,7 +236,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>966.8130.3423.18312</string> </value> <value> <string>966.54628.39321.22579</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -254,8 +254,8 @@ ...@@ -254,8 +254,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1520872134.75</float> <float>1523635564.65</float>
<string>UTC</string> <string>GMT+2</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
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