Commit d9220ced authored by Roque's avatar Roque

erp5_officejs: fix sync on every page reload

parent e5f90f35
...@@ -90,7 +90,9 @@ ...@@ -90,7 +90,9 @@
.declareAcquiredMethod("setSetting", "setSetting") .declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod('getUrlFor', 'getUrlFor') .declareAcquiredMethod('getUrlFor', 'getUrlFor')
.declareMethod('clean', function (appcache_storage, origin_url) { .declareMethod('updateConfiguration', function (appcache_storage, origin_url,
migration_version, current_version,
storage_name) {
if (!appcache_storage) { return; } if (!appcache_storage) { return; }
var gadget = this, var gadget = this,
document_id_list = [origin_url, document_id_list = [origin_url,
...@@ -108,26 +110,25 @@ ...@@ -108,26 +110,25 @@
"portal_types/Web Page Module/text_editor_view", "portal_types/Web Page Module/text_editor_view",
"portal_types/Web Page/text_editor_clone"], "portal_types/Web Page/text_editor_clone"],
promise_list = [], promise_list = [],
i = 0, i = 0;
current_version, if (migration_version !== current_version) {
index; //clean storage if app version changed
current_version = window.location.href.replace(window.location.hash, ""); for (i = 0; i < document_id_list.length; i += 1) {
index = current_version.indexOf(window.location.host) + window.location.host.length; promise_list = [safeJioRemove(appcache_storage, document_id_list[i])];
current_version = current_version.substr(index); }
return gadget.getSetting("migration_version") }
.push(function (migration_version) { return RSVP.Queue()
if (migration_version !== current_version) { .push(function () {
for (i = 0; i < document_id_list.length; i += 1) { return RSVP.all(promise_list);
promise_list = [safeJioRemove(appcache_storage, document_id_list[i])];
}
return RSVP.all(promise_list);
}
}) })
.push(function () { .push(function () {
return gadget.setSetting("migration_version", current_version); return gadget.setSetting("migration_version", current_version);
}) })
.push(function () { .push(function () {
return current_version; return gadget.setSetting("previous_storage_name", storage_name);
})
.push(function () {
return appcache_storage.repair(current_version);
}); });
}) })
...@@ -135,15 +136,25 @@ ...@@ -135,15 +136,25 @@
if (jio_options === undefined) { return; } if (jio_options === undefined) { return; }
var gadget = this, var gadget = this,
appcache_storage, appcache_storage,
current_version,
migration_version,
selected_storage_name,
previous_storage_name,
index,
origin_url = window.location.href; origin_url = window.location.href;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
gadget.getSetting('configuration_manifest'), gadget.getSetting('configuration_manifest'),
gadget.getSetting('jio_storage_name') gadget.getSetting('jio_storage_name'),
gadget.getSetting('previous_storage_name'),
gadget.getSetting('migration_version')
]); ]);
}) })
.push(function (result_list) { .push(function (result_list) {
selected_storage_name = result_list[1];
previous_storage_name = result_list[2];
migration_version = result_list[3];
var jio_appchache_options = { var jio_appchache_options = {
type: "replicate", type: "replicate",
parallel_operation_attachment_amount: 10, parallel_operation_attachment_amount: 10,
...@@ -161,7 +172,7 @@ ...@@ -161,7 +172,7 @@
type: "query", type: "query",
sub_storage: { sub_storage: {
type: "indexeddb", type: "indexeddb",
database: result_list[1] + "-configuration-hash" database: selected_storage_name + "-configuration-hash"
} }
}, },
local_sub_storage: JSON.parse(JSON.stringify(jio_options)), local_sub_storage: JSON.parse(JSON.stringify(jio_options)),
...@@ -191,17 +202,16 @@ ...@@ -191,17 +202,16 @@
gadget.state_parameter_dict.jio_storage = undefined; gadget.state_parameter_dict.jio_storage = undefined;
} }
if (result_list[0] === undefined) { return; } if (result_list[0] === undefined) { return; }
if (result_list[1] === undefined) { return; } if (selected_storage_name === undefined) { return; }
gadget.state_parameter_dict.jio_storage_name = result_list[1]; gadget.state_parameter_dict.jio_storage_name = selected_storage_name;
appcache_storage = jIO.createJIO(jio_appchache_options); appcache_storage = jIO.createJIO(jio_appchache_options);
}) current_version = window.location.href.replace(window.location.hash, "");
.push(function () { index = current_version.indexOf(window.location.host) + window.location.host.length;
return gadget.clean(appcache_storage, origin_url); current_version = current_version.substr(index);
}) if (migration_version !== current_version ||
.push(function (current_version) { previous_storage_name !== selected_storage_name) {
if (appcache_storage) { return gadget.updateConfiguration(appcache_storage, origin_url, migration_version,
//if the app version has changed, force configuration storage sync current_version, selected_storage_name);
return appcache_storage.repair(current_version);
} }
}) })
.push(undefined, function (error) { .push(undefined, function (error) {
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.21248.62721.2184</string> </value> <value> <string>978.63040.35215.11502</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>1568041535.95</float> <float>1570462130.45</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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