Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
erp5
Commits
0028c318
Commit
0028c318
authored
May 20, 2016
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_officejs: serviceworker download only new changed files
parent
22add6fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
41 deletions
+90
-41
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_serviceworker_js.js
...eItem/web_page_module/gadget_officejs_serviceworker_js.js
+88
-39
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_serviceworker_js.xml
...Item/web_page_module/gadget_officejs_serviceworker_js.xml
+2
-2
No files found.
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_serviceworker_js.js
View file @
0028c318
/*jslint indent: 2*/
/*global self, caches, importScripts, fetch, Promise, Request, Response, jIO, console*/
/*global self, caches, importScripts, fetch, Promise, Request, Response, jIO, console
, Headers
*/
var
global
=
self
,
window
=
self
;
(
function
(
self
,
caches
,
fetch
)
{
...
...
@@ -12,10 +12,14 @@ var global = self,
importScripts
(
'
rsvp.js
'
,
'
jiodev.js
'
);
Response
.
prototype
.
metadata
=
function
()
{
var
headers
=
{};
Array
.
from
(
this
.
headers
.
entries
()).
forEach
(
function
(
data
)
{
headers
[
data
[
0
]]
=
data
[
1
];
});
return
{
//'ok': this.ok
url
:
this
.
url
,
headers
:
Array
.
from
(
this
.
headers
.
entries
())
headers
:
headers
};
};
...
...
@@ -41,47 +45,93 @@ var global = self,
// debugger;
// Perform install step: loading each required file into cache
// create a new jio
var
requests
=
self
.
CACHE_REQUIRED_FILES
.
map
(
function
(
file_name
)
{
return
new
Request
(
file_name
);
});
// TODO:
// delete from cache not existing in self.CACHE_REQUIRED_FILES files.
var
result_fetch
=
Promise
.
resolve
(),
// queue for fetching files
result_jio_save
=
Promise
.
resolve
();
// queue for save files
// in end service mark as installed
event
.
waitUntil
(
Promise
.
all
(
requests
.
map
(
function
(
request
)
{
return
fetch
(
request
).
then
(
function
(
response
)
{
return
response
.
metadata_w_blob
();
});
}))
.
then
(
function
(
responses
)
{
return
Promise
.
all
(
responses
.
map
(
function
(
response
,
i
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
jio_key
=
requests
[
i
].
url
;
self
.
jio_cache_storage
.
put
(
jio_key
,
response
.
metadata
)
.
push
(
function
()
{
return
self
.
jio_cache_storage
.
putAttachment
(
jio_key
,
"
body
"
,
response
.
blob
)
.
push
(
function
()
{
console
.
log
(
'
jio_save:
'
+
jio_key
);
resolve
();
});
new
Promise
(
function
(
resolve
,
reject
)
{
self
.
CACHE_REQUIRED_FILES
.
map
(
function
(
url
,
i
)
{
var
request
=
new
Request
(
url
),
requests_len
=
self
.
CACHE_REQUIRED_FILES
.
length
-
1
,
jio_key
=
request
.
url
;
// files download one by one
result_fetch
=
result_fetch
.
then
(
function
()
{
return
new
Promise
(
function
(
resolve
)
{
self
.
jio_cache_storage
.
get
(
jio_key
)
.
push
(
function
(
metadata
)
{
resolve
(
metadata
);
})
.
push
(
undefined
,
function
(
error
)
{
console
.
log
(
error
);
reject
();
});
})
.
then
(
undefined
,
console
.
log
);
.
push
(
undefined
,
resolve
);
});
})
)
.
then
(
function
()
{
console
.
log
(
'
cache loaded
'
);
return
self
.
skipWaiting
();
})
.
then
(
undefined
,
console
.
log
);
.
then
(
function
(
metadata
)
{
if
(
metadata
.
url
!==
undefined
)
{
var
modification_mark_exist
=
false
;
if
(
metadata
.
headers
.
ETag
!==
undefined
)
{
modification_mark_exist
=
true
;
request
.
headers
.
append
(
'
If-None-Match
'
,
metadata
.
headers
.
Etag
);
}
else
if
(
metadata
.
headers
[
'
last-modified
'
]
!==
undefined
)
{
modification_mark_exist
=
true
;
request
.
headers
.
append
(
'
If-Modified-Since
'
,
metadata
.
headers
[
'
last-modified
'
]);
}
if
(
modification_mark_exist
)
return
fetch
(
request
)
.
then
(
undefined
,
function
()
{
// We say 'file not changed' if downloading is not possible with additional header
return
new
Response
(
null
,
{
status
:
304
});
});
}
return
fetch
(
request
);
})
.
then
(
function
(
response
)
{
if
(
response
.
status
===
304
)
{
if
(
i
===
requests_len
)
{
// latest file saved
result_jio_save
=
result_jio_save
.
then
(
resolve
);
}
return
Promise
.
resolve
();
}
else
{
return
response
.
metadata_w_blob
()
.
then
(
function
(
response
)
{
// files save one by one
result_jio_save
=
result_jio_save
.
then
(
function
()
{
return
new
Promise
(
function
(
resolve
)
{
self
.
jio_cache_storage
.
put
(
jio_key
,
response
.
metadata
)
.
push
(
function
()
{
return
self
.
jio_cache_storage
.
putAttachment
(
jio_key
,
"
body
"
,
response
.
blob
)
.
push
(
function
()
{
console
.
log
(
'
jio_save:
'
+
jio_key
);
resolve
();
});
})
.
push
(
undefined
,
function
(
error
)
{
console
.
log
(
error
);
reject
();
});
});
});
if
(
i
===
requests_len
)
{
// latest file saved
result_jio_save
=
result_jio_save
.
then
(
resolve
);
}
return
Promise
.
resolve
();
});
}
});
});
})
.
then
(
function
()
{
console
.
log
(
'
cache loaded
'
);
return
self
.
skipWaiting
();
})
.
then
(
undefined
,
console
.
log
)
);
};
...
...
@@ -92,7 +142,6 @@ var global = self,
.
push
(
function
(
metadata
)
{
return
self
.
jio_cache_storage
.
getAttachment
(
jio_key
,
'
body
'
)
.
push
(
function
(
body
)
{
//console.log(metadata.url + ' return from jio');
resolve
(
new
Response
(
body
,
{
'
headers
'
:
metadata
.
headers
}));
});
})
...
...
bt5/erp5_officejs/PathTemplateItem/web_page_module/gadget_officejs_serviceworker_js.xml
View file @
0028c318
...
...
@@ -230,7 +230,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
951.
9272.8708.15735
</string>
</value>
<value>
<string>
951.
20619.45573.30156
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>
1463
082861.33
</float>
<float>
1463
735862.94
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment