Set serviceWorker to allow offline usage

Close #15, close #14
This commit is contained in:
Joshua Ramon Enslin 2022-11-07 03:55:07 +01:00
parent 3e4554f759
commit 326af61836
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
10 changed files with 172 additions and 29 deletions

View File

@ -36,7 +36,7 @@ body { margin: 2em; background: var(--color-bg-normal);
a { text-decoration: none; color: inherit; }
h1 { display: block; max-width: 600px; margin: 0 auto 1.5em auto; }
h1 { display: block; max-width: 600px; margin: 0 auto 1.5em auto; line-height: 1.2em; }
h1 > * { display: inline-block; vertical-align: middle; color: var(--color-fg-less); }
h1 img { height: 2em; margin-right: .5em; border-radius: .1em; opacity: .7; transition: opacity .4s; }
h1 img:hover { opacity: 1; }
@ -106,13 +106,13 @@ ul.fieldList > li:hover { background: var(--color-bg-normal); border-color: var(
ul.fieldList > li.requiredField:before { display: inline-block; content: " \002612 "; margin-right: .5em; }
ul.fieldList > li.humanTLToggled { border-color: var(--color-accent-hover); background: var(--color-accent-hover); box-shadow: 0 8px 6px -6px black; }
.options > a.buttonLike { display: inline-block; width: auto;
.options > .buttonLike { display: inline-block; width: auto;
margin: .15em 0; padding: .4em .5em;
text-transform: inherit; cursor: pointer;
background: initial; border: 2px solid var(--color-borders);
opacity: 1;
transition: background .4s, opacity .4s; }
.options > a.buttonLike:hover { background: var(--color-borders); }
.options > .buttonLike:hover { background: var(--color-borders); }
.actionList { margin: 1em 0 1em 1em; padding: .5em 0; }
.actionList > li a { display: inline-block; padding: .3em; border-radius: .3em; transition: background .4s; }
@ -135,6 +135,11 @@ ul.fieldList > li.humanTLToggled { border-color: var(--color-accent-hover); back
to { transform: rotate(360deg); }
}
@media screen and (max-width: 75em) {
body { font-size: 1.08em; }
h1 img { display: none; }
}
/* =============
| Dark mode
|============ */

View File

@ -2,7 +2,7 @@
@font-face{font-family:sourceSansPro;src:local('Source-Sans-Pro'),local('Source Sans Pro'),url(../fonts/SourceSansPro-Regular.woff2)format('woff2'),url(../fonts/SourceSansPro-Regular.ttf)format('truetype');font-display:swap}*{box-sizing:border-box;z-index:1}
body{margin:2em;background:var(--color-bg-normal);font-family:sourceSansPro,Arial,Helvetica,Times;font-size:1.2em;line-height:1.5em}
a{text-decoration:none;color:inherit}
h1{display:block;max-width:600px;margin:0 auto 1.5em auto}
h1{display:block;max-width:600px;margin:0 auto 1.5em auto;line-height:1.2em}
h1>*{display:inline-block;vertical-align:middle;color:var(--color-fg-less)}
h1 img{height:2em;margin-right:.5em;border-radius:.1em;opacity:.7;transition:opacity.4s}
h1 img:hover{opacity:1}
@ -27,9 +27,11 @@ ul.fieldList{display:block;margin:.5em 0;padding:0 0;list-style:none}
ul.fieldList>li{display:inline-block;padding:.3em;margin:.1em;border:1px solid var(--color-borders);background:var(--color-bg-raised2);cursor:pointer;transition:background.4s,border.4s,box-shadow.4s}
ul.fieldList>li:hover{background:var(--color-bg-normal);border-color:var(--color-fg-less)}
ul.fieldList>li.requiredField:before{display:inline-block;content:" \002612 ";margin-right:.5em}
ul.fieldList>li.humanTLToggled{border-color:var(--color-accent-hover);background:var(--color-accent-hover);box-shadow:0 8px 6px-6px black}.options>a.buttonLike{display:inline-block;width:auto;margin:.15em 0;padding:.4em.5em;text-transform:inherit;cursor:pointer;background:initial;border:2px solid var(--color-borders);opacity:1;transition:background.4s,opacity.4s}.options>a.buttonLike:hover{background:var(--color-borders)}.actionList{margin:1em 0 1em 1em;padding:.5em 0}.actionList>li a{display:inline-block;padding:.3em;border-radius:.3em;transition:background.4s}.actionList>li a:hover{background:var(--color-accent-hover)}.loading:before,.loading:after{content:" ";display:block;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);height:64px;width:64px;margin:0;padding:0;border-radius:50%;border:8px solid var(--color-accent-hover);border-color:var(--color-accent-hover)transparent transparent transparent;z-index:100;animation:rotating 1.2s cubic-bezier(0.5,0,0.5,1)infinite;animation-delay:-0.15s}.loading:after{animation-delay:-0.45s}
ul.fieldList>li.humanTLToggled{border-color:var(--color-accent-hover);background:var(--color-accent-hover);box-shadow:0 8px 6px-6px black}.options>.buttonLike{display:inline-block;width:auto;margin:.15em 0;padding:.4em.5em;text-transform:inherit;cursor:pointer;background:initial;border:2px solid var(--color-borders);opacity:1;transition:background.4s,opacity.4s}.options>.buttonLike:hover{background:var(--color-borders)}.actionList{margin:1em 0 1em 1em;padding:.5em 0}.actionList>li a{display:inline-block;padding:.3em;border-radius:.3em;transition:background.4s}.actionList>li a:hover{background:var(--color-accent-hover)}.loading:before,.loading:after{content:" ";display:block;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);height:64px;width:64px;margin:0;padding:0;border-radius:50%;border:8px solid var(--color-accent-hover);border-color:var(--color-accent-hover)transparent transparent transparent;z-index:100;animation:rotating 1.2s cubic-bezier(0.5,0,0.5,1)infinite;animation-delay:-0.15s}.loading:after{animation-delay:-0.45s}
@keyframes rotating{from{transform:rotate(0deg)}
to{transform:rotate(360deg)}}
@media screen and(max-width:75em){body{font-size:1.08em}
h1 img{display:none}}
@media(prefers-color-scheme:dark){body{background:#263238;color:#ECEFF1}
input,select,textarea{background:inherit;color:inherit;border:3px solid #37474F;transition:border.4s,box-shadow.4s}
a.buttonLike:focus,.options>a.buttonLike:focus,button:focus,select:focus,textarea:focus,input:focus,textarea:active,input:active,a.buttonLike:hover,.options>a.buttonLike:hover,ul.fieldList>li:hover,button:hover,select:hover,textarea:hover,input:hover{background:inherit;border-color:#FFF;box-shadow:initial;border-radius:.2em}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -1,5 +1,10 @@
"use strict";
if ('serviceWorker' in navigator) {
console.log("Registering service worker");
navigator.serviceWorker.register('/sw.js');
}
class CsvxmlValidator {
fieldList; // {}{}
@ -625,6 +630,7 @@ class CsvxmlPage {
const input = document.createElement("input");
input.type = "file";
input.id = "fileToUpload";
input.setAttribute("tabindex", "1");
input.accept = ".csv";
input.required = "required";
input.addEventListener('change', async function() {
@ -703,8 +709,9 @@ class CsvxmlPage {
function genButton(id, text, link = "") {
const output = document.createElement("a");
const output = document.createElement("span");
output.id = id;
output.setAttribute("tabindex", "1");
output.textContent = text;
output.classList.add("buttonLike");
if (link !== "") output.href = link;
@ -719,7 +726,8 @@ class CsvxmlPage {
const dlAllButton = genButton("dlAll", this.tls.download_csv_all);
dlAllButton.cursor = "pointer";
dlAllButton.addEventListener('click', function() {
dlAllButton.addEventListener('click', function(e) {
e.preventDefault();
app.generateCsv();
});
options.appendChild(dlAllButton);
@ -739,6 +747,7 @@ class CsvxmlPage {
options.appendChild(this.unsetSelectionButton);
this.csvBySelectionButton.addEventListener('click', function(e) {
e.preventDefault();
let selected = document.getElementsByClassName("humanTLToggled");
let selectedFields = [];
@ -750,6 +759,7 @@ class CsvxmlPage {
});
optionSelectRequired.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("requiredField") === false) return;
@ -763,6 +773,7 @@ class CsvxmlPage {
});
optionSelectAll.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("humanTLToggled") === true) return;
@ -775,6 +786,7 @@ class CsvxmlPage {
});
this.unsetSelectionButton.addEventListener('click', function(e) {
e.preventDefault();
app.doForFieldList(function(field) {
if (field.classList.contains("humanTLToggled") === false) return;
@ -893,6 +905,7 @@ class CsvxmlPage {
}
const lang = getLang();
document.documentElement.setAttribute("lang", lang);
document.body.classList.add("loading");

View File

@ -1,4 +1,5 @@
"use strict";class CsvxmlValidator{fieldList;toValidate;errors;constructor(fieldList,csvRaw){this.errors={parsing:[],mandatoryTags:[],duplicateInvNos:[],dependentColumns:[],controlledLists:[],mainImageResource:[],};this.fieldList=Object.freeze(fieldList);const lines=csvRaw.trim().replace("\r\n","\n").split("\n");let separator;let delimiter;if(csvRaw.substr(0,1)==='"'){separator='";"';delimiter='"'}else{separator=';';delimiter=''}
"use strict";if('serviceWorker' in navigator){console.log("Registering service worker");navigator.serviceWorker.register('/sw.js')}
class CsvxmlValidator{fieldList;toValidate;errors;constructor(fieldList,csvRaw){this.errors={parsing:[],mandatoryTags:[],duplicateInvNos:[],dependentColumns:[],controlledLists:[],mainImageResource:[],};this.fieldList=Object.freeze(fieldList);const lines=csvRaw.trim().replace("\r\n","\n").split("\n");let separator;let delimiter;if(csvRaw.substr(0,1)==='"'){separator='";"';delimiter='"'}else{separator=';';delimiter=''}
let headersFields=lines.shift();let headers;if(delimiter==="")headers=headersFields.split(separator);else headers=headersFields.substr(1,headersFields.length-2).split(separator);let expectedFieldCount=headers.length;let toValidate=[];let lineCounter=1;for(let line of lines){if(delimiter!==''){line=line.substr(1,line.length-2)}
if(line.length<=headers.length)continue;let lineContents={};let fields=line.split(separator);if(fields.length!==headers.length){this.errors.parsing.push("Number of columns in line "+lineCounter+" does not match number of headers")}
for(let i=0,max=fields.length;i<max;i++){if(headers[i]===undefined||headers[i]===null){this.errors.parsing.push("ERROR parsing line "+lineCounter+"; column "+i);continue}
@ -47,13 +48,13 @@ ulHl.addEventListener('click',function(){ul.classList.toggle("minimized")});domE
dialogueContent.appendChild(domErrorsSection);const domDlSection=document.createElement("div");const domDlA=document.createElement("span");domDlA.textContent=this.tls.download;domDlA.classList.add("buttonLike");let app=this;domDlA.addEventListener('click',function(){app.zipUploadToXml(validator)});domDlSection.appendChild(domDlA);dialogueContent.appendChild(domDlSection);dialogue=CsvxmlDialogue.drawDialogue(dialogueContent)}
uploadFileForValidation(file){const reader=new FileReader();reader.readAsText(file);let app=this;reader.onload=function(){console.log("Read file");let validator=new CsvxmlValidator(app.fieldListFlat,reader.result);if(validator.isValid()===!0){alert("Document is valid. Press ok to download.");app.zipUploadToXml(validator)}else{app.listValidationErrors(validator)}};reader.onerror=function(){alert(reader.error)}}
renderHeader(){const header=document.createElement("header");const h1=document.createElement("h1");const img=document.createElement("img");img.width="70";img.height="70";img.src="assets/img/mdlogo-csvxml.svg";img.alt="";h1.appendChild(img);const h1Span=document.createElement("span");h1Span.textContent="museum-digital:csvxml";h1.appendChild(h1Span);header.appendChild(h1);document.body.appendChild(header)}
renderUploader(){let app=this;(async function(){const form=document.createElement("form");const label=document.createElement("label");label.textContent=app.tls.select_csv_file_for_upload;label.setAttribute("for","fileToUpload");form.appendChild(label);const input=document.createElement("input");input.type="file";input.id="fileToUpload";input.accept=".csv";input.required="required";input.addEventListener('change',async function(){app.uploadFileForValidation(input.files[0])});form.appendChild(input);app.domUploaderWrapper.appendChild(form)})();document.body.appendChild(this.domUploaderWrapper)}
renderUploader(){let app=this;(async function(){const form=document.createElement("form");const label=document.createElement("label");label.textContent=app.tls.select_csv_file_for_upload;label.setAttribute("for","fileToUpload");form.appendChild(label);const input=document.createElement("input");input.type="file";input.id="fileToUpload";input.setAttribute("tabindex","1");input.accept=".csv";input.required="required";input.addEventListener('change',async function(){app.uploadFileForValidation(input.files[0])});form.appendChild(input);app.domUploaderWrapper.appendChild(form)})();document.body.appendChild(this.domUploaderWrapper)}
doForFieldList(callback){let fieldLists=document.getElementsByClassName("fieldList");for(let i=0,max=fieldLists.length;i<max;i++){let fields=fieldLists[i].getElementsByTagName("li");for(let j=0,maxj=fields.length;j<maxj;j++){callback(fields[j])}}}
toggleListFieldSelectionState(field){let app=this;let newValue=field.getAttribute("data-alt");field.setAttribute("data-alt",field.textContent);field.textContent=newValue;field.classList.toggle("humanTLToggled");if(field.classList.contains("humanTLToggled")===!1)return;let dependencies=this.fieldListFlat[field.id].dependsOn;if(dependencies!==undefined&&dependencies!==null){let linkedFields=this.fieldListFlat[field.id].dependsOn;for(let i=0,max=linkedFields.length;i<max;i++){let linkedField=document.getElementById(linkedFields[i]);if(linkedField.classList.contains("humanTLToggled")===!0)continue;this.toggleListFieldSelectionState(linkedField)}}}
checkCSVBySelectionAccessibility(){let selected=document.getElementsByClassName("humanTLToggled");if(selected.length===0){this.csvBySelectionButton.classList.add("invisible");this.unsetSelectionButton.classList.add("invisible")}else{this.csvBySelectionButton.classList.remove("invisible");this.unsetSelectionButton.classList.remove("invisible")}}
getOptionsSection(){function genButton(id,text,link=""){const output=document.createElement("a");output.id=id;output.textContent=text;output.classList.add("buttonLike");if(link!=="")output.href=link;return output}
const options=document.createElement("div");options.classList.add("options");const app=this;const dlAllButton=genButton("dlAll",this.tls.download_csv_all);dlAllButton.cursor="pointer";dlAllButton.addEventListener('click',function(){app.generateCsv()});options.appendChild(dlAllButton);this.csvBySelectionButton=genButton("csvBySelection",this.tls.download_csv_by_selection);this.csvBySelectionButton.classList.add("invisible");options.appendChild(this.csvBySelectionButton);const optionSelectRequired=genButton("selectRequired",this.tls.select_required_fields);options.appendChild(optionSelectRequired);const optionSelectAll=genButton("selectAll",this.tls.select_all_fields);options.appendChild(optionSelectAll);this.unsetSelectionButton=genButton("unsetSelection",this.tls.unset_selection);this.unsetSelectionButton.classList.add("invisible");options.appendChild(this.unsetSelectionButton);this.csvBySelectionButton.addEventListener('click',function(e){let selected=document.getElementsByClassName("humanTLToggled");let selectedFields=[];for(let i=0,max=selected.length;i<max;i++){selectedFields+=selected[i].getAttribute("data-value")}
app.generateCsv(selectedFields)});optionSelectRequired.addEventListener('click',function(e){app.doForFieldList(function(field){if(field.classList.contains("requiredField")===!1)return;if(field.classList.contains("humanTLToggled")===!0)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});optionSelectAll.addEventListener('click',function(e){app.doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!0)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});this.unsetSelectionButton.addEventListener('click',function(e){app.doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!1)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});return options}
getOptionsSection(){function genButton(id,text,link=""){const output=document.createElement("span");output.id=id;output.setAttribute("tabindex","1");output.textContent=text;output.classList.add("buttonLike");if(link!=="")output.href=link;return output}
const options=document.createElement("div");options.classList.add("options");const app=this;const dlAllButton=genButton("dlAll",this.tls.download_csv_all);dlAllButton.cursor="pointer";dlAllButton.addEventListener('click',function(e){e.preventDefault();app.generateCsv()});options.appendChild(dlAllButton);this.csvBySelectionButton=genButton("csvBySelection",this.tls.download_csv_by_selection);this.csvBySelectionButton.classList.add("invisible");options.appendChild(this.csvBySelectionButton);const optionSelectRequired=genButton("selectRequired",this.tls.select_required_fields);options.appendChild(optionSelectRequired);const optionSelectAll=genButton("selectAll",this.tls.select_all_fields);options.appendChild(optionSelectAll);this.unsetSelectionButton=genButton("unsetSelection",this.tls.unset_selection);this.unsetSelectionButton.classList.add("invisible");options.appendChild(this.unsetSelectionButton);this.csvBySelectionButton.addEventListener('click',function(e){e.preventDefault();let selected=document.getElementsByClassName("humanTLToggled");let selectedFields=[];for(let i=0,max=selected.length;i<max;i++){selectedFields+=selected[i].getAttribute("data-value")}
app.generateCsv(selectedFields)});optionSelectRequired.addEventListener('click',function(e){e.preventDefault();app.doForFieldList(function(field){if(field.classList.contains("requiredField")===!1)return;if(field.classList.contains("humanTLToggled")===!0)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});optionSelectAll.addEventListener('click',function(e){e.preventDefault();app.doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!0)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});this.unsetSelectionButton.addEventListener('click',function(e){e.preventDefault();app.doForFieldList(function(field){if(field.classList.contains("humanTLToggled")===!1)return;app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})});return options}
renderMain(){const domH2=document.createElement("h2");domH2.textContent=this.tls.currently_approved_tags;this.domMainWrapper.appendChild(domH2);this.domMainWrapper.appendChild(this.getOptionsSection());for(let sectionName in this.fieldList){const domDiv=document.createElement("div");const domH3=document.createElement("h3");domH3.textContent=sectionName;domDiv.appendChild(domH3);const domUl=document.createElement("ul");domUl.classList.add("fieldList");const sectionFields=this.fieldList[sectionName];for(let fieldName in sectionFields){const field=sectionFields[fieldName];const domLi=document.createElement("li");domLi.textContent=fieldName;domLi.id=fieldName;domLi.setAttribute("data-alt",field.name_human_readable)
domLi.setAttribute("data-value",fieldName)
if(field.required===!0)domLi.classList.add("requiredField");domUl.appendChild(domLi);const tooltipContent=document.createElement("div");const explicaP=document.createElement("p");explicaP.textContent=field.explica;tooltipContent.appendChild(explicaP);if(field.remarks!==undefined&&field.remarks!==''){const remarkHl=document.createElement("h4");remarkHl.textContent=this.tls.remarks;tooltipContent.appendChild(remarkHl)
@ -62,5 +63,5 @@ if(field.allowedValues!==undefined&&Object.values(field.allowedValues).length!==
CsvxmlTooltip.bindTooltipToElement(domLi,field.name_human_readable,tooltipContent)}
domDiv.appendChild(domUl);this.domMainWrapper.appendChild(domDiv)}
document.body.appendChild(this.domMainWrapper);let app=this;this.doForFieldList(function(field){field.addEventListener('click',function(e){app.toggleListFieldSelectionState(field);app.checkCSVBySelectionAccessibility()})})}}(async function(){function getLang(){const allowedLangs=document.documentElement.getAttribute("data-allowed-langs").split(',');if(navigator.language===undefined)return'en';const browserLang=navigator.language.toLowerCase().substr(0,2);console.log(browserLang);if(allowedLangs.includes(browserLang))return browserLang;else return'en'}
const lang=getLang();document.body.classList.add("loading");let loaded=0;let fieldList;let tls;function loadPage(){document.body.classList.remove("loading");const page=new CsvxmlPage(fieldList,tls);page.renderHeader();page.renderUploader();page.renderMain()}
const lang=getLang();document.documentElement.setAttribute("lang",lang);document.body.classList.add("loading");let loaded=0;let fieldList;let tls;function loadPage(){document.body.classList.remove("loading");const page=new CsvxmlPage(fieldList,tls);page.renderHeader();page.renderUploader();page.renderMain()}
window.fetch('/json/fields.'+lang+'.json',{method:'GET',cache:'no-cache',credentials:'same-origin',}).then(function(response){return response.json()}).then(function(elements){fieldList=elements;loaded++;if(loaded===2)loadPage();});window.fetch('/json/tls.'+lang+'.json',{method:'GET',cache:'no-cache',credentials:'same-origin',}).then(function(response){return response.json()}).then(function(elements){tls=elements;loaded++;if(loaded===2)loadPage();})})()

View File

@ -4,20 +4,30 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Validate import CSV files for museum-digital" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.css" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.min.css" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#aa4400" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />
<meta name="robots" content="noindex" />
<title>CSVXML :: museum-digital</title>
<meta name="twitter:title" content="CSVXML :: museum-digital" />
<meta property="og:title" content="CSVXML :: museum-digital" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@museumdigital" />
<meta name="description" content="Validate import CSV files for museum-digital" />
<meta name="keywords" content="Imports, museum-digital" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />
<link rel="apple-touch-icon" sizes="192x192" href="assets/img/mdlogo-csvxml.svg" />
<meta property="twitter:image" content="assets/img/mdlogo-csvxml.svg" />
<meta property="og:image" content="assets/img/mdlogo-csvxml.svg" />
</head>
<body class="loading">
<script src="assets/js/csvxmlV2.js" type="text/javascript" async></script>
<script src="assets/js/csvxmlV2.min.js" type="text/javascript" async></script>
</body>
</html>
</html>

19
public/manifest.json Normal file
View File

@ -0,0 +1,19 @@
{
"name": "csvxml :: museum-digital",
"short_name": "csvxml",
"start_url": "/",
"display": "standalone",
"background_color": "#F2F2F2",
"theme_color": "#aa4400",
"description": "Validate import CSV files for museum-digital.",
"icons": [{
"src": "assets/img/mdlogo-csvxml-1028x.png",
"sizes": "1028x1028",
"type": "image/png"
}, {
"src": "assets/img/mdlogo-csvxml.svg",
"sizes": "48x48 72x72 96x96 128x128 256x256 512x512",
"type": "image/svg+xml",
"purpose": "any maskable"
}]
}

88
public/sw.js Normal file
View File

@ -0,0 +1,88 @@
const debug = false;
const CACHE_NAME = 'csvxml-cache-v1';
const urlsToCache = [
'/index.htm',
'/assets/js/jszip/dist/jszip.min.js',
'/assets/js/csvxmlV2.min.js',
'/assets/css/csvxml.min.css',
'/assets/fonts/SourceSansPro-Regular.woff2',
'/json/fields.de.json',
'/json/fields.en.json',
'/json/fields.hu.json',
'/json/tls.de.json',
'/json/tls.en.json',
'/json/tls.hu.json',
];
self.addEventListener('install', function(event) {
// Perform install steps
event.waitUntil(
Promise.all([
caches.open(CACHE_NAME)
.then(function(cache) {
if (debug === true) console.log('Opened cache');
return cache.addAll(urlsToCache.map(url => new Request(url, {credentials: 'same-origin'})));
}),
])
);
});
self.addEventListener('fetch', function(event) {
if (event.request.url.startsWith(location.origin) === false) return;
event.respondWith(
caches.match(event.request)
.then(function(response) {
if (response) {
if (debug === true) console.log("Serving " + event.request.url + " from cache.");
return response;
}
// IMPORTANT: Clone the request. A request is a stream and
// can only be consumed once. Since we are consuming this
// once by cache and once by the browser for fetch, we need
// to clone the response.
var fetchRequest = event.request.clone();
return fetch(fetchRequest).then(
function(response) {
// Check if we received a valid response
if(!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
var responseToCache = response.clone();
caches.open(CACHE_NAME)
.then(function(cache) {
if (debug === true) console.log("Added " + event.request.url + "to cache");
cache.put(event.request, responseToCache);
});
return response;
}
).catch(
() => {
console.log("Problem");
if (event.request.url.indexOf("index.php?") == -1) return;
else {
console.log("Fixing");
return caches.open(CACHE_NAME).then(
function(cache) {
// cache.keys().then(function(keys) { console.log(keys); })
// return cache.match("index.php")
});
}
}
);
})
);
});

View File

@ -70,25 +70,30 @@ function generateAppShell():string {
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Validate import CSV files for museum-digital" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.css" />
<link rel="stylesheet" type="text/css" href="assets/css/csvxml.min.css" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#aa4400" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />
<meta name="robots" content="noindex" />
<title>CSVXML :: museum-digital</title>
<meta name="twitter:title" content="CSVXML :: museum-digital" />
<meta property="og:title" content="CSVXML :: museum-digital" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@museumdigital" />
<meta name="description" content="Validate import CSV files for museum-digital" />
<meta name="keywords" content="Imports, museum-digital" />
<link rel="shortcut icon" sizes="128x128" href="assets/img/mdlogo-csvxml.svg" />
<link rel="apple-touch-icon" sizes="192x192" href="assets/img/mdlogo-csvxml.svg" />
<meta property="twitter:image" content="assets/img/mdlogo-csvxml.svg" />
<meta property="og:image" content="assets/img/mdlogo-csvxml.svg" />
</head>
<body class="loading">
<h1>
<img src="assets/img/mdlogo-csvxml.svg" alt="" />
<span>museum-digital:csvxml</span>
</h1>
<script src="assets/js/csvxmlV2.js" type="text/javascript" async></script>
<script src="assets/js/csvxmlV2.min.js" type="text/javascript" async></script>
</body>
</html>';