Commit c4374508 authored by Roque's avatar Roque

WIP: erp5_officejs: replicate appcache content into local storage

parent 52afccee
......@@ -78,6 +78,7 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
......@@ -90,47 +91,16 @@
/////////////////////////////////////////////////////////////////
.declareMethod("getFormDefinition", function (jio_key) {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('hateoas_url'),
gadget.getSetting('default_view_reference'),
gadget.jio_get(jio_key)
]);
})
.push(function (setting_list) {
var jio_options_remote = {
type: "erp5",
url: setting_list[0],
default_view_reference: setting_list[1]
},
jio_options_localIndexdb = {
type: "query",
sub_storage: {
type: "indexeddb",
database: "officejs-forms"
}
},
jio_storage_remote,
jio_indexdb_local = jIO.createJIO(jio_options_localIndexdb),
form_path = 'portal_skins/erp5_officejs_jio_connector/' +
setting_list[2].portal_type.replace(/ /g, '') +
'_viewAsJio';
return jio_indexdb_local.get(form_path)
.push(function (result) {
return result.form_definition;
}, function (error) {
if ((error.constructor.name === 'jIOError' && error.status_code === 404)) {
jio_storage_remote = jIO.createJIO(jio_options_remote);
return jio_storage_remote.get(form_path)
.push(function (result) {
jio_indexdb_local.put(form_path, result);
return result.form_definition;
});
}
throw error;
});
//TODO parameter will be a 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"})
.push(function (result) {
return result._embedded._view.my_form_definition["default"];
});
})
......@@ -203,8 +173,8 @@
var gadget = this,
child_gadget_url;
return gadget.jio_get(options.jio_key)
.push(function (result) {
if (result.portal_type !== undefined) {
.push(function (document) {
if (document.portal_type !== undefined) {
/*child_gadget_url = 'gadget_officejs_jio_' +
result.portal_type.replace(/ /g, '_').toLowerCase() +
'_view.html';*/
......@@ -213,11 +183,12 @@
} else {
throw new Error('Can not display document: ' + options.jio_key);
}
//TODO pass document.portal_type as parameter
return gadget.getFormDefinition(options.jio_key)
.push(function (form_definition) {
return gadget.changeState({
jio_key: options.jio_key,
doc: result,
doc: document,
child_gadget_url: child_gadget_url,
form_definition: form_definition,
editable: options.editable,
......
......@@ -225,7 +225,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.18933.22256.43059</string> </value>
<value> <string>974.22676.24081.12953</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -243,7 +243,7 @@
</tuple>
<state>
<tuple>
<float>1552346315.67</float>
<float>1552570936.02</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -74,21 +74,41 @@
.declareAcquiredMethod('getUrlFor', 'getUrlFor')
.declareMethod('createJio', function (jio_options) {
var gadget = this;
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
jio_appchache_options = {
type: "replicate",
parallel_operation_attachment_amount: 10,
parallel_operation_amount: 1,
conflict_handling: 2,
signature_hash_key: 'hash',
check_remote_attachment_modification: true,
check_remote_attachment_creation: true,
check_remote_attachment_deletion: true,
check_remote_deletion: true,
check_local_creation: false,
check_local_deletion: false,
check_local_modification: false,
signature_sub_storage: {
type: "query",
sub_storage: {
type: "indexeddb",
database: "officejs-hash"
}
},
local_sub_storage: {},
remote_sub_storage: {
type: "appcache",
manifest: "gadget_officejs_discussion_tool.appcache",
version: "app/",
take_installer: false
}
}, appcache_storage;
if (jio_options === undefined) {
return;
}
// adding a layer to replicate appcache content into jio data storage
jio_options = {
type: "replicate",
local_sub_storage: jio_options,
remote_sub_storage: {
type: "appcache",
manifest: "gadget_officejs_discussion_tool.appcache",
version: "app/",
take_installer: true
}
};
jio_appchache_options.local_sub_storage = JSON.parse(JSON.stringify(jio_options));
jio_options = {
type: 'dateupdater',
sub_storage: jio_options,
......@@ -96,13 +116,26 @@
};
try {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
appcache_storage = jIO.createJIO(jio_appchache_options);
} catch (error) {
this.state_parameter_dict.jio_storage = undefined;
appcache_storage = undefined;
}
return this.getSetting("jio_storage_name")
.push(function (jio_storage_name) {
gadget.state_parameter_dict.jio_storage.repair();
gadget.state_parameter_dict.jio_storage_name = 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")
.push(undefined, function (error) {
return appcache_storage.repair()
.push(function () {
return appcache_storage.put("appcache-stored", {})
.push(undefined);
}, function (error) {
console.log("Error while appcache-local storage synchronization");
console.log(error);
});
});
});
})
.declareMethod('allDocs', function () {
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>974.20177.56471.24439</string> </value>
<value> <string>974.22673.21626.15445</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1552422100.12</float>
<float>1552571020.07</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