Commit fd82f0d1 authored by Roque's avatar Roque

erp5_officejs: jio_allDocs queries can be done on local data storage after appcachestorage sync

parent 06d61302
......@@ -90,13 +90,20 @@
/////////////////////////////////////////////////////////////////
.declareMethod("getFormDefinition", function (portal_type) {
var gadget = this;
//TODO: the corresponding action must be get via allDocs -not implemented in appcachestorage yet
return gadget.jio_get("portal_types/HTML Post/2")
.push(function (action_result) {
return gadget.jio_get(action_result._embedded._view.my_action["default"])
.push(function (result) {
return result._embedded._view.my_form_definition["default"];
var gadget = this,
parent = "portal_types/" + portal_type,
query = 'portal_type: "Action Information" AND reference: "jio_view" AND parent_relative_url: "' + parent + '"';
return gadget.jio_allDocs({query: query})
.push(function (data) {
if (data.data.rows.length === 0) {
throw "Can not find jio_view action for portal type " + portal_type;
}
return gadget.jio_get(data.data.rows[0].id)
.push(function (action_result) {
return gadget.jio_get(action_result.action)
.push(function (form_result) {
return form_result.form_definition;
});
});
});
})
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.31714.23130.16571</string> </value>
<value> <string>974.38574.15384.64529</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1553262870.8</float>
<float>1553525314.0</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -734,7 +734,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.31714.43269.18500</string> </value>
<value> <string>974.38461.51527.60023</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -752,7 +752,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1553114789.83</float>
<float>1553524697.35</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -237,7 +237,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.31314.47298.63044</string> </value>
<value> <string>974.38565.24349.65194</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -255,7 +255,7 @@
</tuple>
<state>
<tuple>
<float>1553089133.43</float>
<float>1553525326.06</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -60,6 +60,34 @@
});
}
function processHateoasDict(raw_dict) {
var return_dict = {};
try {
var raw_fields = raw_dict._embedded._view,
type = raw_dict._links.type.name,
parent = raw_dict._links.parent.name;
return_dict.parent_relative_url = "portal_types/" + parent;
return_dict.portal_type = type;
for (var field_key in raw_fields) {
var field_id = "";
if (raw_fields[field_key]["default"] !== undefined && raw_fields[field_key]["default"] !== "") {
if (field_key.startsWith("my_")) {
field_id = field_key.replace("my_", "");
} else if (field_key.startsWith("your_")) {
field_id = field_key.replace("your_", "");
} else {
field_id = field_key;
}
return_dict[field_id] = raw_fields[field_key]["default"];
}
}
} catch (e) {
// raw_dict is a blob
return raw_dict;
}
return return_dict;
}
rJS(window)
.ready(function (gadget) {
......@@ -128,8 +156,8 @@
// the hash layer of the appcachestorage is asociated to local data storage selected
jio_appchache_options.signature_sub_storage.sub_storage.database = "appcachestorage-hash-" + jio_storage_name;
appcache_storage = jIO.createJIO(jio_appchache_options);
// check if appcache-local sync needs to be done
// TODO: find a better flag for this
// verify if appcache-local sync needs to be done
// TODO: find a better flag for this?
return appcache_storage.get(sync_flag)
.push(undefined, function (error) {
return appcache_storage.repair()
......@@ -159,10 +187,8 @@
var urlParams = new URLSearchParams(parser.search);
id = urlParams.get("relative_url");
if (id === null) { id = configuration_ids_dict["" + i]; }
//TODO: remember that the content is the pure hateoas dict returned by the script
// it should be processed in order to save a json document that allows allDocs queries
// without nested levels like _embedded, _view, etc
promise_list.push(appcache_storage.put(id, content_list[i]));
var content = processHateoasDict(content_list[i]);
promise_list.push(appcache_storage.put(id, content));
}
return RSVP.all(promise_list);
})
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.31702.6932.56797</string> </value>
<value> <string>974.38585.37530.16384</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1553112587.71</float>
<float>1553525541.12</float>
<string>UTC</string>
</tuple>
</state>
......
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