Commit f5626fdd authored by Romain Courteaud's avatar Romain Courteaud

erp5_web_renderjs_ui: embed the dependency list in the worker code

Global are deleted when the worker is stopped, which make the current fetch code less interesting...
parent 37640816
/*jslint indent: 2*/
/*global self, caches, fetch, Promise, URL, location*/
(function (self, caches, fetch, Promise, URL, location) {
/*global self, caches, fetch, Promise, URL, location, JSON*/
(function (self, caches, fetch, Promise, URL, location, JSON) {
"use strict";
var prefix = location.toString() + '_',
CACHE_NAME = prefix + '${modification_date}',
required_url_list = [];
REQUIRED_FILES = JSON.parse('${required_url_list}'),
required_url_list = [],
i,
len = REQUIRED_FILES.length;
for (i = 0; i < len; i += 1) {
required_url_list.push(
new URL(REQUIRED_FILES[i], location.toString()).toString()
);
}
self.addEventListener('install', function (event) {
// Perform install step: loading each required file into cache
event.waitUntil(
fetch('WebSection_getPrecacheManifest')
.then(function (response) {
return Promise.all([
response.json(),
caches.open(CACHE_NAME)
]);
})
.then(function (result_list) {
var required_file_dict = result_list[0],
cache = result_list[1],
key,
promise = Promise.resolve(),
url;
.then(function (cache) {
var promise = Promise.resolve();
function append(url) {
function append(url_to_cache) {
promise = promise
.then(function () {
// Use cache.add because safari does not support cache.addAll.
return cache.add(url);
return cache.add(url_to_cache);
});
}
for (key in required_file_dict) {
if (required_file_dict.hasOwnProperty(key)) {
url = new URL(key, location.toString()).toString();
len = required_url_list.length;
for (i = 0; i < len; i += 1) {
// Add all offline dependencies to the cache
// One by one, to not hammer zopes
required_url_list.push(url);
append(url);
}
append(required_url_list[i]);
}
return promise;
})
......@@ -128,4 +124,4 @@
);
});
}(self, caches, fetch, Promise, URL, location));
\ No newline at end of file
}(self, caches, fetch, Promise, URL, location, JSON));
\ No newline at end of file
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>981.49192.3036.63283</string> </value>
<value> <string>981.49307.35014.63180</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1581341953.03</float>
<float>1581348269.23</float>
<string>UTC</string>
</tuple>
</state>
......
from DateTime import DateTime
import json
if REQUEST is None:
REQUEST = context.REQUEST
......@@ -28,8 +29,11 @@ web_content = web_page.getTextContent()
# set headers depending on type of script
if (portal_type == "Web Script"):
response.setHeader('Content-Type', 'application/javascript; charset=utf-8')
if web_page.getTextContentSubstitutionMappingMethodId():
web_content = web_page.TextDocument_substituteTextContent(web_content, mapping_dict={
'modification_date': modification_date_string
'modification_date': modification_date_string,
# Make JSLint happy for the service worker code
'required_url_list': json.dumps(web_section.WebSection_getPrecacheManifest())
})
elif (portal_type == "Web Style"):
......
import json
if REQUEST is None:
REQUEST = context.REQUEST
if response is None:
response = REQUEST.RESPONSE
web_section = context
# Add all ERP5JS gadget
......@@ -180,6 +173,4 @@ precache_manifest_url_list = web_section.getLayoutProperty("configuration_precac
for precache_manifest_script_id in precache_manifest_url_list:
url_list.extend(web_section.restrictedTraverse(precache_manifest_script_id)())
result = json.dumps(dict.fromkeys(url_list, None), indent=2)
response.setHeader('Content-Type', 'application/json')
return result
return url_list
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None</string> </value>
<value> <string></string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
......
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