Commit 5b748f4d authored by Roque's avatar Roque

erp5_officejs: replicate appcache content into local storage

- configurations like form definitions are saved as objects into data-storage.metadata to allow jio.get
parent cef90530
......@@ -78,7 +78,6 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
......@@ -90,15 +89,13 @@
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("getFormDefinition", function (jio_key) {
//TODO parameter will be a portal_type
.declareMethod("getFormDefinition", function (portal_type) {
var gadget = this,
// this urls will change to a more appropiate id like "portal_skins/couscous/MyPortalType_viewAsJio"
// and probably for a jio.get instead of getAttachment
// now it is like this due to the appcachestorage
url = "./app/hateoas/ERP5Document_getHateoas?mode=traverse&relative_url=portal_skins%2Ferp5_officejs_jio_connector%2FHTMLPost_viewAsJio&view=jio_view",
origin_url = "https://softinst112382.host.vifib.net/erp5/web_site_module/officejs_discussion_tool/app/#/?page=ojs_sync&auto_repair=true";
return gadget.jio_getAttachment(origin_url, url, {"format": "json"})
// TODO: how to generate this path? context? portal type definition?
form_path = 'portal_skins/erp5_officejs_jio_connector/' +
portal_type.replace(/ /g, '') +
'_viewAsJio';
return gadget.jio_get(form_path)
.push(function (result) {
return result._embedded._view.my_form_definition["default"];
});
......@@ -183,8 +180,7 @@
} else {
throw new Error('Can not display document: ' + options.jio_key);
}
//TODO pass document.portal_type as parameter
return gadget.getFormDefinition(options.jio_key)
return gadget.getFormDefinition(document.portal_type)
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.22676.24081.12953</string> </value>
<value> <string>974.24071.47465.41915</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1552570936.02</float>
<float>1552654639.85</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, FormData, UriTemplate */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, jIO) {
(function (window, rJS, jIO, RSVP, document, URLSearchParams) {
"use strict";
// jIO call wrapper for redirection to authentication page if needed
......@@ -75,8 +75,13 @@
.declareMethod('createJio', function (jio_options) {
var gadget = this,
// for now using appcachestorage to copy form json from appcache to local
// maybe it will be better to have a new storage
origin_url = window.location.protocol + "//" + window.location.hostname + window.location.pathname,
prefix = "./",
// TODO these values should come from gadget.props.cache_file/version -add script in html body
version = "app/",
manifest = "gadget_officejs_discussion_tool.configuration",
// TODO review this storage because is not necessary to save the attachments into data storage
// it should be enough with only the appcache (and a aux local storage) in order to get the attachments
jio_appchache_options = {
type: "replicate",
parallel_operation_attachment_amount: 10,
......@@ -100,11 +105,13 @@
local_sub_storage: {},
remote_sub_storage: {
type: "appcache",
manifest: "gadget_officejs_discussion_tool.configuration",
version: "app/",
take_installer: false
manifest: manifest,
version: version,
origin_url: origin_url
}
}, appcache_storage;
}, appcache_storage,
sync_flag = "appcache-stored",
configuration_ids_dict = {};
if (jio_options === undefined) {
return;
}
......@@ -125,16 +132,46 @@
.push(function (jio_storage_name) {
// check if appcache-local sync needs to be done
// TODO: find a better flag for this
return appcache_storage.get("appcache-stored")
return appcache_storage.get(sync_flag)
.push(undefined, function (error) {
return appcache_storage.repair()
.push(function () {
return appcache_storage.put("appcache-stored", {})
.push(undefined);
return appcache_storage.allAttachments(origin_url)
.push(function (attachment_dict) {
return new RSVP.Queue()
.push(function () {
var promise_list = [], i = 0,
ignore_urls = [prefix + "/", prefix + version, prefix + version + manifest];
for (var id in attachment_dict) {
if (ignore_urls.indexOf(id) < 0) {
promise_list.push(appcache_storage.getAttachment(origin_url, id, {"format": "json"}));
configuration_ids_dict["" + i] = id;
i += 1;
}
}
return RSVP.all(promise_list);
})
.push(function (content_list) {
var promise_list = [];
for (var i = 0; i < content_list.length; i += 1) {
var id = configuration_ids_dict["" + i],
parser = document.createElement('a');
parser.href = id;
var urlParams = new URLSearchParams(parser.search);
id = urlParams.get("relative_url");
promise_list.push(appcache_storage.put(id, content_list[i]));
}
return RSVP.all(promise_list);
})
.push(function () {
return appcache_storage.put(sync_flag, {})
.push(undefined);
});
});
}, function (error) {
console.log("Error while appcache-local storage synchronization");
console.log(error);
});
console.log("Error while appcache-local storage synchronization");
console.log(error);
});
});
});
})
......@@ -169,4 +206,4 @@
return wrapJioCall(this, 'repair', arguments);
});
}(window, rJS, jIO));
\ No newline at end of file
}(window, rJS, jIO, RSVP, document, URLSearchParams));
\ No newline at end of file
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.22753.27435.21418</string> </value>
<value> <string>974.24075.46226.21333</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1552575739.83</float>
<float>1552654807.29</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